akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

typedef long long int ll;

std::vector<ll> enum_div(ll n);
long long comb(int n, int r);
bool IsPrime(int num);
bool dp[110][10010];
class UnionFind;
using Graph = vector<vector<int>>;

//自作関数一覧---------------------------
ll gcd(ll a, ll b); //最小公倍数の導出
ll lcm(ll x, ll y); //最大公約数の導出
ll bur(ll N, ll X); //??
//---------------------------------------

//UF木
class UnionFind {
public:
	//親
	vector<int> Parent;

	//初期状態
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//サイズ確認
	int size(int A) {
		return -Parent[root(A)];
	}

	int connect(int A, int B) {
		//root同氏をくっつける
		A = root(A);
		B = root(B);

		//結合済み
		if (A == B) {
			return false;
		}
		//大きいほうに小さいほうをくっつける
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズ更新
		Parent[A] += Parent[B];
		//Bの親をAに
		Parent[B] = A;

		return true;
	}

};

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;


	string S, T;
	char fi[50], fv[50];
	char board[4][4];
	bool start = false;
	ll left = 0, right = 0;
	cin >> N >> A;
	
	vector<ll> dis(A);
	rep(i, 0, A)
		cin >> dis[i];
	
	ll max = N;
	while (true) {
		B = max;
		while (B > 0) {

			C = B % 10;

				rep(i, 0, A) {
					if (C == dis[i])
						start = true;

					//cout << C << dis[i] << endl;

			}
				B /= 10;

		}

		if (start == false) {
			cout << max << endl;
			return 0;
		}

		max++;
		start = false;
	}


	cout << bur(N,A) << endl;

	return 0;
}


std::vector<ll> enum_div(ll n)//nの約数を列挙
{
	vector<ll> res;
	for (int i = 1; i*i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}








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;
}



//combination
long long comb(int n, int r) {
	std::vector<std::vector<long long>> v(n + 1, std::vector<long long>(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v[n][r];
}
ll gcd(ll a, ll b) {

	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y / b*x;
}

// 最大公約数を求める関数
ll lcm(ll x, ll y)
{
	if (x == 0 || y == 0)  // 引数チェック
	{
		//fprintf(stderr, "引数エラーです。\n");
		return 0;
	}

	return (x * y / gcd(x, y));
}

ll bur(ll N, ll X) {
	ll pan = 1;
	ll pat = 1;
	ll burg = 0;



	if (X > burg) {
		if (N == 0)
			return pat;


		burg += pan;
		burg += bur(N - 1, X);
		burg += pat;
		burg += bur(N - 1, X);
		burg += pan;


	}

	return burg;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

bool compare_pair(pair<string, int>, pair<string, int>);

void solve(istream& cin, ostream& cout) {
  int N;
  cin >> N;
  map<string, int> m;
  REP(i, N) {
    string str;
    cin >> str;
    m[str]++;
  }
  vector<pair<string, int> > V;
  auto begin = m.begin(), end = m.end();
  for(auto i = begin; i != end; i++) {
    V.push_back(make_pair(i->first, i->second));
  }
  sort(V.begin(), V.end(), compare_pair);
  int max = V[0].second;
  REP(i, V.size()) {
    if (max != V[i].second) break;
    cout << V[i].first << endl;
  }
}

bool compare_pair(pair<string, int> a, pair<string, int> b) {
  // 出現回数の降順
  if (a.second != b.second) {
    return a.second > b.second;
  }
  // アルファベット順
  if (a.first != b.first) {
    return a.first < b.first;
  } else {
    return true;
  }
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 28016
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  int n;
  cin>>n;
  int m;
  cin>>m;
  int mx = m;
  REP(i,n){
    int in,out;
    cin>>in>>out;
    m += in - out;
    if (m < 0) {
      mx = 0;
      break;
    }
    mx=max(mx,m);
  }
  cout<<mx<<endl;
  return 0;
}

Measured memory_bytes: 1160
#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++)
#define _GLIBCXX_DEBUG

int main(){
    int N, ansa=0, ansb=0;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];

    sort(a.begin(), a.end(), greater<int>());

    int* ptr = &a[0];
    while(ptr <= &a[N-1]){
        ansa += *ptr++;
        if(ptr <= &a[N-1]) ansb += *ptr++;
    } 
    cout << ansa - ansb << endl;
}

Measured memory_bytes: 3600
H,W = map(int,input().split())
A = [list(input()) for _ in range(H)]
for h in range(H):
  if A[h].count('.') == W:
    for w in range(W):
      A[h][w] = ''
for h in range(H):
  for w in range(W):
    if A[h][w] == '.':
      for i in range(H):
        if A[i][w] == '#':
          break
        if i == H-1:
          for j in range(H):
            A[j][w] = ''

for i in range(H):
  if ''.join(A[i]) == '':
    continue
  print(''.join(A[i]))

Measured memory_bytes: 3188
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            StringBuilder sb = new StringBuilder("Christmas");
            for (int i = 0; i < 25 - n; i++) {
                sb.append(" Eve");
            }

            out.println(sb.toString());
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



Measured memory_bytes: 21328
#include <bits/stdc++.h>
 
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long int ll;
using namespace std;

struct edge {
    int to, cost; 
    edge(int t, int c): to(t), cost(c) {}
};
const int INF = 1e8;

void dijkstra(const vector<vector<edge> > &G, vector<int> &d, const int s) {
    d.assign(d.size(), INF);
    d[s] = 0;
    typedef pair<int, int> P;
    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0, s));

    while(!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(void) {
    int n, m, s, g1, g2;
    while(cin >> n >> m >> s >> g1 >> g2 && n) {
        vector<vector<edge> > G(n);
        vector<vector<int> > d(n, vector<int>(n));
        --s; --g1; --g2;
        REP(i, m) {
            int b1, b2, c;
            cin >> b1 >> b2 >> c;
            G[b1-1].push_back(edge(b2-1, c));
        }
        REP(i, n) {
            dijkstra(G, d[i], i);
        }
        int ans = 0;
        int cost = numeric_limits<int>::max();
        REP(i, n) {
            cost = min(cost, d[s][i] + d[i][g1] + d[i][g2]);
        }
        cout << cost << endl;
    }
    return 0;
}

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

#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define FILL(v,p) memset(v,p,sizeof v)
#define FIO ios::sync_with_stdio(NULL); cin.tie(NULL)
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define PI acos(-1.0)

const ll MOD = 1000000007;
const ll INF = 2000000000000000001LL;
const ld EPS = 1e-9;

int main()
{
    FIO;
    
    ll n, r;
    cin >> n >> r;
    
    ll in=0;
    
    if(n<10) in = 100*(10-n);
    
    cout << r+in << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
const int MAXN=100005;

int n;
char str[MAXN];
int cnt[30];

int main()
{
	scanf("%s",str+1);
	n=strlen(str+1);
	if(n==2)
	{
		if(str[1]==str[2])
			puts("1 2");
		else
			puts("-1 -1");
		return 0;
	}
	for(int i=1;i+2<=n;i++)
	{
		if(str[i]==str[i+1]||str[i]==str[i+2]||str[i+1]==str[i+2])
		{
			printf("%d %d\n",i,i+2);
			return 0;
		}
	}
	puts("-1 -1");
	
	return 0;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <vector>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <algorithm>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <bits/stdc++.h>

#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define mod 1000000007
#define pii pair <int, int>
#define all(x) x.begin(), x.end()
#define FOR(i, x, y) for (int i = x; i <= y; i++)
//#define tr(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

//using namespace __gnu_pbds;

using namespace std;

//template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct st{
	int a, b, c;
} T[44];

int n, x, y;

int dp[555][555];

void tap(int p)
{
	for (int i = 400; i >= 0; i--)
		for (int h = 400; h >= 0; h--)
			if (dp[i][h]!=inf)
				dp[i+T[p].a][h+T[p].b] = min(dp[i+T[p].a][h+T[p].b], dp[i][h]+T[p].c);
}

int main()
{
	cin >> n >> x >> y;
	
	FOR (i, 1, n)
		cin >> T[i].a >> T[i].b >> T[i].c;
	
	FOR (i, 0, 400)
		FOR (h, 0, 400)
			dp[i][h] = inf;
	
	dp[0][0] = 0;
	FOR (i, 1, n)
		tap(i);
	
	int mn = inf;
	FOR (i, 1, 400)
		FOR (h, 1, 400) {
			int gc = __gcd(i, h);
			if (dp[i][h]!=inf && i/gc==x && h/gc==y) {
				mn = min(mn, dp[i][h]);
			}
		}
	
	if (mn == inf)
		mn = -1;
	cout << mn;
}


Measured memory_bytes: 1152
#include <iostream>
#include<map>
#include<string>

using namespace std;

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

	int num;
	for (int i = 3; i <= n; i++) {
		if (i % 3 == 0) {
			cout << " " << i; continue;
		}
		num = i;
		for (int j = 0; j < 4; j++) {
			if (num % 10 == 3) {
				cout << " " << i;
				break;
			}
			num /= 10;
		}
	}
	cout<<endl;

	return 0;
}


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

int main() {
  string w;
  cin >> w;
  int c=0;
  for(int i=0; i < w.size() ; i++){
    for(int j=0; j < w.size() ; j++){
      if(w.at(i) == w.at(j)) c++;
    }
    if(c % 2 ==1){
      cout << "No" ;
      return 0;
    }
  }
  cout << "Yes" ;
}


Measured memory_bytes: 3560
N, W = map(int, input().split())
wv = []
for _ in range(N):
    wv.append(list(map(int, input().split())))
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(N):
    for j in range(W+1):
        if j >= wv[i][0]:
            dp[i+1][j] = max(dp[i][j], dp[i][j-wv[i][0]]+wv[i][1])
        else:
            dp[i+1][j] = dp[i][j]
print(dp[N][W])

Measured memory_bytes: 120044
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>

using namespace std;
typedef long long ll;

int main(){
  ll q, h, s, d, n;
  cin >> q >> h >> s >> d;
  cin >> n;

  ll buy1 = min(min(q*4, h*2), s);
  ll buy2 = min(buy1*2, d);
  cout << (n / 2) * buy2 + (n % 2) * buy1 << endl;
  return 0;
}


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

int main() {
    int n,m;
    cin>>n>>m;
    int *a= new int[n];
    int votes=0;
    for(int i=0; i<n; i++){
        cin>>a[i];
        votes += a[i];
    }
    float check = (1.0/(4*m*1.0))*(votes*1.0);
    
    sort(a, a+n, greater<int>());
    int i;

    for(i=0; i<m; i++)
    {
        if(a[i] < (check)) 
        {
            cout<<"No";
            return 0;
        }
    }
    
    cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iterator>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  
  vector<int> x;
  vector<int> y;
  
  rep(i, N) {
    int xi;
    cin >> xi;
    x.push_back(xi);
  }
  
  rep(i, M) {
    int yi;
    cin >> yi;
    y.push_back(yi);
  }
  
  int maxx;
  int miny;

  auto maxIt = max_element(x.begin(), x.end());
  auto minIt = min_element(y.begin(), y.end());
  
  size_t maxIndex = distance(x.begin(), maxIt);
  size_t minIndex = distance(y.begin(), minIt);
  
  maxx = x[maxIndex];
  miny = y[minIndex];
  
  int Z ;
  string res = "War";
  for (int i = -100; i < 101 ; ++i){
    Z = i;
    
    if (X < Z && Z <= Y) {
      
      if (maxx < Z && miny >= Z) {
        res = "No War";
      }
    }
  }
  cout << res;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int D;
vector<LL> c(26);
vector<vector<LL>> s;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

LL solve(const vector<LL>& t) {
  LL ans = 0;
  vector<LL> last(26, 0);
  for (int d = 1; d <= D; ++d) {
    int i = d - 1;
    int j = t[i];
    last[j] = d;
    ans += s[i][j];
    for (int k = 0; k < 26; ++k) {
      ans -= c[k] * (d - last[k]);
    }
  }
  return ans;
}

int main() {
  cin >> D;
  cin >> c;
  s.resize(D, vector<LL>(26, 0));
  for (int i = 0; i < D; ++i) cin >> s[i];

  vector<LL> t(D);
  for (int d  =  0; d < D; ++d) t[d] = rand() % 26;

  LL prev = solve(t);
  int d = 0;
  for (int i = 0; i < 10000; ++i) {
    auto best_t = t;
    for (int j = 0; j < 26; ++j) {
      t[i % D] = j;
      LL score = solve(t);
      if (score > prev) {
        prev = score;
        best_t = t;
      }
    }
    t = best_t;
  }

  for (int x : t) cout << x + 1 << endl;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int l,r,d;
  cin>>l>>r>>d;
  int ans=0;
  for(int i=l;i<=r;i++){
    if(i%d==0){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
string S[100];

int main() {
    ll A,B;
    cin >> A >>B;
    --A;--B;
   
    for(int i=0;i<50;i++){
        string s ="";
        for(int j=0;j<100;j++){
            if(A>0 &&i%2 ==1 && j%2==1){
                --A;
                s+=".";
            }else{
                 s += "#";
            }
        }
        S[i] = s;
    }
    for(int i=50;i<100;i++){
        string s ="";
        for(int j=0;j<100;j++){
            if(B>0 &&i%2 ==1 && j%2==1){
                --B;
                s+="#";
            }else{
                 s += ".";
            }
        }
        S[i] = s;
    }
    cout <<"100 100"<<endl;
    for(int i=0;i<100;i++){
        cout <<S[i] << "\n";
    }


    return 0;
}

Measured memory_bytes: 3624
n,y=map(int,input().split())
for i in range(n+1):
	if 10000*i > y:
		break
	for j in range(n+1-i):
		if 10000*i+5000*j > y:
			break
		elif 10000*i+5000*j+1000*(n-i-j) == y:
			print(i, j, n-i-j)
			exit()
print(-1, -1, -1)

Measured memory_bytes: 3060
H, W = map(int, input().split())

amap = [list(map(int, input().split())) for i in range(H)]
bmap = [list(map(int, input().split())) for i in range(H)]
dist_map = [[amap[y][x] - bmap[y][x] for x in range(W)] for y in range(H)]

mid = 80 * 80 * 5 // 2
# mid = 20
dp = [[1 << mid] * W for y in range(H)]

dp[0][0] = ((1 << (dist_map[0][0] + mid)) | (1 << (mid - dist_map[0][0])))


for x in range(1, W):
    y = 0
    d = abs(dist_map[y][x])
    dp[y][x] = (dp[y][x - 1] << d) | (dp[y][x - 1] >> d)


for y in range(1, H):
    x = 0
    d = abs(dist_map[y][x])
    dp[y][x] = (dp[y - 1][x] << d) | (dp[y - 1][x] >> d)


for y in range(1, H):
    for x in range(1, W):
        d = abs(dist_map[y][x])
        dp[y][x] = (dp[y][x - 1] << d) | (dp[y][x - 1] >> d) | ((dp[y - 1][x] << d) | (dp[y - 1][x] >> d))


ans = dp[-1][-1]

for i in range(mid + 1):
    if (ans & (1 << (mid - i))) or (ans & (1 << (mid + i))):
        print(i)
        exit()


Measured memory_bytes: 22516
# -*- coding: utf-8 -*-
"""
Created on Sat Aug  4 15:31:00 2018

@author: maezawa
"""

n, k = list(map(int, input().split()))
d = frozenset(list(map(str, input().split())))
ok = frozenset(list(map(str,range(10)))) - d

for i in range(n, 100000):
    if frozenset(str(i)) <= ok:
        print(i)
        break



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i)
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
    ~debug() { cerr << endl; }
eni(!=) { cerr << boolalpha << i; ris; }
eni(==) { ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << &", " [ 2 * (it == d.b)] << *it;
  ris << "]";
}
#else
    sim dor(const c&) { ris; }
#endif
};
#define imie(...) "" << #__VA_ARGS__ " = " << (__VA_ARGS__) << ""
#define arr array
using ll = long long;
const int INF = 1e9 + 5;
const int N = 1e6 + 5;

int main() {
	int x;
	cin >> x;
	cout << ((x >= 30)?"Yes":"No");
    


    return 0;
}




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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N;
  cin >> N;
  cout << (1000 - N % 1000) % 1000 << "\n";
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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; }

const long long INF = 1LL << 60;

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

  cout << (a+b>=c ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
  int A, B;
  
  scanf("%d", &A);
  scanf("%d", &B);
  
  if(B % A == 0) {
    printf("%d\n", A + B);
  } else {
    printf("%d\n", B - A);
  }
  
  return 0;
}


Measured memory_bytes: 128
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
difVel = V - W
if (difVel < 0):
  print("NO")
else:
  if ( (difVel*T) < abs(B-A) ):
    print("NO")
  else:
    print("YES")
    
  

Measured memory_bytes: 9176
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
	int t;
	string s;
	while (cin >> t >> s && t){
		int sum = 0, n = s.length();
		bool rej = 0;
		VI ans;
		REP(i,1<<(n-1)){
			VI res;
			int x = 0;
			REP(j,n){
				x = 10*x + s[j] - '0';
				if ((i>>j) & 1){
					res.push_back(x);
					x = 0;
				}
			}
			res.push_back(x);
			int p = 0;
			REP(j,res.size()) p += res[j];
			if (p > t) continue;
			if (p > sum){
				sum = p;
				ans = res;
				rej = 0;
			}else if (p == sum){
				rej = 1;
			}
		}
		if (rej) {
			cout << "rejected" << endl;
		}else if (sum == 0){
			cout << "error" << endl;
		}else{
			cout << sum;
			REP(i,ans.size()) cout << " " << ans[i];
			cout << endl;
		}
	}
    return 0;
}

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

int main(void){
	string str;
	while(cin >> str){
		string ans;
		bool ch=true;
		if(str.size()%2==1)cout << "NA" << endl;
		else{
			for(int i=0;i<str.size();i+=2){
				
				if(str[i]>='1' && str[i]<='6' && str[i+1]>='1' && str[i+1]<='5'){
					if(str[i]=='6' && str[i+1]=='2')ans+=".";
					else if(str[i]=='6' && str[i+1]=='3')ans+="?";
					else if(str[i]=='6' && str[i+1]=='4')ans+="!";
					else if(str[i]=='6' && str[i+1]=='5')ans+=" ";
					else ans+=(str[i]-'1')*5+(str[i+1]-'1')+'a';
				}else{
					ch=false;
					break;
				}
			}
			if(ch==true)cout << ans << endl;
			else cout << "NA" << endl;
		}
	}
    return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




class BIT
{
private:
    long long b;    // bit.size() < 2^n になる最小の2^n
    vector<long long> bit;
public:
    BIT(long long n);   // nは要素数
    long long sum(long long i); // iまでの合計
    void add(long long i, long long x); // i番目にxを加算
    long long lower_bound(long long x); // x番目に小さい値を返す
};

BIT::BIT(long long n){
    bit.resize(n + 1);
    
    b = 1;
    while(b <= n){
        b <<= 1;
    }
}

long long BIT::sum(long long i){
    long long sum = 0;
    
    for(i++; i > 0; i -= i & -i){
        sum += bit[i];
    }
    
    return sum;
}

void BIT::add(long long i, long long x){
    for(i++; i < bit.size(); i += i & -i){
        bit[i] += x;
    }
}

long long BIT::lower_bound(long long x){
    long long res = 0;
    
    for(long long i = b; i > 0; i >>= 1){
        if(res + i < bit.size() && bit[res + i] < x){
            x -= bit[res + i];
            res += i;
        }
    }
    
    return res;
}

ll n;

ll f(vector<ll> a, ll x){
    BIT bt(2 * n + 5);
    
    REP(i, n){
        a[i] = (a[i] >= x)? 1 : -1;
        if(i > 0){
            a[i] += a[i - 1];
        }
    }
    
    ll sum = 0;
    bt.add(n, 1);
    REP(i, n){
        sum += bt.sum(a[i] + n);
        bt.add(a[i] + n, 1);
    }
    return sum;
}


int main() {
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    
    ll l = 0, r = 1e10, c = (l + r) / 2;
    while(r - l > 1){
        ((f(a, c) >= ceil(n * (n + 1) / 2.0 / 2.0))? l : r) = c;
        c = (l + r) / 2;
    }
    cout << c << endl;
}


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

int main(){
	int n;	cin>>n;
	vector< pair<int,int> > data(n+1);
	data[0]={0,0};
	for(int i=1;i<=n;i++){
		int count;	cin>>count;
		data[i]={count,i};
	}
	sort(data.begin(), data.end());
	for(int i=1;i<=n;i++){
		if(i>1)cout<<" ";
		cout<<data[i].second;
	}cout<<endl;

	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>

bool is_prime(long long x) {
	if (x % 2 == 0) return false;
	for (long long i = 3; i * i <= x; i+=2)
	{
		if (x % i == 0) {
			return false;
		}
	}
	return true;
}

int main() {
	long long x;

	std::cin >> x;

	if (x == 2) {
		std::cout << 2 << std::endl;
		return 0;
	}

	for (long long i = x; i < x + 10000000; i++)
	{
		if (is_prime(i)) {
			std::cout << i << std::endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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 int INF = 1e9;
const long long INFL = 1LL<<60;

template<typename T> // T: type of cost
struct LCA {
  int n, root, l;
  vector<vector<int>> to;  // グラフ
  vector<vector<T>> co;    // コスト
  vector<int> dep;         // 根からの深さ
  vector<T> costs;         // コスト（距離）
  vector<vector<int>> par;  // ダブリング配列
  LCA(int n):n(n),to(n),co(n),dep(n),costs(n) {
    l = 0;
    while ((1<<l) < n) ++l;
    par = vector<vector<int>>(n+1,vector<int>(l,n));
  }

  // a - b の間にコスト c の辺を張る
  void add_edge(int a, int b, T c=0) {
    to[a].push_back(b); co[a].push_back(c);
    to[b].push_back(a); co[b].push_back(c);
  }
  void dfs(int v, int d=0, T c=0, int p=-1) {
    if (p != -1) par[v][0] = p;
    dep[v] = d;
    costs[v] = c;
    for (int i = 0; i < to[v].size(); ++i) {
      int u = to[v][i];
      if (u == p) continue;
      dfs(u, d+1, c+co[v][i], v);
    }
  }

  // 初期化 _root: 根の頂点番号
  void init(int _root=0) {
    root = _root;
    dfs(root);
    // ダブリングのテーブルを構築する
    for (int i = 0; i < l-1; ++i) {
      for (int v = 0; v < n; ++v) {
        par[v][i+1] = par[par[v][i]][i];
      }
    }
  }
  // LCA
  int lca(int a, int b) {
    if (dep[a] > dep[b]) swap(a,b);  // 深いほうが b になるようにしておく
    int gap = dep[b]-dep[a];         // gap ぶん b から登る
    for (int i = l-1; i >= 0; --i) {
      int len = 1<<i;
      if (gap >= len) {
        gap -= len;
        b = par[b][i];
      }
    }
    if (a == b) return a;
    for (int i = l-1; i >= 0; --i) {
      int na = par[a][i];
      int nb = par[b][i];
      if (na != nb) a = na, b = nb;
    }
    return par[a][0];
  }
  int length(int a, int b) {
    int c = lca(a,b);
    return dep[a]+dep[b]-dep[c]*2;
  }
  T dist(int a, int b) {
    int c = lca(a,b);
    return costs[a]+costs[b]-costs[c]*2;
  }
};

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

  int n;
  cin >> n;
  LCA<ll> lca(n);
  rep(i, n-1) {
    int a, b, c; cin >> a >> b >> c; a--; b--;
    lca.add_edge(a, b, c);
  }
  lca.init(0);

  int q, k;
  cin >> q >> k;
  k--;

  // 全ての頂点の K までの距離を求める
  vector<ll> dist(n, INF);
  rep(i, n) {
    dist[i] = lca.dist(i, k);
  }

  rep(i, q) {
    int x, y; cin >> x >> y; x--; y--;
    cout << dist[x] + dist[y] << endl;
  }

  return 0;
}


Measured memory_bytes: 28544
#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;

vector<ll> Divisor(ll n){
  vector<ll> res;
  for(ll i = 1; i*i <= n; i++){
    if(n%i == 0){
      res.push_back(i);
      if(i*i != n) res.push_back(n/i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}

ll DivisorCnt(ll n){
  if(n < 1) return 0;
  map<ll, ll> mp;
  ll cnt = 0;
  while(n%2 == 0){
    n /= 2;
    cnt++;
  }
  if(cnt != 0) mp[2] = cnt;
  for(ll i = 3; i*i <= n; i += 2){
    cnt = 0;
    while(n%i == 0){
      n /= i;
      cnt++;
    }
    if(cnt != 0) mp[i] = cnt;
  }
  if(n != 1) mp[n] = 1;
  ll res = 1;
  for(auto i : mp){
    res *= (i.second+1);
  }
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N; cin >> N;
  ll ans = DivisorCnt(N-1)-1; // 約数のうち1は除く
  vector<ll> D = Divisor(N);
  for(auto i : D){
    if(i == 1) continue; // 約数のうち1は除く
    ll tmp = N;
    while(tmp%i == 0){
      tmp /= i;
    }
    if(tmp == 1 || tmp%i == 1) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3664
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, x, *a = map(int, read().split())
memo = 0
cnt = 0
if a[0] > x:
    cnt += a[0] - x
    a[0] = x
for i in range(n - 1):
    if a[i + 1] > x:
        cnt += a[i + 1] - x
        a[i + 1] = x
    v = a[i] + a[i + 1] - memo
    if v > x:
        memo = v - x
    else:
        memo = 0
    cnt += memo
print(cnt)


Measured memory_bytes: 13040
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int a, b;
	cin >> a >> b;

	if(a <= b){
		cout << a << endl;
	}else{
		cout << a - 1 << endl;
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int n;
ll a[100010], b[100010];

int main(int argc, char const *argv[])
{
	cin >> n;
	rep(i, n)cin >> a[i] >> b[i];
	vector<pair<ll, int>> v;
	rep(i, n) v.pb(mp(a[i] + b[i], i));
	sort(all(v)); reverse(all(v));
	ll ans = 0;
	rep(i, n) {
		if (i % 2 == 0) ans += a[v[i].se];
		else ans -= b[v[i].se];
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  for(int i=0; i<n-1; i++){
    if(s.substr(i,2)=="AC"){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <string>

using namespace std;

int main(void){
  string S;
  string P;
  cin >> S;
  cin >> P;

  int search = 0;
  int count = 0;
  bool finish = false;
  int preserch = 0;
  bool many_same_char = false;
  vector<tuple<int, int>> st;

  for(int ptr = 0 ; !finish ; ptr++){
    if( S[ptr] == P[search] ){
      preserch = search;
      if( search >= P.length() - 1 ){
        int oldcount = count;
        for(int subptr = ptr ; subptr < S.length() ; subptr++){
          if( S[subptr] == P[search]){
            count++;
          }
        }
        if( count - oldcount == 1){
          if( many_same_char ){
            count = 2000;
          }else{
            count = 1;
          }
          finish = true;
        }


        if(!st.empty()){
          tuple<int,int> t = st.back();
          st.pop_back();
          ptr = get<0>(t);
          search = get<1>(t);
        }else{
          finish = true;
        }

        if(count >= 2){
          finish = true;
        }
      }else{
          st.push_back(make_tuple(ptr, search));
          search++;
      }
    }else if( ptr >= S.length() - 1 ){
      finish = true;
    }else if( S[ptr] == P[preserch] ){
      many_same_char = true;
    }


  }

  if( count == 1 ){
    cout << "yes" << endl;
  }else{
    cout << "no" << endl;
  }

  return 0;

}

Measured memory_bytes: 8232
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define space ' '
typedef long long ll;
typedef long double ld;
const long double PI = 3.14159265358979323846;

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

    string s;
    cin >> s;
    int n = s.size();
    string ans = "";
    int cnt = 0;
    for (int i = n - 1; i >= 0; --i) {
        if (s[i] == 'B') {
            ++cnt;
            continue;
        }
        if (cnt > 0) {
            --cnt;
            continue;
        }
        ans += s[i];
    }
    for (int i = (int)ans.size() - 1; i >= 0; --i) {
        cout << ans[i];
    }
    cout << endl;

    return 0;
}


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

using namespace std ;

const int N = 2e6 + 100 ;
int n , a[N] , dp[N] , k;

int32_t main(){
	cin >> n >> k;
	for(int i = 0 ; i < n ; i++)cin >> a[i] ;
	for(int i = 2 ; i <= n ; i++){
		dp[i] = 1e18 ;
		for(int j = 1 ; j <= k && i - j ; j++)
		dp[i] = min(abs(a[i - 1] - a[i - 1 - j]) + dp[i - j] , dp[i]) ;
	}
	cout << dp[n] << '\n' ;
	return 0 ;
}
/*
#include <radman/roderc++.h>
                     ....._____
                 .~~~~~////////\\                                                                                           ...
              .:::::////////////\\                                          ....::////////..                              (/\\\\...
           .::::://////   \\\\///\\              .:::://                ..:::::///////////////.                           \\\\\$$$$$$
         \\\\\//////      \\\\///\\           //\\\//////             \\\\\////////////////////.                           ""\\$$$$$$$
         \\\\\////         \\\\////         |||||////////.            \\\\\/////     ~~~~~//////          ...                  "\$$$$
         \\\\\//\         ////|||/          \\\\\/////////            \\\\\//\       ~~~~~//////        (/\\\\...                   .
         \\\\\//\        ////|||/          |||||////*\\///.           \\\\\//\       ~~~~~//////        \\\\\$$$$$$                 .@@@@@.
         \\\\\//\       ////|||/           \\\\\///|\\\////           \\\\\//\       ~~~~~//////         ""\\$$$$$$$               @@@@////\
         \\\\\//\ ____---/|||/            |||||///|\\\\\///.          \\\\\//\       ~~~~~//////             "\$$$$                @@@@\///\
         \\\\\//\--|||||||_-'             \\\\\///|\\\\\////          \\\\\//\       ~~~~~//////                                  ,@@@@|///|
         \\\\\//\|||||_"-\\\\\           |||||///|  ~~~~~///.         \\\\\//\      ~~~~~//////     .@@@@.                    /@@@@@|/////
         \\\\\//\///"""\\\\\\\\          \\\\\///|~~~~[[[////.        \\\\\//\     ~~~~~//////      @@@@@@@@                ..@@@@@.//////
         \\\\\//\    \"""\\\\\\\        |||||///|~~[[[[["\////.       \\\\\//\    ~~~~~//////      '@@@@/////\       .:;@@@@@@@..///////"
         \\\\\//\      \"""\\\\\\       \\\\\///|[[[[*\\\\\////.      \\\\\//\   ~~~~~//////        *@@@\//////\@@@@@@@@..//////////"
         \\\\\//\       \:::\\\\/      |||||///|[[[*   \\\\\\///      \\\\\//\~~~~~///////'            *@@\/////////////////////"
         \\\\\//\        \___\\/       \\\\\///|*       \\\\\/"       \\\\\//\~~////////'                 **"///////////"""
         \\\\\//\                     |||||///|                       \\\\\//\///////"
         \\\\\//\                     \\\\\///|                       \\\\\//\////"
         \\\\\///                    |||||////|                       \\\\\////"
         \\\\\/"                     \\\\\///*                        \\\\\/"
                                     """""*
*/


Measured memory_bytes: 5120
#include<iostream>
using namespace std;
bool a,b,c;
int main(void)
{
  	string s;
  	int cnt=0;
  	cin >> s;
  	if(s[0]=='A') a=true;
  	for(int i=2;i<=s.size()-2;i++)
      	if(s[i]=='C')
        {
          	b=true;
          	break;
        }
    for(int i=0;i<s.size();i++)
      	if(s[i]<=90)
          	cnt++;
  	if(cnt==2) c=true;
  	if(a==true && b==true && c==true)
      	cout << "AC";
  	else cout << "WA";
  	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<cstdlib>
#include<string>
#include<algorithm>
#define mod 998244353;
using namespace std;
int a[200001],b[200001];
int main()
{
	int n,m;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	scanf("%d",&a[i]);
	scanf("%d",&m);
	for(int i=0;i<m;i++)
	scanf("%d",&b[i]);
	sort(a,a+n);
	sort(b,b+m);
	int j=0,flag=0,sum=0;
	for(int i=0;i<m;i++)
	{
		if(j==n)
		break;
		if(b[i]>a[j])
		{
			j++;
			i--;
		}
		else if(b[i]==a[j])
		{
			j++;
			sum++;
		}
		else
		{
		//	printf("!%d %d %d\n",a[j],b[i],i);
			flag=1;
			break;
		}
	}
	//printf("%d %d\n",sum,flag);
	if(flag==1||sum<m)
	{
		printf("NO\n");
	}
	else
	{
		printf("YES\n");
	}
 } 

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x)
{
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	x*=f;
	return;
}	
template<typename T>
void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
	return;
}
int main()
{
    int n;
    cin>>n;
    cout<<(n+1)/2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include <math.h>
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i]>>y[i];
typedef long long int ll;
using namespace std;

int main(){
	int n,h,w; cin >>n>>h>>w;
	cout << (n+1-h)*(n+1-w) << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int n;
const int maxn = 100100;
int a[maxn], b[maxn], c[maxn];
int dp[maxn][4];

int rec(int i, int prev)
{
    if (i == n)
    {
        return 0;
    }

    if (dp[i][prev] != -1)
    {
        return dp[i][prev];
    }

    if (prev == 1)
    {
        return dp[i][prev] = max(rec(i+1, 2) + b[i], rec(i+1, 3) + c[i]);
    }
    else if (prev == 2)
    {
        return dp[i][prev] = max(rec(i+1, 1) + a[i], rec(i+1, 3) + c[i]);
    }
    else if (prev == 3)
    {
        return dp[i][prev] = max(rec(i+1, 1) + a[i], rec(i+1, 2) + b[i]);
    }

    return dp[i][prev] = max(rec(i+1, 1) + a[i], max(rec(i+1, 2) + b[i], rec(i+1, 3) + c[i]));
}

int main()
{
    cin >> n;
    rep(i, n)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << rec(0, 0) << endl;
}


Measured memory_bytes: 7680
// AOJ 2249: Road Construction
// 2017.11.15 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 16010
typedef struct { int t, node, c; } QUE;
QUE que[MAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && (que[l].t < que[i].t ||
		que[l].t == que[i].t && que[l].c < que[i].c)) min = l; else min = i;
	if (r < qsize && (que[r].t < que[min].t ||
		que[r].t == que[min].t && que[r].c < que[min].c)) min = r;
	if (min != i) {
		QUE t = que[i]; que[i] = que[min]; que[min] = t;
		min_heapify(min);
	}
}

int deq(int *n, int *t, int *c)
{
	if (qsize == 0) return 0;
	*n = que[0].node, *t = que[0].t, *c = que[0].c;
	que[0] = que[--qsize];
	min_heapify(0);
	return 1;
}

void enq(int n, int t, int c)
{
	int i, min;

	i = qsize++;
	que[i].node = n, que[i].t = t, que[i].c = c;
	while (i > 0 && (que[min = PARENT(i)].t > que[i].t ||
		   que[min].t == que[i].t && que[min].c > que[i].c)) {
		QUE tt = que[i]; que[i] = que[min]; que[min] = tt;
		i = min;
	}
}

#define INF 0x55555555
typedef struct { int len, to[100], d[100], c[100]; } TBL;
TBL *tbl; char *visited; int size;

int dijkstra(int start)
{
	int i, s, e, c, d, ans = 0;
	TBL *tp;

	qsize = 0;
	memset(visited, 0, sizeof(char)*size);
	enq(start, 0, 0);
	while(deq(&s, &d, &c)) {
//		if (s == goal) break;
		if (visited[s]) continue;
		visited[s] = 1;
		ans += c;
		for (tp = tbl+s, i = 0; i < tp->len; i++) {
			e = tp->to[i];
			if (visited[e]) continue;
			enq(e, d + tp->d[i], tp->c[i]);
		}
	}
	return ans;
}


char buf[40], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, m, i, k, u, v, d, c;
	TBL *tp;

	while (fgets(p=buf, 40, stdin) && *p != '0') {
		size = n = getint(), p++, m = getint();

		tbl = calloc(size+2, sizeof(TBL));
		visited = calloc(size+2, sizeof(char));
		memset(tbl, 0, sizeof(TBL)*size);
		for (i = 0; i < m; i++) {
			fgets(p=buf, 40, stdin);
			u = getint()-1, p++, v = getint()-1, p++, d = getint(), p++, c = getint();
			tp = tbl+u;
			k = tp->len, tp->to[k] = v, tp->d[k] = d, tp->c[k] = c, tp->len++;
			tp = tbl+v;
			k = tp->len, tp->to[k] = u, tp->d[k] = d, tp->c[k] = c, tp->len++;
		}
		printf("%d\n", dijkstra(0));

		free(visited), free(tbl);
	}
	return 0;
}

Measured memory_bytes: 12312
#include <iostream>
#include <algorithm>

using namespace std;

int main(){

  int n, v;
  int cost[20] = {0};
  int ans = 0;

  cin >> n;

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

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

  sort(cost, cost + n);

  for(int i = n - 1; i >= 0; i--){
    if(cost[i] > 0){
      ans += cost[i];
    }
    else{
      break;
    }
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;

vector<int> v,x;

int N,M;
int main (){
    cin >> N >> M;
    for(int i=0; i<M; i++) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    sort(v.begin(), v.end());
    for(int i=0; i<M-1; i++) {
        x.push_back(abs(v[i] - v[i+1]));
    }
    sort(x.rbegin(), x.rend());
    long long int ans = 0;
    int add = 0;
    if(N >= 2) add = N-1;
    for(int i=0+add; i<x.size(); i++) ans += x[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
N = input()
NI = int(N)


def f755(d, n, t, f, s):
    if NI < n:
        return 0
    if d < 0 and (t and f and s):
        return 1
    r = 0
    if n == 0 and d > 0:
        r += f755(d - 1, n, t, f, s)
    if d >= 0:
        r += f755(d - 1, n + 3 * (10 ** d), t or 1, f, s)
        r += f755(d - 1, n + 5 * (10 ** d), t, f or 1, s)
        r += f755(d - 1, n + 7 * (10 ** d), t, f, s or 1)
    return r


ans = f755(len(N) - 1, 0, 0, 0, 0)
print(ans)

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

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

    if(h > -r)          cout << 1 << endl;
    else if(h == -r)    cout << 0 << endl;
    else if(h < -r)     cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;

int main(){
  int N,K;
  cin>>N>>K;
  map<int,int> m;
  int n=0;
  vector<int> count;
  for(int i=0;i<N;i++){
    int A;
    cin>>A;
    if(m.count(A)==0){
      m[A]=n;
      count.push_back(1);
      n++;
    }else{
      count.at(m[A])++;
    }
  }
  sort(count.begin(),count.end());
  reverse(count.begin(),count.end());

  int ans=0;
  for(int i=0;i<count.size();i++){
    if(i<K){
      continue;
    }
    ans+=count.at(i);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 10356
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define REP(i, n) for(int i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()

using namespace std;


class COtoshidama {
public:
    ll N, Y;

    void solve(std::istream& in, std::ostream& out) {
        in >> N >> Y;
        REP(i, N+1) REP(j, N-i+1) if (10000 * i + 5000 * j + 1000* (N-i-j) == Y) {
            out << i << " " << j << " " << N-i-j << endl;
            return;
        }
        out << -1 << " " << -1 << " " << -1 << endl;
    }
};


int main() {
    COtoshidama solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k,s;
  cin>>k>>s;
  int ans=0;
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
      int z=s-(x+y);
      if(0<=z && z<=k)ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3632