akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define lo long long 
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 100005
using namespace std;
int n,A[205],cev;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++){
		scanf("%d",&A[i]);
	}
	sort(A+1,A+2*n+1);
	for(int i=1;i<=2*n;i+=2){
		cev+=A[i];
	}
	printf("%d\n",cev);
	return 0;
}


Measured memory_bytes: 256
// #include <bits/stdc++.h>

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int main(void){
  ios::sync_with_stdio(false);

  int h, n;
  cin >> h >> n;
  vector<int> a(n);
  REP(i, n) {cin >> a[i];}
  int res = 0;
  REP(i, n){res += a[i];}

  if (res >= h) cout << "Yes" << endl;
  else cout << "No" << endl;


  return 0;
}



Measured memory_bytes: 640
#include<iostream>
#include<vector>

int main(){
    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for(int i = 0; i < n; i++) std::cin >> a[i];

    int count = 0;
    while(1){
        bool check = true;

        for(int i = 0; i < n; i++){
            if(a[i] % 2 != 0){
                check = false;
                break;
            }
            a[i] /= 2;
        }

        if(check){
            count++;
        }
        else{
            break;
        }
    }

    std::cout << count << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>

using namespace std;  //このネームスペースを使う

int main(){
  int N ;
  int sum,log;
  cin >> N ;
  
  log = log10(N);

  switch(log){
  	case 0 :
  	  sum = N;
  	  break;
  	case 1 :
  	  sum = 9;
  	  break;
  	case 2 :
  	  sum = 9 + (N-99);
  	  break;
  	case 3 :
  	  sum = 909;
  	  break;
  	case 4 :
  	  sum = 9 + 900 + (N-9999);
  	  break;
  	case 5 :
  	  sum = 90909;
  	  break;
  	default :
  	  break;
  }
  cout << sum << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	int cnt=0;
	while(n){
		cnt++;
		n/=2;
	}
	cout << (1<<(cnt-1)) << endl;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;

    cout << (N - M - 1) << endl;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int read()
{
	int x=0,f=1;	char ch=getchar();
	while(ch<'0'||ch>'9')	{if(ch=='-')	f=-1;	ch=getchar();}
	while(ch>='0'&&ch<='9')	{x=(x<<3)+(x<<1)+(ch^48);	ch=getchar();}
	return x*f;
}
int n,m,t;
char s[4]={'R','Y','G','B'};
int main()
{
	n=read();	m=read();	t=read();
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j)
		{
			int x=(i+j+m)/t;	int y=(i-j+m)/t;
			printf("%c",s[((x&1)<<1)|(y&1)]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
  int N;
  cin>>N;
  int cnt=0;
  int previous = -1;
  while(N!=0){
    int d = N%10;
    if(d==previous)cnt++;
    else cnt=0;
    previous=d;
    if(cnt==2) {cout<<"Yes"<<endl;return 0;}
    N/=10;
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
ans = 0

if h*w%3 != 0:
    def div(x,y):
        res = float("inf")
        for i in range(1,x):
            r = x-i
            d1 = (i*y,(r//2)*y,((r+1)//2)*y)
            d2 = (i*y,r*(y//2),r*((y+1)//2))
            m = min(map(lambda x:max(x)-min(x),(d1,d2)))
            res = min(res,m)
        return res
    ans = min(div(h,w),div(w,h))

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
 
using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';
 
int main()
{
// #if ENVIRONMENT == LOCAL
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
// #endif
  int N = input();
 
  map<int, vector<pair<int,int>>> answer;
  for(int i=0;i<N;i++){
    int n = input();
    answer[i + 1] = {};
    for(int j=0;j<n;j++){
      int x = input();
      int y = input();
 
      answer[i + 1].push_back({x,y});
    }
  }
 
  int ret = 0;
  for(int bit=0;bit < (1<<N);bit++){
    bool isOK = true;
    for(auto iter:answer){
      bool isShojiki1 = bit & (1<<(iter.first - 1));
      if(!isShojiki1)continue;
 
      for(auto iter2:iter.second){
        bool isShojiki2 = bit & (1<<(iter2.first-1));
        int isShojiki3 = isShojiki2;
        bool isMatch = isShojiki2 == iter2.second;
        if(isShojiki1 != isMatch){
          isOK = false;
        }
      }
    }
    if(isOK){
      ret = max(ret, __builtin_popcount(bit));
    }
  }
  output(ret);
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
 
int N,D,A;
pair<ll,ll> P[202020];
ll DD[202020];
 
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>D>>A;
	FOR(i,N) {
		cin>>x>>y;
		P[i]={x,(y+A-1)/A};
	}
	sort(P,P+N);
	P[N]={1LL<<60,0};
	
	ll sum=0;
	FOR(i,N) {
		if(i) DD[i]+=DD[i-1];
		P[i].second-=DD[i];
		if(P[i].second>0) {
			x=lower_bound(P,P+N,make_pair(P[i].first+2LL*D+1,-1LL<<60))-P;
			sum+=P[i].second;
			DD[i]+=P[i].second;
			DD[x]-=P[i].second;
		}
	}
	cout<<sum<<endl;
	
	
}
 
 
int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;

int main(){
  int n;
  double *x,*y;
  double p1 = 0,p2 = 0,p3 = 0,p = 0;

  cin >> n;
  
  x = new double[n];
  y = new double[n];


  
  for(int i = 0; i<n; ++i) cin >> x[i];
  for(int i = 0; i<n; ++i) cin >> y[i];
  
  double work;
  for(int i=0; i<n; ++i){
    work = abs(x[i] - y[i]);
    p1 += work;

    p2 += work * work;

    p3 += work * work * work;

    p = max(p,work);
  }

  p2 = sqrt(p2);
  p3 = pow(p3,1.0/3);

  cout << fixed << setprecision(12) << p1 << endl << p2 << endl << p3 << endl << p << endl;

  delete[] x;
  delete[] y;
}



Measured memory_bytes: 3404
#include<iostream>
using namespace std;

int count(int n,int x){
    int cnt =0;
    for (int i=1;i<=n-2;i++){
        for(int j=i+1;j<=n-1;j++){
            for(int k=j+1;k<=n;k++){
                if(i+j+k==x)cnt++;
            }
        }
    }
    return cnt;
}

int main(){
    int n,x;
    
    while(1){
        cin >> n >>x;
        if(n==0 && x==0)break;
        cout<<count(n,x)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int N;

int main(void){
    
    scanf("%d", &N);
    printf("%s\n", (N >= 1200) ? "ARC" : "ABC");
    
    return 0;
}

Measured memory_bytes: 256
uses crt;
var a,b,n:byte;
kt:boolean;
begin
        readln(n);
        b:=0;
        kt:=false;
        if kt=false then
        for a:=1 to 9 do
        begin
        for b:=1 to 9 do
        if b*a=n then begin kt:=true;break;end;
        end;
        if kt=true then write('Yes') else write('No');
        readln
end.



Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn get_line() -> String {
    let stdin = stdin();
    let mut line = String::new();
    stdin.lock().read_line(&mut line).expect("io error.");
    line.trim().to_string()
}

#[allow(dead_code)]
fn cast<T: FromStr>(s: &str) -> T {
    s.parse().ok().expect("parse error.")
}

#[allow(dead_code)]
fn get_word<T: FromStr>() -> T {
    cast(&get_line())
}

#[allow(dead_code)]
fn get_vec<T: FromStr>() -> Vec<T> {
    (&get_line()).split(' ').map(cast::<T>).collect()
}

fn gcd(a: u64, b: u64) -> u64 {
    if a > b {return gcd(b, a)};

    match a {
        0 => b,
        a => gcd(b % a, a),
    }
}

/* ---------- ここまでテンプレ ---------- */


fn main() {
    let v: Vec<i64> = get_vec();
    let n: usize = v[0] as usize;
    let x: i64 = v[1];

    let xv: Vec<i64> = get_vec();
    let mut dis: Vec<u64> = vec![0; n];

    for i in 0..n {
        dis[i] = (xv[i] - x).abs() as u64;
    }

    let mut ans = dis[0];
    for i in 1..n {
        ans = gcd(ans, dis[i]);
    }

    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define LL long long
#define ULL unsigned long long
#define P 1000000007
#define H 10007
#define mod(a,b) a-a/b*b
#define debug(x) cerr<<#x<<"="<<x<<endl
using namespace std;

long long n,t,tmp,lst,ans;

inline long long get_num()
{
	long long now=0;
	char ch=getchar();
	while(ch<'0' || ch>'9')ch=getchar();
	while(ch>='0' && ch<='9'){now=(now<<3)+(now<<1)+ch-'0';ch=getchar();}
	return now;
}

int main()
{
	n=get_num();t=get_num();
	for(int i=1;i<=n;i++)
	{
		tmp=get_num();
		if(lst+t>=tmp)
		{
			ans+=tmp-lst;
		}
		else
		{
			ans+=t;
		}
		lst=tmp;
	}
	ans+=t;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline

mod=10**9+7
MAX=10**5+100

g1=[1,1]
g2=[1,1]
for i in range(2,MAX+1):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    g2.append(pow(num_1,mod-2,mod))

    
N,K=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N-1)]

data=[[] for i in range(N+1)]
for A,B in AB:
    data[A].append(B)
    data[B].append(A)
    
count=[0]*(N+1)
flag=[0]*(N+1)
que=[1]
flag[1]=1
while que:
    h=[]
    for u in que:
        cnt=0
        for v in data[u]:
            if flag[v]==0:
                flag[v]=1
                cnt+=1
                h.append(v)
        count[u]=cnt
    que=h

if K-1-count[1]<0:
    print(0)
    sys.exit()
ans=K*g1[K-1]*g2[K-1-count[1]]%mod

for i in range(2,N+1):
    if count[i]==0:
        continue
    else:
        if K-2-count[i]<0:
            print(0)
            sys.exit()
        ans=ans*g1[K-2]*g2[K-2-count[i]]%mod
    
print(ans)

Measured memory_bytes: 79004
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<string> S(N);
    REP(i, N) {
        cin >> S[i];
    }

    sort(S.begin(), S.end());
    S.erase(unique(S.begin(), S.end()), S.end());
    cout << S.size() << endl;
    return 0;
}

Measured memory_bytes: 9520
def a_irreversible_operation(S):
    n = len(S)
    ans = 0
    num_black_stone = 0
    # 1回操作を行うと、黒色の石は右に1つずれる。
    # よって、操作を行っていくと、右端にもう動かせない黒色の石が溜まっていく。
    for k, s in enumerate(S):
        if s == 'B':
            ans += n - k - 1 - num_black_stone  # 注目している黒色の場所から右に動かせる回数
            num_black_stone += 1
    # なお、BBWW...(ここから右は白のみ) となっている場合は、右の黒から
    # 先に裏返していったほうが回数が多くなるが、上の処理(左の石から見ていく)で問題ない。
    return ans

S = input()
print(a_irreversible_operation(S))

Measured memory_bytes: 3500
#include<bits/stdc++.h>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N;
int Q;
vector<int> G[200200];
int X[400400];
pii vs[200200];
int size = 0;

void dfs(int v, int p) {
    vs[v].first = size;
    size++;
    for (int to:G[v]) {
        if (to == p)continue;
        dfs(to, v);
    }
    vs[v].second = size;
    size++;
}

signed main() {
    cin >> N >> Q;
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0, -1);
    rep(i, Q) {
        int p, x;
        cin >> p >> x;
        --p;
        int left = vs[p].first;
        int right = vs[p].second;
        X[left] += x;
        X[right + 1] -= x;
    }
    rep(i, 2 * N) {
        X[i + 1] += X[i];
    }
    rep(i, N) {
        cout << (i ? " " : "") << X[vs[i].first];
    }
    return 0;
}


Measured memory_bytes: 28928
N, M = map(int, input().split())
piv = N//4+(N%4==3)
pairs = [(str(piv-i), str(piv+1+i)) for i in range(N//4+(N%4==3))]
piv = N - N//4 + (N%4==0)
pairs += [(str(piv-1-i), str(piv+1+i)) for i in range(N//4-(N%4==0))]
for pair in pairs[:M]:
    print(' '.join(pair))

Measured memory_bytes: 27292
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int N;
  cin >> N;
  unordered_map<string,ll> memo;
  rep(i,N){
    string str;
    cin >> str;
    sort(ALLOF(str));
    memo[str]++;
  }

  ll ret = 0;
  FOR(it,memo){
    ll tmp = it->second;
    ret += tmp * (tmp-1) / 2;
  }

  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 10660
N = int(input())
X = list(map(int,input().split()))
l = []

mi = min(X)
ma = max(X)
for i in range(mi, ma+1):
  temp = 0
  for j in X:
    temp += (j-i) ** 2
  l.append(temp)
  
print(min(l))

Measured memory_bytes: 9180
// 以下の(過去問)解説を参照.
// https://img.atcoder.jp/arc065/editorial.pdf
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int x[202020], y[202020];

int main() {
    
    // 1. 入力情報取得.
    int N;
    scanf("%d", &N);
    rep(i, N){
        int tx, ty;
        scanf("%d %d", &tx, &ty);
        // 変換(tx, ty) -> (tx + ty, tx - ty).
        x[i] = tx + ty;
        y[i] = tx - ty;
    }
    
    // 2. sort.
    sort(x, x + N);
    sort(y, y + N);
    
    // 3. 出力.
    int ans = max(x[N - 1] - x[0], y[N - 1] - y[0]);
    printf("%d\n", ans);
    return 0;
    
}

Measured memory_bytes: 5392
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def F(x):
    if x == 0:
        return ''
    if x % 2 == 0:
        return F(x//-2) + '0'
    else:
        return F((x-1)//-2) + '1'

N = ir()
answer = F(N)
if N == 0:
    answer = 0
print(answer)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,a,b,c;
    string s;
    vector<int> res;
    
    cin>>a>>b>>c;

    if(a<b)
    {
        if(a<c && c<b)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
        
    }
    else
    {
        if(a>c && c>b)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
int main(){
  int n, k; cin >> n >> k;
  vector<int> h;
  for(int i=0; i<n; i++){
    int hi; cin >> hi;
    h.push_back(hi);
  }
  vector<int> dp(n, INF);
  dp[0]=0;
  for(int i=0; i<n; i++){
    for(int j=1; j<=k; j++){
      if(i+j==n) break;
      if(dp[i+j]>dp[i]+abs(h[i]-h[i+j])) dp[i+j]=dp[i]+abs(h[i]-h[i+j]);
    }
  }
  cout << dp[n-1];
  return 0;
}

Measured memory_bytes: 1144
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;
int main(int argc, char const *argv[]) {
  string s;std::cin >> s;
  for(int i=0;i<s.size();i+=2) std::cout << s[i];
  std::cout << '\n';
}


Measured memory_bytes: 576
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string forcast, actual;
    cin >> forcast >> actual;
    int result = 0;

    for (size_t i = 0; i < 3; ++i){
        if (forcast[i] == actual[i])
            ++result;
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
s = list(input())
while len(s) > 0:
    if ''.join(s[-7:]) == 'dreamer':
        del s[-7:]    
    elif ''.join(s[-6:]) == 'eraser':
        del s[-6:]
    elif ''.join(s[-5:]) == 'dream' or ''.join(s[-5:]) == 'erase':
        del s[-5:]
    else:
        break
print('NO' if len(s) != 0 else 'YES')

Measured memory_bytes: 3956
import java.util.*;
public class Main {
	public int wcnt(int[] now, int[] to) {
		int cnt = 0;
		int x = to[0] - now[0];
		int y = to[1] - now[1];
		if(x > 0 && y > 0 || x < 0 && y < 0) {
			x = Math.abs(x); 
			y = Math.abs(y); 
			cnt = Math.max(x, y);
		} else {
			x = Math.abs(x); 
			y = Math.abs(y); 
			cnt = x+y;
		}
		return cnt;
	}
	public void doIt(){
		Scanner sc = new Scanner(System.in);
		int[] now = new int[2];
		int[] to = new int[2];
		int cnt = 0;
		sc.nextInt();
		sc.nextInt();
		int n = sc.nextInt();
		now[0] = sc.nextInt();
		now[1] = sc.nextInt();
		for(int i = 1; i < n; i++) {
			to[0] = sc.nextInt();
			to[1] = sc.nextInt();
			cnt += wcnt(now,to);
			now[0] = to[0];
			now[1] = to[1];
		}
		System.out.println(cnt);
	}
	public static void main(String[] args) {
	 	new Main().doIt();
	}
}

Measured memory_bytes: 25460
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<int> s(A), t(B);
    cin >> s >> t;
    REP(i, Q) {
        int X;
        cin >> X;
        auto sl = lower_bound(ALL(s), X);
        auto sr = upper_bound(ALL(s), X);
        auto tl = lower_bound(ALL(t), X);
        auto tr = upper_bound(ALL(t), X);
        
        int l[2] = {-1, -1}, r[2] = {-1, -1};
        if (sl != end(s)) l[0] = *sl;
        if (tl != end(t)) l[1] = *tl;
        if (sr > begin(s)) r[0] = *(sr - 1);
        if (tr > begin(t)) r[1] = *(tr - 1);

        dump(l[0], l[1], r[0], r[1]);

        int ans = INF;
        REP(j, 2) {
            int L = l[j], R = r[j ^ 1];
            if (L == -1 || R == -1) continue;
            int tmp1 = abs(R - X) * 2 + abs(L - X);
            int tmp2 = abs(R - X) + abs(L - X) * 2;
            chmin(ans, min(tmp1, tmp2));
        }
        if (l[0] != -1 && l[1] != -1) {
            chmin(ans, max(l[0], l[1]) - X);
        }
        if (r[0] != -1 && r[1] != -1) {
            chmin(ans, X - min(r[0], r[1]));
        }
        cout << ans << endl;
    }
    return (0^_^0);
}



Measured memory_bytes: 2944
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  int r, c;
  while (cin >> r >> c, r) cout << (even(r) || even(c) ? "yes" : "no") << endl;
}

Measured memory_bytes: 3032
N = int(input())
A = list(map(int, input().split()))

sum_A = sum(A)

x1 = sum_A - 2 * (sum(A[1:N:2]))

ans = [x1]
for i in range(N):
    if (i == 0):
        continue
    if (i + 1 == N):
        ans.append(2 * A[i] - x1)
        break

    ans.append((2 * A[i - 1]) - ans[i - 1])

print(*ans)


Measured memory_bytes: 20724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
/* clang-format off */
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  int n;
  cin >> n;
  if(n<2)cout << 1 << "\n";
  else if(n<4)cout << 2 << "\n";
  else if(n<8)cout << 4 << "\n";
  else if(n<16)cout << 8 << "\n";
  else if(n<32)cout << 16 << "\n";
  else if(n<64)cout << 32 << "\n";
  else cout << 64 << "\n";
  return 0;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int a,b,c,d,e; cin >> a >> b >> c >> d >> e;
	cout << c*60+d-a*60-b-e << endl;
}


Measured memory_bytes: 3608
s=int(input())
t=list(map(int,input().split()))
a=max(t)
b=len(t)
c=0
d=10**6
for i in range(1,a+1):
  for j in range(b):
    c+=(t[j]-i)**2
  d=min(c,d)
  c=0
print(d)

Measured memory_bytes: 3060
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
#define SZ(a) int((a).size())
#define FOR(var,a,b) for(__typeof(b) var=(a)-((a)<(b)?0:1);var!=(b)-((a)<(b)?0:1);var+=((a)<(b)?1:-1))
#define REP(var,n) FOR(var,0,n)
#define INT(n) int n;scanf("%d",&n)
#define VI(v,n) vector<int> v(n);REP(i,n){scanf("%d",&v[i]);}

int main(){
  INT(n); INT(x); VI(as, n);
  vector<int> dp(n); REP(i, n){dp[i] = as[i];}
  ULL ans = -1;
  REP(i, n){
    REP(j, n){
      dp[j] = min(dp[j], as[(j + n - i) % n]);
    }
    ans = min(ans, accumulate(begin(dp), end(dp), 0ULL) + (ULL) x * i);
  }
  printf("%llu\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  int *A, *B;

  int C[VMAX+1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(int)*n+1);
  B = malloc(sizeof(int)*n+1);

  for ( i = 0; i <= VMAX; i++ ) C[i] = 0;

  for ( i = 0; i < n; i++ ){
    scanf("%d", &A[i + 1]);
    C[A[i + 1]]++;
  }

  for ( i = 1; i <= VMAX; i++ ) C[i] = C[i] + C[i - 1];

  for ( j = 1; j <= n; j++ ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 16276
import Control.Applicative
import Data.List
import Data.Array

main = do
  [n,k] <- map read . words <$> getLine :: IO [Integer]
  as <- map read . words <$> getLine :: IO [Integer]

  let
    xs = listArray (0,n) $ scanl (+) 0 as
    ys = listArray (0,n) $ scanl (+) 0 (map (max 0) as)
    s =  sum (map (max 0) as)

  
  print $ maximum $ map (\i -> (max (xs!(i+k-1) - xs!(i-1)) 0) + s - (ys!(i+k-1) - ys!(i-1))) [1..n-k+1]

  


Measured memory_bytes: 104444
n = gets.to_i

n.times do |vez|
  gets.chomp
  map = []
  8.times do
    map << gets.chomp.chars.map(&:to_i)
  end
  x = gets.to_i
  y = gets.to_i

  current_bomb = [y-1, x-1]

  until current_bomb.empty?
    x = current_bomb.pop
    y = current_bomb.pop
    
    -3.upto(3) do |i|
      if 0 <= x+i && x+i <= 7 && map[y][x+i] == 1
        current_bomb.push(y)
        current_bomb.push(x+i)
        map[y][x+i] = 0
      end
      if 0 <= y+i && y+i <= 7 && map[y+i][x] == 1
        current_bomb.push(y+i)
        current_bomb.push(x)
        map[y+i][x] = 0
      end
    end
  end

  puts "Data #{vez+1}:"
  8.times { |i| puts map[i].join }
end

Measured memory_bytes: 6112
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<string>
#include<set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<n; i++)
#define per(i, n) for(int i=n-1; i>=0; i--)
#define reps(i, n) for(int i=1; i<n; i++)
#define pers(i, n)  for(int i=n-1; i>=1; i--)

const int INF = 1001001001;
const int SIZE = 200 + 1;
int gcd_memo[SIZE][SIZE] = {0};
int gcd(int n, int b){
  if(gcd_memo[n][b]!=0) return gcd_memo[n][b];
  if(n<b) return gcd_memo[n][b] = gcd(b, n);
  if(n%b == 0)  return gcd_memo[n][b] = b;
  return gcd_memo[n][b] = gcd(b, n%b);
}
void solve(){
  int k;  cin >> k;
  int sum = 0;
  reps(a, k+1)  reps(b, k+1)  reps(c, k+1){
    sum += gcd(a, gcd(b, c));
  }
  cout << sum << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 3760
fun main() {
    val map = hashMapOf<String, Int>()
    val n = nextInt()
    map["AC"] = 0
    map["WA"] = 0
    map["TLE"] = 0
    map["RE"] = 0
    repeat(n) {
        val s = next()
        map.computeIfPresent(s){k,v -> v+1}
    }
    println("AC x ${map["AC"]}\n" +
            "WA x ${map["WA"]}\n" +
            "TLE x ${map["TLE"]}\n" +
            "RE x ${map["RE"]}\n")
}

val sc = java.util.Scanner(System.`in`)
fun next(): String = sc.next()
fun nextInt() = sc.nextInt()
fun nextIntArray(size: Int) = IntArray(size) { nextInt() }
fun nextLong() = sc.nextLong()
fun nextLine(): String = sc.nextLine()

Measured memory_bytes: 58228
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

// secondの小さい順に並べる
bool cmp(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

int main() {

    int n, m; cin >> n >> m;

    vector<pair<int, int>> p(m);
    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        p[i] = make_pair(a, b);
    }

    sort(p.begin(), p.end(), cmp);

    int ans = 0;
    int end = 0;
    for (int i = 0; i < m; ++i) {
        if (p[i].first >= end) {
            end = p[i].second;
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4040
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define MOD  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back
#define all(x) x.begin(),x.end()
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
signed main(){
    int n,k;cin>>n>>k;
    int h[114514];
    rep(i,0,n)cin>>h[i];
    int dp[114514];
    fill(dp,dp+n,mod);
    dp[0]=0;
    rep(i,0,n){
        rep(j,1,k+1)dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
    }
    cout<<dp[n-1]<<endl;return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<string,int> P;
bool comp(P &lhs,P &rhs)
{
	if(lhs.first==rhs.first)
		return lhs.second>rhs.second;
	else
		return lhs.first<rhs.first;
}

int main()
{
	P r[100];
	P cpr[100];
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string s;
		int p;
		cin>>s>>p;
		r[i]=P(s,p);
		cpr[i]=r[i];
	}
	sort(cpr,cpr+n,comp);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(cpr[i]==r[j])
			{
				cout<<j+1<<endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    ll n;
    cin >> n;
    ll a[n];
    ll sum = 0;
    rep (i, 0, n) {
        cin >> a[i];
        a[i] -= i + 1;
    }
    sort (a, a + n);
    //累積和
    ll s[n + 1];
    s[0] = 0;
    rep (i, 0, n) s[i + 1] = s[i] + a[i];
    //計算
    ll ans = INF;
    for (ll i = 0; i < n; i++) {
        ll sum1 = abs (s[i] - a[i] * i) + abs ((s[n] - s[i]) - a[i] * (n - i));
        ans = min (ans, sum1);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

#define vi vector<int>
#define vii vector<vector<int>>

void testcase(){
    int a,b,c;
    cin>>a>>b>>c;
    if((a == 5 && b == 5 && c==7) ||(a == 5 && b == 7 && c==5) || (a == 7 && b == 5 && c==5)){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }
}

int main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    testcase();
    return 0;
}

Measured memory_bytes: 3572
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	int N;
	cin >> N;
	vector<long long int> L(N), R(N);
	int pos1, pos2;
	P Lmax = P(-INF, -INF), Rmin = P(INF, INF);
	long long int ans = 0;
	for(int i = 0; i < N; i++){
		cin >> L[i] >> R[i];
		if(P(L[i], R[i]) > Lmax){
			Lmax = P(L[i], R[i]);
			pos1 = i;
		}
		if(P(R[i], L[i]) < Rmin){
			Rmin = P(R[i], L[i]);
			pos2 = i;
		}
		ans = max(ans, R[i] - L[i] + 1);
	}
	ans = ans + max(0LL, (R[pos2] - L[pos1] + 1));
	if(pos1 == pos2){
		cout << ans << endl;
		return 0;
	}
	vector<P> sec;
	for(int i = 0; i < N; i++){
		if(i != pos2){
			sec.push_back(P(R[i], L[i]));
		}
	}
	sort(sec.begin(), sec.end());
	long long int L1 = L[pos2], R1 = R[pos2], L2 = L[pos1];
	for(P p : sec){
		long long int R2 = p.first, L_ = p.second;
		//cout << L_ << " " << R2 << endl;
		//cout << "sec : " << L1 << " " << R2 << endl;
		ans = max(ans, max(0LL, R1 - L1 + 1) + max(0LL, R2 - L2 + 1));
		L1 = max(L1, L_);
	}
	ans = max(ans, max(0LL, R1 - L1 + 1) + max(0LL, R[pos1] - L2 + 1));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3956
cs = []
for _ in range(3):
    c0, c1, c2 = input().split()
    cs.append([int(c0), int(c1), int(c2)])
flag = True
for i in range(3):
    for k in range(3):
        if i != k:
            for j in range(3):
                for l in range(3):
                    if j != l:
                        if cs[i][j] - cs[i][l] != cs[k][j] - cs[k][l]:
                            flag = False
                        if cs[i][j] - cs[k][j] != cs[i][l] - cs[k][l]:
                            flag = False
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

void main_()
{
    ll H, W;
    cin >> H >> W;
    vector<string> ass;
    for (ll i = 0; i < H; ++i) {
        string s;
        cin >> s;
        ass.push_back(move(s));
    }

    for (ll i = 0; i < H; ++i) {
        for (ll j = 0; j < W; ++j) {
            if (ass[i][j] != '#')
                continue;
            if ((i > 0 && j > 0 && ass[i - 1][j] == ass[i][j - 1])
                || (i < H - 1 && j < W - 1 && ass[i + 1][j] == ass[i][j + 1])) {
                cout << "Impossible\n";
                return;
            }
        }
    }
    cout << "Possible\n";
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,a,b) for(register int i=a;i<=b;++i)
#define DREP(i,a,b) for(register int i=a;i>=b;--i)
using namespace std;
char s[100];
int main(){
	scanf("%s",s);
	s[3]='8';
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
    public static void main(String[] args) {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        try {
            String[] str = br.readLine().split(" ");
            int a = Integer.parseInt(str[0]);
            int b = Integer.parseInt(str[1]);
            if(a < b){
            System.out.println("a < b");
            }else if(a > b){
            System.out.println("a > b");
            }else{
            System.out.println("a == b");
            }
        } catch(IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 24208
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;

vector<ll> vec;
ll n, k;
ll sol() {
	set<ll> vls;
	ll cnt = 0;
	for (int i = 0; i < k; i++) vls.insert(vec[i]);

	vector<ll> pref;
	pref.push_back(0);

	for (int i = 1; i < n; i++) {
		ll vl = (vec[i] < vec[i - 1]);
		pref.push_back(pref.back() + vl);
	}

	bool k3 = 0;

	if (pref[k - 1]) {
		cnt++;
	}
	else {
		k3 = 1;
	}

	for (int i = k; i < n; i++) {
		ll k2 = *(vls.begin());
		if (i - k >= 0) vls.erase(vec[i - k]);

		ll mn = -2;
		if (vls.size() > 0) mn = *(vls.rbegin());

		if (mn > vec[i] || (i - k >= 0 && k2 != vec[i - k])) {
			if ((pref[i] - pref[i - k + 1])) {
				cnt++;
			}
			else {
				k3 = 1;
			}
		}
		vls.insert(vec[i]);
	}

	return cnt + k3;
}

void input() {
	cin >> n >> k;
	vec.resize(n);

	for (int i = 0; i < n; i++) cin >> vec[i];

}

ll brute() {
	for (int i = 0; i < n; i++) {
		if (i + k <= n) {
			vector<ll> nw;
			for (int j = i; j < i + k; j++) {
				nw.push_back(vec[j]);
			}
			sort(nw.begin(), nw.end());
		}
	}
	return 0;
}
int main()
{
	fastInp;

	input();

	cout << sol();

	return 0;
}

Measured memory_bytes: 16196
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<=n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}




int main(void){
    ll K;
    cin>>K;
    ll ans=0;
    REP(i,K){
        REP(j,K){
            REP(k,K){
                ans+=__gcd(__gcd(i,j),k);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
///                                   ahmocs
#include <bits/stdc++.h>
typedef long long ll;
#define ahmocs  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const ll N=1e5+5;
int ans[N],h[N];
using namespace std;
int main()
{
    ahmocs
    int n,k; cin>>n>>k;
    for (int i=0; i<n; ++i) cin>>h[i];
    ans[0]=0; ans[1]=abs(h[1]-h[0]);
    for (int i=2; i<n; ++i)
    {
        ans[i]=1e9;
        for (int j=i; j>=max(0,i-k); --j)
            ans[i]=min(ans[i],abs(h[i]-h[j])+ans[j]);
    }
    cout<<ans[n-1];
    return 0;
}



Measured memory_bytes: 1024
#include <iostream>

using namespace std;

const int MAX_N = 1e5 + 5;

typedef long long ll;

ll arr [MAX_N];

int main () {
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += arr[i] / 2;
    arr[i] %= 2;
    if (arr[i] == 1 && arr[i + 1] >= 1) {
      arr[i]--;
      arr[i + 1]--;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4408
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<numeric>
#include<algorithm>
#include<queue>
#include<tuple>
using namespace std;

const char WALL = '#';
const char FLOOR = '.';

const int dx[4] = { 0, 1, 0, -1 };
const int dy[4] = { 1, 0, -1, 0 };

int main(void)
{
    int H, W;
    cin >> H >> W;

    vector<string> S(H);
    for (int i = 0; i < H; i++)
        cin >> S[i];

    vector<string> stage(H + 2, string(W+2, WALL));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++)
            stage[i + 1][j + 1] = S[i][j];
    }

    int ans = 0;
    for (int i = 0; i < H + 2; i++) {
        for (int j = 0; j < W + 2; j++) {
            if (stage[i][j] == WALL)
                continue;

            const int init = -1;
            vector<vector<int>> dist(H + 2, vector<int>(W + 2, init));

            priority_queue<tuple<int, int, int>> task;
            task.push(make_tuple(0, j, i));

            while (!task.empty()) {
                auto t = task.top();
                task.pop();

                int x, y, d;
                tie(d, x, y) = t;
                d = -d;

                if (stage[y][x] == WALL)
                    continue;
                if (dist[y][x] != init && dist[y][x] <= d)
                    continue;

                dist[y][x] = d;
                ans = max(ans, d);

                for (int k = 0; k < 4; k++) {
                    int nx, ny;
                    nx = x + dx[k];
                    ny = y + dy[k];

                    task.push(make_tuple(-(d + 1), nx, ny));
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) a[i] = sc.nextInt();
		int[] b = new int[n];
		for(int i = 0 ; i < n ; i++) b[i] = a[i] - (i + 1);
		Arrays.sort(b);
		long ans = 0;
		long dis = b[n / 2];
		for(int i = 0 ; i < n ; i++) {
			ans += Math.abs(b[i] - dis);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 63888
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <deque>
#include <algorithm>

typedef long long ll;
typedef unsigned long long ull;
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < n; ++i)

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, k;
	cin >> n >> k;
	char s;
	char t;
	cin >> s;
	int ans = 0;
	for (int i = 1; i < n; ++i) {
		cin >> t;
		if (s == t) ++ans;
		s = t;
	}

	cout << min(n - 1, ans + 2 * k) << "\n";
 }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main(){
  cin>>a>>b>>c>>d;
  if(a+b>c+d)cout<<"Left"<<endl;
  else if(a+b<c+d)cout<<"Right"<<endl;
  else cout<<"Balanced"<<endl;
}

Measured memory_bytes: 256
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
// const long long MOD = (ll)1e9+7;
const long long MOD = (ll)1e6+3;
const long long MAX = (ll)170 * 80;

vector<pair<char,int>> vOp;
string s;

ll Check(ll start) {
   ll now = start;
   for(auto op: vOp) {
      if (s[now]!=op.first) continue;
      now += op.second;
      if (now<0) break;
      if (now>=s.size()) break;
   }
   return now;
}

int main(void) {
   ll N,Q;
   cin>>N>>Q;
   cin>>s;
   rep(i,0,Q) {
      char t;
      char d;
      cin>>t>>d;
      vOp.push_back(make_pair(t,d=='L'?-1:1));
   }
   ll ans0;
   int le = 0;
   int re = (int)s.size()-1;
   if (Check(le)>=0) ans0 = 0;
   else {
      while(1) {
         int ne = (le+re)/2;
         if (ne == le || ne == re) break;
         if (Check(ne)<0) le = ne;
         else re = ne;
      }
      if (Check(re)<0) ans0= re+1;
      else ans0 = le+1;
   }
   // cout<<ans0<<endl;
   ll ans1;
   le = 0;
   re = (int)s.size()-1;
   if (Check(re)<N) ans1 = 0;
   else {
      while(1) {
         int ne = (le+re)/2;
         if (ne == le || ne == re) break;
         if (Check(ne)>=N) re = ne;
         else le = ne;
      }
      if (Check(le)>=N) ans1= N-le;
      else ans1 = N-re;
   }
   // cout<<ans1<<endl;

   if (ans0+ans1>=N) cout<<0<<endl;
   else cout<<N-ans0-ans1<<endl;


   return 0;
}

Measured memory_bytes: 2680
#include<cstdio>
int main(){
    int a,b,c,d;
    scanf("%d%d%d",&a,&b,&c);
    d=a+b+c;
    if(a<b)a=b;
    if(a<c)a=c;
    d-=a;
    printf("%d\n",d);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  int k=0;
  
  for(int i=1;i<=n;i++){
    int j=i*1.08;
    if(j==n){
      k=i;
      break;
    }
  }
  if(k==0)
    cout << ":(" << endl;
  else
    cout << k << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main()    
{
    int n,k;
    cin>>n>>k;
    int a[n],dp[n];
    int mx = 1e9+5;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=1;i<n;i++)
        dp[i] = mx;
    dp[0] = 0;
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            if((i+j)>=n) break;
            dp[i+j] = min(dp[i+j],dp[i]+abs(a[i+j]-a[i]));
        }
    }
    cout<<dp[n-1];

}

Measured memory_bytes: 4364
#include <iostream>
#include <utility>
#include <cstdio>
using namespace std;

void insertionSort(int A[], const int n, const int g, int *cnt)
{
    for( int i = g; i < n; ++i ){
        int tmp = A[i];
        int j = i - g;
        while( -1 < j && tmp < A[j] ){
            //cout << A[j+g] << "<-->" << A[j] << endl;
            A[j+g] = A[j];
            j = j - g;
            ++*cnt;
        }
        A[j+g] = tmp;
    }
}

void shellSort(int A[], const int n)
{
    int cnt = 0;
    int m;
    int G[100];
    for( int i = 0; i < 100; ++i ){
        if( i == 0 ) G[i] = n / 2 + 1;
        else G[i] = G[i-1] / 2 - 1;
        if( G[i] < 0 ){
            G[i-1] = 1;
            G[i] = 0;
            m = i;
            break;
        }
    }

    for( int i = 0; i < m; ++i )
        insertionSort(A, n, G[i], &cnt);

    //出力
    printf("%d\n", m);
    for( int i = 0; i < m; ++i ){
        if( i ) printf(" ");
        printf("%d", G[i]);
    }
    printf("\n%d\n", cnt);
    for( int i = 0; i < n; ++i )
        printf("%d\n", A[i]);
}

int main()
{
    //入力
    int n;
    scanf("%d", &n);
    int A[n];
    for( int i = 0; i < n; ++i )
        scanf("%d", &A[i]);

    //シェルソート
    shellSort(A, n);

    return 0;
}



Measured memory_bytes: 7136