akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

const long N = 16777216;
char str[N][13];
long n;

int getInt(char ch){
	switch (ch)
	{
	case 'A': return 1;
	case 'T': return 2;
	case 'G': return 3;
	case 'C': return 4;
	}
	return 0;
}
long getKey(char* tmp){
	long sum = 0, p=1;
	for (int i = 0; i < strlen(tmp); ++i){
		sum += p*getInt(tmp[i]);
		p *= 5;
	}
	return sum;
}

int main(){
	scanf("%ld",&n);
	while (n--){
		char ch[13], CH[13]; scanf("%s", ch);
		scanf("%s", CH); long tmp = getKey(CH);
		if ( strcmp(ch,"insert")==0){
			strcpy(str[tmp], CH);
		}
		else if ( strcmp(ch, "find")==0){
			if (strcmp(str[tmp],CH)==0) cout << "yes\n";
			else cout << "no\n";
		}
	}
}

Measured memory_bytes: 108908
#include <iostream>

using namespace std;
const int maxn = 1e5 + 50;
int box[maxn];
int n, x;

int main() {
    while (cin >> n >> x) {
        for (int i = 0; i < n; ++i) {
            cin >> box[i];
        }
        long long sum;
        long long ans=0;
        for (int j = 0; j < n - 1; ++j) {
            sum = box[j] + box[j + 1] - x;
            if(sum<=0)
                continue;
            else if (sum > 0 && box[j+1]-sum>=0) {
                box[j+1]-=sum;
                ans+=sum;
            } else if(sum>0){
                box[j+1]=0;
                ans+=sum;
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
//#define endl '\n'
#define all(x) x.begin(),x.end()
using namespace std;
const lli INF = 1e18L+5;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
//cout.precision(10);
//cout.setf(ios::fixed,ios::floatfield);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
	lli T=1;
    //cin>>T;
	while(T--)
	{
		lli i,j,n,ans=0,p,a;
		string s,t;
		cin>>s>>t;
		map<char,lli> mp;
		vector<lli> v[26];
		for(i=0;i<s.size();i++)
		mp[s[i]]++;
		for(i=0;i<t.size();i++)
		{
			if(mp[t[i]]==0)
			break;
		}
		if(i!=t.size())
		{
			cout<<"-1"<<endl;
			return 0;
		}
		for(i=0;i<s.size();i++)
		{
			//if(pos[s[i]]==0)
			//pos[s[i]]=i;
			v[s[i]-97].pb(i);
		}
		ans=v[t[0]-97][0];
		a=ans;
		p=a;
		for(i=1;i<t.size();i++)
		{
			a=lower_bound(v[t[i]-97].begin(),v[t[i]-97].end(),p+1)-v[t[i]-97].begin();
			if(a==v[t[i]-97].size())
			a=v[t[i]-97][0];
			else
			a=v[t[i]-97][a];
			if(p<a)
			ans+=(a-p);
			else
			ans+=((s.size()-p)+a);
			p=a;
		}
		cout<<ans+1<<endl;
	}
}
/*
contest
tt
*/


Measured memory_bytes: 1736
H, W = map(int, input().split())
S = []
for i in range(0, H):
    S.append(input())
for i in range(0, H):
    out = ""
    for j in range(0, W):
        if S[i][j]=="#":
            out = out+"#"
        else:
            count = 0
            for k in range(max(0, i-1), min(H, i+2)):
                for l in range(max(0, j-1), min(W, j+2)):
                    if S[k][l]=="#":
                        count = count+1
            out = out+str(count)
    print("{}".format(out))


Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
//#define int long long
#define ALL(x) begin(x),end(x)
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
int cnt;
/*signed*/int main(void) {   
    string s;
    cin >> s;
    rep(i,  s.size()) {
        if (s[i] == '1') ++cnt;
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef long long ll;
typedef pair<ll,ll> PP;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

signed main(void){
    int N,a;
    vector<int> A,B;
    cin >> N;
    REP(i,N){
        cin >> a;
        A.push_back(a);
    }
    
    REP(i,N){
        B.push_back(i-A[i]);
    }
    
    //REP(i,N){cout << B[i] << " ";}cout << endl;
    
    sort(B.begin(),B.end());
    
    int Ans=0;
    
    REP(i,N){
        int pos1=distance(B.begin(),lower_bound(B.begin(), B.end(),A[i]+i));
        int pos2=distance(B.begin(),upper_bound(B.begin(), B.end(),A[i]+i));
        
        Ans+=pos2-pos1;
        //cout << pos2-pos1 << " ";
        
    }
    
    cout << Ans << endl;
    
    return 0;
}




Measured memory_bytes: 7932
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		if(a==1) {
			System.out.println("Hello World");
		}
		else {
			int b=scan.nextInt();
			int c=scan.nextInt();
			System.out.println(b+c);
		}
		}
	}

Measured memory_bytes: 21844
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    vll h(n); REP(i, n) cin >> h[i];
    vll dp(n, HIGHINF);
    dp[0] = 0;
    rep(i, 1, n) rep(j, 1, k+1) if (i-j>=0) chmin(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
    cout << dp[n-1] << '\n';
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n;
    cin>>n;
    VL a(n);
    REP(i,n)cin>>a[i];
    multiset<LL> mset;
    LL max_val = a[0];
    mset.insert(a[0]);
    FOR(i,1,n){
        LL val = a[i];
        //if(val > max_val){
        //    mset.erase(mset.find(max_val));
        //    max_val = val;
        //    mset.insert(val);
        //    continue;
        //}
        auto lower = mset.lower_bound(val);
        //auto upper = mset.upper_bound(val);
        //if(upper == mset.end()){
        //    auto last = mset.end();
        //    mset.insert(val);
        //    continue;
        //}
        //else{
        //    mset.erase(itr);
        //    mset.insert(val);
        //}
        if(lower != mset.begin()){
            mset.erase(--lower);
        }
        mset.insert(val);
    }
    PUTS(mset.size());
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    ll a,b,c; cin >> a >> b >> c;
    ll to_b = b/c+1;
    ll to_a = (a-1)/c+1;
    if(a==0) to_a = 0;
    pr(to_b-to_a);
    
}


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

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

    string predict, infact;
    cin >> predict >> infact;

    int correct, i;

    for (i = 0; i < 3; i++) {
        if (predict[i] == infact[i])
            correct++;
    }
    cout << correct << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n, w[3010], K;
long long D[3010][3010];
int main() {
	int i, j, k;
	scanf("%d", &n);
	for (i = 1; i <= n; i++)scanf("%d", &w[i]);
	for (int L = 1; L <= n; L++) {
		for (i = 1; i <= n - L + 1; i++) {
			j = i + L - 1;
			if (L == 1) {
				D[i][j] = w[i];
				continue;
			}
			D[i][j] = max(w[i] - D[i + 1][j], w[j] - D[i][j - 1]);
		}
	}
	printf("%lld\n", D[1][n]);
}

Measured memory_bytes: 70016
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;
 
#define X first
#define Y second
 
const int N=1e5+10;
int n,a[N][2];
int h[N];
priority_queue <ii> pq[2];
 
 
void modified(ll &ans,int L,int R,int &cen){
        if (cen<L){
                ans+=L-cen;
                cen=L;
                return;
        }
        if (cen>R){
                ans+=cen-R;
                cen=R;
                return;
        }
}
long long solve(){
        long long ans=0;
        for(int j=0;j<=1;j++){
                memset(h,0,sizeof(h));
                for(int i=1;i<=n;i++){
                        pq[0].push(ii(a[i][0],i));
                        pq[1].push(ii(-a[i][1],i));
                }
                int pos=0;
                ll cans=0;
                for(int i=1,side=j;i<=n;i++,side^=1){
                        while (h[pq[side].top().Y]) pq[side].pop();
                        int use=pq[side].top().Y;
                        pq[side].pop();
                        h[use]=1;
 
                        modified(cans,a[use][0],a[use][1],pos);
                }
                ans=max(ans,cans+abs(pos));
        }
        return ans;
}
int main(){
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i][0]>>a[i][1];
        cout<<solve();
}


Measured memory_bytes: 4840
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int p[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);
	}
	priority_queue<int>Q;
	for(int i=0;i<a;i++){
		Q.push(p[i]);
	}
	for(int i=0;i<b;i++){
		int t=Q.top();
		Q.pop();
		t/=2;
		Q.push(t);
	}
	long long ret=0;
	while(Q.size()){
		int tmp=Q.top();Q.pop();ret+=tmp;
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 1276
n, m = map(int, input().split())
s = []
for i in range(n):#h:高さ
    s.append([int(m) for m in input().split()])
for i in range(n):
    s[i].append(s[i][0] + s[i][1] + s[i][2])
    s[i].append(s[i][0] + s[i][1] - s[i][2])
    s[i].append(s[i][0] - s[i][1] + s[i][2])
    s[i].append(-s[i][0] + s[i][1] + s[i][2])
    s[i].append(s[i][0] - s[i][1] - s[i][2])
    s[i].append(-s[i][0] - s[i][1] + s[i][2])
    s[i].append(-s[i][0] + s[i][1] - s[i][2])
    s[i].append(-s[i][0] - s[i][1] - s[i][2])
maxtotal = 0
for i in range(8):
    s.sort(key=lambda x:(x[i + 3]), reverse=True)
    total = 0
    for j in range(m):
        total += s[j][i + 3]
    if maxtotal < total:
        maxtotal = total
print(maxtotal)


Measured memory_bytes: 3572
import java.awt.geom.Line2D;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			double[] x = new double[n];
			double[] y = new double[n];
			double[] r = new double[n];
			for (int i = 0; i < n; ++i) {
				x[i] = sc.nextDouble();
				y[i] = sc.nextDouble();
				r[i] = sc.nextDouble();
			}

			double[][] p = new double[2 * n][];
			p[0] = new double[] { x[0], y[0] };
			p[2 * n - 1] = new double[] { x[n - 1], y[n - 1] };

			for (int i = 0; i < n - 1; ++i) {
				double a = -2 * (x[i] - x[i + 1]);
				double b = -2 * (y[i] - y[i + 1]);
				double c = x[i] * x[i] - x[i + 1] * x[i + 1] + y[i] * y[i] - y[i + 1] * y[i + 1] - r[i] * r[i]
						+ r[i + 1] * r[i + 1];

				double w = -c * a / (a * a + b * b);
				double v = -c * b / (a * a + b * b);

				double f = 1 / (a * a + b * b) * (-b * (w - x[i]) + a * (v - y[i]));
				double g = 1 / (a * a + b * b) * ((w - x[i]) * (w - x[i]) + (v - y[i]) * (v - y[i]) - r[i] * r[i]);
				double t1 = -f + Math.sqrt(f * f - g);
				double t2 = -f - Math.sqrt(f * f - g);
				p[2 * i + 1] = new double[] { w - b * t1, v + a * t1 };
				p[2 * i + 2] = new double[] { w - b * t2, v + a * t2 };

			}

			Line2D.Double[] seg = new Line2D.Double[n - 1];
			for (int i = 0; i < n - 1; ++i) {
				seg[i] = new Line2D.Double(p[2 * i + 1][0], p[2 * i + 1][1], p[2 * i + 2][0], p[2 * i + 2][1]);
			}

			double[][] dis = new double[2 * n][2 * n];
			for (int i = 0; i < 2 * n; ++i) {
				for (int j = 0; j < 2 * n; ++j) {
					if (i != j)
						dis[i][j] = Double.MAX_VALUE / 100;
				}
			}
			for (int src = 0; src < 2 * n; ++src) {
				for (int dst = src + 1; dst < 2 * n; ++dst) {
					int s = (src == 0 ? -1 : (src - 1) / 2) + 1;
					int d = (dst - 1) / 2 - 1;
					boolean f = true;
					Line2D.Double path = new Line2D.Double(p[src][0], p[src][1], p[dst][0], p[dst][1]);
					for (int i = s; i <= d; ++i) {
						if (!path.intersectsLine(seg[i]))
							f = false;

					}
					if (f) {
						double distance = Math.sqrt((p[src][0] - p[dst][0]) * (p[src][0] - p[dst][0])
								+ (p[src][1] - p[dst][1]) * (p[src][1] - p[dst][1]));
						dis[src][dst] = distance;
						dis[dst][src] = distance;
					}
				}
			}
			for (int mid = 0; mid < 2 * n; ++mid) {
				for (int src = 0; src < 2 * n; ++src) {
					for (int dst = 0; dst < 2 * n; ++dst) {
						dis[src][dst] = Math.min(dis[src][dst], dis[src][mid] + dis[mid][dst]);
					}
				}
			}
			System.out.println(dis[0][2 * n - 1]);

		}
		sc.close();
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 68652
//g++  5.4.0

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<bool> vb;

int main(){
    int n, m, x, y;
    cin >> n >> m;
    vi nums(n + 1, 1);
    vb marked(n + 1, 0);
    marked[1] = true;
    
    for(int i=0; i<m; i++) {
        cin >> x >> y;
        //cout << nums[x] << ' ' << nums[y] << endl;
        if(nums[x] > 0) {
            
            nums[x]--;
            
                        
            nums[y]++;
            if(marked[x]) marked[y] = true;
            
            if(nums[x] == 0 && marked[x]) marked[x] = false;

        
        }        
    }
    
    int cont = 0;
    for(int i=1; i<=n; i++) {
        //cout << nums[i] << ' ';
        if(marked[i])cont++;
    }//cout << endl;
    cout << cont << '\n';    
    return 0;    
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
using namespace std;

int main()
{
	long long r;
	cin >> r;
	cout << 3 * pow(r, 2) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;

int main() {
  int n;
  cin >> n;
  int count = n;
  long long a,b;
  long long v[n];
  for (size_t i = 0; i < count; i++) {
    cin >> v[i];
  }
  sort(v, v+n, greater<int>());
  for (int i = 1; i < count; i++) {
    if (i == count - 1) {
      a = v[0];
      b = v[i];
    } else if (v[i] <= v[0]/2) {
      a = v[0];
      if (v[0]/2 - v[i] < v[i-1] - v[0]/2) b = v[i];
      else b = v[i-1];
      break;
    }
  }
  cout << a << ' ' << b << endl;
}


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

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main(){
  int X; cin >> X;
  for(int i=X;;i++){
    if(IsPrime(i)==true){
      cout << i << endl;
      return 0;
    }
  }
}
  
  

Measured memory_bytes: 256
using System.Linq;
using System;
class A
{
    static void Main()
    {
        long a = long.Parse(Console.ReadLine());
      //  a = long.MaxValue;
        string str = a.ToString();
        bool flag = true;
        for (int i = 0; i < str.Length; i++) { if (str[i] != '9'&&i!=0) { flag = false; } }
        if (flag) { Console.WriteLine((str.Length-1) * 9+(long.Parse((str.Substring(0,1)))));Console.ReadLine(); return; }
        else {
            if (str.Length == 1) { Console.WriteLine(a);Console.ReadLine(); return; }
            Console.WriteLine((str.Length - 1) * 9 + int.Parse(str.Substring(0, 1))-1); }
        Console.ReadLine();
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
using namespace std;

int main(){
  int n, input;
  scanf("%d", &n);

  int a[n];
  for(int i = 0; i < n; i++){
    scanf("%d", &input);
    a[i] = input;
  }

  for(int i = n-1; i > 0; i--){
    printf("%d ", a[i]);
  }
  printf("%d", a[0]);
  printf("\n");
}



Measured memory_bytes: 2728
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N;	cin>>N;
	ll ans=0;
	vector<ll> data(N);
	FOR(i,0,N) cin>>data.at(i);
	FOR(i,0,N-1){
		if(data.at(i)>data.at(i+1)){
			ans+=data.at(i)-data.at(i+1);
			data.at(i+1)=data.at(i);
		}
	}

	cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 4776
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
// #define fore(i,a) for(auto &i:a)
// #define all(x) (x).begin(),(x).end()
// #pragma GCC optimize ("-O3")
// using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
// typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
// template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
// template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using namespace std;

int main(void)
{
  string str;
  
  cin>>str;
  
  if(str.find('7')!=str.npos){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

using namespace std;

string s;

long long solve ()
{
	long long sum = 0;
	string S;
	S.push_back (s[0]);
	for (int i = 1; i < s.size(); i++)
	{
		S.push_back ('_');
		S.push_back (s[i]);
	}
	int n = S.size();
	for (int mask = 0; mask < (1 << n); mask++)
	{
		long long add = 0, atual = 0, total = 0;
		bool ok = 1;
		for (int i = 0; i < n; i++)
		{
			if ((1 << i) & mask)
			{
				if (S[i] != '_')
				{
					ok = false;
					break;
				}
				else 
					total += add, add = 0;
			}
			else 
				{
					if (S[i] == '_')
						continue;
					add = add * 10 + (S[i] - '0');
				}
		}
		total += add;
		if (ok)
			sum += total;
	}
	return sum;
}

int main ()
{
	cin.sync_with_stdio (false);
	cin >> s;
	cout << solve () << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  vec s(n);
  for(ll i=0;i<n;i++) cin >> s[i];
  sort(s.begin(),s.end());
  ll ans=0;
  for(ll i=0;i<n;i++) {
    ans+=s[i];
  }
  for(ll i=0;i<n;i++) {
    if(ans%10==0&&s[i]%10) {
      ans-=s[i];
    }
  }
  if(ans%10) cout << ans << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        
        // input
        String input = scan.next();
        long k = scan.nextLong();

        if(k == 1){
            System.out.println(input.charAt(0));
        } else {
            for(int i = 0; i < 100; i++){
                if(input.charAt(i) == '1' && i == k - 1){
                    System.out.println(1);
                    break;
                } else if(input.charAt(i) != '1'){
                    System.out.println(input.charAt(i));
                    break;
                }
            }
        }


    }
}

Measured memory_bytes: 21844
void main()
{
    long[] tmp = readln.split.to!(long[]);
    long a = tmp[0], b = tmp[1];

    writeln(a * b / gcd(a, b));
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include<iostream>

#define MAX 5000000

int H, A[MAX];

void maxHeapify(int i) {
    int lIdx, rIdx, largestIdx;
    largestIdx = i;
    lIdx = i * 2;
    rIdx = i * 2 + 1;
    if (lIdx <= H && A[lIdx] > A[largestIdx]) {
        largestIdx = lIdx;
    }
    if (rIdx <= H && A[rIdx] > A[largestIdx]) {
        largestIdx = rIdx;
    }
    if (largestIdx != i) {
        std::swap(A[i], A[largestIdx]);
        maxHeapify(largestIdx);
    }
}

void buildHeap() {
    for (int i = H / 2; i >= 1; i--) {
        maxHeapify(i);
    }
}

int main() {
    std::cin >> H;
    for (int i = 1; i <= H; i++) {
        std::cin >> A[i];
    }
    buildHeap();
    for (int i = 1; i <= H; i++) {
        std::cout << " " << A[i];
    }
    std::cout << std::endl;
    return 0;
}


Measured memory_bytes: 5000
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int N,L; cin >> N >> L;
  string S[110];
  for (int i=0; i<N; i++){
    cin >> S[i];
  }
  sort(S, S+N);
  for (int i=0; i<N; i++){
    cout << S[i];
  }
  cout << endl;
}

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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	int n[5];
	for(int i=0;i<5;i++){
		cin >> n[i];
	}
	for(int i=0;i<5;i++){
		if(n[i]==0){
			cout << i+1 << endl;
			return 0;
		}
	}
	return 0;
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int l[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>l[i];
	}
	sort(l,l+n);
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = i+1; j < n; ++j)
		{
			int ng=distance(lower_bound(l,l+n,l[i]+l[j]),l+n);
			ans+=n-j-1-ng;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=998244353;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



int main(){
    int n;cin >> n;
    string s;cin >> s;
    vector<int> a(3,0);
    LL ans = 1;
    for (int i = 0; i < n; i++) {
        ans = ans * (i + 1) % mod;
    }
    for (int i = 0; i < s.length(); i++) {
        vector<P> v(3);
        for (int j = 0; j < 3; j++) {
            v[j] = mp(a[j],j);
        }
        sort(ALL(v));
        auto f = [&](int k){
            if(v[0].fs == v[2].fs) return 1LL;
            LL pp = v[2].fs - v[1].fs;
            LL p = v[1].fs - v[0].fs;
            if(v[0].sc == k){
                if(!p) return pp;
                else return p;
            }
            else if(v[1].sc == k){
                if(!pp) return 1LL; 
                else return pp;
            }
            else return 1LL;
        };
        if(s[i]=='R'){
            ans = (ans * f(0))%mod;
            a[0]++;
        }
        else if(s[i]=='G'){
            ans = (ans * f(1))%mod;
            a[1]++;
        }
        else{
            ans = (ans * f(2))%mod;
            a[2]++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 900
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	r1 := scanInt()
	c1 := scanInt()
	r2 := scanInt()
	c2 := scanInt()

	facInit(r2+c2+2)

	a := (comb(r2+1+c2+1, c2+1)-1)%mod
	a = (a-(comb(r2+1+c1, c1)-1)%mod)%mod
	a = (a-(comb(c2+1+r1, r1)-1)%mod)%mod
	a = (a+(comb(c1+r1, r1)-1)%mod)%mod
	if a < 0 {
		a = (a+mod)%mod
	}

	fmt.Println(a)

}

const mod = 1000000007

var fac, ifac []int

func facInit(n int) {
	fac = make([]int,n+1)
	ifac = make([]int,n+1)

	mpow := func (x,n int) int {
		res := 1
		for n!=0 {
			if n&1 == 1 { res = res*x%mod }
			x = x*x%mod; n >>= 1
		}
		return res
	}

	fac[0] = 1; ifac[0] = 1

	for i := 0; i < n; i++ {
		fac[i+1] = fac[i]*(i+1)%mod
		ifac[i+1] = ifac[i]*mpow(i+1,mod-2)%mod
	}
}

func comb(a,b int) int { return (fac[a]*ifac[b]%mod)*ifac[a-b]%mod }
func perm(a,b int) int { return fac[a]*ifac[a-b]%mod }

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

int main(int argc, char *argv[]) {
    int K,S;
    int64_t cnt = 0;
    cin >> K >> S;
    
    for(int i=0;i<=K;i++) {
    for(int j=0;j<=K;j++) {
        if((i+j) <= S){
            if(S-(i+j)<=K)
             cnt++;
        }
        else{ break;
        }
    }
    }
    cout << cnt << "\n";
    

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int solve(vector<int> &a) {
  int n = a.size(), ans = 0;
  REP(i, n) {
    if (a[i] == 1) ans += n - 1 == (i | (n - 1 - i));
  }
  return ans & 1;
}

int main() {
  int n; string s; cin >> n >> s;
  vector<int> a(n);
  REP(i, n) a[i] = s[i] - '0' - 1;
  if (count(ALL(a), 1) == 0) {
    REP(i, n) {
      if (a[i] == 2) a[i] = 1;
    }
    cout << (solve(a) == 1 ? 2 : 0) << '\n';
  } else {
    REP(i, n) {
      if (a[i] == 2) a[i] = 0;
    }
    cout << solve(a) << '\n';
  }
  return 0;
}


Measured memory_bytes: 5276
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cmath> 
using namespace std;
const int Maxn=1000000;
long long A, B, C, D, x, ans=1;
long long gcd(long long a, long long b)
{
	if(b==0)
		return a;
	gcd(b, a%b);
}
int main()
{
	cin>>A>>B>>C>>D;
	long long x1=B/C-(A-1)/C;
	long long x2=B/D-(A-1)/D;
	long long x3=C*D/gcd(C, D);
	long long x4=B/x3-(A-1)/x3;
	x=B-A+1-x1-x2+x4;
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

h,w,m = map(int,readline().split())
inp = [list(map(int,readline().split())) for i in range(m)]

x = [0] * h
y = [0] * w

for i in range(m):
    inp[i][0] -= 1
    inp[i][1] -= 1

for xi,yi in inp:
    x[xi] += 1
    y[yi] += 1

ansx = max(x)
idx = []
for i,xi in enumerate(x):
    if xi == ansx:
        idx.append(i)

ansy = max(y)
idy = []
for i,yi in enumerate(y):
    if yi == ansy:
        idy.append(i)

s = set()

for xi,yi in inp:
    s.add(xi*1000000+yi)
#print(s)

for xx in idx:
    for yy in idy:
        if xx*1000000+yy not in s:
            print(ansx+ansy)
            exit()
print(ansx+ansy-1)


Measured memory_bytes: 168616
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class Test
    {
        public static void Main(string[] args)
        {
            var test = new Test();
            var n = Console.ReadLine();
            var s = Console.ReadLine();
            var count = 0;

            for(var i = 0; i<s.Length - 2; i++)
            {
               if(s[i] == 'A')
                {
                    if(s[i + 1] == 'B')
                    {
                        if (s[i + 2] == 'C')
                        {
                            count++;
                        }
                    }
                }
            }
            Console.WriteLine(count);
        }       

        public string[] ReadInput()
        {
            return Console.ReadLine().Split(' ');
        }

        public int[] ConvertIntArray(string[] x)
        {
            var convertedArray = new int[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = int.Parse(x[i]);
            }

            return convertedArray;
        }

        public double[] ConvertDoubleArray(string[] x)
        {
            var convertedArray = new double[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = int.Parse(x[i]);
            }

            return convertedArray;
        }

        public long[] ConvertLongArray(string[] x)
        {
            var convertedArray = new long[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = long.Parse(x[i]);
            }

            return convertedArray;
        }
    }
}

Measured memory_bytes: 13140
import java.util.ArrayDeque
import kotlin.Comparator
import kotlin.String

fun main(args: Array<String>) {
    val (n, q) = readIntList()

    val tree = List(n) { mutableSetOf<Int>() }
    repeat(n - 1) {
        val (a, b) = readIntList()
        tree[a - 1].add(b - 1)
        tree[b - 1].add(a - 1)
    }

    val cnt = MutableList(n) { 0 }
    repeat(q) {
        val (p, x) = readIntList()
        cnt[p - 1] += x
    }

    val queue = ArrayDeque<Int>()
    queue.addLast(0)
    val visited = MutableList(n) { false }
    while (!queue.isEmpty()) {
        val node = queue.removeLast()
        visited[node] = true
        tree[node].forEach {
            if (!visited[it]) {
                cnt[it] += cnt[node]
                queue.addLast(it)
            }
        }
    }

    val ans = StringBuilder()
    ans.append(cnt[0])
    for (i in 1 until n) {
        ans.append(" ${cnt[i]}")
    }
    println(ans.toString())
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)


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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll n, m;
  cin >> n >> m;
  ll result = (1900 * m + 100 * (n - m)) * pow(2, m);
  cout << result << endl;

}

Measured memory_bytes: 256
using System;
 
public class ITP1_7_D
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int n = int.Parse(input[0]);
    int m = int.Parse(input[1]);
    int l = int.Parse(input[2]);
    long[,] A = new long[n, m];
    long[,] B = new long[m, l];
    long[,] C = new long[n, l];
 
    for (int i = 0; i < n; i++)
    {
      string[] data = Console.ReadLine().Split(' ');
      for (int j = 0; j < m; j++)
      {
        A[i, j] = int.Parse(data[j]);
      }
    }
 
    for (int i = 0; i < m; i++)
    {
      string[] data = Console.ReadLine().Split(' ');
      for (int j = 0; j < l; j++)
      {
        B[i, j] = int.Parse(data[j]);
      }
    }
    
    for (int i = 0; i < n; i++)
    {
      for (int j = 0; j < m; j++)
      {
        for (int k = 0; k < l; k++)
        {
          C[i, k] += A[i, j] * B[j, k];
        }
      }
    }
    
    for (int i = 0; i < n; i++)
    {
      for (int j = 0; j < l; j++)
      {
        if (j + 1 != l)
        {
          System.Console.Write(C[i, j] + " ");
        }
        else
        {
          System.Console.Write(C[i, j]);
        }
      }
      System.Console.Write("\n");
    }
  }
}

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

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int K = in.nextInt();
            int[] h = new int[N];
            for (int i = 0; i < N; i++) {
                h[i] = in.nextInt();
            }

            Arrays.sort(h);

            int min = (int) 1e9;
            for (int i = 0; i < N; i++) {
                if (i + (K - 1) >= N) {
                    continue;
                }
                min = Math.min(min, h[i + (K - 1)] - h[i]);
            }

            System.out.println(min);
        }
    }
}


Measured memory_bytes: 50136
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
using namespace std;

const int MAXN = 2005;
int ans = 1e9, n;
deque<bool> a, b;
deque<int> dpr, dpl;
string tmp;

void prpdp() {
	dpr.clear();
	dpl.clear();
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++)
			if (b[(i + j) % n]) {
				dpr.push_back(j);
				break;
			}
		for (int j = 0; j < n; j++)
			if (b[(i - j + n) % n]) {
				dpl.push_back(j);
				break;
			}
	}
}
void shift() {
	int e = a.front(), w = dpr.front(), z = dpl.front();
	a.pop_front(), dpr.pop_front(), dpl.pop_front();
	a.push_back(e), dpr.push_back(w), dpl.push_back(z);
}
void shiftr() {
	int e = a.back(), w = dpr.back(), z = dpl.back();
	a.pop_back(), dpr.pop_back(), dpl.pop_back();
	a.push_front(e), dpr.push_front(w), dpl.push_front(z);
}
void solve() {
	prpdp();
	for (int x = 0; x <= n; x++) {
		int ne = 0;
		for (int i = 0; i < n; i++)
			ne += a[i] != b[i];
		vector<pair<int, int> > rf;
		int R = x, L = 0;
		for (int i = 0; i < n; i++) {
			if (dpl[i] - x > 0 && a[i] != b[i])
				rf.push_back({ dpr[i] + x, i });
		}
		sort(rf.begin(), rf.end());
		reverse(rf.begin(), rf.end());
		for (int i = 0; i < rf.size(); i++) {
			R = rf[i].first;
			ans = min(ans, min(n, (R + L)) * 2 - x + ne);
			L = max(L, dpl[rf[i].second] - x);
		}
		ans = min(ans, min(n, (R + L)) * 2 - x + ne);
		ans = min(ans, n + x + ne);
		shift();
	}
	shiftr();
}
void todeq(string &a, deque<bool> &b) {
	for (int i = 0; i < a.size(); i++)
		b.push_back(a[i] - '0');
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> tmp;
	todeq(tmp, a);
	cin >> tmp;
	todeq(tmp, b);
	n = a.size();
	if (a == b)
		return cout << 0, 0;
	int c = 0, d = 0;
	for (int i = 0; i < b.size(); i++)
		c += b[i];
	for (int i = 0; i < a.size(); i++)
		d += a[i];
	if (c == 0 && d != c)
		return cout << -1, 0;
	solve();
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	solve();
	cout << ans;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int a, b;

	cin>>a>>b;

	if(a%3==0||b%3==0||(a+b)%3==0){
		cout<<"Possible"<<endl;
	}else{
		cout<<"Impossible"<<endl;
	}
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int N, W; cin >> N >> W;
	int INF = 1001001001;
	vector<ll> w(N + 1), v(N + 1);
	rep(i, 1, N)cin >> w[i] >> v[i];
	vector<vector<ll>> dp(N + 1, vector<ll>(100200, INF));
	rep(i, 0, N)dp[i][0] = 0;
	rep(i, 1, N)rep(j, 0, 100150)
	{
		if (dp[i - 1][j] != INF)
		{
			dp[i][j + v[i]] = dp[i - 1][j] + w[i];
			dp[i][j] = min(dp[i - 1][j], dp[i][j]);
		}
	}
	int ans = 0;
	rep(i, 1, N)rep(j, 0, 100150)
	{
		if (dp[i][j] <= W)ans = max(ans, j);
	}
	cout << ans << endl;
}

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

using namespace std;

using int64 = long long;

int main() {
  int N, A[100000];

  cin >> N;
  for(int i = 0; i < N; i++) cin >> A[i];
  A[N++] = 0;
  int64 ret = 0;
  stack< int > st;
  for(int i = 0; i < N; i++) {
    int height = A[i];
    while(st.size() && st.top() > A[i]) {
      height = max(height, st.top());
      st.pop();
    }
    ret += height - A[i];
    st.emplace(A[i]);
  }
  cout << ret << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, K; cin >> N >> K;
  vector<ll> rem;
  vector<ll> tops(N+1);
  for (ll i = 0; i < N; i++) {
    ll t, d; cin >> t >> d;
    if (tops[t] < d) {
      rem.push_back(tops[t]);
      tops[t] = d;
    }else {
      rem.push_back(d);
    }
  }
  sort(rem.begin(), rem.end(), greater<ll>());
  sort(tops.begin(), tops.end(), greater<ll>());
  ll sumtop = 0;
  ll q = 0;
  for (; q < K && tops[q] > 0; q++) sumtop += tops[q];
  ll p = 0;
  ll sumdt = 0;
  for (; p < K - q; p++) sumdt += rem[p];
  ll ans = q * q + sumdt + sumtop;
  
  while (q - 1 >= 0 && p < (ll)rem.size() && tops[q - 1] < rem[p]) {
    sumtop -= tops[q - 1];
    sumdt += rem[p];
    q--;
    p++;
    ans = max(ans, q * q + sumdt + sumtop);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 4968
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() 
{
    Int N, X; cin >> N >> X;
    Int ans = N;
    Int A = X, B = N - X;
    while (B) {
        if (A > B) swap(A, B);
        ans += B / A * A * 2;
        B %= A;
    }
    ans -= A;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256