akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
int main(){
    int a[3];
    scanf("%d %d %d",&a[0],&a[1],&a[2]);
    int k;
    scanf("%d",&k);
    int i=0;
    while(i!=k){
        if(a[0]>=a[1]) a[1]*=2;
        else if(a[1]>=a[2]) a[2]*=2;
        else a[2]*=2;
        i++;
        //printf("%d %d %d\n",a[0],a[1],a[2]);
    }
    if(a[0]<a[1]&&a[1]<a[2]) printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N, W;
struct Item {
  ll w, v;

  bool operator<(const Item &that) const { return v > that.v; }
};

vector<Item> items;
int main() {
  cin >> N >> W;
  items.resize(N);
  rep(i, N) cin >> items[i].w >> items[i].v;

  vector<Item> s[4];
  rep(i, N) { s[items[i].w - items[0].w].push_back(items[i]); }
  rep(i, 4) sort(all(s[i]));

  vector<vector<ll>> sw(4, vector<ll>(N + 1, 0)), sv(4, vector<ll>(N + 1, 0));
  rep(i, 4) rep(j, N) {
    sw[i][j + 1] = sw[i][j] + (j < s[i].size() ? s[i][j].w : 0);
    sv[i][j + 1] = sv[i][j] + (j < s[i].size() ? s[i][j].v : 0);
  }

  ll ans = 0;
  rep(i, N + 1) rep(j, N + 1) rep(k, N + 1) rep(l, N + 1) {
    ll w = sw[0][i] + sw[1][j] + sw[2][k] + sw[3][l];
    if (w > W) continue;
    ans = max(ans, sv[0][i] + sv[1][j] + sv[2][k] + sv[3][l]);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    ll num = 0;
    ll d1,d2;
    rep(i,0,n){
        cin>>d1>>d2;
        if (d1==d2){
            num++;
            if (num==3){
                cout<<"Yes"<<endl;
                return 0;
            }
        }else{
            num = 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int>PII;
const int maxn = 2e5 + 10;
int a[maxn];
int t,n,m;
map<int,int>maps; 
int main(void) {
	scanf("%d",&n);
	for(int i = 1; i <= n; i ++) {
		scanf("%d",&a[i]);
	}
	LL ans = 0;
	for(int i = 1; i <= n; i ++) {
		if(maps.count(i - a[i]) != 0) {
			ans += maps[i - a[i]];
		}		
		maps[i + a[i]] ++;
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 13808
# ABC073 C:Sentou
N,T = map(int, input().split())
l = list(map(int, input().split()))
x = T

for i in range(1,N):
    interv = l[i] - l[i-1]
    if interv < T:
        x += interv
    else:
        x += T
print(x)



Measured memory_bytes: 30804
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1001001001
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

struct SegmentTree{
private:
    int n;
    vector<int> node;

public:
    SegmentTree(vector<int> v){
        int sz = v.size();
        n = 1; while(n < sz) n*=2;
        node.resize(2*n-1, -1);
        for (int i = 0; i < sz; i++) node[i+n-1] = v[i];
        for (int i = n-2; i>=0; i--) node[i] =max(node[2*i+1], node[2*i+2]);
    }
    void update(int x, int val){
        x += (n-1);
        node[x] = val;
        while(x>0){
            x = (x-1)/2;
            node[x] = max(node[2*x+1], node[2*x+2]);
        }
    }
    int getmax(int a, int b, int k=0, int l=0, int r=-1){
        if (r < 0) r=n;
        if (r <= a || b <= l) return -1;
        if (a <= l && r <= b) return node[k];
        int vl = getmax(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmax(a, b, 2*k+2, (l+r)/2, r);
        return max(vl, vr);
    }
    int getval(int x){
        x += (n-1);
        return node[x];
    }

};

struct robot
{
    int id;
    int pos;
    int range;
};

bool cmp(const robot &a, const robot &b){  
    return a.pos < b.pos;
}

int main()
{
    int n;
    cin >> n;
    vector<robot> a;
    rep(i, n){ 
        int  tp, tr;
        cin >>tp >> tr;
        robot r = {i, tp, tr};
        a.push_back(r);
    }
    sort(a.begin(), a.end(), cmp);

    vector<int> position;
    rep(i, n){
        position.push_back(a[i].pos);
    }
    vector<int> effect;
    rep(i, n){
        int x = lower_bound(position.begin(), position.end(), a[i].pos + a[i].range) - position.begin();
        effect.push_back(x-1);
    }
    SegmentTree st(effect);
    rep(i, n){
        int id = n-1-i;
        int val = st.getmax(id, effect[id]+1);
        st.update(id, val);
    }

    ll tmpmod = 998244353;
    vector<ll> dp(n+1);
    dp[n] = 1;
    rep(i, n){
        int id = n-1-i;
        dp[id] = dp[id+1] + dp[st.getval(id) + 1];
        dp[id] %= tmpmod;
    }
    cout << dp[0] << endl;

}


Measured memory_bytes: 9456
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n >> m;
    string a = to_string(n);
    string b = to_string(m);
    string aa = "", bb = "";
    for(int i = 1; i <= m; i++) aa += a; 
    for(int i = 1; i <= n; i++) bb += b;

    cout << ((aa < bb) ? aa : bb); 
}

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

int main()
{
  int n;
  int amount = 100000;

  cin >> n;

  for(int i=0; i<n; i++) {
    amount = amount * 1.05;
    if(amount % 1000 != 0) {
      amount = amount + 1000 - amount % 1000;
    }
  }

  cout << amount << "\n";

  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int A, B, ans;
    cin >> A >> B;
    ans = -1;
    for ( int i = 1; i < 2000; i++ ){
        int ValA = i * 0.08;
        int ValB = i * 0.10;
        if ( A == ValA && B == ValB ){
            ans = i;
            cout << ans << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
/*動かない・・・
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _roverload3(_1,_2,_3,name,...) name
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(...) _roverload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
//*/
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
//*/
#define All(a) (a).begin(),(a).end()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
//*/
using namespace std;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数
int a, b;

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

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

	cin >> a >> b;
	REPS(i, 1300) {
		//cout << i*0.08 << " " << i*0.1 << endl;
		if ((int)(i*0.08) == a&&(int)(i*0.1) == b) {
			cout << i << endl;
			return 0;
		}
	}
	cout << "-1" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;

ll n;
ll dp[101][1000000];
ll find(ll arr[][2], ll curr, ll w, ll i) {
	if (curr <= 0)
		return 0;

	if (i == n)
		return INT_MAX;

	if (dp[i][curr] != -1)
		return dp[i][curr];

	dp[i][curr] = min(find(arr, curr, w, i + 1), arr[i][0] + find(arr, curr - arr[i][1], w - arr[i][0], i + 1));
	return dp[i][curr];
}


int main() {
	ll w;
	cin >> n >> w;
	memset(dp, -1, sizeof(dp));
	// vector<vector<ll>> arr(n, vector<ll>(2));
	ll arr[n][2];
	for (ll i = 0; i < n; i++)
		cin >> arr[i][0] >> arr[i][1];
	ll ans = 0;
	for (int i = 100000; i >= 0; i--) {
		if (find(arr, i, w, 0) <= w) {
			ans = i;
			break;
		}
	}
	cout << ans;
	return 0;
}

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

using namespace std;

int main ()
{
    int n;
    int a[10];
    while (cin >> n) {
        memset(a,0,sizeof(a));
        a[3] = n%10;
        a[2] = n/10%10;
        a[1] = n/100%10;
        a[0] = n/1000%10;
        int sum1 = a[0]+a[1]+a[2]+a[3];
        if (sum1 == 7) {
            cout << a[0] << "+" << a[1] << "+" << a[2] << "+" << a[3] << "=" << 7;
            cout << endl;
            continue;
        }
        int sum2 = a[0]+a[1]+a[2]-a[3];
        if (sum2 == 7) {
            cout << a[0] << "+" << a[1] << "+" << a[2] << "-" << a[3] << "=" << 7;
            cout << endl;
            continue;
        }
        int sum3 = a[0]-a[1]+a[2]+a[3];
        if (sum3 == 7) {
            cout << a[0] << "-" << a[1] << "+" << a[2] << "+" << a[3] << "=" << 7;
            cout << endl;
            continue;
        }
        int sum4 = a[0]+a[1]-a[2]+a[3];
        if (sum4 == 7) {
            cout << a[0] << "+" << a[1] << "-" << a[2] << "+" << a[3] << "=" << 7;
            cout << endl;
            continue;
        }
        int sum5 = a[0]+a[1]-a[2]-a[3];
        if (sum5 == 7) {
            cout << a[0] << "+" << a[1] << "-" << a[2] << "-" << a[3] << "=" << 7;
            cout << endl;
            continue;
        }
        int sum6 = a[0]-a[1]+a[2]-a[3];
        if (sum6 == 7) {
            cout << a[0] << "-" << a[1] << "+" << a[2] << "-" << a[3] << "=" << 7;
            cout << endl;
            continue;
        }
        int sum7 = a[0]-a[1]-a[2]+a[3];
        if (sum7 == 7) {
            cout << a[0] << "-" << a[1] << "-" << a[2] << "+" << a[3] << "=" << 7;
            cout << endl;
            continue;
        }
        int sum8 = a[0]-a[1]-a[2]-a[3];
        if (sum8 == 7) {
            cout << a[0] << "-" << a[1] << "-" << a[2] << "-" << a[3] << "=" << 7;
            cout << endl;
            continue;
        }
    }
}


Measured memory_bytes: 256
n = int(input())
if n==0:
    print(0)
    exit()
res = []
while n != 0:
    x = n%-2

    if x<0:
        res.append(1)
        n -= 1
        n //= -2
    else:
        res.append(0)
        n //= -2

res.reverse()
print("".join(str(c) for c in res))

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

int main()
 {
 	int i,n,s,j;
 	int m=INT_MAX;
 	cin>>n;
 	int a[n];
 	for(i=0;i<n;i++)
 		cin>>a[i];
	for(i=-100;i<=100;i++)
		{
			s=0;
			for(j=0;j<n;j++)
				{
					s+=pow(a[j]-i,2);
				}
			if(s<m)
			{
				m=s;
			}
		}
		cout<<m<<endl;
 }

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

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

  int n;
  cin >> n;

  int sum = 0;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum ^= a[i];
  }

  for (int i = 0; i < n; ++i) cout << (sum ^ a[i]) << (i == n-1 ? '\n' : ' ');

  return (0);
}


Measured memory_bytes: 3884
function Main(input){
	let n = (input.split("\n"))[0]-"0"
	let str = "1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 8 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 9 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 8 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1";
	for( let i = 2*n-3; i > 0; i -= 2 ){
		console.log( str.substr(0, i) )
	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;




int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    int a, b, c;
    cin >> a >> b >> c;
    cout << (c - min(c, a - b));





}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long hxtype;
typedef pair<int,int>pii;
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
const ll p=998244353ll;
const int N=20;
map<pii,ll>S[N][N];
ll a[N];
inline ll dp(int l,int r,int L,int R){
	if(r==l+1)return 0ll;
	if(S[l][r].find(mp(L,R))!=S[l][r].end())return S[l][r][mp(L,R)];
	int M=L+R,m;ll s=1000000000000000000ll;
	REP(m,l+1,r)cmin(s,dp(l,m,L,M)+dp(m,r,M,R)+M*a[m]);
	return S[l][r][mp(L,R)]=s;
}
int main(){
	int n,i;
	scanf("%d",&n);
	rep(i,1,n)scanf("%lld",&a[i]);
	printf("%lld",dp(1,n,1,1)+a[1]+a[n]);
	return 0;
}

Measured memory_bytes: 18560
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

ll mod_pow(ll x, ll n, ll mod){ // x ^ n % mod
    ll res = 1;
    while(n > 0){
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll h, w, n, K;
int a[55][55];

int main() {
    cin >> h >> w >> n >> K;
    rep(i,h)rep(j,w)a[i][j] = 0;

    // 愚直
    int cnt = 0;
    rep(i,h){
        rep(j,w){
            cout << "? " << i << " " << j << " " << i << " " << j << endl << flush;
            // fflush(stdout);
            int res;
            cin >> res;
            a[i][j] = res;
            cnt += a[i][j];
            if(cnt == n)break;
        }
    }

    // ans出力
    ll ans = 0;
    ll p = 1;
    rep(i,h){
        rep(j,w){
            // ans = (ans + mod_pow(2,i*w+j,K)) % K;
            if(a[i][j])ans = (ans+p) % K;
            p = p*2%K;
        }
    }
    cout << "! " << ans << endl << flush;
    // fflush(stdout);
    return 0;
}




Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int b[n+1]={};

    for(int i=n;i>0;i--){
        b[i]=a[i];
        for(int j=i+i;j<=n;j+=i){
            b[i]+=b[j];
        }
        b[i]=b[i]%2;
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(b[i]>0){
            ans++;
        }
    }
    cout<<ans<<endl;
    for(int i=1;i<=n;i++){
        if(b[i]>0){
            cout<<i<<endl;
        }
    }
    return 0;
}


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

int main() {
    int A,B,C,X;
    int count =0;
    cin >> A >> B >> C >> X;
    for(int a=0; a<=A; a++){
        for(int b=0; b<=B; b++){
            for(int c=0; c<=C; c++){
                int sum = 500*a + 100*b + 50*c;
                if(sum == X){
                 count++;
            }
        }
    }
 }
 cout << count <<endl;
} 


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

namespace ABC086A
{
    class Program
    {
        static void Main(string[] args)
        {
            List<long> input = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToList();
            var r1 = input[0] * input[2];
            var r2 = input[0] * input[3];
            var r3 = input[1] * input[2];
            var r4 = input[1] * input[3];
            var answer = Math.Max(r1,r2);
            answer = Math.Max(answer,r3);
            answer = Math.Max(answer, r4);

            System.Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 28248
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353 //1000000007 // //100000000
#define INF 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

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

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}

void solve(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    sort(a, a+n);
    ll ans = 0;
    for(ll i = n-1; i >= 0; i-=2)
    {
        ans += a[i];
    }
    for(ll i = n-2; i >= 0; i-=2)
    {
        ans -= a[i];
    }
    cout << ans;
}
main(){
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
N,Y=map(int,input().split())

Y=int(Y/1000)
A=B=C=-1

for c in range(N+1):
  for b in range(N+1):
    a=N-b-c
    if c+5*b > Y:
      break
    if c+5*b+10*a == Y:
      A,B,C=a,b,c
      
print(A,B,C)

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REP2(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
typedef long long ll;

vector<pair<ll, ll> > prime_factorize(ll n){
    vector<pair<ll, ll> > res;
    for(ll i = 2; i * i <= n; i++){
        if(n % i != 0) continue;

        ll ex = 0;
        while(n % i == 0){
            ex++;
            n /= i;
        }
        res.push_back({i, ex});
    }
    if(n != 1) res.push_back({n, 1});
    return res;
}

int main() {
    ll n, p; cin >> n >> p;
    const auto &pf = prime_factorize(p);
    ll ans = 1;
    for(auto p : pf){
        for(int i = 0; i < p.second / n; i++) ans *= p.first;
    }
    OP(ans);
}


Measured memory_bytes: 256
#区間の和を求める時は累積和を計算しておけば早く求まる
#それを全探索していても間に合わない(o(N^2))
#区間の和が０になる。累積和のリストに対してs_i-s_j=0になるようなs_iとs＿jの組みの総数は？
#累積和のリストをCounterで数えてnC2で計算すればいい
n=int(input())
a=list(map(int,input().split()))
from itertools import accumulate
from collections import Counter

a=[0]+list(accumulate(a))
a=Counter(a)
ans=0
for i in a:
  ans=ans+a[i]*(a[i]-1)//2
print(ans)


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

namespace ITP1_11_A
{
    class Dice
    {


        public Dice()
        {
            Top = 0;
            Front = 1;
            Right = 2;
        }

        public void RotateNorth()
        {
            var temp = Top;
            Top = Front;
            Front = Inverse(temp);
        }


        public void RotateSouth()
        {
            var temp = Top;
            Top = Inverse(Front);
            Front = temp;
        }


        public void RotateEast()
        {
            var temp = Top;
            Top = Inverse(Right);
            Right = temp;
        }


        public void RotateWest()
        {
            var temp = Top;
            Top = Right;
            Right = Inverse(temp);
        }


        public bool RotateTo(int top, int front)
        {

            return false;
        }


        public int Top { get; private set; }


        public int Front { get; private set; }


        public int Right { get; private set; }


        public int Inverse(int surface)
        {
            return 5 - surface;
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            var aliasOfSurface = Console.ReadLine().Split(' ');
            var dice = new Dice();

            foreach (var n in Console.ReadLine())
            {
                switch (n)
                {
                    case 'N': dice.RotateNorth(); break;
                    case 'S': dice.RotateSouth(); break;
                    case 'E': dice.RotateEast(); break;
                    case 'W': dice.RotateWest(); break;
                }
            }

            Console.WriteLine(aliasOfSurface[dice.Top]);
        }
    }
}

Measured memory_bytes: 5268
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  bool n1=0,n9=0,n7=0,n4=0;
  for(int i=0; i<4; i++){
    cin >> n;
    if(n==1){
      n1=1;
    }
    if(n==9){
      n9=1;
    }
    if(n==7){
      n7=7;
    }
    if(n==4){
      n4=1;
    }
  }
  if(n1&&n9&&n7&&n4){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

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

long long int kuriage(long long int x, long long int y) {
    return (x + (y - 1)) / y;
}

int main() {
    long long int n; 
    cin >> n;
    long long int a, b;
    cin >> a >> b;
    rep (i, n - 1) {
        long long int c, d;
        cin >> c >> d;
        long long int kake = max (kuriage(a,c), kuriage(b,d));
        a = c * kake; b = d * kake;
    }
    cout << a + b << endl;
}


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

long long int a,b,c,ans,k;
string s;

int main(){
    cin>>k;
    cin>>s;
    if(s.length()<=k){
        cout<<s<<endl;
    }else{
        for(int i=0;i<k;i++){
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }


}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,M;
  ll K;
  cin >> N >> M >> K;
  vl A(N);
  rep(i,N) {
    cin >> A[i];
  }
  vl B(M);
  rep(i,M) {
    cin >> B[i];
  }
  vl accA(N+1,0);
  rep(i,N) {
    accA[i+1]=accA[i]+A[i];
  }
  vl accB(M+1,0);
  rep(i,M) {
    accB[i+1]=accB[i]+B[i];
  }
  accB.push_back(INF);
  ll ans = 0;
  rep(i,N+1) {
    ll cnt = i;
    if(K<accA[i]) continue;
    int d = upper_bound(rng(accB),K-accA[i]) - accB.begin();
    cnt += d-1;
    chmax(ans,cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11136
#include<stdio.h>
int n,d=3;
  int a[100000];
  int b[100000];
void l(void){
  int i;
  for(i=0;i<n-1;i++){
  //  printf("a");
    if(a[i]>a[i+1]){
      //printf("a");
      if(a[i]-1>a[i+1]||b[i]){
        //printf("No\n");
        d=0;
      }else{
        b[i]=1;
        a[i]--;
        return (l());
      }
    }

  }
  //printf("Yes\n");
  if(d==3)
  d=1;
}
int main(void){
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++)
  scanf("%d",&a[i]);
  l();
  if(d){
    printf("Yes\n");

  }
  else
  printf("No\n");
  //for(i=0;i<n;i++){
    //printf("%d,",a[i]);
  //}
  return(0);
}


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

int main(void)
{
    int n,a,b;
    int res=0;
    scanf("%d%d%d",&n, &a, &b);
    for(int i=1;i<=n;i++)
    {
        int x=i;
        int sum=0;
        while (x)
        {
            sum+=x%10;
            x/=10;
        }
        if(sum>=a && sum<=b)
            res += i;
    }
    printf("%d\n",res);
    return 0;
}


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

int main(){
  int n;
  cin>>n;
  map<string,int>mp;
  vector<string>s(n+1);
  for(int i=1;i<=n;i++){
    cin>>s[i];
    mp[s[i]]++;
  }
  int m;
  cin>>m;
  vector<string>t(m+1);
  for(int i=1;i<=m;i++){
    cin>>t[i];
    mp[t[i]]--;
  }
  int mx=0;
  for(int i=1;i<=n;i++){
      mx=max(mx,mp[s[i]]);
  }
  cout<<mx<<endl;
}
  
  

Measured memory_bytes: 256
// import std = require('tstl')

{
  type Print = void | string | number | string[] | number[]
  let outs: Print[] = []

  const main = (): Print => {
    const r = _io()
    const ns = r.s()

    const lib = 'pphbhhphph'

    return lib[Number(ns[ns.length - 1])] + 'on'
  }

  const _io = (i = 0) => {
    const str: string = require('fs').readFileSync('/dev/stdin', 'utf8')
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')

    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map((v) => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  outs.push(main())

  console.log(
    outs
      .map((line) => (typeof line === 'object' ? line.join(' ') : String(line)))
      .join('\n')
  )
}


Measured memory_bytes: 29628
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
/*
template <typename T>  using ordered_set =
    tree<T, null_type, less<T>,   /// greater<T> for sorting decreasingly
    rb_tree_tag, tree_order_statistics_node_update>;
*/

#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         SET(m)                      memset(m, 1,sizeof m)
#define         RESET(m)                    memset(m,0,sizeof m)
#define         mp(a,b)                     make_pair(a,WWb)
#define         mod                         1000000007
#define         INF                         1e17
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;

int main(){
    ll a,b;
    cin>>a>>b;
    ll ans=a/b;
    if(a%b!=0) ans++;
    cout << ans << endl;   
}

Measured memory_bytes: 256
// HTTF.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include "bits/stdc++.h"
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
//不可解すぎるバグは配列外参照（配列の長さ）を検討

#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define int LL
#define pb emplace_back
#define eb pb

using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr, greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5 * 1e5 + 1000;
const int SIZE2 = 2010;
const int SIZE3 = 400;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p = 7 + 1e9;
const ld INF = 1e18;
const long double EPS = 1e-7;
typedef pair<ld, ut> pld;
ut N, M, K, X, L, Y, Q, D;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE], maps2[SIZE2][SIZE2], answer = zero;
LL maps[SIZE2][SIZE2];
LL A[SIZE],B[SIZE];
LL solve() {
	cin >> N;
	REP(i, N) {
		cin >> A[i] >> B[i];
	}
	LL now = 0;
	LL ans = 0;
	RREP(i, N - 1) {
		LL x = (B[i]-((A[i]+now) % B[i]))%B[i];

		now += x;
	}
	cout << now << endl;
	return 0;
}
signed main() {
	solve();
	cin >> N;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 18048
#include<bits/stdc++.h>
using namespace std;
#define LL long long 
#define ULL unsigned long long 

const int N = 2e3+11;
const int M = 1e6+11;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const LL inff = 0x3f3f3f3f3f3f3f3f;


/*-----------------------------------------*/

int prm[N+11],sz=0;
bool su[N+11]={1,1,0};
void init(){
	for(int i=2;i<N;i++){
		if(!su[i]) {
			prm[sz++]=i;
			for(int j=i*i;j<N;j+=i) 
				su[j]=1;
		}
	}
//	for(int i=0;i<10;i++) printf("%d \n",prm[i]);
}
void solve(LL n){
	LL ans=1;
	for(int i=0;i<sz && prm[i]<=n;i++) {
		LL cnt=0;LL t=n;
		while(t){
			cnt+=t/prm[i];
			t/=prm[i];
		}
		ans=(ans*(cnt+1)%mod)%mod;
	}
	printf("%lld\n",ans);
}
int main(){
	init();
 	LL n;scanf("%lld",&n);
    solve(n);
return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val xList = readLine()?.split(" ")?.map { it.toInt() } ?: return

    val middleIndex = xList.size / 2
    val sortedX = xList.sorted()

    val middleValue = sortedX[middleIndex] // 真っ二つにしたときに、大きい方の1番目に該当する値
    val lessMiddleValue = sortedX[middleIndex - 1] // 真っ二つにしたときに、小さい方のlastに該当する値

    // Xiが↑の中央値より大きいかどうか
    val moreOrLessList = xList.withIndex().map { it.value >= middleValue }

    for (isMore in moreOrLessList) {
        if (isMore) {
            println(lessMiddleValue)
        } else {
            println(middleValue)
        }
    }
}

Measured memory_bytes: 94364
using System;

namespace abc178_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            long all = 1;
            for (int i = 0; i < n; i++)
            {
                all *= 10;
                all = all % 1000000007;
            }

            long except09 = 1;
            for (int i = 0; i < n; i++)
            {
                except09 *= 8;
                except09 = except09 % 1000000007;
            }

            long except0or9 = 1;
            for (int i = 0; i < n; i++)
            {
                except0or9 *= 9;
                except0or9 = except0or9 % 1000000007;
            }
            except0or9 = sub(except0or9, except09);
            except0or9 = (except0or9 * 2) % 1000000007;
            all = sub(all, except09);
            all = sub(all, except0or9);
            Console.WriteLine(all);
        }

        static long sub(long x, long y)
        {
            if (x < y)
            {
                return 1000000007 - (y - x);
            }
            else
            {
                return x - y;
            }

        }
    }
}


Measured memory_bytes: 27464
import itertools
n,m,r=map(int,input().split())
R=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(m)]

distance=[[99999999 for i in range(n)] for j in range(n)]
for i in range(n):
  distance[i][i]=0
for i in range(m):
  distance[l[i][0]-1][l[i][1]-1]=l[i][2]
  distance[l[i][1]-1][l[i][0]-1]=l[i][2]

for k in range(n):
  for i in range(n):
    for j in range(n):
      distance[i][j]=min(distance[i][j],distance[i][k]+distance[k][j])

ans=99999999
for i in itertools.permutations(R):
  L=list(i)
  ct=0
  for j in range(r-1):
    ct+=distance[L[j]-1][L[j+1]-1]
  ans=min(ans,ct)
print(ans)

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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

/////////////////////////////////

int const MAX = 55;

int n, x, d;
int m[MAX];
vi e[MAX];
ll ds[MAX];
int dq[MAX];

void dfs1(int x, int p = -1) {
	dq[x] = 1;
	ds[x] = m[x];
	for (int y : e[x]) {
		if (y == p) continue;
		dfs1(y, x);
		ds[x] += ds[y];
		dq[x] += dq[y];
	}
}

struct Don {
	ll q, w, c;
	Don () {};
	Don (ll q, ll w, ll c) : q(q), w(w), c(c) {};
	bool operator<(const Don & a) {
		return c * a.w - a.c * w > 0;
	}
};

vector<Don> a, b;

ll const INF = 1e9 + 41;
int const MAXQ = MAX * MAX * MAX;
ll dp[2][MAXQ];

void setval(int id) {
	fi(0, MAXQ - 1) {
		dp[id][i] = INF;
	}
}

ll mult(ll a, ll b) {
	if (a == 0) return 0;
	if (b == 0) return 0;
	if (a > INF || b > INF) return INF;
	return min(INF, a * b);
}

void solve() {
	dfs1(1);
	ll q = x / ds[1];
	a.pb(Don(min(q, 50LL), ds[1], dq[1]));
	if (q > 50) {
		b.pb(Don(q - 50, ds[1], dq[1]));
	}
	fi(2, n) {
		ll q = x / ds[i];
		q = min(q, (ll) d);
		a.pb(Don(min(q, 50LL), ds[i], dq[i]));
		if (q > 50) {
			b.pb(Don(q - 50, ds[i], dq[i]));
		}				
	}
	sort(b.begin(), b.end());

	setval(0);
	setval(1);
	dp[0][0] = 0;
	fi(0, sz(a) - 1) {
		setval(1);
		memcpy(dp[1], dp[0], sizeof(dp[1]));

		ll rem = a[i].q;
		for (ll take = 1; take <= rem; take *= 2) {
			ll c1 = mult(a[i].w, take);
			fdj(MAXQ - 1, 0) {
				if (c1 + dp[1][j] >= INF) continue;
				dp[1][j + take * a[i].c] = min(dp[1][j + take * a[i].c], dp[1][j] + c1);				
			}
			rem -= take;	
		}
		
		if (rem) {
			ll take = rem;
			ll c1 = mult(a[i].w, take);
			fdj(MAXQ - 1, 0) {
				if (c1 + dp[1][j] >= INF) continue;
				dp[1][j + take * a[i].c] = min(dp[1][j + take * a[i].c], dp[1][j] + c1);				
			}
		}

		memcpy(dp[0], dp[1], sizeof(dp[0]));	
	}			

	ll ans = 0;
	fi(0, MAXQ - 1) {
		int rem = x - dp[0][i];
		if (rem < 0) continue;
		int cur = i;
		fj(0, sz(b) - 1) {
			ll mini = min(b[j].q, rem / b[j].w);
			cur += mini * b[j].c;
			rem -= b[j].w * mini;
		}
		ans = max(ans, (ll) cur);
	}

	printf("%lld\n", ans);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d %d %d", &n, &x, &d);
	scanf("%d", &m[1]);
	fi(2, n) {
		int p;
		scanf("%d %d", &m[i], &p);
		e[p].pb(i);
	}  
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>

int main(void){
	int x,y;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0)break;
		if(x>y){
			printf("%d %d\n",y,x);
		}
		else{
			printf("%d %d\n",x,y);
		}
	}
	return 0;
}

Measured memory_bytes: 596
import java.io.*;
import java.util.*;
import java.lang.Math;
import java.util.Arrays;

public class Main {
    public static void main(final String[] args) {

        Scanner sc = new Scanner(System.in);

        int h, w;
        MainRoop : while(true){
            h = sc.nextInt();
            w = sc.nextInt();
            if(h == 0 && w == 0)break MainRoop;
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++)System.out.print("#");
                System.out.print("\n");
            }
            System.out.print("\n");
        }
    }
  
}


Measured memory_bytes: 37724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 400 + 10;
const ll mod = 1e9 + 7;
int n, c;
int a[maxn], b[maxn];
ll p[maxn][maxn], u[maxn][maxn], f[maxn][maxn];
int main()
{
	scanf("%d%d", &n, &c);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for(int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	for(int j = 0; j < maxn; ++j) 
	{
		p[j][0] = 1;
		for(int k = 1; k <= c; ++k)
			p[j][k] = p[j][k - 1] * j % mod;
	}
	for(int i = 1; i <= n; ++i)
		for(int k = 0; k <= c; ++k)
			for(int j = a[i]; j <= b[i]; ++j)
				u[i][k] = (u[i][k] + p[j][k]) % mod;
	f[0][0] = 1;
	for(int i = 1; i <= n; ++i)
		for(int j = 0; j <= c; ++j)
			for(int k = 0; k <= j; ++k)
				f[i][j] = (f[i][j] + f[i - 1][j - k] * u[i][k] % mod) % mod; 
	printf("%lld\n", f[n][c]);
	return 0;
}

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

using namespace std;

int main(void){
    int N;
    cin>>N;
    double result;
    if(N%2==0) result=1.0/2.0;
    else result=(double)(N+1)/(2.0*(double)N);
    cout<<fixed;
    cout<<setprecision(6)<<result<<endl;
    return 0;
}

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

using namespace std;


const int MAX = 100005;
const int NIL = -1;
typedef long long ll;

struct Node { int p, l, r; };
Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
    if (u == NIL)
        return;
    D[u] = d;
    setDepth(T[u].l, d + 1);
    setDepth(T[u].r, d + 1);
}

int setHeight(int u) {
    int h1 = 0, h2 = 0;
    if (T[u].l != NIL)
        h1 = setHeight(T[u].l) + 1;
    if (T[u].r != NIL)
        h2 = setHeight(T[u].r) + 1;
    return H[u] = max(h1, h2);
}

int getSibling(int u) {
    if (T[u].p == NIL)
        return NIL;
    if (T[T[u].p].l != u && T[T[u].p].l != NIL)
        return T[T[u].p].l;
    if (T[T[u].p].r != u && T[T[u].p].r != NIL)
        return T[T[u].p].r;
    return NIL;
}

void print(int u) {
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "sibling = " << getSibling(u) << ", ";

    int deg = 0;
    if (T[u].l != NIL) deg++;
    if (T[u].r != NIL) deg++;

    cout << "degree = " << deg << ", ";
    cout << "depth = " << D[u] << ", ";
    cout << "height = " << H[u] << ", ";

    
    if (T[u].p == NIL) cout << "root";
    else if (T[u].l == NIL && T[u].r == NIL) cout << "leaf";
    else cout << "internal node";
    cout << endl;
}


int main() {
    int root = 0;

    cin >> n;
    for (int i = 0; i < n; i++)
        T[i].p = NIL;

    for (int i = 0; i < n; i++) {
        int v, l, r; cin >> v >> l >> r;
        T[v].l = l;
        T[v].r = r;
        if (l != NIL) T[l].p = v;
        if (r != NIL) T[r].p = v;
    }

    for (int i = 0; i < n; i++) {
        if (T[i].p == NIL)
            root = i;
    }

    setDepth(root, 0);
    setHeight(root);

    for (int i = 0; i < n; i++)
        print(i);
}


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


int MOD=1000000007;

int main(void){
    int N;
    cin >> N;
    if(N<=9) cout << N << endl;
    else if(N<=99) cout << 9 << endl;
    else if(N<=999) cout << 9+(N-99) << endl;
    else if(N<=9999) cout << 909 << endl;
    else if(N<=99999) cout << 909+(N-9999) << endl;
    else cout << 90909 << endl;

}

Measured memory_bytes: 256
/*Allah Vorosha*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define n_p next_permutation
#define p_p prev_permutation
#define in insert
#define rev reverse
#define pf push_front
#define pob pop_back
#define uniq(v)         v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define all(x) (x).begin(),(x).end()
#define pof pop_front
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define scn scanf
#define prt printf
#define rep(i, a, n) for(int i = a; i < n; i++)
#define mod 1000000007
#define yes cout << "YES\n"
#define no cout << "NO\n";
#define take for(auto &it : a) cin >> it;
#define out cout << a << "\n";
#define l_b lower_bound
#define u_b upper_bound
#define Max 100005
template<typename T> T mymax(T x, T y) {
    return (x > y ? x : y);
}

using namespace std;

const int N = 1e6 + 5;

void solve() {
    int mul;
    cin >> mul;
    bool was[N];
    memset(was, 0, sizeof(was));
    int m = 0, ans = 1;
    while(true) {
        m *= 10;
        m += 7;
        m %= mul;
        if(m == 0) {
            printf("%d\n", ans); return;
        }
        if(was[m]) {
            printf("-1"); return;
        }
        ans++;
        was[m] = 1;
    }
    return;
}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 4652
#include "bits/stdc++.h"

using namespace std;

int main() {
	long double A,B;//<<10^15
	cin >> A >>B;
	//long long C = (long long )(100 * B);//10^3
	long long nAns = floor(A * B);//10^18
	//nAns /= 100;//10^16
	std::cout << nAns << endl;
	return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=301000;
int n,cnt[10];
ll ans=1;
char s[N];
int main() {
	scanf("%d",&n);
	scanf("%s",s);
	int mx=0,mn=0,mid=0;
	rep(i,0,3*n) {
		if (s[i]=='R') cnt[0]++;
		else if (s[i]=='G') cnt[1]++;
		else if (s[i]=='B') cnt[2]++;
		int nmx=*max_element(cnt,cnt+3),nmn=*min_element(cnt,cnt+3);
		int nmid=i+1-nmx-nmn;
		if (nmx!=mx) ans=ans*nmx%mod;
		else if (nmn!=mn) ans=ans*(nmid-nmn+1)%mod;
		else ans=ans*(nmx-nmid+1)%mod;
		mx=nmx; mn=nmn; mid=nmid;
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 512
N = int(input())

blank = 2
h = list(map(int,input().split())) + [0] * blank

INF = 10 ** 9 + 1
dp = [INF] * (N + blank)
dp[0] = 0

for i in range(N):
  if dp[i + 1] > dp[i] + abs(h[i + 1] - h[i]):
    dp[i + 1] = dp[i] + abs(h[i + 1] - h[i])
  if dp[i + 2] > dp[i] + abs(h[i + 2] - h[i]):
    dp[i + 2] = dp[i] + abs(h[i + 2] - h[i])

print(dp[N - 1])

Measured memory_bytes: 20572