akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
typedef unsigned int uint;
typedef long long ll;

const int c_INF = 100000;

int main() {
	int D, G, P[10], C[10];
	scanf("%d%d", &D, &G);
	for (int i = 0; i < D; i++)scanf("%d%d", &P[i], &C[i]);


	int count[10000];
	for (int i = 0; i < 10000; i++)count[i] = 0;
	int countMin = c_INF;
	for (int i = 0; i < (1 << D); i++) {//iは解く問題のリスト
		int score = 0;
		int maxNum = 0;
		for (int j = 0; j < D; j++) 
			if (i & 1 << j) {
				score += 100 * (j + 1)*P[j] + C[j];
				count[i] += P[j];
				//printf("%d,%d,%d\n", j,P[j],count[i]);
			}
			else maxNum = j;
		if (score < G){
			double temp = (G - score) / (100.*(maxNum + 1));
			if (temp >= P[maxNum])count[i] = c_INF;
			else if ((G - score) % (100 * (maxNum + 1)) == 0)count[i] += temp;
			else count[i] += (int)temp + 1;
			//printf("i=%d,最終カウント=%d,maxNum=%d,temp=%lf,score=%d\n", i,count[i],maxNum,temp,score);
		}
		if (count[i] < countMin)countMin = count[i];
	}
	printf("%d", countMin);
	
}


/*         提出前の確認

・デバッグ用の関数は＜＜コメント化＞＞しているか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

signed main(void){
  int a;
  int b;
  scanf("%d %d", &a, &b);

  int c = b-a;
  int sum = 0;
  rep(i,c){
    sum += i;
  }

  printf("%d", sum-a);

  return 0;
}


Measured memory_bytes: 256
using System;

namespace ITP1_3_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strAry = Console.ReadLine().Split(' ');

            int v1 = int.Parse(strAry[0]);
            int v2 = int.Parse(strAry[1]);
            int v3 = int.Parse(strAry[2]);

            int num = 0;
            int j;
            for (j = v1; j <= v2; j++)
            {
                if (v3 % j == 0)
                    num++;
            }

            Console.WriteLine(num);
        }
    }
}

Measured memory_bytes: 9172
implicit none
INTEGER :: n,i,j,count,challenge_divide
INTEGER,ALLOCATABLE,DIMENSION(:) :: a

READ(5,*) n
ALLOCATE(a(n))
READ(5,*) (a(i),i=1,n)

count = 0

do j=1,1000
    challenge_divide = 0

    do i=1,n
        if (MOD(a(i),2)==0) then
            challenge_divide = challenge_divide+1
        endif
    enddo

    if (challenge_divide==n) then
        count = count+1
        do i=1,n
            a(i) = a(i)/2
        enddo
    else
        exit
    endif
enddo

WRITE(6,*) count

end


Measured memory_bytes: 384
#include <iostream>
#include <list>
#include <bitset>
#include <cmath>

int main()
{
	const int max = 104730;
	std::bitset<max + 1> bitTable;
	
	bitTable.set(0);
	bitTable.set(1);
	
	int loop = sqrt(max);
	
	for (int i = 2; i <= loop; ++i) {
		if (bitTable.test(i) == false) {
			for (int j = i * i; j <= max; j += i) {
				bitTable.set(j);
			}
		}
	}
	
	std::list<int> primeList;
	for (int i = 2; i <= max; ++i) if (bitTable.test(i) == false) primeList.push_back(i);
	
	int n;
	while (std::cin >> n) {
		if (n == 0 || n > 10000) break;
		
		std::list<int>::iterator itr = primeList.begin();
		int num = 0;
		
		for (int i = 0; itr != primeList.end() && i < n; ++itr, ++i) {
			num += *itr;
		}
		
		std::cout << num << std::endl;
	}
	
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  int S=N%10;
  if(S==4 || S==2 || S==5 || S==7 || S==9){
      cout << "hon" << endl;
    }
    else if(S==0 || S==1 || S==6 || S==8){
      cout << "pon" << endl;
    }
    else if(S==3){
      cout << "bon" << endl;
    }
}

Measured memory_bytes: 3596
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

X, K, D = map(int, input().split())

a = abs(X) // D
if K - a <= 0:
    print(abs(X) - K*D)
    sys.exit()

remain = K - a
if remain > 0:
    if remain % 2:
        print(abs(abs(X) - (a+1)*D))
    else:
        print(abs((abs(X) - a * D)))




Measured memory_bytes: 9188
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

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

    ll N, M, K;
    cin >> N >> M >> K;
    vec A(N), B(M);
    Rep (i, N) {
        cin >> A[i];
    }
    Rep (i, M) {
        cin >> B[i];
    }

    vec sa(N+1, 0), sb(M+1, 0);
    Rep (i, N) {
        sa[i+1] = sa[i] + A[i];
    }
    Rep (i, M) {
        sb[i+1] = sb[i] + B[i];
    }

    ll ans = 0;
    Rep (i, N+1) {
        if (sa[i] > K) break;
        ll tmp = i + (upper_bound(sb.begin(), sb.end(), K-sa[i]) - sb.begin()) - 1;
        // cout << i << " " << tmp << "\n";
        chmax(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 9532
def root(v):
    if v == par[v]:
        return v
    par[v] = root(par[v])
    return par[v]

def unite(u, v):
    u = root(u)
    v = root(v)
    if u == v:
        return
    if rank[u] < rank[v]:
        par[u] = v
    else:
        par[v] = u
        if rank[u] == rank[v]:
            rank[v] += 1

def same(u, v):
    u = root(u)
    v = root(v)
    if u == v:
        return 1
    return 0

N, M = map(int, input().split())
P = list(map(int, input().split()))
par = list(range(N))
rank = [0] * N
for _ in range(M):
    x, y = map(int, input().split())
    unite(x-1, y-1)

ans = 0
for i in range(N):
    ans += same(i, P[i] - 1)

print(ans)



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

int main(){
  int N,M;
  cin >> N >> M;
  for (int i=0;i<M;i++){
    int A;
    cin >> A;
    N -= A;
  }
  if (N<0){
    N = -1;
  }
  cout << N << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n) for(ll i=0;i<(n);i++)
#define For1(i,n) for(ll i=1;i<(n);i++)
#define MOD 1000000007

/*ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

ll comb(ll n, ll r){
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}*/
int main(){
    ll n,k;cin>>n>>k;
    vector<vector<ll>> comb(2019,vector<ll>(2019));
    For(i,2019){
        For(j,2019){
            comb.at(i).at(j)=0;
        }
    }
    For(i,2019){
        comb.at(i).at(0)=1;
        comb.at(i).at(i)=1;
    }
    For1(i,2019){
        For1(j,i+1){
            comb.at(i).at(j)=(comb.at(i-1).at(j-1)+comb.at(i-1).at(j))%MOD;
        }
    }
    For1(i,k+1){
        ll ans=0;
        For1(j,i+1){
            ans+=(comb.at(k-1).at(i-1)*comb.at(n-k+1).at(i))%MOD;
        }
        cout<<ans/i<<endl;
    }
    /*For(i,10){
        For(j,i+1){
            cout<<comb.at(i).at(j);
        }
        cout<<endl;
    }*/
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong N;
  vector<llong> V, C;

  cin >> N;
  V.resize(N);
  C.resize(N);
  for (auto &in: V) {
    cin >> in;
  }
  for (auto &in: C) {
    cin >> in;
  }

  llong ans = 0;
  for (int i = 0; i < N; ++i) {
    ans += max(0ll, V[i] - C[i]);
  }

  cout << ans << endl;

  return 0;
}

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

int main()
{
int a, b, c;
cin >> a >> b >> c;

bool kawaisou = false;
if (a == b && b != c) {
        kawaisou = true;
}
else if ((b == c && c != a) || (a == c && c != b)) {
        kawaisou = true;
}

if (kawaisou) {
        cout << "Yes" << endl;

}
else {
        cout <<"No" << endl;
}


}


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

int main()
{
	//input
	int N; cin >> N;
	vector<unsigned int> A(N); 
	for (int i = 0; i < N; i++) cin >> A[i];
	//compute
	int ans = 0;
	int cnt = 0;
	while(1){
		for (int i=0; i<N; i++){
			if(A[i] % 2 != 0) cnt = 1;
			A[i] = A[i] / 2;
		}
		if (cnt == 1) break;
		ans++;
	}
	//output
	cout << ans << endl;
} 

Measured memory_bytes: 256
A,B,M = [int(zz) for zz in input().split()]
lia = [int(zz) for zz in input().split()]
lib = [int(zz) for zz in input().split()]

ans = min(lia)+min(lib)
for _ in range(M):
    x,y,c = [int(zz) for zz in input().split()]
    ans = min(ans,lia[x-1]+lib[y-1]-c)

print(ans)


Measured memory_bytes: 18488
/***********************************************
 *                   _ooOoo_                   *
 *                  o8888888o                  *
 *                  88" . "88                  *
 *                  (| -_- |)                  *
 *                  O\  =  /O                  *
 *               ____/`---'\____               *
 *             .'  \\|     |//  `.             *
 *            /  \\|||  :  |||//  \            *
 *           /  _||||| -:- |||||-  \           *
 *           |   | \\\  -   * |    |           *
 *           | \_|  ''\---/''  |   |           *
 *           \  .-\__  `-`  ___/-. /           *
 *         ___`. .'  /--.--\  `. . __          *
 *      ."" '<  `.___\_<|>_/___.'  >'"".       *
 *     | | :  `- \`.;`\ _ /`;.`/ - ` : | |     *
 *     \  \ `-.   \_ __\ /__ _/   .-` /  /     *
 *======`-.____`-.___\_____/___.-`____.-'======*
 *                   `=---='                   *
 *^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

             佛祖保佑       永无BUG

   本程序已经经过开光处理，绝无可能再产生bug
 **********************************************/
#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define ll long long
#define INF 0x3f3f3f3f
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
using namespace std;

int num[100010];

int main(void)
{
    #ifdef test
    freopen("in.txt","r",stdin);
    //freopen("in.txt","w",stdout);
    clock_t start=clock();
    #endif //test

    int h,n;
    scanf("%d%d",&h,&n);
    for(int i=0;i<n;i++)
        scanf("%d",&num[i]);
    sort(num,num+n);
    for(int i=n-1;i>=0;i--)
    {
        h-=num[i];
//        db2(h,num[i]);
        if(h<=0)
        {
            printf("Yes\n");break;
        }
    }
    if(h>0)printf("No\n");

    #ifdef test
    clockid_t end=clock();
    double endtime=(double)(end-start)/CLOCKS_PER_SEC;
    printf("\n\n\n\n\n");
    cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位
    cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位
    #endif //test
    return 0;
}


// ━━━━━━神兽出没━━━━━━
//      ┏┓       ┏┓
//     ┏┛┻━━━━━━━┛┻┓
//     ┃           ┃
//     ┃     ━     ┃
//     ????━????   ┃
//     ┃           ┃
//     ┃    ┻      ┃
//     ┃           ┃
//     ┗━┓       ┏━┛
//       ┃       ┃
//       ┃       ┃
//       ┃       ┗━━━┓
//       ┃           ┣┓
//       ┃           ┏┛
//       ┗┓┓┏━━━━━┳┓┏┛
//        ┃┫┫     ┃┫┫
//        ┗┻┛     ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━


Measured memory_bytes: 640
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int,int> tp;
// typedef vector<tp> vt;
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;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

//nCr mod m
#define MOD 1000000007
#define M 2200000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}

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

	int n,m;
	cin>>n>>m;
	string s;
	cin>>s;
	priority_queue<pii>q;
	q.push({0,-n});
	vi out(n+1,-1);
	for(int i=n-1;i>=0;i--)if(s[i]-'1'){
		pii p;
		while(1){
			if(q.empty()){
				cout<<-1<<endl;
				return 0;
			}
			p=q.top();
			if(-p.second-i<=m)break;
			q.pop();
		}
		out[i]=-p.second;
		q.push({p.first-1,-i});
	}
	int t=0;
	while(out[t]+1){
		cout<<out[t]-t<<" ";
		t=out[t];
	}
}


Measured memory_bytes: 3188
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define all(m) m.begin(), m.end()
#define uid uniform_int_distribution
#define init(m, x) memset(m, x, sizeof(m));
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ll x, k, d; cin>>x>>k>>d;
    x = abs(x);
    ll full = x/d;
    if(full>=k){
        cout<<x-k*d;
        return 0;
    }
    x -= full*d;
    k -= full;
    ll y = abs(x-d);
    cout<<(k&1 ? y : x);
}

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

using namespace std;

const int maxn = 1e5 + 5;

int vis[maxn];
int main() {
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		vis[x]++;
		if(x - 1 > 0) vis[x - 1]++;
		vis[x + 1]++;
	}
	sort(vis, vis + 100001);
	printf("%d\n", vis[100000]);
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long
#define vi vector<int>

const double PI = 3.14159265358979323846;

int main() {
    int N, K;
    cin >> N >> K;
    cout << (N % K > 0 ? 1 : 0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=200010;
char s[N];
int main() {
    scanf("%s",s);
    int n=strlen(s),ans=n;
    for(int i=0,j=0;i<n;i++)
	if(s[i]=='S') ++j;
	else if(j) --j,ans-=2;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N;
	cin >> N;
	vector<long long> x( N );
	vector<long long> y( N );
	for( int i = 0; i < N; i++ ) {
		cin >> x[i] >> y[i];
	}

	long long zmax = 0;
	long long zmin = INT64_MAX / 2;
	long long wmax = INT64_MIN / 2;
	long long wmin = INT64_MAX / 2;
	for( int i = 0; i < N; i++ ) {
		long long z = x[i] + y[i];
		long long w = x[i] - y[i];
		zmax = max( zmax, z );
		zmin = min( zmin, z );
		wmax = max( wmax, w );
		wmin = min( wmin, w );
	}
	long long ans = max( zmax - zmin, wmax - wmin );

	cout << ans << endl;
}


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

using namespace std;

int n, k;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> k;
    if (k == 1) {
        cout << 0 << endl;
    } else {
        cout << n - k << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }
        private const long MOD = 1000000007;
        
        static void Solve()
        {
            var o = ReadAndParseIntArr();
            int n = o[0];
            int x = o[1];
            var a = ReadAndParseLongArr();

            long ans = GetProcTotal(a, x);
            Console.WriteLine(ans);
        }
        private static long GetProcTotal(long[] b, long x)
        {
            var a = new long[b.Length];
            Array.Copy(b, a, b.Length);
            long ans = 0;
            for (long i = 0; i < a.Length - 1; ++i)
            {
                long t = a[i] + a[i + 1];
                if (t > x)
                {
                    long sub = t - x;
                    ans += sub;

                    if (a[i] > x)
                    {
                        
                        a[i] = x - a[i+1];
                        a[i + 1] = 0;
                    }
                    else
                    {
                        a[i + 1] -= sub;
                    }
                }
            }
            return ans;
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)

#define SORT(c) sort((c).begin(),(c).end())
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
const int MAX = 10001;

struct init{
    init(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
} init;

int N,K;
VI h;

void input(){
  std::cin >> N >> K;
  h.reserve(N+1);
  for (int i = 0; i < N; i++) {
    int tmp; std::cin >> tmp;
    h.PB(tmp);
  }
}


void solve(){
  int ans=INTINF;
  SORT(h);
  REP0(i,N-K+1){
    ans = min( ans, h[K+i-1] - h[i] );
  }
  std::cout << ans << '\n';
}


int main(int argc, char const *argv[]) {
  input();
  solve();

  return 0;
}


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

/*
code credits : ਜ਼ੈਲਦਾਰ
dashan jot singh
*/
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define inf LLONG_MAX
#define p pair<ll,ll>
ll n,k;
ll arr[100010];
ll dp[100010];
ll solve(ll cur){
	if(cur==n-1){
		return 0;
	}
	if(cur>n){
		return 1e11;
	}
	if(cur<0){
		return 1e11;
	}
	if(dp[cur]!=-1){
		return dp[cur];
	}
	ll xx=1e11;
	for(ll i=1;i<=k;i++){
		if(cur+i>=n){
			break;
		}
		else{
			xx=min(xx,abs(arr[cur+i]-arr[cur])+solve(i+cur));
		}
	}
	dp[cur]=xx;
	return dp[cur];
}
int main(){
	fast;
	cin>>n>>k;
	for(ll i=0;i<n;i++){
		cin>>arr[i];
	}
	memset(dp,-1,sizeof(dp));
	cout<<solve(0)<<endl;
	return 0;
}

Measured memory_bytes: 6528
N,K = map(int,input().split())
*A, = map(int,input().split())
A.sort()

mod = 10**9+7

m = 10**5 +1 
fac = [1]*m
ninv = [1]*m
finv = [1]*m
for i in range(2,m):
    fac[i] = fac[i-1]*i%mod
    ninv[i] = (-(mod//i)*ninv[mod%i])%mod
    finv[i] = finv[i-1]*ninv[i]%mod

def comb(n,k):
    return (fac[n]*finv[k]%mod)*finv[n-k]%mod

ans = 0
for i,a in enumerate(A):
    if K-1 > N-i-1: break
    ans -= a * comb(N-1-i,K-1)
    ans %= mod
for i,a in enumerate(A[::-1]):
    if K-1 > N-i-1: break
    ans += a * comb(N-1-i,K-1)
    ans %= mod
print(ans)

Measured memory_bytes: 20244
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repA(i,a,b) for(int i=a;i<=b;i++)
#define repD(i,b,a) for(int i=b;i>=a;i--)
#define fill(a) memset(a,0,sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main(){
    int n,m;
    cin>>n>>m;
    int h[n];
    repA(i,1,n)
    cin>>h[i];
    int check[n];
    repA(i,1,n)
    check[i]=1;
    int res=0;
    rep(i,0,m)
    {
        int a,b;
        cin>>a>>b;
        if(h[a]<h[b]){
            check[a]=0;
            //cout<<a<<endl;
        }
        else if(h[b]<h[a])
            check[b]=0;
        else
        {
            check[a]=0;
            check[b]=0;
        }

    }
    repA(i,1,n)
    {
        if(check[i]==1)
            res++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 4372
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  char s[101], t[101] ;
  scanf("%s %s", s, t);

  printf("%s%s\n", t, s);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define _printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printV(vec) cout<<#vec<<":";_printV(vec)
#define _printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define printA(arr) cout<<#arr<<":";_printA(arr,sizeof(arr)/sizeof(arr[0]))
#define LLINF = (1LL<<62)
#define puts(var) cout<<#var<<":"<<var<<" "
typedef long long ll;

ll lcm( int m, int n )
{
	return (m / __gcd(m, n) * n);
}
 
 
int main()
{
  int N,M;
  cin >> N >> M;
  string S;
  string T;
  cin >> S;
  cin >> T;
 
 
  int step = __gcd(N,M);

  // cout << step << endl;
  for(int i=0;i<step;i++){
    // printf("===== i %d\n",i);
    // cout << L/M <<endl;
    // cout <<"S:" << S[i*N/step] << endl;
    // cout << L/N <<endl;
    // cout <<"T:" << T[i*M/step] << endl;
    if(S[i*N/step] != T[i*M/step]){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << (ll) N/step*M << endl;
  return 0;
}

Measured memory_bytes: 512
//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

const assert = require('assert');

const SIZE = 8;

rc = require('fs').readFileSync(config.input, 'ascii')
  .trim()
  .split(config.newline);
k = rc.shift();

b = new Array(SIZE);
function getInitialRow() {
  var res = new Array(SIZE), i;
  for (i = 0; i < SIZE; i++) res[i] = false;
  return res;
}
for (i = 0; i < SIZE; i++) b[i] = getInitialRow();

rest_row = getInitialRow();
rest_col = getInitialRow();
cnt = 0;

function place(r, c) {
  assert(!rest_row[r]);
  assert(!rest_col[c]);
  assert(!b[r][c]);
  assert(cnt < SIZE);
  rest_row[r] = true;
  rest_col[c] = true;
  b[r][c] = true;
  cnt++;
}

function remove(r, c) {
  assert(rest_row[r]);
  assert(rest_col[c]);
  assert(b[r][c]);
  assert(cnt > 0);
  rest_row[r] = false;
  rest_col[c] = false;
  b[r][c] = false;
  cnt--;
}

function diagonal_check(r, c) {
  var r_init = r, c_init = c;
  while (r > 0 && c > 0) { r--; c--; if (b[r][c]) return false; }
  r = r_init, c = c_init;
  while (r > 0 && c < SIZE - 1) { r--; c++; if (b[r][c]) return false; }
  r = r_init, c = c_init;
  while (r < SIZE - 1 && c > 0) { r++; c--; if (b[r][c]) return false; }
  r = r_init, c = c_init;
  while (r < SIZE - 1 && c < SIZE - 1) { r++; c++; if (b[r][c]) return false; }
  return true;
}

for (i in rc) {
  ary = rc[i].split(' ');
  place(ary[0], ary[1]);
}

function find() {
  var i, j;
  if (cnt === 8) return true;
  for (i in rest_row) {
    if (rest_row[i]) continue;
    for (j in rest_col) {
      if (rest_col[j]) continue;
      if (!diagonal_check(i, j)) continue;
      place(i, j);
      if (find()) return true;
      remove(i, j);
    }
  }
  return false;
}

find();
for (i in b) {
  console.log(
    b[i].map(function (flag) { return flag ? 'Q' : '.'; })
        .join(''));
}

Measured memory_bytes: 17372
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

signed main(void) {
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    rep(i,n)if(s[i] == 'J'){
        int a = 0, b = 0, c = 0;
        while(i < n && s[i] == 'J'){
            i++,a++;
        }
        while(i < n && s[i] == 'O'){
            i++,b++;
        }
        while(i < n && s[i] == 'I'){
            i++,c++;
        }
        i--;
        if(a < b || c < b)continue;
        ans = max(ans,b);
    }
    cout << ans << endl;

}



Measured memory_bytes: 3988
import bisect


class BTreeNode:
    def __init__(self):
        self.key = []
        self.child = []


class BTree:
    def __init__(self):
        self.root = BTreeNode()

    def search_higher(self, key):
        ptr = self.root
        ret = None
        while ptr.child:
            i = bisect.bisect_right(ptr.key, key)
            if i != len(ptr.key):
                ret = ptr.key[i]
            ptr = ptr.child[i]
        i = bisect.bisect_right(ptr.key, key)
        if i != len(ptr.key):
            ret = ptr.key[i]
        return ret

    def search_lower(self, key):
        ptr = self.root
        ret = None
        while ptr.child:
            i = bisect.bisect_left(ptr.key, key)
            if i != 0:
                ret = ptr.key[i - 1]
            ptr = ptr.child[i]
        i = bisect.bisect_left(ptr.key, key)
        if i != 0:
            ret = ptr.key[i - 1]
        return ret

    def insert(self, key):
        def insert_rec(ptr):
            b_size = 512
            if not ptr.child:
                bisect.insort(ptr.key, key)
                if len(ptr.key) == b_size * 2 - 1:
                        ret = BTreeNode()
                        ret.key = ptr.key[:b_size]
                        ptr.key = ptr.key[b_size:]
                        return ret
            else:
                i = bisect.bisect(ptr.key, key)
                temp = insert_rec(ptr.child[i])
                if temp is not None:
                    ptr.key.insert(i, temp.key.pop(-1))
                    ptr.child.insert(i, temp)
                    if len(ptr.child) == b_size * 2:
                        ret = BTreeNode()
                        ret.child = ptr.child[:b_size]
                        ptr.child = ptr.child[b_size:]
                        ret.key = ptr.key[:b_size]
                        ptr.key = ptr.key[b_size:]
                        return ret
            return None
        temp = insert_rec(self.root)
        if temp is not None:
            root = BTreeNode()
            root.key = [temp.key.pop(-1)]
            root.child = [temp, self.root]
            self.root = root

    def dump(self):
        def dump_rec(ptr, dep):
            for _ in range(0, dep):
                print("  ", end="")
            print(ptr.key)
            for c in ptr.child:
                dump_rec(c, dep + 1)
        dump_rec(self.root, 0)
        print("")


def main():
    n = int(input())
    p = list(map(int, input().split()))
    idx = [0] * n
    for i in range(0, n):
        idx[i] = i
    idx.sort(key=lambda i: - p[i])
    t = BTree()
    t.insert(-1)
    t.insert(n)
    ans = 0
    for i in idx:
        nex = t.search_higher(i)
        nexnex = t.search_higher(nex)
        pre = t.search_lower(i)
        prepre = t.search_lower(pre)
        if prepre != None:
            ans += p[i] * (pre - prepre) * (nex - i)
        if nexnex != None:
            ans += p[i] * (i - pre) * (nexnex - nex)
        t.insert(i)
    print(ans)


main()


Measured memory_bytes: 99308
#include <stdio.h>

int main(void)
{
	int a,b,c,d,i;
	d=0;
	while(1)
	{
		c=0;
		scanf("%d%d",&a,&b);
		if(a==0&&b==0)
		{
			break;
		}
		if(d==1)
		{
			printf("\n");
		}
		for(i=a;i<=b;i++)
		{
			if(i%400==0)
			{
				printf("%d\n",i);
				c=1;
			}
			if(i%4==0)
			{
				if(i%100!=0)
				{
					printf("%d\n",i);
					c=1;
				}
			}
		}
		if(c==0)
		{
			printf("NA\n");
		}
		d=1;
	}
	
	return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)

const ll mod = (ll)1e9+7;
const ll maxn = (ll)2e5+5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};


void solve(){
	queue < ll > q;
	ll k;
	cin >> k;
	for(ll i = 1; i <= 9; i++){
		q.push(i);
	}
	while(--k){
		ll s = q.front();
		q.pop();
		if(s%10 != 0) q.push((s*10LL)+((s%10)-1));
		q.push((s*10LL)+((s%10)));
		if(s%10 != 9) q.push((s*10LL)+((s%10)+1));
	}
	cout << q.front();
	return;
}


int main() {
   
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
   // cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}
    
    return 0;
}


Measured memory_bytes: 4792
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;

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

int sheet[101][101];

int main()
{	
	int r, c;
	cin >> r >> c;

	for (int i = 0; i < r; i++)
	{
		for (int j = 0; j < c; j++)
		{
			cin >> sheet[i][j];
			sheet[i][c] += sheet[i][j];
			sheet[r][j] += sheet[i][j];
			sheet[r][c] += sheet[i][j];
		}
	}

	for (int i = 0; i < r+1; i++)
	{
		cout << sheet[i][0];

		for (int j = 1; j < c+1; j++)
		{
			cout << " " << sheet[i][j];
		}

		cout << endl;
	}
	

	return 0;
}



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

#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int N;
int K;
int M[103];
int p[103][103];
int l[103];

bool check(int i_) {
    rep(i,K) {
        rep(j,M[i_]) {
            if(l[i]==p[i_][j]) {
                goto go;
            }
        }
        return false;
go:;
    }
    return true;
}

void solve() {
    rep(i,103) {
        rep(j,103) p[i][j]=0;
        M[i]=0;
        l[i]=0;
    }
    rep(i,N) {
        cin>>M[i];
        rep(j,M[i]) {
            cin>>p[i][j];
        }
    }
    cin>>K;
    rep(i,K) cin>>l[i];

    int ans = 0;
    rep(i,N) {
        if(check(i)) {
            if(ans==0) ans=i+1;
            else ans = -1;
        }
    }
    if(ans==0) ans=-1;
    cout<<ans<<endl;
}

int main() {
    while(cin>>N) {
        if(!N) return 0;
        solve();
    }

    return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=210;
struct as{
    int x;
    int y;
}a[maxn],b[maxn];
bool cmp(struct as p1,struct as p2)
{
    if(p1.x!=p2.x)
    return p1.x<p2.x;
    else
    return p1.y<p2.y;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    scanf("%d%d",&a[i].x,&a[i].y);
    for(int i=1;i<=n;i++)
    scanf("%d%d",&b[i].x,&b[i].y);
    sort(a+1,a+1+n,cmp);
    sort(b+1,b+1+n,cmp);
    int flag1[105];
    memset(flag1,0,sizeof(flag1));
    int tmp=0;
    for(int i=1;i<=n;i++)
    {
        int minn=-1,h=0;
        for(int j=1;j<=n;j++)
        {
          if(a[j].x<b[i].x&&a[j].y<b[i].y&&flag1[j]==0)
          {
              h++;
              if(h==1)
              minn=j;
              else
              {
              if(a[j].y>a[minn].y)
               minn=j;
              }
          }
        }
        if(minn>0)
        {
        flag1[minn]=1;
        tmp++;
        }

    }
    printf("%d\n",tmp);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

void solve()
{   
    int x;
    cin>>x;
    cout<<1-x<<'\n';
}
int main(){
    IOS;
    int tt;
    tt = 1;
    // cin>>tt;
    int i = 1;
    while(tt--){
        // cout<<"tc "<<i<<" ";
        solve();
        i++;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;

void solve()
{
	int n;
	string s;
	cin>>n;
	string arr[] = {"AC", "WA", "TLE", "RE"};
	map<string, int> mp;
	REP(i,n)
	{
		cin>>s;
		mp[s]++;
	}	
	REP(i, 4)
	{
		cout<<arr[i]<<" x "<<mp[arr[i]]<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int n;
  cin >> n;
  int to=n;
  int bl=0;
  int wh=0;
  vector<int>w(n+1);
  vector<int>b(n+1);
  vector<char>x(n);
  rep(i,n){
    cin>>x.at(i);
  }
  rep(i,n){
    if(x.at(i)=='#'){
      bl++;
    }
    w.at(i+1)=bl;
  }
  for (int i = n-1; i >=0; i--){
    if(x.at(i)=='.'){
      wh++;
    }
    b.at(i)=wh;
  }
  rep(i,n){
    to=min(to,w.at(i)+b.at(i+1));
  }  
  cout<<to<<endl;  
}

Measured memory_bytes: 2048
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	long ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

signed main() {
	int a, b;
	cin >> a >> b;
	a--; b--;
	if (b % a == 0)cout << b / a << endl;
	else cout << (b / a) + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W; cin >> H >> W;
  vector<string> S(H);
  REP(i, H){
    cin >> S[i];
  }
  REP(i, W+2){
    cout << "#";
  }
  cout << endl;
  REP(i, H){
    cout << "#" << S[i] << "#" << endl;
  }
  REP(i, W+2){
    cout << "#";
  }
  cout << endl; 
}

Measured memory_bytes: 3660
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

static const int NMAX = 2*1e5+5;

vector<int> ct(NMAX);
vector<int> v[NMAX];

vector<int> visited;

void dfs(int node)
{
    visited[node] = true;
    for(auto &child : v[node])
    {
        if(!visited[child])
        {
            ct[child]+=ct[node];
            dfs(child);
        }
    }
}

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

    int n,q;
    cin >>n >> q;
    ct.resize(n+1); 
    visited.resize(n+1);
    for(int i =0; i < n-1; ++i)
    {
        int a,b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i = 0; i< q; ++i)
    {
        int p, x;
        cin >> p >> x;
        ct[p]+=x;
    }
    dfs(1);
    for(int i=  1; i <=n ; ++i)
    {
        cout << ct[i] << " ";
    }
    return 0;
}

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

template <i64 p>
class fp {
    public:
    i64 x;
    fp() : x(0) {}
    fp(i64 x_) : x((x_ % p + p) % p) {}
    fp operator+() const { return fp(x); }
    fp operator-() const { return fp(-x); }
    fp& operator+=(const fp& y) {
        x += y.x;
        if (x >= p) x -= p;
        return *this;
    }
    fp& operator-=(const fp& y) { return *this += -y; }
    fp& operator*=(const fp& y) {
        x = x * y.x % p;
        return *this;
    }
    fp& operator/=(const fp& y) { return *this *= fp(inverse(y.x)); }
    fp operator+(const fp& y) const { return fp(x) += y; }
    fp operator-(const fp& y) const { return fp(x) -= y; }
    fp operator*(const fp& y) const { return fp(x) *= y; }
    fp operator/(const fp& y) const { return fp(x) /= y; }
    bool operator==(const fp& y) const { return x == y.x; }
    bool operator!=(const fp& y) const { return !(*this == y); }
    i64 extgcd(i64 a, i64 b, i64& x, i64& y) {
        i64 d = a;
        if (b != 0) {
            d = extgcd(b, a % b, y, x);
            y -= (a / b) * x;
        } else {
            x = 1;
            y = 0;
        }
        return d;
    }
    i64 inverse(i64 a) {
        i64 x, y;
        extgcd(a, p, x, y);
        return (x % p + p) % p;
    }
};

template <i64 p>
i64 abs(const fp<p>& x) { return x.x; }

template <i64 p>
ostream& operator<<(ostream& os, const fp<p>& x) {
    os << x.x;
    return os;
}

template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "[";
    for (const auto& v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

template <typename A, typename T, size_t size>
void fill(A (&ary)[size], const T& val) {
    fill((T*)ary, (T*)(ary + size), val);
}

constexpr int inf = 1.01e9;
constexpr i64 inf64 = 4.01e18;
constexpr double eps = 1e-9;

void solve() {
    //constexpr i64 mod = 1'000'000'007;
    i64 A,B,C;
    cin >> A >> B >> C;
    cout << max(i64(0),C-(A-B)) << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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


using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  if (a > 0){
    cout << "Positive" << endl;
  }else if ((a <= 0) && (b >= 0)){
    cout << "Zero" << endl;    
  }else if (b == 0){
    cout << "Zero" << endl;
  }else{//a < 0 && b < 0;
    if (((b-a)+1) % 2 == 0){
      cout << "Positive" << endl;
    }else{
      cout << "Negative" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i <= (n); i++)
#define MOD 1000000007
using ll = long long;
typedef pair<int, int> P;

int main(){
    int n,k,m;
    cin>>n>>k;k--;
    rep(i,n){
        if(m==1) continue;
        int a;
        cin>>a;
        if(a==1){
            m=i;
        }
    }
    int ans=(m-1)/k+((m-1)%k!=0);
    n-=(m-1)%k;
    ans+=(n-m)/k+((n-m)%k!=0);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3580
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;

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

  // string s;
  // cin >> s;
  // if (s[2] == s[3] && s[4] == s[5]) {
  //   cout << "Yes";
  // } else {
  //   cout << "No";
  // }

  int x;
  cin >> x;
  int tot = 0;
  tot += 1000 * (x / 500);
  x %= 500;
  tot += 5 * (x / 5);
  cout << tot;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
   char m[100010];
   int a,b;
   while (cin>>m)
    {
       a=strlen(m);
       if (m[0]==m[a-1])
	   b=a-3;
       else 
	   b=a-2;
       if (b%2==1)
	   cout<<"First"<<endl;
       else 
	   cout<<"Second"<<endl;
    }
   return 0;
}

Measured memory_bytes: 764