akhauriyash/Code-Regression huggingface dataset:
#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

vector<int> G[100010];
deque<int> path;
set<int> st;

void dfs(int p) {
	path.push_back(p);
	st.insert(p);
	rep(i, G[p].size()) {
		if (st.find(G[p][i]) != st.end() ) {
			dfs(G[p][i]);
			return;
		}
	}
}

bool check() {
	int p[2] = { path.front(), path.back() };
	rep(j, 2) {
		rep(i, G[p[j]].size()) {
			if (st.find(G[p[j]][i]) == st.end()) {
				if (j == 0)
					path.push_front(G[p[j]][i]);
				else 
					path.push_back(G[p[j]][i]);
				st.insert(G[p[j]][i]);
				return false;
			}
		}
	}
	return true;
}


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	rep(i, M) {
		int A, B;
		cin >> A >> B;
		G[A].push_back(B);
		G[B].push_back(A);
	}
	dfs(1);
	while (!check());
	cout << path.size() << endl;
	for (auto itr = path.begin(); itr != path.end(); ++itr) {
		if (itr != path.begin()) cout << " ";
		cout << *itr;
	}
	cout << endl;



    return 0;
}


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

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

    ll minN = pow(10,12) + 1;

    for(ll i = 1; i <= pow(N,0.5); i++)
    {
        if(N % i == 0)
        {
            minN = min(minN,(i + N / i));
        }
    }

    cout << minN - 2 << endl;
    return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n; 
    
    cin >> n;
    int count = 0;
    while(n > 0){
        count++;
        n = n-2;
    }
    
    cout<<count<<" ";
    return 0;
}

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  vector<int> v = a;
  sort(v.begin(), v.end());
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int rk = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
    if ((i - rk) & 1) {
      cnt++;
    }
  }
  printf("%d\n", cnt / 2);
  return 0;
}


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

const int inf = 2e9;
const int N = 100100;

int n, x[N], L, Q, dp[N][17];

void calc() {
	for (int i = 0; i < N; i++)
		for (int j = 0; j < 17; j++)
			dp[i][j] = inf;
	for (int i = 1; i <= n; i++) {
		auto it = upper_bound(x + 1, x + 1 + n, x[i] + L);
		it--;
		dp[i][0] = it - x;
	}
	for (int j = 1; j < 17; j++)
		for (int i = 1; i <= n; i++) 
			dp[i][j] = dp[dp[i][j - 1]][j - 1];			
}

int get(int l, int r) {
	if (l > r) swap(l, r);
	int ll = 1, rr = n - 1, res = r - l;
	while (ll <= rr) {
		int mid = ll + rr >> 1, cur = l;
		for (int i = 0; i < 17; i++)
			if (mid & (1 << i)) cur = dp[cur][i];
		if (cur >= r) {
			res = mid;
			rr = mid - 1;
		} else ll = mid + 1;
	}
	return res;
}

int main() {
	cin >> n;
	fill(x, x + N, inf);
	for (int i = 1; i <= n; i++) 
		cin >> x[i];
	cin >> L >> Q;
	calc();
	while (Q--) {
		int l, r;
		cin >> l >> r;
		cout << get(l, r) << '\n';
	}
}


Measured memory_bytes: 10636
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  cin >> n >> m;
  P a[n];
  rep(i,n) cin >> a[i].F >> a[i].S;
  ll dp[1111];
  fill(dp,dp+1111,-MAX);
  dp[0]=0;
  rep(i,n) {
    rrep(j,1111) {
      rep(k,a[i].F+1) {
        if(j+k>=1111) break;
        dp[j+k]=max(dp[j+k],dp[j]+(i+1)*100*k+(k==a[i].F?a[i].S:0));
      }
    }
  }
  rep(i,1111) {
    if(dp[i]>=m) {
      pr(i);
      return;
    }
  }
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100000000000000000;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll H,N;
    cin >> H >> N;
    ll sum = 0;
    rep(i,N){
        ll a;
        cin >> a;
        sum += a;
    }
    if(H <= sum){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}



Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}

int main(){
	int a,b,c;scanf("%d%d%d",&c,&a,&b);
	if(a>=b)printf("delicious\n");
	else if(a+c>=b)printf("safe\n");
	else printf("dangerous\n");
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
using namespace std;
set<string> a;
string c;
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        cin>>c;
        a.insert(c);
    }
    cout<<a.size();
    return 0;
}


Measured memory_bytes: 19228
#include<stdio.h>
int main(){
  int a[4],i,at=0,bt=0;
  for(i=0;i<4;i++){
    scanf("%d",&a[i]);
    at+=a[i];
  }
  for(i=0;i<4;i++){
    scanf("%d",&a[i]);
    bt+=a[i];
  }
  if(at<bt){
    printf("%d\n",bt);
  }
  else{
    printf("%d\n",at);
  }
  return(0);
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;

const int INF = 1e9 + 7;
int N;
int coun[100001];
ll ans = 1;
vector <int> human;

int main() {
  cin >> N;

  for(int i = 0; i < N; i++) {
    int A;
    cin >> A;
    coun[A]++;
    human.push_back(A);
  }
  sort(human.begin(),human.end());

  if(N % 2 == 1) {
    if(coun[0] != 1){ cout << '0' <<endl; return 0; }
    for(int i = 2; i < N; i += 2) {
      if(coun[i] != 2) { cout << '0' <<endl; return 0; }
    }
  }

  else {
    for(int i = 1; i < N; i+= 2) {
      if(coun[i] != 2) {cout << '0' <<endl; return 0; }
    }
  }

  for(int i = 0; i < N / 2; i++) {
    ans = ans * 2 % INF;
  }
      

  cout << ans <<endl;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int main()
{
  int n;
  while (scanf("%d", &n) != EOF)
  {
    int rem = n % 10;
    printf("%s\n", rem == 3 ? "bon" : (rem == 0 || rem == 1 || rem == 6 || rem == 8 ? "pon" : "hon"));
  }
  return 0;
}

Measured memory_bytes: 3764
results = []
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
 
    results.append([m,f,r])

for result in results:
    m, f, r = result[0], result[1], result[2]
    if m == -1 or f == -1:
        print("F")
        continue
        
    # 中間試験と期末試験の合計点数が 80 以上ならば成績は A 。
    if m + f >= 80:
        print("A")
    elif m + f >= 65:
        print("B")
    elif m + f >= 50:
        print("C")
    elif m + f >= 65:
        print("B")
    elif m + f >= 30:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")


Measured memory_bytes: 5596
#include <stdio.h>

int main() {
  int W, H, x, y , r;
  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
  if ((x - r < 0) || (W < x + r )) {
    printf("No\n");
    return 0;
  }
  if ((y - r < 0) || (H < y + r )) {
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    string t; 
    cin >> t;
    int n = t.size();
    rep(i,n){
        if(t[i]!='P')t[i]= 'D';
    }
    cout << t << endl;
    /*int cnt = 0;
    rep(i,n){
        if(t[i]=='D')cnt++;
        if(i<n-1){
            if(t[i]=='P'&&t[i+1]=='D')cnt++;
        }
    }
    cout << cnt << endl;*/
    return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
int main(){
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    int ans=0;
    rep(i,1,n+1){
        if (i<=k) ans=ans+x;
        else ans=ans+y;
    }
    cout<<ans;
}

    

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

int main() {
	string S, T;
	cin >> S >> T;

	if (S == T) {
		cout << "Yes" << endl;
	}
	else {
		for (int i = 1; i < S.size(); i++) {
			char& A = S[0];
			S.push_back(A);
			S.erase(S.begin());

			if (S == T) {
				cout << "Yes" << endl;
				return 0;
			}
		}
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
N,M=map(int,input().split())
numbers=[' ',]*N
kotae=0
for a in range(M):
    suuji=[]
    s,c=input().split()
    if numbers[int(s)-1]==' ':
        numbers[int(s)-1]=int(c)
    else:
        if numbers[int(s)-1]==int(c):
            continue
        else:
            print('-1')
            kotae+=1
            break
if numbers[0]==' ' and N==3:
    numbers[0]=1
if N==2 and numbers[0]==' ':
    numbers[0]=1
for a in range(N):
    if numbers[a]==' ':
        numbers[a]=0
if N==3:
    if numbers[0] == 0:
        del numbers[0]
        if numbers[0] == 0:
            del numbers[0]
            if numbers[0] == 0:
                del numbers[0]
if N==2:
    if numbers[0] == 0:
        del numbers[0]
        if numbers[0] == 0:
            del numbers[0]
if kotae==0:
    if len(numbers)!=N:
        print('-1')
    else:
       moji=''
       for a in numbers:
           moji+=str(a)
       print(int(moji))


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

int main(){
  int n,k,q; cin >>n>>k>>q; vector<int>a(n);
  for(int i=0; i<q; i++)
  {int x; cin >>x; a[x-1]++;}
  for(int i=0; i<n; i++)
  {
    if(a[i]+k-q>0){cout <<"Yes"<<endl;}
    else{cout <<"No"<<endl;}
  }

return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

int N,Q;
string S;
int L[100010],R[100010];
int num[100010];
int cnt=0;

signed main(){
	cin>>N>>Q>>S;
	REP(i,Q){
		cin>>L[i]>>R[i];
	}
	for(int i=0;i<S.size();i++){
		num[i]=cnt;
		if(i<N-1&&S[i]=='A'&&S[i+1]=='C'){
			num[i+1]=cnt+1;
			cnt++;
			i++;
		}
	}
	DEB(num[3])END
	REP(i,Q){
		cout<<num[R[i]-1]-num[L[i]-1]<<endl;
	}
	return 0;
}


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

#define MAX (1<<18)
typedef long long ll;
int N,M;
ll A[100001];
ll B[100001];
ll C[100001];
int P[100001];


ll data[MAX];
int n;
void init(){
  n = 1;
  while( n < N ) n*=2;
  memset(data,0,sizeof(data));
}

void add(int a,int b,ll x,int k,int l,int r){
  if( r <= a|| b <= l ) return;
  if( a <= l && r <= b ) data[k] += x;
  else {
    add(a,b,x,2*k+1,l,(l+r)/2);
    add(a,b,x,2*k+2,(l+r)/2,r);
  }
} 
void add(int a,int b,ll x){
  add(a,b,x,0,0,n);
}

ll get(int id){
  id += n-1;
  ll ret = data[id];
  while( id > 0 ){
    id = (id- 1)/2;
    ret += data[id];
  } 
  return ret;
}

int main(){
  cin >> N >> M;
  for(int i=0;i<M;i++){
    cin >> P[i]; --P[i];
  }
  init();
  for(int i=0;i<N-1;i++){
    cin>> A[i] >> B[i] >> C[i];
  }
  int s = P[0];
  for(int i=1;i<M;i++){
    int e=P[i];
    if( s > e ) add(e,s,1LL);
    else add(s,e,1LL);
    s = e;
  }

  ll res = 0;
  for(int i=0;i<N-1;i++){
    ll st = get(i);
    res+= min( st * A[i] , st * B[i] + C[i] );
  }
  cout << res << endl;

  

}

Measured memory_bytes: 5952
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    int i ;
    i = 0 ;
    while(i<19)
    {
        if( s[i] == ',' ){
            s[i]=' ' ;
        }
        i++;
    }
    cout<<s;



    return 0;
}


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

int main(){
    int N, K, Q;
    cin >> N >> K >> Q;
    int num[100000] = {0};
    for(int i=0; i<Q; i++){
        int a;
        cin >> a;
        num[a-1]++;
    }
    for(int i=0; i<N; i++) cout << (K - (Q-num[i]) > 0 ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define N 310
#define mod 1000000007
#define pa(a, b) (data){a, b}
using namespace std;
struct data{int x, y;};
int n, m, x, y, z, f[N][N][N], ans;
vector<data>son[N];
inline int check(int x, int y, int i){
	for(int j=0; j<son[i].size(); j++){
		if(son[i][j].y==1&&son[i][j].x<=y)return 0;
		if(son[i][j].y==2&&(son[i][j].x<=x||son[i][j].x>y))return 0;
		if(son[i][j].y==3&&son[i][j].x>x)return 0;
	}
	return 1;
}
int main(){
	scanf("%d%d", &n, &m);
	for(int i=1; i<=n; i++)son[i].clear();
	for(int i=1; i<=m; i++){scanf("%d%d%d", &x, &y, &z); son[y].push_back(pa(x, z));}
	memset(f, 0, sizeof(f)); f[0][0][0]=1;
	for(int i=0; i<=n-1; i++)
		for(int j=0; j<=i; j++)
			for(int k=j; k<=i; k++)if(f[i][j][k]){
				if(check(j, k, i+1))f[i+1][j][k]=(f[i+1][j][k]+f[i][j][k])%mod;
				if(check(k, i, i+1))f[i+1][k][i]=(f[i+1][k][i]+f[i][j][k])%mod;
				if(check(j, i, i+1))f[i+1][j][i]=(f[i+1][j][i]+f[i][j][k])%mod;
			}
	ans=0;
	for(int i=0; i<=n; i++)
		for(int j=i; j<=n; j++)ans=(ans+f[n][i][j])%mod;
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 116608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define MAX_SIZE (100000)

using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  int A[MAX_SIZE];
  for (size_t i = 1; i < N+1; i++) {
    cin >> A[i];
  }
  A[0] = 0;
  A[N+1] = 0;
  int a, remain;
  unsigned long sum = 0;
  for (size_t i = 1; i <= N; i++) {
    a = A[i-1] + A[i];
    sum += a / 2;
    A[i] = min(a % 2, A[i]);
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 640
N, H = map(int, input().split())
slash = 0
Throw = []
for _ in range(N):
    a, b = map(int, input().split())
    slash = max(slash, a)
    if b > a: Throw.append(b)    
#slash=斬撃最大ダメージ、投げてslash超のダメージが出るならばその刀をダメージが大きい順に投げる
Throw = sorted([th for th in Throw if th > slash], reverse=True)
dmg, cnt = 0, 0
for throw in Throw:
    if dmg >= H: break
    dmg += throw
    cnt += 1
if dmg < H:
    from math import ceil
    cnt += ceil((H-dmg)/slash)
print(cnt)

Measured memory_bytes: 14904
#include <stdio.h>

int main(void) {
  int n, p, count[50], t = 0, i, j;

  while (1) {
    scanf("%d %d", &n, &p);
    if (n == 0 && p == 0) break;

    for (i = 0; i < n; i++)
      count[i] = 0;

    t = p;
    i = 0;
    while (1) {
      if (t > 0) {
	count[i]++;
	t--;
      }
      else {
	t = count[i];
	count[i] = 0;
      }
      if (count[i] == p) {
        printf("%d\n", i);
	break;
      }
      i++;
      if (i == n) i = 0;
    }
  }

  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <map>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-9

int main(){
	int n,a,b,c,x;
	int reel[100];
	while(scanf("%d%d%d%d%d",&n,&a,&b,&c,&x),n|a|b|c|x){
		rep(i,n)scanf("%d",&reel[i]);
		int k = 0;
		int i;
		for(i=0; i<10001; i++){
			if( x==reel[k] ){
				k++;
				if( k==n )break;
			}
			x = (a*x + b) % c;
		}
		//printf("i:%d\n",i);
		printf("%d\n",i==10001?-1:i);
	}
	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll a,b,c; cin >> a >> b >> c;
  if (b >= c) cout << b+c << endl;
  else {
    if (a+b >= c) cout << b+c << endl;
    else cout << b + (a+b+1) << endl;
  }
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) (1 + (int)((a) - 1)/(int)(b))
//#define int long long

signed main(){
    map<string, int> blue, red;
    int n; cin >> n;
    rep(i,n){
        string s; cin >> s;
        blue[s]++;
    }
    int m; cin >> m;
    rep(i,m){
        string s; cin >> s;
        red[s]++;
    }
    
    int ans = 0;
    for(auto p : blue){
        string s = p.first;
        int money = p.second;
        
        if(red.count(s)) money -= red[s];
        if(ans > money) continue;
        
        ans = money;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
use std::io;

fn read_input() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s);
    s
}

fn wa() {
    println!("WA");
    std::process::exit(0);
}

fn solve(s: String) {
    let mut c = 0;
    for (i, j) in s.chars().enumerate() {
        match (i, j) {
            (0, 'A') => continue,
            (0, _) => wa(),
            (1, 'A'...'Z') => wa(),
            (i, 'C') if i == 1 || i >= s.len() - 2 || c == 1 => wa(),
            (i, 'C') => c += 1,
            (_, 'A' ... 'Z') => wa(),
            (_, _) => continue,
        }
    }
    if c == 0 {
        wa();
    }
    println!("AC");
}

fn main() {
    solve(read_input());
}


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

int main(){
  int N; cin >> N;
  vector<int> h(N);
  for(int i = 0; i < N; i++){
    cin >> h[i];
  }
  vector<int> dp(N, 0);
  dp[1] = abs(h[1] - h[0]);
  for(int i = 0; i < N - 2; i++){
    dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 1] + abs(h[i + 2] - h[i + 1]));
  }
  cout << dp[N - 1] << endl;
}

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

int main()
{
    string s;
    while(getline(cin,s))
	{
        for(int i=0;i<26;++i)
		{
            for(int j=0;j<s.size();++j) 
				if('a'<=s[j]&&s[j]<='z')
					{
						s[j]=((s[j]-'a'+1)%26+'a');
				}
            if(s.find("the")!=-1||s.find("this")!=-1||s.find("that")!=-1)
break;
        }
        cout<<s<<endl;
    }
    return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);
int n, k;
int main(void) {
  // Here your code !
  scanf("%d %d", &n, &k);
  
  printf("%d\n", (n % k != 0) ? 1 : 0);

  return 0;
}


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

int main() {
  string S;
  cin >> S;
  int n = 0, w = 0, s = 0, e = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'N') n = 1;
    else if (S[i] == 'S') s = 1;
    else if (S[i] == 'E') e = 1;
    else w = 1;
  }
  cout << (n == s && e == w ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>

#define int long long
#define dotimes(i, n) for (int i : range(n))

using namespace std;

class range {
  class iterator {
    int i, s;
  public:
    iterator(int i, int s): i(i), s(s) {}
    int& operator*() {
      return i;
    }
    void operator++() {
      i += s;
    }
    bool operator!=(iterator const& that) {
      return i < that.i;
    }
  };
  iterator b, e;
public:
  range(int e): b({0, 1}), e({e, 1}) {}
  range(int b, int e): b({b, 1}), e({e, 1}) {}
  range(int b, int e, int s): b({b, s}), e({e, s}) {}
  iterator begin() {
    return b;
  }
  iterator end() {
    return e;
  }
};

int rint() {
  int n;
  scanf("%lld", &n);
  return n;
}

void wint(int n) {
  printf("%lld\n", n);
}

template<typename T>
inline int size(T container) {
  return static_cast<int>(container.size());
}

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

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

signed main() {
  for (;;) {
    int n = rint();
    if (!n)
      break;
    int w[n];
    dotimes(i, n)
      w[i] = rint();
    bool dp[n/2+1][n] = {};
    dotimes(i, n)
      dp[0][i] = true;
    for (int i : range(1, n/2+1))
      dotimes(j, n-2*i+1)
        if (abs(w[j] - w[j+2*i-1]) <= 1 && dp[i-1][j+1])
          dp[i][j] = true;
        else
          for (int k : range(1, i))
            if (dp[k][j] && dp[i-k][j+2*k]) {
              dp[i][j] = true;
              break;
            }
    int ls[n+1] = {};
    for (int i = n - 1; i >= 0; i--) {
      ls[i] = ls[i+1];
      dotimes(j, (n-i)/2)
        if (dp[j+1][i])
          maxs(ls[i], 2*(j+1) + ls[i+2*(j+1)]);
    }
    wint(ls[0]);
  }
  return 0;
}



Measured memory_bytes: 2664
function Main(input) {
    var input = input.split(' ');
    var Connect = input[0] + input[1];
    var int = parseInt(Connect);
    var square = Math.pow(int, 1/2);
    if (square % 1 === 0) {
        console.log('Yes');
    } else {
        console.log('No');
    }
    
    }
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, K;
	cin >> N >> K;
	vector<int> CNT(N, 0);

	int d, a;
	rep(i, 0, K)
	{
		cin >> d;
		rep(j, 0, d)
		{
			cin >> a;
			a--;
			CNT[a]++;
		}
	}

	int ans = 0;
	rep(i, 0, N)
	{
		if (CNT[i] == 0)ans++;
	}

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

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };


int n, a, b, w = 0, h = 0, e = 0;
bool f = false;
VVI box;
int c[ 1000 ][ 1000 ];
VI d;

int main() {
	d.push_back( 0 );
	while ( ~scanf( "%d", &n ) && n ) {
		memset( c, -1, sizeof( c ) );
		c[ 500 ][ 500 ] = 0;
		for ( int i = 1; i < n; i++ ) {
			scanf( "%d %d", &a, &b );
			for ( int j = 0; j < 1000; j++ ) {
				for ( int k = 0; k < 1000; k++ ) {
					if ( c[ j ][ k ] == a ) {
						c[ j + dy[ b ] ][ k + dx[ b ] ] = i;
					}
				}
			}
		}
		int startmark = INF, endmark = -1;
		for ( int i = 0; i < 1000; i++ ) {
			f = false;
			for ( int j = 0; j < 1000; j++ ) {
				if ( c[ i ][ j ] >= 0 ) {
					h += !f;
					f = true;
					startmark = min( startmark, j );
					endmark = max(endmark, j);
				}
			}
			w = max( endmark - startmark + 1, w );
		}
		printf( "%d %d\n", w, h );
		w = h = 0;
	}
	return 0;
}

Measured memory_bytes: 5100
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	M := nextInt()

	fmt.Println(min((2*N+M)/4, M/2))
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	if x < y {
		return x
	}

	return y
}

// ---------- Util.


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

int main() {
  int N, K; cin >> N >> K;
  int R, S, P; cin >> R >> S >> P;
  string T; cin >> T;
  vector<char> a(N);
  int score = 0;
  for (int i = 0; i < N; i++) {
    if (i < K) {
      if (T.at(i) == 'r') {
        score += P;
        a.at(i) = 'p';
      }
      else if (T.at(i) == 's') {
        score += R;
        a.at(i) = 'r';
      }
      else {
        score += S;
        a.at(i) = 's';
      }
      continue;
    }

    if (T.at(i-K) == T.at(i) && a.at(i-K) != 'x') {
      a.at(i) = 'x';
    }
    else {
      if (T.at(i) == 'r') {
        score += P;
        a.at(i) = 'p';
      }
      else if (T.at(i) == 's') {
        score += R;
        a.at(i) = 'r';
      }
      else {
        score += S;
        a.at(i) = 's';
      }
    }

  }
  cout << score << endl;
}

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

int main(){
  int H,W;
  while(1){
    cin >> H;
    cin >> W;
    if(H == 0 && W == 0){
      break;
    }
    for(int j = 0;j < W;j++){
      cout<<'#';
    }
    cout<<endl;
    for(int i = 0;i < H-2;i++){
      for(int j = 0;j < W;j++){
        if(j == 0 || j == W-1){
          cout<<'#';
        }else{
          cout<<'.';
        }
      }
      cout<<endl;
    }
    for(int j = 0;j < W;j++){
      cout<<'#';
    }
    cout<<endl;
    cout<<endl;
  }
  return 0;
}


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

int main() {
    int n;
    while(cin >> n, n){
        int sum=0,ma=0,mi=IINF;
        REP(i,n){
            int a;
            cin >> a;
            sum+=a;
            ma = max(ma, a);
            mi = min(mi, a);
        }
        cout << (sum-ma-mi)/(n-2) << endl;
    }
    return 0;
}



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

int main()
{
	string s1;
	string s2;
	getline(cin, s1);
	getline(cin, s2);
	string s3 = s1 + s1;
	bool flag = false;
	for (int i = 0; i < s1.size() + s2.size(); i++) {
		if (s3[i] == s2[0] && s1.size()-i >= 0) {
			string s4 = "";
			for (int j = 0; j < s2.size(); j++) {
				s4 += s3[i + j];
			}
			//cout << s4 << endl;
			if (s4 == s2) {
				flag = true;
				break;
			}
		}
	}
	cout << (flag ? "Yes" : "No") << endl;
	
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

long int M = 1e+9+7;
int main(void){
    string c[3];
    rep(i,3){
        cin >> c[i];
    }
    cout << c[0][0] << c[1][1] << c[2][2] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
vector <long long int> prime;
 
void eratos()
{
	bool isprime[31624];
	memset(isprime,true,sizeof(isprime));
 
	for(int i=2;i<=31623;i++)
	{
		if(isprime[i])
		{
			prime.push_back(i);
			for(int j=2*i;j<=31623;j+=i)
			{
				isprime[j] = false;
			}
		}
	}
}
 


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	long long int n,m;
 
	cin >> n >> m;
 
 	eratos();
 
	long long int t = m;
 	long long int res = 1;

	for(int i=prime.size()-1;i>=0;i--)
	{
		if(t==1)
		{
			break;
		}
		if(t%prime[i]==0)
		{
			while(1)
			{
				if(t%prime[i]!=0)
				{
					break;
				}
				if(res*prime[i]*n<=m)
				{
					res*=prime[i];
				}
				t/=prime[i];
			}
		}
	}
 	
 	if(t!=1)
 	{
 		if(t*n<=m)
 		{
 			res = t;
 		}
 	}
 
 	
	if(m%n==0)
	{
		res = max(res,m/n);
	}
 
	for(long long int i=2;i<=sqrt(m);i++)
	{
		if(m%i==0 && i*n<=m)
		{
			long long int x = i;
			while(1)
			{
				if(i*x*n>m || m%(i*x)!=0)
				{
					break;
				}
				x*=i;
			}
			res = max(res,x);
		}
	}
 
	cout << res << '\n';
 
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	for (int i = 1; i <= b; i++) {
		if ((a*i) % b == c) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
count=0
for i in range(n):
    if a[i]%2==0 and (a[i]%3!=0 and a[i]%5!=0):
        count+=1
if count>0:
    print('DENIED')
else:
    print('APPROVED')

Measured memory_bytes: 3060
import numpy as np

def calc(i,x):
    if i ==0:
        return int((x % 4 == 1) or (x % 4 == 2))
    else:
        return int((x % (2**(i+1)) >= 2**i) and (x % 2 == 0))

def main():
    A,B = map(int, input().split())
    
    #2^10 > 10^3⇒ 2^10^4 > 10^3^4
    ans = 0
    for i in range(41):
        ans += 2**i*(calc(i,A-1)^calc(i,B))# ^ calc(i,B)))
    print(ans)
    
main()

Measured memory_bytes: 12504
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!{
        a: i32,
        s: String,
    }
    println!("{}", if a >= 3200 { s } else { "red".to_string() });
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <cstring>
 
using namespace std;
 
#define MAX 100
 
int tx, ty, ans;
int n, X[MAX][MAX], Y[MAX][MAX];
bool visited[MAX][MAX], found[MAX][MAX];
bool used[MAX][MAX], flg;
 
void rec(int x, int y){
    if(visited[x][y]){
	if(!found[x][y] && tx == x && ty == y){
	    found[x][y] = flg = true;
	    ans++;
	} 
	return;
    }
    visited[x][y] = true;
    rec(X[x][y],Y[x][y]);
}
 
void draw(int x,int y){
    if(tx == x && ty == y){
	return;
    }
    used[x][y] = true;
    draw(X[x][y],Y[x][y]);
}
 
int main(){
    while(cin >> n ,n){
	for(int i = 0 ; i < n ; i++){
	    for(int j = 0 ; j < n ; j++){
		cin >> X[j][i] >> Y[j][i];
	    }
	}
 
	ans = 0;
	memset(found,false,sizeof(found));
	memset(used,false,sizeof(used));
	for(int i = 0 ; i < n ; i++){ 
	    for(int j = 0 ; j < n ; j++){
		memset(visited,false,sizeof(visited));
		if(!used[i][j]){
		    flg = false;
		    visited[i][j] = true;
		    tx = i, ty = j;
		    rec(X[i][j], Y[i][j]);
		    if(flg){
			draw(X[i][j], Y[i][j]);
		    }
		}
	    }
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3152
N, M = map(int, input().split())
X = sorted(list(map(int,input().split())))

diff = [0]*(M-1)
for i in range(M-1):
  diff[i] = X[i+1] - X[i]

diff = sorted(diff)
print(sum(diff[0:max(M-N, 0)]))

Measured memory_bytes: 13968
j = 0
while j < 10**10:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    
    for i in range (h):
        for j in range(w):
            if (i+j)%2 == 0:
                print('#',end='')
            else:
                print('.',end='')
        print()
    print()


Measured memory_bytes: 7004
a,b=map(int,input().split())
ans=['Positive','Negative','Zero']

if a*b<=0:
    print(ans[-1])
elif a>0:
    print(ans[0])
else:
    if (b-a+1)%2==0:
        print(ans[0])
    else:
        print(ans[1])

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

int main(){
  int64_t S=0;
  int N;
  cin >> N;
  vector<int> a(3*N);
  
  for (int i = 0; i < 3*N; i++){
    cin >> a.at(i);
  }
  
  sort(a.begin(), a.end());
  
  for (int i = 0; i < N; i++){
    S += a.at(2*i+N);
  }
  
  cout << S << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (ll i = (ll)(start); i < (ll)(n); ++i)
static const ll INFTY = 1L << 62L;
ll solver(ll *a, ll N)
{
    ll min = a[0], ans = 0;
    rep(i, 0, N)
    {
        if (a[i] < min)
        {
            ans += min - a[i];
        }
        else
        {
            min = a[i];
        }
    }
    return ans;
}
int main()
{
    ll N;
    cin >> N;
    ll a[N];
    rep(i, 0, N) cin >> a[i];
    cout << solver(a, N) << endl;
}

Measured memory_bytes: 5192
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using std::swap;

// priceをキーに降順でソート
//sort(fruits.begin(), fruits.end(),
//     [](const fruit& x, const fruit& y) { return x.price > y.price;});

/*
int main() {
    long long int S;
    int r;
    std::cin >> r;
    S= 3*r*r;
    std::cout << S << std::endl;
    return 0;
}
 */

int main(){
    int K, D;
    int ans;
    std::cin >> K >> D;
    ans = (K+2*D)/(2*D+1);
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz
    
    int n;
    cin>>n;

    vi v(n);
    vi s;

    for(int &x:v) cin>>x;

    int ans = 0;

    for(int i=0;i<n;i++){
        if(s.empty()) s.pb(v[i]);
        else{
            if(s.back() < v[i]) s.pb(v[i]);
            else{
                ans += s.back() - v[i];
            }
        }
    }

    cout<<ans;
} 

Measured memory_bytes: 6712
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

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

const int MAX_N = 1e5 + 5;
int n;
int col[MAX_N];
vector <pii> G[MAX_N];

void dfs (int v, int p = 0, int c = 0) {
	col[v] = c;
	for (pii u: G[v])
		if (u.first != p)
			dfs(u.first, v, c ^ u.second);
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i + 1 < n; i++) {
		int v, u, w;
		cin >> v >> u >> w;
		v--, u--, w &= 1;

		G[v].push_back({u, w});
		G[u].push_back({v, w});
	}

	dfs(0);
	for (int i = 0; i < n; i++)
		cout << col[i] << "\n";
	return 0;
}

Measured memory_bytes: 8448
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
//#define all(v) ((v).begin(),(v).end())
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
    ll q,h,s,d;
    cin>>q>>h>>s>>d;
    ll n;
    cin>>n;
    ll ans=0;
    ll dd=n/2;
    ans+=min(dd*d,min(2*dd*s,min(4*dd*h,8*dd*q)));

    n=fmod(n,2.0);
    dd=n;
    ans+=min(dd*s,min(2*dd*h,4*dd*q));

    n=fmod(n,1.0);
    dd=n/0.5;
    ans+=min(dd*h,2*dd*q);

    n=fmod(n,0.5);
    dd=n/0.25;
    ans+=dd*q;

    cout<<ans<<endl;

    

    return 0;
}




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

double min( double a, double b )
{
    if( a > b )
        return b;
    else
        return a;
}

int main()
{
    int d, w, h, n, p;

    while( cin >> d >> w >> h )
    {
        if( d == 0 && w == 0 && h == 0 )
            break;

        double a = sqrt( d * d + w * d ), b = sqrt( d * d + h * h ), c = sqrt( w * w + h * h );
        double m = min( min( a, b ), min( b, c ) ) / 2;         //外接円の半径を求め、入り口の半径の大きさと比べる。

        cin >> n;

        for( int i = 0; i < n; i++ )
        {
            cin >> p;
            if( m < p )
                cout << "OK" << endl;
            else
                cout << "NA" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3016
#include <cstdio>
using namespace std;

typedef long long Int;

int main() {
	const int MAX_N = 100000;
	int A[MAX_N], B[MAX_N], N;
	Int count, add;

	scanf("%d", &N);

	for (int i = 0;i < N;i++) {
		scanf("%d%d", &A[i], &B[i]);
	}

	count = 0;
	for (int i = N - 1;i >= 0;i--) {
		if ((A[i] + count) % B[i]) {
			add = B[i] - ((A[i] + count) % B[i]);
			count += add;
		}
	}

	printf("%lld\n", count);
	return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n,a;
    cin>>n>>a;


    cout<<n*n - a<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 256
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo

show_flg=False
show_flg=True


ans=0

n,m=LI()

a=[0]*n
w=[0]*n
for i in range(m):
    p,s=input().split()
    p=int(p)-1
    if s=='AC':
        a[p]=1
    elif s=='WA':
        if a[p]==0:
            w[p]+=1


for i in range(n):
    if a[i]==0:
        w[i]=0

print(sum(a),sum(w))



Measured memory_bytes: 42856