akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (2010)
#define P ()
#define M (N<<1)
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c) {
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
int n,m,fi[N],ne[M],b[M],mx[N],siz[N],mn[N],ans=inf,tmp,E; char str[N];
int uni(int u,int x,int y){
	if(mn[x]>mn[y])swap(x,y);
	if(mx[x]>mn[y])return (mx[x]+mx[y])&1;
	else return mn[y]-mx[x];
}
void dfs(int u,int pre,int d){
	mx[u]=mn[u]=siz[u]=0;
	for(int i=fi[u];i;i=ne[i]){
		int v=b[i];
		if(v==pre)continue;
		dfs(v,u,d+1),mx[v]+=siz[v],mn[v]+=siz[v];
		mn[u]=uni(u,u,v),siz[u]+=siz[v],mx[u]+=mx[v];
	}
//	cout<<u<<" "<<mn[u]<<endl;
	if(str[u]=='1')tmp+=d,siz[u]++;
}
void add(int x,int y){
	ne[++E]=fi[x],fi[x]=E,b[E]=y;
}
int main(){
	read(n);
	for(int i=1;i<=n;i++)readc(str[i]);
	for(int i=1;i<n;i++){
		int x,y;
		read(x),read(y);
		add(x,y),add(y,x);
	}
	for(int i=1;i<=n;i++){
		tmp=0,dfs(i,0,0);
		if(mn[i]==0)ans=min(ans,tmp/2);
//		cout<<i<<" "<<mn[i]<<" "<<tmp<<endl;
	}
	if(ans<inf)printf("%d\n",ans);else puts("-1");
}

Measured memory_bytes: 2560
#include <iostream>
#include<vector>
#include <math.h>
#include<stdio.h>
#include <climits>
#include<algorithm>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int a,b,c,i,j,k,ans=0,n,l;
	int kari;
	string x;
	vector<string> s;
	cin >> n >> l ;
	
	for (i = 0; i < n; i++) {
		cin >> x;
		s.push_back(x);
	}
	sort(s.begin(), s.end());
	for (i = 0; i < n; i++) {
		cout << s[i];
	}

	cout << "\n";
}


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

using namespace std;

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

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

long long abst(long long a) {
    if(a < 0) return -a;
    else return a;
}

int main() {

    int n;
    cin >> n;
    vector<long long> dp(n, LLONG_MAX);
    vector<long long> data(n);

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

    dp[0] = 0;
    dp[1] = abst(data[0] - data[1]);
    for(int i=2; i<n; i++) {
        change_min(dp[i], abst(data[i]-data[i-1]) + dp[i-1]);
        change_min(dp[i], abst(data[i]-data[i-2]) + dp[i-2]);
    }

    cout << dp[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define vec(j,n) vector<int>(j(n))
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main(){
    double d,t,s;
    cin >> d >> t>> s;
    double ans;
    ans =  d /s;
    if (ans <=t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3660
a,b,c,x,y = map(int,input().split())

if min(a,b)>=2*c:
    print(max(x,y)*2*c)
elif a+b>=2*c:
    if x==y:
        print(x*2*c)
    elif x>y:
        print(y*2*c+(x-y)*min(a,2*c))
    else:
        print(x*2*c+(y-x)*min(b,2*c))
else:
    print(a*x+b*y)


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

int main(){
    int n,a;
    cin >> n >> a;
    cout << n*n-a << endl;
    
    return 0;
}


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

int main () {
    ios_base::sync_with_stdio(false);
    int N,M,sum;
    cin>>N>>M;
    vector<int> v;
    sum = 0;
    for(int i=0;i<N;i++) {
        int A;
        cin>>A;
        v.push_back(A);
        sum+=A;
    }
    sort(v.begin(),v.end(),greater<int>());
    bool selectable = true;
    for(int i=0;i<M;i++) {
        if(v[i] < sum*1.0*1/(4*M)) {
            selectable = false;
        }
    }
    if(selectable) {
        cout<<"Yes"<<"\n";
    }
    else {
        cout<<"No"<<"\n";
    }
    return 0;
}

Measured memory_bytes: 256
using System;

namespace abc156_a
{
    class Program
    {
        static void Main(string[] args)
        {
            //入力（空白区切り）
            string[] input = Console.ReadLine().Split(' ');
            int N = Convert.ToInt32(input[0]);
            int R = Convert.ToInt32(input[1]);

            //判定、出力
            if (N < 10)
            {
                Console.WriteLine(R+(100 * (10 - N)));
            }
            else
            {
                Console.WriteLine(R);
            }
        }
    }
}


Measured memory_bytes: 11220
from collections import defaultdict

n, m = map(int, input().split())
A = list(map(int, input().split()))
dic = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
usable = defaultdict(int)

for num in A:
    use = dic[num]
    if usable[use] < num:
        usable[use] = num

DP = [-1]*(n+10)
DP[0] = 0

for i in range(n):
    digits = DP[i]
    if digits < 0:
        continue

    for use in usable.keys():
        if i+use <= n and DP[i+use] < digits + 1:
            DP[i+use] = digits + 1
        else:
            continue

digits = DP[n]
num_of_match = n
ans = ''

for _ in range(n):
    if digits == 0:
        break

    for num in sorted(usable.values(), reverse=True):
        use = dic[num]
        if DP[num_of_match - use] == digits - 1:
            digits -= 1
            num_of_match -= use
            ans += str(num)
            break
        else:
            continue

print(ans)

Measured memory_bytes: 3696
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005

struct Edge{
	Edge(int arg_to,int arg_index){
		to = arg_to;
		index = arg_index;
	}
	int to,index;
};

int N;
int K;
vector<Edge> G[SIZE];
int ans[SIZE];

void dfs(int node_id,int pre_node,int pre_color){

	int tmp = 0;


	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i].to;
		if(child == pre_node)continue;

		int index = G[node_id][i].index;

		tmp++;
		if(tmp == pre_color)tmp++;

		K = max(K,tmp);

		ans[index] = tmp;
		dfs(child,node_id,tmp);
	}
}


int main(){

	scanf("%d",&N);

	int from,to;

	for(int i = 0; i < N-1; i++){

		scanf("%d %d",&from,&to);
		from--;
		to--;

		G[from].push_back(Edge(to,i));
		G[to].push_back(Edge(from,i));
	}

	K = 0;

	dfs(0,-1,-1);

	printf("%d\n",K);

	for(int i = 0; i < N-1; i++){

		printf("%d\n",ans[i]);
	}

	return 0;
}


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

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

    static class B1 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long x = in.nextLong();
            long n = 100;
            double k = 0;
            int i = 0;
            do {
                i++;
                k = Math.ceil((double) (n / 100));
                n += (long) k;
            } while (n < x);
            out.println(i);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 32960
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 105
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef priority_queue<ll> PQ;
typedef pair<double, double> doup;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef map<ll, ll> Map;


class Edge {
public:
    ll s, t, w;
    bool p;
    Edge(ll s, ll t, ll w, bool p=false): s(s), t(t), w(w), p(p) {}
};

ll N, M;
ll dist[100][100];
vector<Edge> edges;

int main(void) {
    cin >> N >> M;
    ll i, j, k;
    ll a, b, c;
    ll s, t;
    for(i=0; i<N; i++) {
        for(j=0; j<N; j++) {
            dist[i][j]=(i==j ? 0 : INF);
        }
    }
    
    for(i=0; i<M; i++) {
        cin >> a >> b >> c;
        a--; b--;
        edges.push_back(Edge(a, b, c));
        dist[a][b]=dist[b][a]=c;
    }
    
    for(k=0; k<N; k++) {
        for(i=0; i<N; i++) {
            for(j=0; j<N; j++) {
                dist[i][j]=min(dist[i][j], dist[i][k]+dist[k][j]);
            }
        }
    }
    
    for(s=0; s<N; s++) {
        for(t=0; t<N; t++) {
            for(i=0; i<M; i++) {
                if(dist[s][t]==dist[s][edges[i].s]+edges[i].w+dist[edges[i].t][t])
                    edges[i].p=true;
            }
        }
    }
    
    ll ans=0;
    
    for(i=0; i<edges.size(); i++) {
        if(!edges[i].p) ans++;
    }
    
    prin(ans);
    
}

Measured memory_bytes: 384
#define scanf_s scanf
#include <string>
#include <stdio.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <iostream>
using namespace std;

#define MAX 100
//#define MAX_ 1000
struct Graph
{
	int id, k = 0;
	list<int> node;
	int d = 0, f = 0;
};
Graph G[MAX];
int cou = 1;
void Depth(Graph *g)
{
	if (g->k >= 0) {
		if (g->d)
			return; 
		
		g->d = cou;
		++cou;
		for (auto i = g->node.begin(); i != g->node.end(); ++i) {
			Depth(&G[*i]);
		}
		g->f = cou;
		++cou;
		
	}
}

int main(void)
{
	int n, u, xk, v;
	scanf_s("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf_s("%d %d", &u, &xk);
		G[u - 1].id = u - 1;
		G[u - 1].k = xk;
		for (int j = 0; j < xk; ++j) {
			scanf_s("%d", &v);
			G[u - 1].node.push_back(v - 1);
		}
	}
	for (int i = 0; i < n; ++i) {
		if (G[i].d == 0 && G[i].f == 0) 
			Depth(&G[i]);
		
	}
	for (int i = 0; i < n; ++i) {
		printf("%d %d %d\n", G[i].id + 1, G[i].d, G[i].f);
	}
}

Measured memory_bytes: 3224
import java.util.*;

class Main{

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int x = sc.nextInt();
        int cnt = 0;

        int[] m = new int[n];
        for(int i = 0; i < n; i++){
            m[i] = sc.nextInt();
            if(x-m[i] >= 0){
                x -= m[i];
                cnt++;
            }
        }

        int max = 0;
        if(x != 0){
            for(int i = 0; i < n; i++){
                max = Math.max(max, x/m[i]);
            }
        }
        System.out.println(cnt+max);
        
        sc.close();
    }
}

Measured memory_bytes: 21844
# -*- coding: utf-8 -*-
N=int(input())
restaurant=[]
for i in range(N):
    s,p=input().split()
    restaurant.append((i+1,s,int(p)))
restaurant.sort(key=lambda x:(x[1],-x[2]))
for j in range(N):
    print(restaurant[j][0])

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

int main(){
  int n,m,x,l=0,r=0;cin>>n>>m>>x;
  REP(i,m){
    cin>>n;
    if(n<x) l++;
    else r++;
  }
  cout<<min(l,r);
}

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

int main() {
  int N;
  cin >> N;
  long long ans = 0;
  int base; //最低限必要な高さ
  cin >> base;
  for (int i = 1; i < N; i++) {
    int a;
    cin >> a;
    if (base >= a) {
      ans += base - a;
    } else {
      base = a;
    }
  }
  
  cout << ans;
}

Measured memory_bytes: 3632
import numpy as np
N = int(input())
a = np.array(list(map(int, input().split())))
a_max = a.max()
a_min = a.min()
if abs(a_max) >= abs(a_min):
	add_idx = a.argmax() + 1
else:
	add_idx = a.argmin() + 1
if a_max + a_min >= 0:
	rng_idx = range(1, N)
	sgn = 1
else:
	rng_idx = range(N, 1, -1)
	sgn = -1
print(2 * N - 1)
for i in range(1, N + 1):
	print(add_idx, i)
for i in rng_idx:
	print(i, i + sgn)


Measured memory_bytes: 19992
#include <iostream>
#include "math.h"
#include "stdio.h"
//#include <cstdlib>
using namespace std;

int main(){
    double point[4],x,y,d;
    for(int i = 0;i < 4;++i){
        cin >> point[i];
    }
    x = fabs(point[2] - point[0]);
    y = fabs(point[3] - point[1]);
    d = sqrt(pow(x,2) + pow(y,2));
    printf("%.8lf\n",d);
}



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


int main() {
  string s;
  cin >> s;
  int g=s.size();
  if(s[g-1]=='s'){cout << s << "es" << endl;}else{cout << s << 's' << endl;}
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int line[3][4] = {{1,2,4,3},{0,3,5,2},{0,1,5,4}}; 

struct dice {
	int f2n[6];
	map<int,int> n2f;
};

int main(void) {
	dice d;
	for (int i = 0; i < 6; ++i) {
		cin >> d.f2n[i];
		d.n2f[d.f2n[i]] = i;
	}

	int noq,top,front;
	cin >> noq;
	for (int q = 0; q < noq; ++q) {
		cin >> top >> front;
		top = d.n2f[top];
		front = d.n2f[front];
		int neg = 1;
		if (top > 2) {
			neg = -1;
			top = 5-top;
		}
		for (int i = 0; i < 4; ++i) {
			if (line[top][i] == front) {
				int next = (i+neg)%4;
				if (next < 0) {
					next = 3;
				}
				cout << d.f2n[line[top][next]] << endl; 
			}
		}
	}

	return 0;
}




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

#define rep(i, n) for(int i = 0; i < n; i++)
#define in_arr(type, a, n) for(int i = 0; i < n; i++) scanf(type, &((a)[i]));
#define ll long long int

int sum_digit(ll a);

int main(){
    ll a, max = 0;
    scanf("%lld", &a);
    if(a < 10){
        printf("1");
        return 0;
    }
    for(ll i = (int)sqrt(a); i > 9; i--){
        if(a % i == 0) {
            printf("%d", sum_digit(a / i));
            return 0;
        }
    }
    
    printf("%d", sum_digit(a));
    return 0;
}

int sum_digit(ll a){
    int ret = 0;
    while(a > 0){
        ret++;
        a /= 10;
    }
    return ret;
}


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

int main() {
    int N,K,Q;
    cin >> N >> K >> Q;
    vector<int>A(Q);
    vector<int>cnt(N);
    for(int i = 0; i < N; i++) {
        cnt[i] = K-Q;
    }
    for(int i = 0; i < Q; i++) {
        cin >> A[i]; 
        cnt[A[i]-1]++;
    }
    for(int i = 0; i < N; i++) {
        if(cnt[i] > 0) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;

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

int main() {
    string S;
    cin >> S;
    ll N = S.length();
    ll cntL = 0;
    ll cntR = 0;
    ll r = 0;
    ll out[N];
    rep(i,N) out[i] = 0;
    rep(i,N){
        if(S[i]=='R'){
            if(S[i+1]=='R') cntR++;
            else{
                r = i;
                out[r] += 1+cntR/2;
                out[r+1] += 1+(cntR+1)/2;
                cntR = 0;
            }
        }else{
            if(S[i+1]=='L') cntL++;
            else{
                out[r] += (cntL+1)/2;
                out[r+1] += cntL/2;
                cntL = 0;
            }
        }
    }
    rep(i,N){
        cout << out[i];
        if(i<N-1) cout << " ";
        else cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1408
def solve(k, n):
    if k & 1 == 0:
        return [k // 2] + [k] * (n - 1)
    ans = [k // 2 + 1] * n
    l = n
    for i in range((n - 2) // 2 + 1):
        if ans[-1] == 1:
            ans.pop()
            l -= 1
        else:
            ans[-1] -= 1
            if l < n:
                ans += [k] * (n - l)
                l = n
    return ans


k, n = map(int, input().split())

print(*solve(k, n))


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

const string YES = "Yes";

const string NO = "No";

void solve(int N, int K, int Q, vector<int> A)
{
    vector<int> c(N);
    for (int i = 0; i < Q; i++)
    {
        c.at(A.at(i) - 1)++;
    }
    for (int i = 0; i < N; i++)
    {
        if (Q - c.at(i) < K)
            cout << YES << endl;
        else
            cout << NO << endl;
    }
}

int main()
{
    int N;
    cin >> N;
    int K;
    cin >> K;
    int Q;
    cin >> Q;
    vector<int> A(Q);
    for(int i = 0; i < Q; i++) {
        cin >> A.at(i);
    }
    solve(N, K, Q, move(A));
    return 0;
}


Measured memory_bytes: 4052
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  long double a,b;
  cin >> a >> b;
  long long ans;
  ans = a*b;
  cout << ans << endl;
}

Measured memory_bytes: 3728
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/

int main(void){
  int x, y, z;
  cin >>  x >> y >> z;
  int total = x-z;
  int waru = y+z;
  cout << total/waru << endl;


}


Measured memory_bytes: 384
H, N = map(int, input().split())
AB = []
for _ in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))

INF = 10**20
dp = [0]
for i in range(1, H + 1):
    min_mp_cost = INF
    for damage, mp_cost in AB:
        parent = max(0, i - damage)
        new_cost = dp[parent] + mp_cost
        if new_cost < min_mp_cost:
            min_mp_cost = new_cost
    dp.append(min_mp_cost)
print(dp[-1])


Measured memory_bytes: 42460
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N = int(input())
As = list(mi())

cnt4 = 0
cnt2 = 0
cnt1 = 0

for a in As:
  if a % 4 == 0:
    cnt4 += 1
  elif a % 2 == 0:
    cnt2 += 1
  else:
    cnt1 += 1

possiblelength = 0
if cnt1 ==0:
  print('Yes')
  exit()
if cnt4 >= 1 and cnt2 >= 1:
  possiblelength = (cnt4 * 2) + cnt2
elif cnt4 >= 1 and cnt2 == 0:
  possiblelength = cnt4 * 2 + 1
elif cnt4 == 0 and cnt2 >= 1:
  possiblelength = cnt2 -1
else:
  possiblelength = 0

if possiblelength >= N:
  print('Yes')
else: print('No')



Measured memory_bytes: 63472
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;


int main(){
   int a,b;
   cin>>a>>b;
   int ans=0;
   if(a>=13)ans=b;
   else if(a<=5)ans=0;
   else ans=b/2;
   cout<<ans<<endl;

}

   


Measured memory_bytes: 888
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let mut s = read::<String>().chars().collect::<Vec<_>>();
    while !s.is_empty() {
        if s.len() >= 5 {
            if s[s.len() - 5..s.len()].iter().cloned().collect::<String>() == "dream"
                || s[s.len() - 5..s.len()].iter().cloned().collect::<String>() == "erase"
            {
                for _ in 0..5 {
                    s.pop();
                }
                continue;
            }
        }
        if s.len() >= 6 {
            if s[s.len() - 6..s.len()].iter().cloned().collect::<String>() == "eraser" {
                for _ in 0..6 {
                    s.pop();
                }
                continue;
            }
        }
        if s.len() >= 7 {
            if s[s.len() - 7..s.len()].iter().cloned().collect::<String>() == "dreamer" {
                for _ in 0..7 {
                    s.pop();
                }
                continue;
            }
        }
        println!("NO");
        return;
    }
    println!("YES");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a, b, c;
  a=0;
  b=0;
  c=0;
  cin >> n ;
  a = n%10;
  b = (n-a)%100;
  c = n-(a+b);
  if(a == 1){a = 9;
            }else{a=1;
                 }
  if(b == 10){b = 90;
            }else{b=10;
                 }
  if(c == 100){c = 900;
            }else{c=100;
                 }
  
  cout << c+b+a<< endl;
}


Measured memory_bytes: 256
from collections import deque
n = int(input())
g = [[] for i in range(n)]

for i in range(n-1):
    a, b = map(int, input().split())
    a-=1; b-=1
    g[a].append(b)
    g[b].append(a)

def bfs(src):
    dist = [-1]*n
    dist[src] = 0
    dq = deque([src])
    while dq:
        now = dq.popleft()
        for to in g[now]:
            if dist[to]>=0: continue
            dist[to] = dist[now] + 1
            dq.append(to)
    return dist

df = bfs(0)
ds = bfs(n-1)

fscore = 0
sscore = 0
for f, s in zip(df, ds):
    if f <= s:
        fscore += 1
    else:
        sscore += 1
if fscore > sscore:
    print('Fennec')
else:
    print('Snuke')

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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

vector<string> res;

void search(string s, char c) {
  if (c=='a') {
    res.psb(s);     
    return;
  } 

  for (int i=0; i<(int)s.size(); i++) {
    if (s[i]==c) return;
    if (s[i]==c-1) {
      string t = s;
      t[i] = c;
      search(t, c-1);
    }
  }

  search(s, c-1);
}

int main() {
  string s, t;
  int i;
  while (1) {
    cin >> s;
    if (s=="#") break;

    res.clear();
    search(s, 'z');

    sort(res.begin(), res.end());
    res.erase(unique(res.begin(), res.end()), res.end()); 
    cout << res.size() << endl;
    if (res.size() <= 10) {
      for (i=0; i<(int)res.size(); i++)     
        cout << res[i] << endl;
    } else {
      for (i=0; i<5; i++)     
        cout << res[i] << endl;
      for (i=0; i<5; i++) 
        cout << res[res.size() - 5 + i] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 2352
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <random>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
#define bicnt(x)	__buildin__popcount(x)
#define debug(x)	cout<<"debug: "<<x<<endl
#define DEBUG 0

const ll inf = (ll)1e8;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

int main() {
	int n;	cin >> n;
	vint a(n);
	rep(i, n)	cin >> a[i];
	map<int, int> mp;
	rep(i, n) {
		mp[a[i] - 1]++;
		mp[a[i]]++;
		mp[a[i] + 1]++;
	}
	int ret = 0;
	for (auto it : mp)	ret = max(ret, it.scn);
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 5120
#include <stdio.h>
int soma(int a){
	int som=0;
	while(a!=0){
		som+=a%10;
		a/=10;
	}
		return som;
}
int main(void){
	int n,resul;
	scanf("%d", &n);
	if(n%2){
		resul = soma(n);
	}
	if(!(n%2)){
		if(soma(n/2)*2<=soma(n-1)+1){
			resul = soma(n/2)*2;
		}
		else resul=soma(n);
	}
	printf("%d\n", resul);
	return 0;
}

Measured memory_bytes: 128
line = $stdin.gets
hp = line.split(' ').map{|s| s.to_i}[0]

line = $stdin.gets
attack_list = line.split(' ').map{|s| s.to_i}

ans = false
attack_list.each do |a|
  hp -= a
  if hp <= 0
    ans = true
    break
  end
end

if ans
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 8068
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void dfs ( vector< vector<int> > &v , int x , vector<int> &vis , vector<int> &par )
{
    vis[x] = 1;

    rep(i,0,v[x].size())
    {
        if( vis[v[x][i]] == 0 )
        {
            dfs(v,v[x][i],vis,par);
            par[v[x][i]] = x;
        }
    }
}

void dfs2( vector< vector<int> > &v , int x , vector<int> &vis , vector<int> &par , int cnt[] )
{
    vis[x] = 1;

    rep(i,0,v[x].size())
    {
        if( vis[v[x][i]] == 0 )
        {
            // ans[v[x][i]] += val;
            // out1(v[x][i]);
            cnt[v[x][i]] += cnt[par[v[x][i]]];
            dfs2(v,v[x][i],vis,par,cnt);
        }
    }
}

//START OF CODE ->->->->->->->

void solve()
{
    int n,q;
    cin>>n>>q;

    vector< vector<int> > v(n+1);

    rep(i,0,n-1)
    {
        int a,b;
        cin>>a>>b;

        v[a].pb(b);
        v[b].pb(a);
    }
    
    int c[n+1] = {0};
    
    while(q--)
    {
        int p,x;
        cin>>p>>x;

        c[p] += x;
    }
    vector<int> vis(n+1,0);
    vector<int> par(n+1,0);
    par[1] = -1;
    dfs(v,1,vis,par);
    vector<int> vis1(n+1,0);
    dfs2(v,1,vis1,par,c);
    // rep(i,2,n+1)
    // {
    //     c[i] += (c[par[i]]);
    // }

    rep(i,1,n+1)
    {
        cout<<c[i]<<" ";
    }
    cout<<endl;

}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



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

int main()
{
	int n, br=0, j, a[99999], k=0, br2=0;
	cin >> n;

	for(int i=11; i<=55555; i++){
		for(j=2; j<i; j++){
			if(i%j == 0){
				br++;
				break;
			}
		}
		if(br == 0 && j%5==1 && br2<=55){
			a[k] = j;
			k++;
			br2++;
		}
		if(br2>=55) break;
		br=0;
	}

	for(int i=0; i<n; i++){
		cout << a[i] << " ";
	}

    return 0;
}


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

#define ll long long
#define pi pair<int,int>
#define ppi pair<pi,pi>
#define mp make_pair
using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "



int p[2000020];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0) , cout.tie(0);

    int n; cin >> n;
    for(int i = 0;i < n;i++)
    {
        cin >> p[i];
    }
    sort(p , p + n);
    int c1 = p[n / 2];
    int c2 = p[n / 2 - (n % 2 == 0)];
    cout << c1 - c2 << '\n';
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXV = 100005;
const ll INF = 1e18;

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

  vector<int> v(n);
  vector<ll> w(n);

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

  vector< vector<ll> > dp(n + 1, vector<ll>(MAXV, INF));
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= MAXV; ++j) {
      if (j - v[i] >= 0) {
	dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
      }
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
    }
  }

  int ans = 0;
  for (int i = 0; i < MAXV; ++i)
    if (dp[n][i] <= W) ans = i;

  cout << ans << '\n';
  return 0;
}


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


#include <cstdlib>  // abs() for integer 絶対値求めやつ


#include <cmath>    // abs() for float, and fabs()


#include <algorithm>


 


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


#define SORT(a) sort((a).begin(),(a).end());


#define che(a,string) cout<<string<<":"<<(a)<<endl;


#define ch(a,string) cout<<string<<":"<<(a)<<" ";


using namespace std;


typedef pair<int,int> P;




int main(){

	int n,i;
	cin >> n >> i ;
	cout << n - i + 1 <<endl;

}




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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if((A + B) > (C + D)){
    cout << "Left" << endl;
  }
  else if((A + B) < (C + D)){
    cout << "Right" << endl;
  }
  else if((A + B) == (C + D)){
    cout << "Balanced" << endl;
  }
}


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

typedef vector< ll > 	vi;
typedef vector< vi > 	vvi;
typedef pair< ll,ll > 	ii;

#define pb 		push_back
#define all(c) 		(c).begin(),(c).end()
#define present(c,x) 	((c).find(x) != (c).end())
#define rep(i,n)        for(ll i=0LL; i<(n); i++)

#define MOD 	1000000007
#define INF 	(int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))

//Maths functions
ll Digit(ll N){ll res=0;while(N) res++, N/=10;return res;}
ll Gcd(ll a,ll b){ return b?Gcd(b,a%b):abs(a); }


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

	string s;
	cin>>s;
	ll n= s.length();
	for(ll i=0; i<n; i++)
		cout<<"x";
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(998244353)
#define INF (2e9)
#define EPS (1e-6)
#ifdef LOCAL_TEST
#define debug(...) do{\
	cerr<<__PRETTY_FUNCTION__<<" - "<<__LINE__<<\
	" : ("#__VA_ARGS__<<") = ";\
	_OUT(__VA_ARGS__);\
}while(0)
template<typename T>void _OUT(T x){cerr<<x<<endl;}
template<typename T,typename...I>void _OUT(T x,I ...tail){cerr<<x<<", ";_OUT(tail...);}
#else
#define debug(...)
#endif
void INIT(){
#ifdef LOCAL_TEST
	freopen("D:\\input.in","r",stdin);
	freopen("D:\\output.out","w",stdout);
	freopen("D:\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
}

ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll fpow(ll b,ll p){
	b%=MOD;
	ll ans=1;
	while(p>0){
		if(p&1) ans=(ans*b)%MOD;
		p/=2;
		b=(b*b)%MOD;
	}
	return ans;
}

int dp[3050];

int32_t main() {
	INIT();
	//code...
	ll n,s; cin>>n>>s;
	memset(dp,0,sizeof(dp));
	dp[0]=1;
	ll ans=0;
	for(ll i=n;i>=1;i--){
		ll t; cin>>t;
		if(t<=s) ans=(ans+i*dp[s-t])%MOD;
		for(ll j=s-1;j>t;j--){
			if(j-t>=0) dp[j]=(dp[j]+dp[j-t])%MOD;
		}
		if(t<s) dp[t]=(dp[t]+n-i+1)%MOD;
		dp[0]++;
		//For(j,0,s) cerr<<dp[j]<<" \n"[j==s];
		//cerr<<t<<" "<<ans<<"\n";
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 3660
n,m=map(int,input().split())
b=list(map(int, input().split()))
h = {i: b for i, b in enumerate(b)}


ab=[list(map(int, input().split())) for _ in range(m)]

d=set()
# ans=0
# a=[1 for i in range(n)]

for i in range(m):
    if h[ab[i][0]-1]<h[ab[i][1]-1]:
        d.add(ab[i][0]-1)
    elif h[ab[i][0]-1]>h[ab[i][1]-1]:
        d.add(ab[i][1]-1)
    elif h[ab[i][0]-1]==h[ab[i][1]-1]:
        d.add(ab[i][0]-1)
        d.add(ab[i][1]-1)
#


# print(h[ab[0][0]-1])
# #
print(n-len(d))

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

signed main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int t;
    std::cin >> t;

    int cnt = 0;
    bool ans = false;

    while (t--) {
        int a, b;
        std::cin >> a >> b;
        if (a == b) {
            ++cnt;
            ans |= (cnt == 3);
        }
        else {
            cnt = 0;
        }
    }

    if (ans) std::cout << "Yes";
    else std::cout << "No";

    return 0;
}

Measured memory_bytes: 3608
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

a,b,c = myinput()
l = [a,b,c]
M = max(l)
g = M*3
sa = g - sum(l)

if sa%2==0:
    ans = sa//2
else:
    g = (M+1)*3
    ans = (g-sum(l))//2
    
print(ans)

Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<stack>
using namespace std;

int main(){
	int N;
	cin>>N;
	int u[N-1],v[N-1];
	long w[N-1];
	for(int i=0;i<N-1;++i){
		cin>>u[i]>>v[i]>>w[i];
		w[i]%=2;
	}
	map<int,vector<int> >even,odd;
	vector<int>tmp;
	for(int i=0;i<N-1;++i){
		if(w[i]%2==0){
			even[u[i]].push_back(v[i]);
			even[v[i]].push_back(u[i]);
		}
		else{
			odd[u[i]].push_back(v[i]);
			odd[v[i]].push_back(u[i]);
		}
	}
	/*
	for(int i=1;i<=N;++i){
		cout<<"yy"<<i<<endl;
		for(int j=0;j<even[i].size();++j){
			cout<<even[i][j]<<" ";
		}
		cout<<endl;
		for(int j=0;j<odd[i].size();++j){
			cout<<odd[i][j]<<" ";
		}
		cout<<endl;
	}
	*/
	int ans[N+1];
	for(int i=2;i<=N;++i){
		ans[i]=-1;
	}
	ans[1]=0;
	stack<int>statearr;
	statearr.push(1);
	int state;
	while(!statearr.empty()){
		state = statearr.top();
		statearr.pop();
		for(int i=0;i<even[state].size();++i){
			if(ans[even[state][i]]==0 || ans[even[state][i]]==1)continue;
			statearr.push(even[state][i]);
			if(ans[state]==0){
				ans[even[state][i]]=0;
			}
			else{
				ans[even[state][i]]=1;
			}
		}
		for(int i=0;i<odd[state].size();++i){
			if(ans[odd[state][i]]==0 || ans[odd[state][i]]==1)continue;
			statearr.push(odd[state][i]);
			if(ans[state]==0){
				ans[odd[state][i]]=1;
			}
			else{
				ans[odd[state][i]]=0;
			}
		}
	}
	for(int i=1;i<=N;++i){
		cout<<ans[i]<<endl;
	}
}


Measured memory_bytes: 22272
#!/usr/bin/python3

import array
from fractions import Fraction
import functools
import itertools
import math
import os
import sys


def main():
    while True:
        N, M = read_ints()
        if (N, M) == (0, 0):
            break
        A = read_ints()
        W = read_ints()
        print(solve(N, M, A, W))


def solve(N, M, A, W):
    weights = set([])
    for w in W:
        wl = list(weights)
        weights.add(w)
        for w0 in wl:
            if w0 + w > 0:
                weights.add(w0 + w)
            if w0 - w > 0:
                weights.add(w0 - w)
            if w - w0 > 0:
                weights.add(w - w0)

    rest = set()
    for a in A:
        if a not in weights:
            rest.add(a)

    if not rest:
        return 0

    rest = list(rest)
    cands = None
    for w in rest:
        r = set([w])
        for w0 in weights:
            r.add(w0 + w)
            if w0 - w > 0:
                r.add(w0 - w)
            if w - w0 > 0:
                r.add(w - w0)
        if cands is None:
            cands = r
        else:
            cands &= r

    if not cands:
        return -1
    return min(cands)


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()



Measured memory_bytes: 19004
#include <stdio.h>
#include <math.h>
 
int main(void){
    int R,G,B;
    int N;
  	 scanf("%d", &R);
   	scanf("%d", &G);
   	scanf("%d", &B);
    scanf("%d", &N);//数値の取得
  	int i,j,k;
  int v;
  	int ans = 0;
  int sum = 0;
  
	for(i=0;i<N+1;i++){
		for(j=0;j<N+1;j++){
          v = i*R + G*j;
            if(v <= N && (N -v)%B == 0){
              ans++;
            }
          
        }
    }
    
    printf("%d",ans);
 
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n == 0 && m == 0) break;

			String[] s = new String[100];
			map = new HashMap<String,String>();

			sc.nextLine();
			for(int i=0;i<n;i++){
				String name = sc.nextLine();
				int len = 0;

				for(;name.charAt(len)==' ';len++);
				name = name.trim();
				s[len] = name;
				if(len != 0){
					map.put(name,s[len-1]);
				}
			}

			while(m-- > 0){
				String X = sc.next();
				sc.next(); sc.next();
				String op = sc.next();
				sc.next();
				String Y = sc.nextLine();
				Y = Y.substring(1,Y.length()-1);

				boolean flg = false;

				if(op.equals("child")) flg = map.get(X) != null && map.get(X).equals(Y);
				else if(op.equals("parent")) flg = map.get(Y) != null && map.get(Y).equals(X);
				else if(op.equals("sibling")) flg = map.get(X) != null && map.get(Y) != null && map.get(X).equals(map.get(Y));
				else if(op.equals("descendant")) flg = solve(X,Y);
				else if(op.equals("ancestor")) flg = solve(Y,X);

				System.out.println(flg ? "True" : "False");
			}
			System.out.println();
		}
	}

	private static HashMap<String,String> map;

	private static boolean solve(String from,String to){
		if(from.equals(to)) return true;
		if(map.get(from) == null) return false;

		return solve(map.get(from),to);
	}
}

Measured memory_bytes: 13000
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstdlib>


namespace vector {
  template<typename T, size_t dcap = 16ULL>
  class vec {
    size_t sz;
    size_t cap;
    T* a;
  public:
    vec() : sz(0), cap(dcap) {
      a = (T*)std::malloc(sizeof(T) * cap);
    }
    vec(size_t n) : sz(n), cap(dcap) {
      while (cap < sz) cap <<= 1;
      a = (T*)std::malloc(sizeof(T) * cap);
    }
    vec(size_t n, T v) : sz(n), cap(dcap) {
      while (cap < sz) cap <<= 1;
      a = (T*)std::malloc(sizeof(T) * cap);
      for (size_t i = 0; i < sz; i++) {
        a[i] = v;
      }
    }
    T& operator[](size_t i) {
      return a[i];
    }
    size_t size() const {
      return sz;
    }
    void output(std::ostream& out, char delim = ' ') const {
      for (size_t i = 0; i < sz; i++) {
        if (i) out << delim;
        out << a[i];
      }
    }
    friend std::ostream& operator<<(std::ostream& out, const vec& v) {
      v.output(out);
      return out;
    }
    void input(std::istream& in) {
      for (size_t i = 0; i < sz; i++) {
        in >> a[i];
      }
    }
    friend std::istream& operator>>(std::istream& in, vec& v) {
      v.input(in);
      return in;
    }
    ~vec() {
      std::free(a);
    }
  };
}

namespace algorithm {
  template<typename T>
  void insertion_sort(vector::vec<T>& v, bool verbose = false) {
    for (int i = 0, n = v.size(); i < n; i++) {
      int x = v[i], j;
      for (j = i - 1; j >= 0 && v[j] > x; j--) {
        v[j + 1] = v[j];
      }
      v[j + 1] = x;
      if (verbose) std::cout << v << std::endl;
    }
  }
  template<typename T>
  size_t bubble_sort(vector::vec<T>& v) {
    size_t cnt = 0;
    int n = v.size();
    for (int i = 0; i < n - 1; i++) {
      for (int j = n - 1; j > i; j--) {
        if (v[j] < v[j - 1]) {
          T t = v[j - 1];
          v[j - 1] = v[j];
          v[j] = t;
          cnt++;
        }
      }
    }
    return cnt;
  }
  template<typename T>
  size_t selection_sort(vector::vec<T>& v) {
    size_t cnt = 0;
    int n = v.size();
    for (int i = 0; i < n; i++) {
      int minj = i;
      for (int j = i; j < n; j++) {
        if (v[j] < v[minj]) minj = j;
      }
      T t = v[i];
      v[i] = v[minj];
      v[minj] = t;
      cnt += (v[i] != v[minj]);
    }
    return cnt;
  }
}

int main() {
  using namespace vector;
  using namespace algorithm;

  int N;
  std::cin >> N;

  vec<int> A(N);
  std::cin >> A;

  size_t cnt = selection_sort(A);
  std::cout << A << std::endl << cnt << std::endl;
  
  return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))

int main()
{
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a)
		cout<<k<< endl;
	else if(k<=a+b)
		cout<<a<< endl;
	else
		cout<<a-(k-a-b)<< endl;
	
	return 0;
}


Measured memory_bytes: 3632
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
set<string> x={
    "KIHBR",
    "KIHBRA",
    "KIHBAR",
    "KIHBARA",
    "KIHABR",
    "KIHABRA",
    "KIHABAR",
    "KIHABARA",
    "AKIHBR",
    "AKIHBRA",
    "AKIHBAR",
    "AKIHBARA",
    "AKIHABR",
    "AKIHABRA",
    "AKIHABAR",
    "AKIHABARA"
};
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(x.find(s)!=x.end())
        cout<<"YES";
    else
        cout<<"NO";
    cout<<endl;
}

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

constexpr int si = 1000 * 1001;
int n;
int64_t ar[si];

int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   while (cin >> n)
   {
      for (int i = 1; i <= n; i++) {
         cin >> ar[i];
         ar[i] += ar[i-1];
      }

      int64_t ans = numeric_limits<int64_t>::max();
      for (int i = 1; i < n; i++) {
         auto x = ar[i], y = ar[n]-x, ca = abs(x-y);
         ans = min(ans, ca);
      }
      cout << ans << '\n';
   }
  
   return 0;
}

Measured memory_bytes: 1792