akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	if(b>a)return 0;
	if(a==b)return 1;
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
//int g(int x){
//	x=modpow(x,MOD-2);
//	return x;
//}
int a,b;
set<int>st;
signed main(){
	cin>>a>>b;
	int g=gcd(a,b);
	for(int i=2;i*i<=g;i++){
		while(g%i==0){
			st.insert(i);
			g/=i;
		}
	}
	if(g!=1)st.insert(g);
	cout<<st.size()+1<<endl;	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define tag "spoj"
#define maxn 100007
#define oo 1000000007
#define mid ((l+r)>>1)
#define meset(a,x) memset(a,x,sizeof(a))
#define loop(x) for(int LoOpEr=1;LoOpEr<=x;LoOpEr++)
///>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
int main()
{
    #ifdef dmdd
    freopen(tag".inp","r",stdin); freopen(tag".out","w",stdout);
    #endif //dmdd
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

    if(a>b)swap(a,b);
    b-=a;

    if(b%2) cout<<"IMPOSSIBLE";
    else cout<<a+b/2;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int a[20000021];
multiset<int> s;
int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		s.insert(a[i]);
	}
	for (int i = 1; i <= n; i++) {
		multiset<int> :: iterator it;
		if ((it = s.find(a[i])) != s.end()) {
			s.erase(it);
		}
		multiset<int> :: iterator l = s.end();
		l--;
		printf("%d\n", *l);
		s.insert(a[i]);
	}
	return 0;
}

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

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

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define N_MAX	(  50 )
#define STR_MAX	(  51 )

char str_arg[N_MAX][STR_MAX] = { 0 };

char str_merge[STR_MAX] = { 0 };

int alphabet_count[N_MAX][27] = { 0 };
const char src_alphabet[27] =
{
	'a', 'b', 'c', 'd', 'e', 'f', 'g', 
	'h', 'i', 'j', 'k', 'l', 'm', 'n', 
	'o', 'p', 'q', 'r', 's', 't', 'u', 
	'v', 'w', 'x', 'y', 'z'
};

int main()
{
	int n;
	int i;
	int alphabet;
	
	scanf( "%d", &n );
	
	for ( i = 0; i <= n; i++ )
	{
		scanf( "%s", str_arg[i] );
	}
	
	for ( i = 0; i < n; i++ )
	{
		for ( alphabet = 0; alphabet < 27; alphabet++ )
		{
			char *p_str = str_arg[i];
			while ( *p_str != '\0' )
			{
				if ( src_alphabet[alphabet] == *p_str )
				{
					alphabet_count[i][alphabet]++;
				}
				p_str++;
			}
		}
	}
	
	int alphabet_num[27];
	
	for ( alphabet = 0; alphabet < 27; alphabet++ )
	{
		alphabet_num[alphabet] = STR_MAX - 1;
		for ( i = 0; i < n; i++ )
		{
			if ( alphabet_num[alphabet] > alphabet_count[i][alphabet] )
			{
				alphabet_num[alphabet] = alphabet_count[i][alphabet];
			}
		}
	}
	
	char *p_str_ans = str_merge;
	for ( alphabet = 0; alphabet < 27; alphabet++ )
	{
		int char_count;
		for ( char_count = 0; char_count < alphabet_num[alphabet]; char_count++ )
		{
			*p_str_ans = src_alphabet[alphabet];
			p_str_ans++;
		}
	}
	
	printf( "%s\n", str_merge );
	
	return 0;
}


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

#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

#include<unordered_map>
#include<random>

#define Seg_Max_N (1<<19) 

using Value = int ;
const Value ini =0 ;
struct segtree {
	int N;
	vector<Value>dat;

	segtree() {}
	segtree(int n) :dat(2 * Seg_Max_N) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++) {
			dat[i] = ini;
		}
	}
	Value connect(const Value&l, const Value&r) {
		return l+r;
	}
	// update k th element
	void update(int k, Value a) {
		k += N - 1;
		dat[k] = a;

		while (k > 0) {
			k = (k - 1) / 2;
			const Value al(dat[k * 2 + 1]);
			const Value ar(dat[k * 2 + 2]);
			dat[k] = connect(al, ar);
		}
	}
	// min [a, b)
	Value  query(int a, int b) { return query(a, b, 0, 0, N); }
	Value  query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return ini;
		if (a <= l and r <= b) return dat[k];
		const int m = (l + r) / 2;
		const Value al(query(a, b, k * 2 + 1, l, m));
		const Value ar(query(a, b, k * 2 + 2, m, r));
		return connect(al, ar);
	}
};
bool check(const vector<int>&oks) {
	segtree seg(4*oks.size());

	int m=2*oks.size();
	long long int sum=0;
	long long int kk=(oks.size()*static_cast<long long int>(oks.size()+1)/2);

	for (int i = 0; i < oks.size(); ++i) {
		if (oks[i]) {
			seg.update(m,1+seg.query(m,m+1));
			m--;
			int plus=seg.query(m, 4 * oks.size());
			sum+=plus;
		}
		else {
			seg.update(m, 1 + seg.query(m, m + 1));
			m++;
			int plus=seg.query(m, 4 * oks.size());
			sum+=plus;
		}
	}
	return (kk+1)/2<=sum;
}

bool solve(const vector<int>&v,int m) {
	vector<int>oks(v.size());
	for (int i = 0; i < v.size(); ++i) {
		if(v[i]>=m)oks[i]=true;
	}
	return check(oks);
}


int main() {
	int N;cin>>N;
	vector<int>as(N);
	for (int i = 0; i < N; ++i) {
		cin>>as[i];
	}
	int amin=0;
	int amax=1e9+2;

	while (amin + 1 != amax) {
		int amid=(amin+amax)/2;
		if (solve(as, amid)) {
			amin=amid;
		}
		else {
			amax=amid;
		}
	}
	cout<<amin<<endl;

	return 0;
} 

Measured memory_bytes: 7160
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, k;
    cin >> n >> k;
    const ll m = n*(n+1)/2;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    vl rui(n+1);
    rep(i, n) {
        rui[i+1] = rui[i] + a[i];
    }

    vl v;
    rep(i, n) {
        exrep(j, i+1, n) {
            v.pb(rui[j] - rui[i]);
        }
    }

    ll ans = 0;
    vl dame(m);  // dame[i] : v[i]は使用しないとき1
    for(ll d = 50; d >= 0; d--) {
        ll mask = 1LL<<d;
        ll cnt = 0;
        rep(i, m) {
            if(dame[i]) {
                continue;
            }
            if(v[i] & mask) {
                cnt++;
            }
        }
        if(cnt >= k) {
            ans += mask;
            rep(i, m) {
                if(!(v[i] & mask)) {
                    dame[i] = 1;
                }
            }
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 8304
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>


int main(){
  int A, B,C;
  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&C);
  std::cout << std::max(0,C-(A-B)) << std::endl;
  return 0;
}


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

using namespace std;

typedef long long  ll;
const ll MOD = 1e9 + 7;

ll Solve(int n, int c, const vector<int> &a, const vector<int> &b) {
    const int MAX_AB = 401;
    vector<vector<ll>> pow_sum(c + 1, vector<ll>(MAX_AB, 0));

    for (int j = 1; j < MAX_AB; ++j)
        pow_sum[0][j] = 1;
    for (int i = 1; i <= c; ++i)
        for (int j = 1; j < MAX_AB; ++j)
            pow_sum[i][j] = (pow_sum[i - 1][j] * j) % MOD;
    for (int i = 0; i <= c; ++i)
        for (int j = 2; j < MAX_AB; ++j)
            pow_sum[i][j] = (pow_sum[i][j] + pow_sum[i][j - 1]) % MOD;

    vector<vector<ll>> dp(n + 1, vector<ll>(c + 1, 0));
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= c; ++j) {
            ll sum = 0;
            for (int k = 0; k <= j; ++k) {
                ll x_k = (pow_sum[k][b[i]] - pow_sum[k][a[i] - 1] + MOD) % MOD;
                sum = (sum + (dp[i][j - k] * x_k) % MOD) % MOD;
            }
            dp[i + 1][j] = sum % MOD;
        }
    }

    return dp[n][c];
}

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

    int n, c;

    cin >> n >> c;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ++i)
        cin >> b[i];

    cout << Solve(n, c, a, b) << endl;

    return 0;
}


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

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

	int fa;
	cin >> fa;
	int pa = fa;

	vector<int> d(n);
	int m = 0;
	int mi = -1;
	for (int i = 1; i < n; ++i) {
		int a;
		cin >> a;

		int di = a - pa;
		d[i - 1] = di;
		
		if (di > m) {
			m = di;
			mi = i - 1;
		}

		pa = a;
	}

	d[n - 1] = k - pa + fa;
	if (d[n - 1] > m) {
		m = d[n - 1];
		mi = n - 1;
	}

	int s = 0;
	for (int i = 0; i < n; ++i) {
		if (i == mi) {
			continue;
		}

		s += d[i];
	}

	cout << s;

	return 0;
}
	

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
int x[8], y[8];
int n;

double dist(int i, int j){
  return sqrt((double)((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])));
}

int validroute(int route[]){
  int v[8];
  int i;
  for(i=0;i<n;i++) v[i]=0;
  for(i=0;i<n;i++){
    if(v[route[i]]){
      return 0;
    }
    v[route[i]]++;
  }
  return 1;
}

void increment(int route[],int idx){
  route[idx]++;
  if(idx>0 && route[idx]==n){
    route[idx]=0;
    increment(route,idx-1);
  }
}

int main()
{
  int i;
  int nroute=0;
  double sumdist=0;
  scanf("%d", &n);
  for(i=0;i<n;i++){
	scanf("%d%d", &x[i], &y[i]);
  }
  int route[8]={0,0,0,0,0,0,0,0};
  while(route[0]<n){
    increment(route,n-1);
    if(validroute(route)){
      nroute++;
      for(i=1;i<n;i++){
        sumdist+=dist(route[i-1],route[i]);
      }
    }
  }

  printf("%.10f\n",sumdist/(double)nroute);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int A, B;
int kosuu = 0;

void kai(int i)
{
  if (i / 10000 == i % 10)
  {
    if ((i / 1000) % 10 == ((i % 100) - (i % 10)) / 10)
    {
      kosuu++;
    }
  }
}

int main()
{
  cin >> A >> B;

  for (int i = A; i <= B; i++)
  {
    kai(i);
  }

  cout << kosuu << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;
#include<algorithm>



int main(){
     
    long n;
    double rt;    
    
    cin>>n;
    rt=floor(sqrt((double)n));
    for(int i=rt;i>=0;i--){
        if(n%i==0){
            cout<<floor(log10(n/i))+1<<endl;
            break;
        }
    }
     
    return 0;
}
 

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int MOD=1e9+7;

int32_t main()
{
   IOS
   int n,k;cin>>n>>k;
   vector<int>h(n+1);
   for(int i=1;i<=n;i++)
   cin>>h[i];
   vector<int>dp(n+1);
   dp[1]=0;
   for(int i=2;i<=n;i++){
	   dp[i]=1e9;
	   for(int j=1;j<=k;j++){
		   if( i-j >= 1 ){
			   dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
		   }
	   }
   }
   cout<< dp[n] << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main () {
int i,j;
char n[100000] = {0};
int  x[1001] = {0};

i = 0;
j = 0;


while(1) {
scanf("%c",&n[i]);
if(n[i] == '0' && n[i-1] == '\n'|| n[0] == '0') {break;}

if(n[i] >= '1' && '9' >= n[i] && n[i] != '\n') {
x[j] += n[i]-48;
}
  if(n[i] == '\n') {
j = j + 1;
}

i= i+1;

}

for(i=0; i < j;i++) {
printf("%d",x[i]);
printf("\n"); 

} 

return 0;

}


Measured memory_bytes: 2044
// author - saiku_ni_naro
// TO THE TOP

#include<bits/stdc++.h>
using namespace std;
#define F_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define double long double
#define endl '\n'
#define For(i,a,n) for(int i=(a);i<=(n);i++)
#define RFor(i,a,n) for(int i=(n);i>=(a);i--)
#define SET(a,val) memset((a),(val),sizeof((a)))
#define X first
#define Y second
#define pb push_back
#define over(v) v.begin(),v.end()
#define sz(x) (int)x.size()
#define inp(x) cin>>x;
#define oup(x) cout<<x<<endl;

const int N = 2e5 + 10;
int a[N];
const int MOD = 1e9 + 7;
vector<int> Pos,Neg;
vector<double> PosSum,NegSum;
vector<int> NegPair;
vector<double> NegPairSum;

void solving_problem(){
    int n,k; cin>>n>>k;

    For(i,1,n) cin>>a[i];
    sort(a+1,a+n+1);

    int product = 1;

    if(a[n] == 0 && (k&1)){
        cout<<0<<endl;
        return;
    }

    if(a[n] <= 0 && (k&1)){
        RFor(i,n-k+1,n) product = (product*a[i])%MOD, product = (product+MOD)%MOD;
        cout<<product<<endl;
        return;
    }

    int i = 1,j = n;

    if(k&1){
        product = (product*a[j])%MOD;
        j--,k--;
    }

    k>>=1;

    For(itr,1,k){
        int leftP = a[i]*a[i+1];
        int rightP = a[j]*a[j-1];

        if(leftP > rightP){
            leftP = leftP%MOD;
            product = (product*leftP)%MOD;
            i+=2;
        }else {
            rightP = rightP%MOD;
            product = (product*rightP)%MOD;
            j-=2;
        }
    }
	
  	product = (product+MOD)%MOD;
    cout<<product<<endl;
}

signed main(){
    F_IO;


    int testcases = 1; 
    // cin>>testcases;

    For(i,1,testcases){
        // cout<<"Cases #"<<i<<": ";
        solving_problem();
    }
}


    // For(i,1,n){
    //     cin>>a[i];
    //     if(a[i] < 0) Neg.push_back(-a[i]);
    //     else if(a[i] > 0) Pos.push_back(a[i]);
    //     else zero++;
    // }

    // sort(all(Pos)); reverse(all(Pos));
    // sort(all(Neg)); reverse(all(Neg));

    // For(i,0,sz(Pos)-1) PosSum.push_back(log(Pos[i]));
    
    // For(i,1,sz(Neg)-1) NegPair.push_back(Neg[i]*Neg[i-1]);
    // For(i,0,sz(NegPair)) NegPairSum.push_back(log(NegPair[i]));

    // if(sz(Pos) + sz(Neg) < k){
    //     cout<<0<<endl; 
    //     return;
    // }

    // int NegC = -1;
    // double Sum = 0;

    // For(i,0,sz(NegSum)){
    //     double sumTemp = 0;
    //     if(i > 0) sumTemp += NegPairSum[i-1];

    //     int Left = k - 2*i;
    //     if(Left < 0 || sz(Pos) < Left) continue;

    //     int FromPos = min(Left,sz(Pos));
    //     if(FromPos > 0) sumTemp += PosSum[FromPos-1];

    //     if(sumTemp > Sum) Sum = sumTemp,NegC = i;
    //     continue;
    // }

    // if(NegC == -1){
    //     if(zero) cout<<0<<endl;
    //     else 
    // }

Measured memory_bytes: 5196
#include<bits/stdc++.h>
using namespace std;
int n,m,x;
int a[50][50],c[50],s[50],ans=2147483647;
struct node{
	int p,v[50];
	bool operator<(const node&B)const{
		return p<B.p;
	}
}q[50];
int main(){
	scanf("%d%d%d",&n,&m,&x);
	for(int i=1;i<=n;++i){
		scanf("%d",&q[i].p);
		for(int j=1;j<=m;++j)scanf("%d",&q[i].v[j]),s[j]+=q[i].v[j];
	}
	for(int i=1;i<=m;++i)if(s[i]<x){puts("-1");return 0;}
	for(int i=0;i<=(1<<n)-1;++i){
		fill(s+1,s+m+1,0);
		int res=0;
		for(int j=0;j<n;++j){
			if((i>>j)&1){
				//选择第j+1个书
				res+=q[j+1].p;
				for(int k=1;k<=m;++k)s[k]+=q[j+1].v[k];
			}
		}
		//cout<<i<<":"<<res<<endl;
		for(int j=1;j<=m;++j)if(s[j]<x){res=2147483647;break;}
		ans=min(ans,res);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3772
//ITNOA
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
const long long INF=1e9+10,MAX=2e5+1e4,MOD=1e9+7;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
void OUT(long double o,int x){
	 cout<<fixed<<setprecision(x)<<o;
	 return;
}
ll a[MAX];
map<ll,int> mp;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,x=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	sort(a,a+n);
	for(int i=n-1;i>=0;i--){
		if(x==0){
			if(mp[a[i]]>3)
				return cout<<a[i]*a[i],0;
			if(mp[a[i]]>1)
				x=a[i];
		}
		else if(x!=a[i]){
			if(mp[a[i]]>1)
				return cout<<x*a[i],0;
		}
	}
	cout<<0;
	return 0;
}


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 3;
  if (a == b){
    ans--;
  }
  if (b == c){
    ans--;
  }
  if(c == a){
    ans--;
  }
  if(a == b && b == c){
    ans++;
  }
  cout << ans << endl;
}
    
    

Measured memory_bytes: 256
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <random>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    vector<int> v;
    for (int i = 0; i < 3; ++i) {
        int t;
        cin >> t;
        v.emplace_back(t);
    }
    sort(v.begin(), v.end());
    int ans;
    ans = v[2] - v[1];
    v[0] += ans;
    ans += (v[2] - v[0]) / 2;
    v[0] += ((v[2] - v[0]) / 2) * 2;
    if (v[0] == v[2]) {
        
    } else if ((v[2] - v[0]) % 2 > 0) {
        ans += 2;
    } else {
        ans += 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
long long x,y;
int main()
{
	int n;
	int t,a;
	long long h;
	scanf("%d",&n);
	scanf("%lld%lld",&x,&y);
	for(int i=2;i<=n;i++)
	{
		scanf("%d%d",&t,&a);
		h=max((x+t-1)/t,(y+a-1)/a);
		x=h*t;
		y=h*a;
	}
	printf("%lld",x+y);
	return 0;
}

Measured memory_bytes: 256
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  
def main():
  a,b = map(int,input().split())
  ans = 0
  outlet = 1
  while outlet < b:
    outlet -=1
    outlet += a
    ans += 1
    
    
  print(ans)
if __name__ == '__main__':
  main()

Measured memory_bytes: 2940
import Control.Monad

main :: IO ()
main = do
  n <- readLn :: IO Int
  -- putStrLn . showbm2 . solve $ n
  putStrLn . showbm2 . reverse . solve' $ n

solve :: Int -> [Int]
solve 0 = [0]
solve n = head . join $ [ [ cand | cand <- greedCandidates i, bm2 cand == n]| i <- [0..]]

greedCandidates n = replicateM n [0, 1]

bm2 as = sum $ zipWith (\a i -> a * (-2) ^ i) (reverse as) [0..]

showbm2 :: [Int] -> String
showbm2 as = concat $ map show as

solve' :: Int -> [Int]
solve' 0 = [0]
solve' 1 = [1]
solve' n = a : solve' ((n - a) `div` (-2))
  where
    a = n `mod` 2


Measured memory_bytes: 508
#include<stdio.h>
int main(){
   int a;
   int b;
   scanf("%d %d",&a,&b);
   if(a<b){
      for(int i=0;i<b;i++){
         printf("%d",a);
      }
   }else{
      for(int i=0;i<a;i++){
         printf("%d",b);
      }
   }
   return 0;
}


Measured memory_bytes: 1700
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

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

    bool ok = true;
    REP(i, 0, N) {
        int a; cin >> a;
        if (a % 2 != 0) continue;
        if (a % 3 != 0 && a % 5 != 0) ok = false;
    }
    if (ok) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
    return 0;
}

Measured memory_bytes: 256
import math
import functools
import itertools


N = int(input())
positions = list()
for _ in range(N):
    positions.append([int(i) for i in input().split(" ")])

d = dict()
for a, b in itertools.product(range(N), range(N)):
    a_x, a_y = positions[a]
    b_x, b_y = positions[b]
    distance = math.sqrt((a_x - b_x) ** 2 + (a_y - b_y) ** 2)
    d[(a, b)] = distance

total = 0
multiplier = functools.reduce(lambda x, y: x*y, range(1, N))
for key in d:
    total += d[key] * multiplier

print(total / functools.reduce(lambda x, y: x*y, range(1, N+1)))



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

using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define INF (ll)2e9
#define MOD ((ll)1e9+7)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define bit(n) (1LL<<(n))

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

template<class InputIterator>
InputIterator adv(InputIterator x, typename std::iterator_traits<InputIterator>::difference_type n) {
    advance(x, n);
    return x;
}

class mod {
    static ll fact[];
public:

    template<class... A>
    static ll mul(A... args) {
        ll res = 1;
        for (ll i : std::initializer_list < ll > {args...}) {
            res = (res * i) % MOD;
        }
        return res;
    }

    static ll power(ll base, ll exp) {
        if (exp == 0) return 1;
        if (exp & 1) {
            return mul(base, power(base, exp - 1));
        } else {
            ll p = power(base, exp / 2);
            return mul(p, p);
        }
    }

    static ll factorial(int n) {
        if (fact[n] != 0) return fact[n];
        if (n == 0) return 1;
        return fact[n] = mul(n, factorial(n - 1));
    }

    static ll inverse(int n) {
        return power(n, MOD - 2);
    }

    static ll comb(int n, int r) {
        if (r < 0 || r > n) return 0;
        return mul(factorial(n), inverse(factorial(n - r)), inverse(factorial(r)));
    }

    template<class... A>
    static ll div(ll dividend, A... args) {
        ll res = dividend;
        for (ll i : std::initializer_list < ll > {args...}) {
            res = mul(res, inverse(i));
        }
        return res;
    }

    template<class... A>
    static ll add(A... args) {
        ll res = 0;
        for (ll i : std::initializer_list < ll > {args...}) {
            res = (res + i) % MOD;
        }
        return res;
    }

    template<class... A>
    static ll sub(ll l, A... args) {
        ll res = l;
        for (ll i : std::initializer_list < ll > {args...}) {
            res = (res - i + MOD) % MOD;
        }
        return res;
    }
};

ll mod::fact[(int) 1e6 + 1];

int ni() {
    int i;
    cin >> i;
    return i;
}

ll nll() {
    ll l;
    cin >> l;
    return l;
}

int main() {
    int H = ni(), W = ni(), A = ni(), B = ni();

    ll ans = 0;
    REP(i, H-A) {
        ans = mod::add(ans, mod::mul(mod::comb(i + (B-1), B-1), mod::comb((H-1-i) + (W-1-B), W-1-B)));
    }

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

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=1000000;
const ll inf=1e9;
const ll mod=998244353;


int a[MX];

int main()
{

    FasterIO;


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

    ll sm=0, c=0;
    for(int i=1; i<=n; i++)
    {
        int d=a[i]+c;
        sm+=d/2;
        if(a[i]) c=d%2;
        else     c=0;
    }
    cout<<sm<<endl;
    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) begin(v), end(v)

using int64 = long long;
const int INF = 1 << 30;
const int mod = 1e9 + 7;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};


int main()
{
  int N, X[100000], Y[100000];

  cin >> N;
  rep(i, N) cin >> X[i] >> Y[i];
  vector< int > ord(N);
  iota(all(ord), 0);
  sort(all(ord), [&](int x, int y)
  {
    return (X[x] < X[y]);
  });

  vector< tuple< int, int, int > > es;
  for(int i = 1; i < N; i++) {
    es.emplace_back(X[ord[i]] - X[ord[i - 1]], ord[i], ord[i - 1]);
  }

  iota(all(ord), 0);
  sort(all(ord), [&](int x, int y)
  {
    return (Y[x] < Y[y]);
  });

  for(int i = 1; i < N; i++) {
    es.emplace_back(Y[ord[i]] - Y[ord[i - 1]], ord[i], ord[i - 1]);
  }

  sort(begin(es), end(es));

  int64 ret = 0;
  UnionFind uf(N);
  for(auto &e : es) {
    int a, b, c;
    tie(a, b, c) = e;
    if(uf.unite(b, c)) ret += a;
  }

  cout << ret << endl;
}

Measured memory_bytes: 6132
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef unsigned long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)

//#define DEBUG

class Solve
{
	public:

		vector<int> v1,v2;
		int n, p, w, ans;

		void input()
		{
			cin >> n;
			rep(i, n)
			{
				cin >> p;
				v1.push_back(p);
			}

			rep(i, n)
			{
				v2.push_back(i+1);
			}
		}

		void solve()
		{
			//sort(v1.begin(), v1.end());

		#ifdef DEBUG
			rep(i, n) cout << v1[i] << ' ';
			cout << endl;
			rep(i, n) cout << v2[i] << ' ';
			cout << endl;
		#endif

			rep(i,n)
			{
				if(v1[i] != v2[i])
				{
					w++;
				}
			}
		#ifdef DEBUG
			cout << w << endl;
		#endif
		}

		void output()
		{
			if(w == 0 || w == 2)
			{
				cout << "YES" << endl;
			}
			else
			{
				cout << "NO" << endl;
			}
        }
};

Solve s;
int main()
{
    s.input();
	s.solve();
	s.output();
	return 0;
}


Measured memory_bytes: 256
/* ex4_3
    fmuacshai */
 
#include<stdio.h>
//プロトタイプ宣言
int snow(int w_height,int e_height);
 
int main (void){
    //与えられる西の塔の高さと東の塔の高さをwestとeastと定義
    int west,east;
    //westを入力
    scanf("%d",&west);
    //eastを入力
    scanf("%d",&east);
    //snow関数の結果を出力
    printf("%d\n",snow(west,east));
    return 0;
}
 //西の塔w_heightと東の塔e_heightを変数とした関数snowを定義
int snow(int w_height,int e_height){
    //結果ansと低い方の塔の番号numと西の塔の実際の高さをsumとする
    int ans,num,sum;
    //numの計算
    num=e_height-w_height;
    num-=1;
    //sumの初期設定
    sum=0;
    //sumの計算
    while(num>0){
        sum+=num;
        num-=1;
    }
    //ansの計算
    ans=sum-w_height;
    //返り値を返す
    return(ans);
}

Measured memory_bytes: 128
// Problem : A - Five Variables
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;

int x;
map<int,int> mp;
int main() {
    ios::sync_with_stdio(false);cin.tie(0);
	for(int i=1;i<=5;++i){
		cin>>x;
		mp[x]++;
	}
	for(int i=1;i<=5;++i){
		if(!mp[i]){
			cout<<i;
			break;
		}
	}
	



    return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
int main(void){
  int a,b,c;
  if(scanf("%d%d%d",&a,&b,&c)<3) return 1;
  if(a+b+c>21){
    printf("bust\n");
  }
  else{
    printf("win\n");
  }
  return 0;
}

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

int main()
{
	int n, k;
	cin >> n;
	long long a[n+5][5];
	for(int i = 1 ; i<=n ; i++)
	{
		for(int j = 1 ; j<=3 ; j++)
		{
			cin >> a[i][j];
		}
	}
	for(int i = 2 ; i<=n ; i++)
	{
		for(int j = 1 ; j<=3 ; j++)
		{
			if(j==1)
				a[i][j] = a[i][j] + max(a[i-1][j+1] , a[i-1][j+2]);
			else if(j==2)
				a[i][j] = a[i][j] + max(a[i-1][j-1] , a[i-1][j+1]);
			else
				a[i][j] = a[i][j] + max(a[i-1][j-1] , a[i-1][j-2]);
		}
	}
	cout << max(a[n][1], max(a[n][2],a[n][3]));
	return 0;
}

Measured memory_bytes: 4096
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
 
using namespace std;
int main(){
  int m,n;
  cin>>m>>n;
  cout<<(m-1)*(n-1)<<endl;
}  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b[100001]{},cnt=0,maxcnt=0;
	bool c[100001]{};
	cin>>a>>b[0];
	for (int i=1;i<a;i++)
	{
		cin>>b[i];
		if (b[i]<=b[i-1])
			c[i-1]=true;
		else
			c[i-1]=false;
	}
	for (int i=0;i<a-1;i++)
		if (c[i])
			cnt++;
		else
		{
			maxcnt=max(cnt,maxcnt);
			cnt=0;
		}
	maxcnt=max(cnt,maxcnt);
	cout<<maxcnt;
	return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<map>
#include<utility>
using namespace std ;
int main()
{
    vector < pair < string ,int >  > v ;
    int n,ans=0;
    cin >> n ;
    for(int i=0;i<n;i++)
    {
        string s  ; int x ;
        cin >> s >> x ;
        v.push_back(make_pair(s,x));
    }
    string str ;
    cin >> str ;
    int f=0;
    for(int i=0;i<n;i++)
    {
        string s = v[i].first ;
        int x = v[i].second;
        if(f==1){ans+=x;}
        if(s==str){f=1;}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N, = map(int, input().split())
Ps = map(float, input().split())
dp = [[0]*(N+1)for _ in range(N+1)]
dp[0][0] = 1
for i, p in enumerate(Ps):
    for j in range(N+1):
        dp[i+1][j] = p*dp[i][j-1] + (1-p)*dp[i][j]
r = 0
for i in range(N, N//2, -1):
    r += dp[N][i]
print(r)


Measured memory_bytes: 259208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct UnionFind {
    UnionFind() {}
    UnionFind(int n) {
        resize(n);
    }
    
    void resize(int n) {
        par.resize(n, -1);
    }
    
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    
    bool merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    
    bool is_same(int x, int y) {
        return (root(x) == root(y));
    }
    
    int size(int x) {
        return -par[root(x)];
    }
    
private:
    vector<int> par;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m, k;
    cin >> n >> m >> k;
    vector<set<ll>> ng(n);
    UnionFind uf(n);
    rep(i, m) {
        ll c, d;
        cin >> c >> d;
        c--; d--;
        ng[c].insert(d);
        ng[d].insert(c);
        uf.merge(c, d);
    }
    rep(i, k) {
        ll c, d;
        cin >> c >> d;
        c--; d--;
        ng[c].insert(d);
        ng[d].insert(c);
    }
    rep(i, n) {
        ll ans = uf.size(i) - 1;
        for(auto x : ng[i]) {
            if (uf.is_same(x, i)) ans--;
        }
        printf("%lld%s", ans, (i == (n - 1)) ? "\n" : " ");
    }
    return 0;
}


Measured memory_bytes: 24704
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var K = cin.ReadInt;
            var l = cin.ReadIntArray(N);

            Array.Sort(l);
            Array.Reverse(l);

            var ans = 0;
            for (int i = 0; i < K; i++)
            {
                ans += l[i];
            }

            WriteLine(ans);
        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 

const ll large_P = 1e9 + 7;


int main(){
  int N; cin >> N;
  vector<int> P(N), Q(N);
  rep(i, N) cin >> P.at(i); 
  rep(i, N) cin >> Q.at(i);
  
  vector<int> R(N);
  rep(i, N) R.at(i) = i + 1;
  
  int a, b;
  int count = 0;
  
  
  do{
    bool temp_P = true;
    bool temp_Q = true;
    rep(i, N){
      if(P.at(i) != R.at(i)) temp_P = false;
      if(Q.at(i) != R.at(i)) temp_Q = false;
    }
    if(temp_P) a = count;
    if(temp_Q) b = count;
   
    
    //rep(i, N) cout << R.at(i) << " ";
    //cout << "count " << count << endl;
    count++;
  } while(next_permutation(R.begin(), R.end()));
  
  
  cout << abs(a - b) << endl;
  //cout << a << endl;
  //cout << b << endl;

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int r, g, b, n;
long long cnt;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> r >> g >> b >> n;
	for (int i = 0; i*r <= n; i++) {
		for (int j = 0; j*g <= n; j++) {
			int tmp = n - i*r - j*g;
			if (0 <= tmp && tmp%b == 0) cnt++;
		}
	}
	cout << cnt << "\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
using namespace std;


int main(){
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];

  sort(a.begin(), a.end());

  cout << a[0] << " " << a[1] << " " << a[2] << endl;

  return 0;
}








// EOF

Measured memory_bytes: 3152
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

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

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long MOD = 1000000007;

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

	int h, n;
	cin >> h >> n;
	pii* magic;
	magic = new pii[n];
	rep(i, n) cin >> magic[i].first >> magic[i].second;

	sort(magic, magic + n, [](pii &x, pii &y) {
		if (x.second != y.second) {
			return x.second < y.second;
		}
		else {
			return x.first > y.first;
		}
		});

	int* p;
	p = new int[h+1];
	p[0] = 0;
	REP(i, 1, h+1) {
		p[i] = MOD;
		rep(j, n) {
			if (i <= magic[j].first) {
				if (p[i] >= magic[j].second) {
					p[i] = magic[j].second;
					break;
				}
			}
			else {
				p[i] = min(p[i], p[i - magic[j].first] + magic[j].second);
			}
		}
	}

	cout << p[h] << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; 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)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
    string s; cin >> s;
    rep(i,3){
        if(s[i]==s[i+1]){
            cout<<"Bad"<<endl;return 0;
        }
    }
    cout<<"Good"<<endl;
    return 0;
}
 
 


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define vec vector<int>
#define pb push_back
#define lis list<int> lst(1000)


int main(){
	int N,Y;

	scanf("%d%d",&N,&Y);

	for(int a=0;a<=N;a++){
		for(int b=0;b+a<=N;b++){
			int c = N-a-b;
			if ((a*10000+b*5000+c*1000)==Y){
				cout << a << " " << b << " " << c << endl;
				return 0;
			}
			
		}
	}

 cout << "-1 -1 -1" << endl;
 return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
	int a,b,c,d,e,k; scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&k);
	int box[5]={a,b,c,d,e};
	int judge=0;
	for (int i = 0; i < 5; ++i)
	{
		for (int j = 0; j < 5; ++j)
		{
			if(abs(box[i]-box[j])>k){
				printf(":(");
				judge++;
				break;			
			}
		}

		if(judge==1) break;
		if(judge==0&&i==4) printf("Yay!");

	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){
    int M;
    while(cin >> M){
        long long res = 0;
        long long sum = 0;
        for(int i=0;i<M;i++){
            long long d, c; cin >> d >> c;
            res += c;
            sum += d*c;
        }
        --res;
        res += (sum-1)/9;
        cout << res << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            int p,bestp;
            double h,w,bmi,bestbmi=100000.0;
            for (int i=0;i<n;i++) {
                cin>>p>>h>>w;
                h=h/100;
                bmi=w/(h*h);
                //cout<<bmi<<endl;
                if (abs(22.0-bmi)<bestbmi) {
                    bestp=p;
                    bestbmi=abs(22-bmi);
                }
            }
            cout<<bestp<<endl;
        }
    }
}


Measured memory_bytes: 3180
N = int(input())
A = input()
ai = A.split()
B = input()
bi = B.split()
i = 0
a = []
b = []
for i in range(N):
    a.append(int(ai[i]))
    b.append(int(bi[i]))

i = 0
asum = 0
bsum = 0
for i in range(N):
    asum += a[i]
    bsum += b[i]

c = True
j = 0
if asum > bsum:
    print("No")
    c = False
elif asum == bsum:
    for j in range(N):
        if a[j] != b[j]:
            print("No")
            c = False
            break
    if c:
        print("Yes")
        c = False
else:
    k = 0
    Da = 0
    Db = 0
    d = bsum - asum 
    while Da <= d and Db <= d:
        dab = 0
        if a[k] < b[k]:
            dab = b[k] - a[k]
            if dab // 2 == 0:
                Da += 1
                a[k] += 2
            else:
                Da += dab // 2
                a[k] += (dab // 2) * 2 
        elif a[k] == b[k]:
            k += 1
        else:
            dab = a[k] - b[k]
            Db += dab
            b[k] += dab
        if k == N:
            break
if c:
    for j in range(N):
        if a[j] != b[j]:
            print("No")
            c = False
            break
    if c:
        if (d - Da) * 2 == (d - Db) * 1:
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 5620
const val P = 1000000007L

// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

fun solveCase(): Long {
  val n = readLine()!!.toInt()
  val xs = fastReadInts(n)
  val xorArray = IntArray(n + 1)
  for (i in 1..n) {
    xorArray[i] = xorArray[i - 1] xor xs[i - 1]
  }
  val zeroCountArray = IntArray(n + 1)
  zeroCountArray[0] = 1
  for (i in 1..n) {
    zeroCountArray[i] = zeroCountArray[i - 1] + (if (xorArray[i] == 0) 1 else 0)
  }

  val indexLists = Array(1 shl 20, { mutableListOf<Int>() })
  for (i in 1..n) {
    if (xorArray[i] != 0) {
      indexLists[xorArray[i]].add(i)
    }
  }

  if (xorArray[n] != 0) {
    val x = xorArray[n]
    // println(indexLists[x])
    val xIndexArray = indexLists[x].toIntArray()
    if (xIndexArray.size == 1) return 1L

    val dp1 = LongArray(xIndexArray.size)
    val dp2 = LongArray(xIndexArray.size)
    dp1[0] = 1
    dp2[0] = 1
    for (i in 1 until dp1.size) {
      val zeroCountDiff = zeroCountArray[xIndexArray[i]] - zeroCountArray[xIndexArray[i - 1]]
      dp1[i] = dp2[i - 1] * zeroCountDiff  + dp1[i - 1]
      dp1[i] %= P
      dp2[i] = dp2[i - 1] + dp1[i]
      dp2[i] %= P
    }

    return dp1.last()
  }

//  println(xorArray.asList())
//  println(zeroCountArray.asList())
  var count = pow2(zeroCountArray.last() - 2)
  for (x in 1 until (1 shl 20)) {
    if (indexLists[x].isEmpty()) continue
//    println("x: $x")
//    println(indexLists[x])
    if (indexLists[x].size == 1) {
      count += 1
      count %= P
      // println("count: $count")
      continue
    }

    val xIndexArray = indexLists[x].toIntArray()
    val dp1 = LongArray(xIndexArray.size)
    val dp2 = LongArray(xIndexArray.size)
    dp1[0] = 1
    dp2[0] = 1
    for (i in 1 until dp1.size) {
      val zeroCountDiff = zeroCountArray[xIndexArray[i]] - zeroCountArray[xIndexArray[i - 1]]
      dp1[i] = dp2[i - 1] * zeroCountDiff  + dp1[i - 1]
      dp1[i] %= P
      dp2[i] = dp2[i - 1] + dp1[i]
      dp2[i] %= P
    }

    count += dp2.last()
    count %= P
    // println("count: $count")
  }
  return count
}

fun pow2(p: Int): Long {
  var ret = 1L
  repeat(p) {
    ret *= 2L
    ret %= P
  }
  return ret
}

fun main(args: Array<String>) {
  println(solveCase())
}


Measured memory_bytes: 126944
#include<iostream>
#include<string>
#include<stdio.h>
int main() {

	int N = 0;

	double x[10] = {};

	std::string mozi[10];

	double money = 0.0;
	double bit = 380000.0;

	std::cin >> N;

	for (int i = 0; i < N; i++) {
		std::cin >> x[i];
		std::cin >> mozi[i];
	}

	for (int i = 0; i < N; i++) {
		if (mozi[i] == "JPY") {
			money += x[i];
		}
		else if (mozi[i] == "BTC") {
			money += bit * x[i];
		}
	}

	std::cout << money << std::endl;


}

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

import bisect
ans = 0

L.sort()
for i in range(0,N-2):
    for j in range(i+1,N-1):
        a = L[i]
        b = L[j]
        index = bisect.bisect_left(L,a+b)
        if index > j:
            ans += index-j-1
            
print(ans)

Measured memory_bytes: 9220
//
// Created by yamunaku on 2020/03/22.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    //CFS;
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    int ans = IINF;
    rep(i, 1 << (h - 1)){
        int tmp = 0;
        int sz = 1;
        rep(j, h - 1){
            if(i & (1 << j)){
                tmp++;
                sz++;
            }
        }
        vi count(sz, 0);
        vi add(sz, 0);
        rep(j, w){
            int idx = 0;
            rep(x, h){
                if(s[x][j] == '1') add[idx]++;
                if(i & (1 << x)) idx++;
            }
            bool cut = false;
            rep(x, sz){
                if(add[x] > k) tmp = IINF;
                if(count[x] + add[x] > k) cut = true;
            }
            if(cut){
                tmp++;
                rep(x, sz) count[x] = 0;
            }
            rep(x, sz){
                count[x] += add[x];
                add[x] = 0;
            }
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256