akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
  
typedef struct node{
    int p;
    int left;
    int right;
} Node;
  
int searchHight(int);
  
Node *trees;
  
int main(){
      
    int n,i,id,depth,tmpP,deg,nowNode,sibling;
  
    scanf("%d", &n);
  
    trees = malloc(sizeof(Node)*n);
  
    for (i = 0; i < n; ++i){
        trees[i].p = -1;
    }
  
    for (i = 0; i < n; ++i){
        scanf("%d",&id);
        scanf("%d%d",&trees[id].left,&trees[id].right);
	trees[trees[id].left].p = id;
	trees[trees[id].right].p = id;
    }
  
    nowNode = 0;
    while(1){
        if (trees[nowNode].left != -1 && trees[nowNode].right != -1)
        {
            break;
        } else if (trees[nowNode].left == -1)
        {
            nowNode = trees[nowNode].right;
        } else {
            nowNode = trees[nowNode].left;
        }
    }
  
    for (i = 0; i < n; ++i){
          
        tmpP = trees[i].p;
        if (tmpP == -1) sibling = -1;
        else if(trees[tmpP].left == i) sibling = trees[tmpP].right;
        else sibling = trees[tmpP].left;

        depth = 0;
        while(tmpP != -1){
            tmpP = trees[tmpP].p;
            depth++;
        }
  

        deg = 0;
        if (trees[i].left != -1) deg++;
        if (trees[i].right != -1) deg++;
  
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, "
            ,i,trees[i].p,sibling,deg,depth,searchHight(i));
  
        if(trees[i].p == -1) printf("root\n");
        else if(trees[i].left == -1 && trees[i].right == -1) printf("leaf\n");
        else printf("internal node\n");
    }
  
    return 0;
}
  
int searchHight(int index){
    int hLeft = 0;
    int hRight = 0;
  
    if (trees[index].left != -1){
        hLeft = searchHight(trees[index].left) +1;
    }
    if (trees[index].right != -1){
        hRight = searchHight(trees[index].right) +1;
    }
    if (hLeft < hRight) return hRight;
    else return hLeft;
}

Measured memory_bytes: 612
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s[ohara], co;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
map<string, ll> mp;

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

  cin >> n;
  rep(i, n) {
    cin >> co;
    sort(all(co));
    s[i] = co;
  }
  rep(i, n) { mp[s[i]]++; }
  rep(i, n) {
    ans += mp[s[i]] * (mp[s[i]] - 1) / 2;
    mp[s[i]] = 0;
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 19072
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)




int main(){
   ll N,M;
   cin>>N>>M;


   vector<ll> s(M);
   vector<ll> c(M);
   vector<ll> keta(N,-1);

   for(ll i=0;i<M;i++){
       cin>>s[i]>>c[i];
   }
ll ok=1;
   for(ll i=0;i<M;i++){
       if(keta[s[i]-1]!=-1&&keta[s[i]-1]!=c[i]){
           ok=0;

           break;
       }
       else{
           keta[s[i]-1]=c[i];
       }
   }

   if(N!=1){
       if(keta[0]==0)
       ok=0;
   }

   if(ok==0){
       cout<<-1<<endl;
       return 0;
   }

    if(N==1){
        if(keta[0]==-1){
            cout<<0<<endl;
            return 0;
        }
   }

   for(ll i=0;i<N;i++){
       if(keta[i]==-1){
           if(i==0){
               keta[i]=1;
           }
           else{
               keta[i]=0;
           }
       }
   }



for(ll i=0;i<N;i++){
    cout<<keta[i];
}
cout<<endl;
return 0;





}


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

int main() {
    ll x, ans=0, tmp, it;
    cin >> x;
    
    for(ll i=-1e3; i<1e3; i++){
	tmp = -(x-i*i*i*i*i);
	
	if (tmp<=0) 
	    it=-1;
	else
	    it=1;
	
	for(ll j=0; ; j+=it){
	    ll a=j*j*j*j*j;
	    if(a ==tmp){
		cout << i << " " <<j<< endl;
		return 0;
	    }
	    if(a>tmp*it)
		break;
	}
    }

} 




Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    if (S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes" << endl;
        return 0;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = 0;
    for(int i=0; i<3; i++){
      a += sc.nextInt();
    }
    if(a>=22){
      System.out.println("bust");
    }
    else{
      System.out.println("win");
    }
  }
}

Measured memory_bytes: 22740
X, Y = map(int, input().split())

# どちらか一方のみいる場合
if X * 2 == Y or X * 4 == Y:
  print('Yes')
  exit()
  
# 両方いる場合
for i in range(1,X+1):
  tmp = 2 * i + 4 * (X - i)
  if tmp == Y:
    print('Yes')
    exit()

print('No')

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

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

#define MOD 1000000007

using namespace std;

int main(){
	int n;	cin >> n;
	n %= 10;

	switch(n){
		case 2:
		case 4:
		case 5:
		case 7:
		case 9:
		cout << "h";
		break;

		case 0:
		case 1:
		case 6:
		case 8:
		cout << "p";
		break;

		case 3:
		cout << "b";
		break;
	}

	cout << "on" << endl;

	return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
int main(){
	int a,b,i,j;
	while(1){
		scanf("%d%d",&a,&b);
		if(a==0 && b==0)break;
		for(i=0;i<a;i++){
			for(j=0;j<b;j++){
				if(i==0 || i==a-1 || j==0 || j==b-1)printf("#");
				else printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2020
# -*- coding: utf-8 -*-
"""
Created on Thu Sep  3 21:04:57 2020

@author: liang
"""
from operator import add

#import numpy as np
N, M, X = map(int, input().split())

#A = [np.array(list(map(int, input().split()))[1:]) for _ in range(N)]
A = [list(map(int, input().split())) for _ in range(N)]
ans = 10**7
for i in range(2**N):
    C_list = list()
    for j in range(N):
        if i>>j&1 == 1:
            C_list.append(j)
    #tmp = np.array( [0]*M )
    tmp = [0]*(M+1)
    for i in C_list:
        tmp = list(map(add, A[i], tmp))
    if all([ i >= X for i in tmp[1:]]) and tmp[0] < ans :
        ans = tmp[0]
    #print(tmp)
if ans == 10**7:
    ans = -1
print(ans)

Measured memory_bytes: 9248
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=105,P=1e9+7;

int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }

int n, f[N][N], m; 
char g[N][N]; 

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("d.in", "r", stdin); 
#endif
	read(n), read(m); 
	rep(i, 1, n) scanf("%s", g[i]+1); 
	mem(f, 0x3f); 
	f[0][1] = f[1][0] = 0; 
	g[0][1] = g[1][0] = '&';
	rep(i, 1, n) rep(j, 1, m) {
		if (g[i][j] == '.') {
			f[i][j] = min(f[i-1][j],f[i][j-1]); 
		} else {
			f[i][j] = min(f[i-1][j]+(g[i-1][j]!='#'),f[i][j-1]+(g[i][j-1]!='#')); 
		}
	}
	printf("%d\n", f[n][m]); 
	return 0;
}


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

  long long maxAbsValExpr(vector<long long>& x, vector<long long>& y) {
       	long long res=0;
       	long long d[4][x.size()];
        for (int i=0;i<x.size();i++){
            d[0][i]=x[i]+y[i];
            d[1][i]=-x[i]-y[i];
            d[2][i]=x[i]-y[i];
            d[3][i]=-x[i]+y[i];
        }
        for (int i=0;i<4;i++)
        {
        	sort(d[i],d[i]+x.size());
        }

        for (int i=0;i<4;i++)
        {
        	res=max(res,d[i][x.size()-1]-d[i][0]);
        }
        return res;
    }
int main()
{
	int n;
	cin >> n;
	
		vector <long long> x(n);
		vector <long long> y(n);

	for(int i=0;i<n;i++) cin >> x[i] >> y[i];

	cout << maxAbsValExpr(x,y);
	return 0;
}

Measured memory_bytes: 12664
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

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

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

	int ans = 0;
	for (int i = 0; i < k; i++)ans += p[i];

	cout << ans;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

using ll = long long;

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

    vector<int> v(n);

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

    multiset<int> st;
    int out = 0;

    for(int i = n - 1; i >= 0; --i) {
        int x = v[i];
        auto it = st.upper_bound(x);
        if(it == st.end()) {
            ++out;
            st.insert(x);
            continue;
        }

        st.erase(it);
        st.insert(x);
    }

    cout << out << endl;

    return 0;
}


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

int n, m;
int a[500];

int main() {
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++) scanf("%d", &a[i]);
    if(m == 1) {
        if(n == 1) printf("%d\n%d\n%d\n", 1, 1, 1);
        else printf("%d\n2\n%d %d\n", n, n - 1, 1);
    }
    else {
        vector<int>f, g;
        for(int i = 0; i < m; i++)
        if(a[i] % 2) f.push_back(a[i]);
        else g.push_back(a[i]);
        if(f.size() > 2) {
            puts("Impossible");
            return 0;
        }
        vector<int>ans, ans1;
        if(f.size()) ans.push_back(f[0]);
        for(int i = 0; i < g.size(); i++) ans.push_back(g[i]);
        if(f.size() > 1) ans.push_back(f[1]);
        if(ans[0] == 1) {
            ans1.push_back(2);
            for(int i = 1; i < ans.size(); i++)  {
                int t = ans[i];
                if(i == ans.size() - 1) t--;
                if(t) ans1.push_back(t);
            }
        }
        else {
            ans1.push_back(ans[0] - 1);
            for(int i = 1; i < ans.size(); i++) {
                int t = ans[i];
                if(i == ans.size() - 1) t++;
                ans1.push_back(t);
            }
        }
        for(int i = 0; i < m; i++) cout << ans[i] << " ";
        cout << endl;
        cout << ans1.size() << endl;
        for(int i = 0; i < ans1.size(); i++) cout << ans1[i] << " ";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int room[4][3][10];
	int n;
	int i,j,k;
	for (i=0;i<4;i++){
		for (j=0;j<3;j++){
			for (k=0;k<10;k++){
				room[i][j][k]=0;
			}
		}
	}
	cin>>n;
	for (i=0;i<n;i++){
		int b,f,r,v;
		cin>>b>>f>>r>>v;
		room[b-1][f-1][r-1]+=v;
	}
	for (i=0;i<4;i++){
		for (j=0;j<3;j++){
			for (k=0;k<10;k++){
				cout<<" "<<room[i][j][k];
			}
			cout<<endl;
		}
		if (i!=3){
			cout<<"####################"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
import numpy as np
n,k=map(int,input().split())
sunuke=np.zeros(n,dtype=int)
for i in range(k):
    number=input()
    data=list(map(int,input().split()))
    for j in data:
        sunuke[j-1]=1
print(np.count_nonzero(sunuke==0))

Measured memory_bytes: 27184
#include<stdio.h>

int LinearSearch(int [],int,int);

int main(){
  int i,n,A[10001],j,key;
  int count = 0;

  scanf("%d",&n);
  for(i = 0;i< n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&j);
  for(i = 0;i < j;i++){
    scanf("%d",&key);
    if(LinearSearch(A,n,key))
      count++;
  }
  printf("%d\n",count);

  return 0;
}

int LinearSearch(int A[],int n,int key){
  int i = 0;
  A[n] = key;
  while(A[i] != key){
    i++;
  }
  return i != n;
 }




Measured memory_bytes: 2104
#include<cstdio>
#include<cctype>
#include<cstring>
const int maxn=100010,mod=1000000007;
int n,m;
int a[maxn];
struct Matrix {
	int a[3][3];
	void cls() {
		memset(a,0,sizeof a);
	}
}c;
Matrix operator * (const Matrix &a,const Matrix &b) {
	c.cls();
	for(register int i=0;i<3;++i)for(register int k=0;k<3;++k)for(register int j=0;a.a[i][k]&&j<3;++j)
	b.a[k][j]?c.a[i][j]=(c.a[i][j]+1ll*a.a[i][k]*b.a[k][j])%mod:0;
	return c;
}
Matrix sp,cm[40],s;
int In() {
	register char c;
	for(;c=getchar(),c!='-'&&!isdigit(c););
	register bool f=c=='-';
	register int s=f?0:c-'0';
	for(;c=getchar(),isdigit(c);)s=s*10+c-'0';
	return f?-s:s;
}
void pw(register long long y) {
	for(register int i=32;~i;--i)if(y>>i&1) s=cm[i]*s;
}
int main() {
	n=In(),m=In();
	a[0]=-1;
	for(register int i=1;i<=m;++i)a[i]=In();
	cm[0]=(Matrix){1,0,1,2,1,2,1,1,2},sp=(Matrix){1,0,0,2,1,0,1,1,1};
	for(register int i=1;i<=32;++i)cm[i]=cm[i-1]*cm[i-1];
	s=(Matrix){1};
	for(register int i=1;i<=m;++i)pw(a[i]-a[i-1]-1),s=sp*s;
	pw(n-a[m]-1);
	printf("%d\n",s.a[2][0]);
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int try(long n, long div){
	return (n % div) ? (n % div == 1) : try(n/div, div);
}

int main(void){
	long n;
	int count = 0;

	scanf("%ld", &n);

	for(long i=2; i*i <= n; i++) {
		if(try(n, i)) {
			count++;
			if(i != n / i && try(n, n/i))
				count++;
		}
	}
	printf("%d", (n==2) ? count+1 : count+2);

	return 0;
}


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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;i<(n);i++)
#define dup(x,y) (((x)+(y)-1)/(y))
#define vecadd emplace_back

typedef long long ll;

int main(){
  int a;
  cin>>a;
  cout<<a*a*a;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int ans,bmax;
  vector<int>a(110,2e5),b(110);
  cin>>n;
  for(int i=0;i<n-1;i++)cin>>b[i];
  for(int i=1;i<n-1;i++)ans+=min(b[i],b[i-1]);
  ans+=b[n-2]+b[0];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
 
#define sPRINT(str) printf(#str "\n")
#define yOUT sPRINT(Yes)
#define nOUT sPRINT(No)
#define YOUT sPRINT(YES)
#define NOUT sPRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
 
using namespace std;

int main(void)
{   
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n){
        cin >> a[i];
        a[i] --;
    }
    int i=0, tmp, cnt=1;
    while(1){
        if(a[i] == 1){
            cout << cnt << endl;
            return 0;
        }
        else if(a[i] == -1){
            cout << -1 << endl;
            return 0;
        }
        tmp = i;
        i = a[i];
        a[tmp] = -1;
        cnt++;

    }
}


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

#define fi first
#define se second
#define pii pair<int,int>
using namespace std;
const int maxn = 2e5+15;
int n,Q,a,b,c,d,cnt,head[maxn];
struct edge{
    int to,nxt,col,len;
}e[maxn<<1];
pii p[maxn];
inline void add(int u,int v,int c,int d){
    e[++cnt] = (edge){v,head[u],c,d};
    head[u] = cnt;
}
int fa[maxn],sz[maxn],son[maxn],dep[maxn];
void dfs1(int x,int pa,int depth){
    dep[x] = depth; fa[x] = pa; int num = 0;
    for(int i = head[x];i > 0; i=e[i].nxt){
        int v = e[i].to;
        if(v == pa) continue;
        dfs1(v,x,depth+1);
        sz[x] += sz[v]; p[v] = pii(e[i].col,e[i].len);
        if(sz[v] > num) num=sz[v],son[x] = v;
    }
    sz[x]++;
}
int id[maxn],top[maxn],rk[maxn],tot;
void dfs2(int x,int t){
    top[x] = t; id[x] = ++tot; rk[tot] = x;
    if(!son[x]) return ; dfs2(son[x],t);
    for(int i = head[x];i > 0;i = e[i].nxt){
        int v = e[i].to;
        if(v==son[x]||v==fa[x]) continue;
        dfs2(v,v);
    }
}
struct tree{
    int l,r,num,sum;
}T[maxn*160];
int root[maxn],k,x,y,u,v;
void build(int l,int r,int &x,int y,int c,int d){
    T[++k] = T[y];T[k].num++;T[k].sum+=d;x = k;
    if(l == r) return ;
    int mid = (l+r) >> 1;
    if(c > mid) build(mid+1,r,T[x].r,T[y].r,c,d);
    else build(l,mid,T[x].l,T[y].l,c,d);
}
void query(int l,int r,int L,int R,int ql,int qr,int &num,int &sum){
    if(l > R || r < L) return ;
    if(l >= L && r <= R){
        num += T[qr].num - T[ql].num;
        sum += T[qr].sum - T[ql].sum;
        return ;
    }
    int mid = (l+r) >> 1;
    query(l,mid,L,R,T[ql].l,T[qr].l,num,sum);
    query(mid+1,r,L,R,T[ql].r,T[qr].r,num,sum);
}
int solve(int u,int v,int x,int y){
    int res = 0,num = 0,sum = 0;
    while(top[u] != top[v]){
        if(dep[top[u]] < dep[top[v]]) swap(u,v);
        query(0,n,x,x,root[id[top[u]]-1],root[id[u]],num,sum);
        res += T[root[id[u]]].sum - T[root[id[top[u]]-1]].sum;
        u = fa[top[u]];
    }
    if(id[u] > id[v]) swap(u,v);
    query(0,n,x,x,root[id[u]],root[id[v]],num,sum);
    res += T[root[id[v]]].sum - T[root[id[u]]].sum;
    return res - sum + num*y;
}
int main(){
    scanf("%d %d",&n,&Q);
    for(int i = 1;i < n; ++i){
        scanf("%d %d %d %d",&a,&b,&c,&d);
        add(a,b,c,d); add(b,a,c,d);
    }
    dfs1(1,0,1); dfs2(1,1);
    for(int i = 1;i <= n; ++i) build(0,n,root[i],root[i-1],p[rk[i]].fi,p[rk[i]].se);
    while(Q--){
        scanf("%d %d %d %d",&x,&y,&u,&v);
        printf("%d\n",solve(u,v,x,y));
    }
    return 0;
}

Measured memory_bytes: 49536
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  int ans=0;
  cin>>S;
  int ss=S.size();
  for(int i=0; i<ss/2; i++){
    if(S.at(i)!=S.at(ss-1-i)){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

const int INF = 1001001001;

// dp
// 薬品i番目までで、Aをj(g)、Bをk(g)の溶液を作るときの最小コスト
int dp[41][405][405];

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

    // dpテーブルの初期化
    for(int i = 0; i <= 40; ++i){
        for(int j = 0; j <= 400; ++j){
            for(int k = 0; k <= 400; ++k){
                dp[i][j][k] = INF;
            }
        }
    }
    dp[0][0][0] = 0;

    int budget = INF;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= 400; ++j){
            for(int k = 0; k <= 400; ++k){
                if(dp[i][j][k] == INF)      continue;
                // 薬品iを入れない場合
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);

                // (j,k)が比の条件(ma:mb)を満たしていれば、budgetと比較する
                if((j != 0 && k != 0) && j*mb == k*ma){
                    budget = min(budget, dp[i+1][j][k]);
                }

                // 薬品iを入れる場合
                if(j+a[i] <= 400 && k+b[i] <= 400){
                    dp[i+1][j+a[i]][k+b[i]] = min(dp[i][j][k]+c[i], dp[i+1][j+a[i]][k+b[i]]);

                    // (j,k)が比の条件を満たしていれば、budgetと比較
                    if((j+a[i])*mb == (k+b[i])*ma){
                        budget = min(budget, dp[i+1][j+a[i]][k+b[i]]);
                    }
                }
            }
        }
    }

    if(budget == INF)   budget = -1;
    cout << budget << endl;
}

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

nalist=[]
nblist=[]
for i in range(N):
    na, nb = input().split()
    nalist.append(na)
    nblist.append(int(nb))
X = input()
a=nalist.index(X)
del nblist[0:a+1]
ans=sum(nblist)
print(ans)

Measured memory_bytes: 3064
D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
  s.append(list(map(int, input().split())))
  
sdictlist = []
sdictlistsorted = []
for i in range(D):
  onedict = {}
  for j in range(26):
    onedict[j] = s[i][j]
  sdictlist.append(onedict)
  onesorteddict = sorted(onedict.items(), key=lambda x:x[1], reverse=True)
  sdictlistsorted.append(onesorteddict)

cignorelen = 5
csorted = sorted(c)
csorted = csorted[:cignorelen]
ignorelist = []
for i in range(26):
  if(c[i] in csorted):
    ignorelist.append(i+1)
    
lenpastmax = 20 #26まで設定できる
#26 -> 145419
#25 -> 18657778
#24 -> 40796238
#23 -> 54875726
#22 -> 63195752
#21 -> 66843963
#20 -> 67734290
pastlist = []
for i in range(D):
  j = 0
  while(sdictlistsorted[i][j][0] in pastlist or sdictlistsorted[i][j][0]+1 in ignorelist):
    j += 1
  print(sdictlistsorted[i][j][0]+1)
  pastlist.append(sdictlistsorted[i][j][0])
  if(len(pastlist)==lenpastmax):
    pastlist.pop(0)

Measured memory_bytes: 10480
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;

void solve()
{
    IN(n);
    string s;
    cin >> s;
    rep(i, s.length())
    {
        cout << (char)('A' + (s[i] - 'A' + n) % 26);
    }
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<climits>
#include<ctime>
#include<complex>
using namespace std;
typedef vector<string>vs;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<double>vd;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll>pll;
typedef vector<ll>vl;
#define rrep(i,x,n) for(int i=(x);i<(n);++i)
#define rep(i,x) rrep(i,0,(x))
#define fi first
#define se second
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define maxs(a,b) (a)=max(a,b)
#define mins(a,b) (a)=min(a,b)

const int dx[]={-1,0,1,-1,1,-1,0,1};
const int dy[]={-1,-1,-1,0,0,1,1,1};

int main(){
    int N;
    double R;
    scanf("%d%lf",&N,&R);
    set<pii>S;
    rep(i,N){
        double x,y;
        scanf("%lf%lf",&x,&y);
        int ny=(int)floor(x/R);
        int nx=(int)floor(y/R);
        S.insert(pii(ny,nx));
    }

    int ans=0;

    each(it,S){
        int y=it->fi,x=it->se;
        rep(i,8){
            int ty=y+dy[i];
            int tx=x+dx[i];
            if(S.find(pii(ty,tx))!=S.end()){
                S.erase(pii(ty,tx));
            }
        }
        ans++;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 9764
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
typedef unsigned long long ull;
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define f(i,a,b) for(ll i=a;i<=b;i++)
#define testcases ll t;cin>>t;while(t--)
#define dec(x) greater<x>()

/*** Define Values ***/
#define mx 200005
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-7
#define size1 100005
const char nl = '\n';

#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mem(name, value) memset(name, value, sizeof(name))

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** Sorts ***/
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
inline bool cmp(pll a, pll b) { if (a.ff == b.ff)return a.ss < b.ss; return a.ff > b.ff; }

#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'
#define case cout << "Case " << t++ << ": "

/*** Functions
ll BigMod(ll base, ll pow, ll modvalue){ if (pow == 0) return 1;  ll ans = BigMod(base, pow / 2, modvalue);ll total = ((ans % modvalue) * (ans % modvalue)) % modvalue;  if(pow % 2 == 0) return total; else{ return (total * (base % modvalue) ) % modvalue; } }
ll InverseMod(ll base, ll pow) { if(pow == 0) return 1; ll ans = InverseMod(base, pow / 2); ans = (ans * ans) % mod; if(pow & 1){ return (ans * base) % mod; } else{ return ans; } }
bool checkprime(ll num) { if(num < 2) return false; for(ll i = 2; i * i <= num; i++){ if(num % i == 0) return false; } return true; }
ll EularPHI(ll num) { double ans = num; for(ll i = 2; i * i <= num; i++){ if(num % i == 0){ while (num % i == 0) { num /= i; } ans *= (1.0 - (1.0 / (double)i)); } } if(num > 1) ans *= (1.0 - (1.0 / (double)num)); return (ll)ans; }
ll sumofdigit(long ll n){ll sum=0;while(n){sum=sum+n%10;n=n/10;}return sum;}
ll countDigit(ll n) { if (n == 0) return 0; return 1 + countDigit(n / 10); }
ll countDigit(ll n) { return floor(log10(n) + 1); } //only positive
 ***/
// ll sumofdigit(ll n){ll sum=0;while(n){sum=sum+n%10;n=n/10;}return sum;}

template <class T> inline T gcd(T a, T b) {if (b == 0)return a; return gcd(b, a % b);}
template <class T> inline T lcm(T a, T b) {return a * b / gcd<T>(a, b);}
template <class T> inline T power(T b, T p) {ll ans = 1; while (p--) ans *= b; return ans;}

void solve()
{	
	char s[200010];
	scanf("%s",s);
	int len=strlen(s);
	int sum=0;
	for(int i=0;i<len;i++)sum+=s[i]-'0';
		if(sum%9==0){
			puts("Yes");
		}else{
			puts("No");
		}
	}


	int main()
	{

#ifndef ONLINE_JUDGE
		freopen("C:/Users/91731/Documents/input.txt", "r", stdin);
		freopen("C:/Users/91731/Documents/output.txt", "w", stdout);
		freopen("C:/Users/91731/Documents/error.txt", "w", stderr);
#endif

		ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

		solve();
	}


Measured memory_bytes: 3924
N = int(input())
A = list(map(int, input().split()))

INF = 10 ** 18

if N % 2:
    dp = [[-INF for j in range(N)] for i in range(3)]
    dp[0][0] = A[0]
    dp[1][1] = A[1]
    dp[2][2] = A[2]
    for j in range(N):
        for i in range(3):
            if dp[i][j] == -INF:
                continue
            for k in range(3):
                if i + k < 3 and j + k + 2 < N:
                    dp[i + k][j + k + 2] = max(dp[i + k][j + k + 2], dp[i][j] + A[j + k + 2])
    print(max(max(dp[0][-3:-1]), max(dp[1][-2:]), max(dp[2][-1:])))
    
else:
    dp = [[-INF for j in range(N)] for i in range(2)]
    dp[0][0] = A[0]
    dp[1][1] = A[1]
    for j in range(N):
        for i in range(2):
            if dp[i][j] == -INF:
                continue
            for k in range(2):
                if i + k < 2 and j + k + 2 < N:
                    dp[i + k][j + k + 2] = max(dp[i + k][j + k + 2], dp[i][j] + A[j + k + 2])
    print(max(max(dp[0][-2:]), max(dp[1][-1:])))

Measured memory_bytes: 129216
#include<cstring>
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    char c;
    int i=0;
    while(scanf("%c",&c)!=EOF)
    {
        if(i%2==0)cout<<c;
        i++;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    print(a[0] + a[1]);
    
    
}

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

#define y1 dmytxdy
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int cys=1000000007;
int n,ncnt;
ll d[105],f[105],a[105];

ll mod(ll x){return x>=cys?x-cys:x;}

ll qpow(ll x,ll p){
	ll ret=1;
	for(;p;p>>=1,x=x*x%cys) if(p&1) ret=ret*x%cys;
	return ret;
}

int solve(int l,int r,int x){
	int rt=++ncnt;
	if(l==r){
		d[rt]=0,f[rt]=qpow(2,a[l]-x);
		return rt;
	}
	ll mina=1<<30;
	for(int i=l;i<=r;i++) chkmin(mina,a[i]);
	int lst=l-1;
	f[rt]=qpow(2,mina-x),d[rt]=1;
	for(int i=l;i<=r;i++){
		if(a[i]==mina){
			d[rt]=mod(d[rt]<<1);
			if(lst+1==i){
				lst=i;
				continue;
			}
			int tmp=solve(lst+1,i-1,mina);
			f[rt]=f[rt]*f[tmp]%cys;
			d[rt]=d[rt]*(d[tmp]+(f[tmp]<<1))%cys;
			lst=i;
		}
	}
	if(lst!=r){
		int tmp=solve(lst+1,r,mina);
		f[rt]=f[rt]*f[tmp]%cys;
		d[rt]=d[rt]*(d[tmp]+(f[tmp]<<1))%cys;
	}
	d[rt]=mod(d[rt]+cys-f[rt]*qpow((cys+1)/2,mina-x-1)%cys);
	return rt;
}

int main(){
	n=readint();
	for(int i=1;i<=n;i++) a[i]=readint();
	int tmp=solve(1,n,0);
	printf("%lld\n",mod(d[tmp]+f[tmp]));
	return 0;
}

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

int main(void){
    ll i;
    cin >> i;

    if(i == 2){
        ll a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }else{
        cout << "Hello World" << endl;
    }

    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Union Find tree
//-------------------------------------------------
class UnionFind
{
private:
    ::std::vector<int> par;
    ::std::vector<int> rank;
public:
    UnionFind(int n):par(n), rank(n){
        for(int i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    int root(int x){
        if (par[x]==x) return x;
        return par[x] = root(par[x]);
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx==ry) return;
        if (rank[rx]>rank[ry]){
            par[ry] = rx;
        }else{
            par[rx] = ry;
            if (rx==ry) rank[ry]++;
        }
    }
};

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    vi a(m),b(m);
    rep(i,m){
        cin>>a[i]>>b[i]; a[i]--; b[i]--;
    }
    int ans=0;
    rep(i,m){
        UnionFind uf(n);
        rep(j,m) if (j!=i) uf.unite(a[j],b[j]);
        bool ok = true;
        rep(j,n-1){
            ok &= uf.same(j,j+1);
        }
        if (!ok) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

for h in range(1,3501):
  for n in range(1,3501):
    if (4*h*n-N*n-N*h) and (4*h*n-N*n-N*h) > 0 and (N*h*n) % (4*h*n-N*n-N*h)==0:
      print(h,n,(N*h*n) // (4*h*n-N*n-N*h))
      exit()

Measured memory_bytes: 67152
#include<stdio.h>

int main(void)
{
    int a, b;
    int ans = 0;

    scanf("%d%d", &a, &b);

    for (; a <= b; a++) {
        if ((a/10000 == a%10) && ((a%10000)/1000) == ((((a%10000)%1000)%100)/10)) {
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

int main()
{
    int i,j,k,n,m,p,q,r;
    int x,y,z,xx,zz;
    scanf("%d",&n);

    scanf("%d %d",&x,&y);
    long long yy=100000000;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&p);
        z=1000*x-(p*6);
        xx=abs(z-y*1000);
        if(xx<yy)
        {
            yy=xx;
            zz=i;
        }
    }
    printf("%d\n",zz);
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>

using namespace std;

int main()
{
	int N;
	string S;
	cin >> N;
	cin >> S;
	int minval = (int)N;
	int val = 0;

	bool first = 1;

	for (int i = 0; i < N; ++i) {
		if (first) {
			for (int j = 1; j < N; ++j) {
				if (S[j] == 'E')
					++val;
			}
			first = 0;
		}
		else {
			if (S[i - 1] == 'W' && S[i] == 'W')
				++val;
			else if (S[i - 1] == 'E' && S[i] == 'E')
				--val;
		}

		if (minval > val)
			minval = val;
	}

	cout << minval << endl;
	return 0;
}

Measured memory_bytes: 900
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    std::string str;
    cin >> str;

    if (str.size() % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    size_t half = str.size() / 2;
    std::string str1(str.begin(), str.begin()+half);
    std::string str2(str.begin() + half, str.end());
    if (str1 == str2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))

a = max(A)
b = min(A)

# import sys
# if a - b > 1:
#     print("No")
#     sys.exit()

ok = 0

if a - b == 1:
    C = [0, 0]
    for i in range(n):
        C[A[i] - b] += 1
    if a - C[0] > 0 and C[1] // 2 >= a - C[0]:
        ok = 1
elif a == b:
    if n == a + 1:
        ok = 1   
    if n // 2 >= a:
        ok = 1

if ok == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 52292
let () = Scanf.scanf "%d" @@ fun n ->
  let counts = Array.init (n + 1) @@ fun i -> i in
  for p = 0 to int_of_float (ceil (log (float_of_int n) /. log 6.)) do
    for i = int_of_float (6. ** float_of_int p) to n do
      counts.(i) <- min counts.(i) (counts.(i - int_of_float (6. ** float_of_int p)) + 1)
    done
  done;
  for p = 0 to int_of_float (ceil (log (float_of_int n) /. log 9.)) do
    for i = int_of_float (9. ** float_of_int p) to n do
      counts.(i) <- min counts.(i) (counts.(i - int_of_float (9. ** float_of_int p)) + 1)
    done
  done;
  Printf.printf "%d\n" counts.(n)


Measured memory_bytes: 2688
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<functional>
using namespace std;

#define INF 1<<21
#define MOD 1000000007

int main(void) {
  int n;
  int a, b;
  cin >> n;
  int ans[100005];
  fill(ans, ans + 100005, 0);
  for (int i = 0; i < n; i++) {
	cin >> a >> b;
	ans[a]++;
	ans[b + 1]--;
  }

  int m = 0;
  for (int i = 1; i <= 100005; i++) {
	ans[i] += ans[i-1];
  }
  for (int i = 1; i <= 100005; i++) {
	if (ans[i+1] >=i) {
	  m = i;
	}
  }
  cout << m << endl;
}

Measured memory_bytes: 3480
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n; cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  auto itr = max_element(v.begin(), v.end());
  int N = *itr;
  v.erase(itr);
  sort(v.begin(), v.end(), [&](int a, int b) {
    return abs(N - a*2) < abs(N - b*2);
  });
  cout << N << ' ' << v[0] << endl;
}

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

int main(){
    int k;
    int a,b;
    cin>>k>>a>>b;
    int bi=a/k;
    for(int i=bi;i*k<=b;i++){
        if(i*k>=a&&i*k<=b){
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;
ll a[105];
int main(void){
    ll n,x;cin>>n>>x;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<n;i++){
        if(a[i]<=x){
            if(i==n-1){
                if(a[i]==x){
                    ans++;
                    x-=a[i];
                }
            }else{
                ans++;
                x-=a[i];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
readLine :: String -> [Int]
readLine = map read . words

solve :: Int -> Int -> Int -> Int
solve a b k
  | even k = a - b
  | otherwise = b - a

solve' :: Int -> String
solve' i
  | abs i > 1000000000000000000 = "Unfair"
  | otherwise = show i

main = do
  [a, b, c, k] <- readLine <$> getLine
  putStrLn $ solve' $ solve a b k


Measured memory_bytes: 508
#include<bits/stdc++.h>
#define for(i,a,b) for(int i=a;i<=b;i++)
#define _inline __inline__ __attribute__((always_inline))
#define ll long long
using namespace std;
_inline void read(ll &x){
	ll res=0,f=1;
	char c=getchar();
	if(c=='-') f=-1;
	while(c>'9'||c<'0') c=getchar();
	while(c>='0'&&c<='9'){
		res=res*10+c-'0';
		c=getchar();
	}
	x=res*f;
}
inline void print(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
ll k,a,b;
int main(){
	read(k),read(a),read(b);
	if(k<=a) puts("1"),exit(0);
	else if(a<=b) puts("-1"),exit(0);
	else printf("%lld\n",((k-a)/(a-b)+bool((k-a)%(a-b)))<<1|1);
	exit(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
int main()
{
    int a[3];
    for(int i = 0 ;i<3;i++) cin>>a[i];
    sort(a,a+3);
    int sum  = abs(a[2] - a[1]);
    if((a[2]-a[0]-sum)%2!=0) {
        a[2]++;
        sum +=(a[2]-a[0]-sum)/2;
        sum++;
    }
    else sum +=(a[2]-a[0]-sum)/2;
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};



int main(){
    IOS;
    make(ll,x);
    if(x>=30) cout<<"Yes \n";
    else cout<<"No \n";

    return 0;
}


Measured memory_bytes: 3652
program main
   implicit none
   character(100000) s,st
   integer le,i
   read(*,*)st
   le=len_trim(st)
   do i=1,le
      s(i:i)=st(le-i+1:le-i+1)
   enddo
   i=1
   do
    !  write(*,*)i
      if(i==le+1)then
         write(*,"(A3)")"YES"
         STOP
      endif
      if(s(i:i+4)=="maerd")then
      i=i+5
      cycle;
     endif
      if(s(i:i+6)=="remaerd")then
      i=i+7
      cycle;
     endif
     if(s(i:i+4)=="esare")then
      i=i+5
      cycle;
     endif
      if(s(i:i+5)=="resare")then
      i=i+6
      cycle;
     endif
     write(*,"(A2)")"NO"
     STOP
      
   enddo
end program main
   


Measured memory_bytes: 768
#include <iostream>
#include <cmath>
#include <iomanip>

const double pi = 3.141592653589;

double dsin(double deg)
{
	return std::sin(deg * pi / 180.0);
}

double dcos(double deg)
{
	return std::cos(deg * pi / 180.0);
}

int main()
{
	double a, b, C;
	double S, L, h, c;
	
	std::cin >> a >> b >> C;
	
	S = 0.5 * a * b * dsin(C);
	
	c = std::sqrt((a * a) + (b * b) - (2.0 * a * b * dcos(C)));
	
	L = a + b + c;
	
	h = 2.0 * S / a;
	
	std::cout << std::fixed << std::setprecision(4);
	std::cout << S << " " << L << " " << h << std::endl;
	
	
	
	return 0;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	string s;
  cin >> s;
  if(s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
int main(void)
{
  int n, m, y, k;
  std::cin>> n >> y;
  y /= 1000;
  m = y % 10;
  for(int i = y / 10; i >= 0; i--){
    k = m % 5;
    for(int j = m / 5; j >= 0; j--){
      if(i + j + k == n){
        std::cout << i << " " << j << " " << k << std::endl;
        return 0;
      }
      k += 5;
    }
    m += 10;
  }
  std::cout << "-1 -1 -1" << std::endl;
  return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: u8,
        s: String,
    }
    let offset = 'A' as u8;
    println!("{}", s.bytes().map(|c| ((c - offset + n) % 26 + offset) as char).collect::<String>());
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
bool kaiseki(int a){
  std::string str;
  str = std::to_string(a);
  bool flag = true;
  for(int i=0;i<str.size()/2;i++){
    if(str[i]!=str[str.size()-1-i]) flag = false;
  }
  return flag;
}
int main(){
  int a,b;cin >> a >> b;
  int ans = 0;
  for(int i=a;i<=b;i++){
    if(kaiseki(i)) ans++;
  }
  cout << ans << endl;
}


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

int main()
{
  int64_t a,b,k;
  cin>>a>>b>>k;
  
  if(a>=k)
    a-=k;
  else
  {
    k-=a;
    a=0;
    if(b>=k)
      b-=k;
    else
    {
      k-=b;
      b=0;
    }
  }
      
  
  
  cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;

int main() {
    ll h,w;
    cin >> h >> w;
    ll ans;
    if (h==1 || w==1) ans=1;
    else ans=(h*w+1)/2;
    cout << ans << endl;
}

Measured memory_bytes: 256