akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
const int MOD=30;
vector<int> v1;
map<int,int> m1;
char ca[5005];

int check(int a,int b,int t){
	int s=0;
	for(int i=0;i<t;i++){
		s*=MOD;
		if(a+i<=b)s+=(int)ca[a+i]-(int)'a'+1;
	}
	return s;
}

int main(){
	int n,t;
	int i,j,k;
	int a,b;
	cin>>ca;
	cin>>t;
	n=strlen(ca);
	for(i=0;i<n;i++){
		a=0;
		for(j=i;j<=i+t;j++){
			if(j>=n)break;
			a=check(i,j,t);
			if(m1[a]==1)continue;
			m1[a]=1;
			v1.push_back(a);
		}
	}
	sort(v1.begin(),v1.end());
	int s[10];
	for(i=0;i<t;i++){
		s[i]=v1[t-1]%MOD;
		v1[t-1]/=MOD;
	}
	for(i=t-1;i>=0;i--){
		if(s[i]==0)continue;
		cout<<(char)(s[i]+'a'-1);
	}
	cout<<endl;
	return 0;
}
			
			


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	int n;
	string s;
	cin >> n >> s;
	vector<int> w(s.size());
	for(int i=1; i<n; i++){
		w[i]=w[i-1];
		if(s[i-1]=='W')
			w[i]++;
	}
	vector<int> e(s.size());
	for(int i=n-2; i>=0; i--){
		e[i]+=e[i+1];
		if(s[i+1]=='E')
			e[i]++;
	}
	int mini=e[0];
	for(int i=1; i<n-1; i++)
		mini = min(mini, w[i]+e[i]);
	mini = min(mini, w[n-1]);
	cout << mini << endl;
	return 0;
}

Measured memory_bytes: 3076
import math
from itertools import permutations

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

acc = 0
for route in permutations(towns, n):
    dist = 0
    for i in range(n-1):
        x1, y1 = route[i]
        x2, y2 = route[i+1]
        dist += math.sqrt((x1-x2)**2 + (y1-y2)**2)
    acc += dist
print(acc / math.factorial(n))


Measured memory_bytes: 3060
n = gets.to_i
a = gets.split.map &:to_i;
total = a.inject(:+)
x = 0;  y = total;  res = 10**9 * 2
0.upto(n-2) {|i|
  x += a[i];  y = total - x
  res = ((x-y).abs < res ? (x-y).abs : res)
}
puts res


Measured memory_bytes: 15236
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    string a,b;
    cin >> a>> b;
    
    if (a=="H")cout << b << endl;
    else if (a == "D" && b=="H")cout << "D" << endl;
    else cout << "H" << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	// your code goes here
	int n,a[10001],value=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		while(1){
			if(a[i]%2!=0) break;
			else {
				value++;
				a[i]/=2;
			}
		}
	}
	printf("%d\n",value);
	return 0;
}


Measured memory_bytes: 256
n, m, q = map(int, input().split())
abcd = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    abcd.append([a-1, b-1, c, d])

from itertools import combinations

a = [i for i in range(1, n+m+1)]
As = list(combinations(a, n))
ans = []

for a in As:
    A = []
    now = 0
    for i in range(1, n+m+1):
        if i in a:
            A.append(now)
        else:
            now += 1
    if A[0] == 0:
        continue
    D = 0
    for abc in abcd:
        if A[abc[1]] - A[abc[0]] == abc[2]:
            D += abc[3]
    ans.append(D)
print(max(ans))

Measured memory_bytes: 37876
#include <set>
#include <cmath>
#include <stack>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <numeric>
#include <vector>
#include <ctime>
#include <queue>
#include <list>
#include <map>
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
#define clr(x)  memset(x,0,sizeof(x));
#define clrto(x,siz,y)  for(int xx=0;xx<=siz;xx++)  x[xx]=y;
#define clrset(x,siz)  for(int xx=0;xx<=siz;xx++)  x[xx]=xx;
#define clr_1(x) memset(x,-1,sizeof(x));
#define clrmax(x) memset(x,0x3f,sizeof(x));
#define clrvec(x,siz) for(int xx=0;xx<=siz;xx++)  x[xx].clear();
#define fop2   freopen(".in","r",stdin); //freopen(".out","w",stdout);
#define fop   freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);
#define myprogram By_135678942570
#define clrcpy(x,siz,y)  for(int xx=0;xx<siz;xx++)  x[xx]=y[xx];
#define pb push_back
using namespace std;
int main()
{
	int n;
	int ent[1011]={0};
	while(1)
	{
		char s[5];
		int m,d,h,mi,id;
		scanf("%d",&n);
		if(n==0)
			break;
		int lastm=-1,lastd=-1;
		int all[1011]={0};
		for(int i=0;i<n;i++)
		{
			scanf("%d/%d%d:%d%s%d",&m,&d,&h,&mi,s,&id);
			int nowtime=h*60+mi;
			if(lastm!=m||lastd!=d)
			{
				if(ent[0])
				{
					for(int j=0;j<1000;j++)
						if(ent[j]!=0)
							all[j]+=24*60-ent[j];
				}
				clr(ent);
			}
			if(s[0]=='I')
			{
				ent[id]=nowtime;
				if(id==0)
					for(int j=0;j<1000;j++)
						if(ent[j]!=0)
							ent[j]=nowtime;
			}
			else
			{
				if(id==0)
				{
					for(int j=0;j<1000;j++)
						if(ent[j]!=0)
							all[j]+=nowtime-ent[j];
					ent[0]=0;
				}
				else if(ent[0])
				{
					all[id]+=(nowtime-ent[id]);
					ent[id]=0;
				}
				ent[id]=0;
			}
			lastm=m,lastd=d;
		}
		printf("%d\n",*max_element(all+1,all+1000));
	}
}
/*
4
1/1 02:30 I 001
1/1 09:00 I 000
1/1 09:53 O 001
1/1 09:55 O 000
*/

Measured memory_bytes: 1200
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

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

    vector<vector<int>> g(n, vector<int>(0));
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }

    vector<int> res(n, -1);
    res[0] = 0;

    queue<int> que;
    que.push(0);
    while (!que.empty()) {
        int q = que.front();
        que.pop();

        for (int i = 0; i < static_cast<int>(g[q].size()); i++) {
            if (res[g[q][i]] < 0) {
                res[g[q][i]] = q;
                que.push(g[q][i]);
            }
        }
    }

    cout << "Yes" << endl;
    for (int i = 1; i < n; i++) {
        cout << res[i] + 1 << endl;
    }
}


Measured memory_bytes: 10228
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>

using namespace std;
int main(){
    string s;
    cin >> s;
    
    bool ok = true;
    for(int i(0);i<s.size();i++){
        if(i%2 == 1 && s[i] == 'R') ok = false;
        if(i%2 == 0 && s[i] == 'L') ok = false;
    }
    
    if(ok) puts("Yes");
    else puts("No");
    
    return 0;
}


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

int main()
{
    int N; cin >> N;
    vector<int> P(N), Q(N), A(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];
    rep(i, N) A[i] = i + 1;

    int p = 0, q = 0, c = 0;
    do {
        c++;
        if (P == A) p = c;
        if (Q == A) q = c;
    } while (next_permutation(A.begin(), A.end()));

    cout << abs(p - q) << endl;
}


Measured memory_bytes: 256
n = int(input())
swaps = 0
ar = [int(x) for x in input().split()]
for i in range(len(ar)):
    mn = ar[i]
    mi = i
    for j in range(i, len(ar)):
        if mn > ar[j]:
            mn = ar[j]
            mi = j
    if mi != i:
        if swaps == 1:
            print("NO")
            exit(0)
        ar[i], ar[mi] = ar[mi], ar[i]
        swaps += 1
print("YES" if swaps <= 1 else "NO")


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

typedef long long ll;
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define endl '\n'
const int N = 1e5 + 10;
using namespace std;
int n, t, sum[N] = {};
string s;

int main() {
    IO;
    cin >> n >> t >> s;
    s = "@" + s;
    for (int i = 1; i <= n; ++i) {
        if (s[i] == 'A' and s[i + 1] == 'C') {
            sum[i]++;
        }
    }
    for (int i = 1; i <= n; ++i) {
        sum[i] += sum[i - 1];
    }
    /*for (int i = 1; i <= n; ++i) {
        sum[i] += sum[i - 1];
    }*/
    /*for (int i = 1; i <= n; ++i) {
        cout << sum[i] << " ";
    }
    cout << endl;*/
    while (t--) {
        int l, r;
        cin >> l >> r;
        cout << sum[r - 1] - sum[l - 1] << endl;
    }


}


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

int main(){
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++){
        if((i + 1)%3 != 0 and (i + 1)%5 != 0){
            A[i] = i + 1;
        }
        else{
            A[i] = 0;
        }
    }
    long ans = 0;
    for(int i = 0; i < N; i++){
        ans += A[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 7496
#include<stdio.h>
int main(void){

  int a,b,c;

  scanf("%d %d %d",&a,&b,&c);
  if (a <= b && b <= c)
    printf("%d %d %d\n",a,b,c);
  else if (b <= a && a <= c)
    printf("%d %d %d\n",b,a,c);
    else if (a <= c && c <= b )
      printf("%d %d %d\n",a,c,b);
    else if (c <= a && a <= b)
      printf("%d %d %d\n",c,a,b);
      else if (c <= b && b <= a)
	printf("%d %d %d\n",c,b,a);
      else
	printf("%d %d %d\n",b,c,a);
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#include<climits>
 
using namespace std;
 
#define debug(x,y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
typedef long long int lld; 
 
lld n,a[100001],b[100001],c[100001],dp[100001][4];
 
//TOP-DOWN
lld educationalVacation(lld n,lld comp){
    lld ans=INT_MIN;
    if(n<0) return 0;
    if(dp[n][comp]!=-1) return dp[n][comp];
    if(comp==0){
        ans=max(ans,max(educationalVacation(n-1,1)+a[n],max(educationalVacation(n-1,2)+b[n],educationalVacation(n-1,3)+c[n])));
    }
    else if(comp==1){
        ans=max(ans,max(educationalVacation(n-1,2)+b[n],educationalVacation(n-1,3)+c[n]));
    }
    else if(comp==2){
        ans=max(ans,max(educationalVacation(n-1,1)+a[n],educationalVacation(n-1,3)+c[n]));
    }
    else{
        ans=max(ans,max(educationalVacation(n-1,1)+a[n],educationalVacation(n-1,2)+b[n]));
    }
    return dp[n][comp]=ans;
}
 
 
int main(){
    fast;
    cin.tie(0);
    lld i,j;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<educationalVacation(n-1,0)<<endl;
}

Measured memory_bytes: 12032
#include<stdio.h>

int A[1000000];
int n;

int binarySearch(int key){
  
  int left = 0;
  int right = n;
  int mid;
  
 while(left < right){
    mid = (left + right) / 2;
	  if(key == A[mid])return 1;
	  else if(key < A[mid]) right = mid;
        else left = mid + 1;
  }
  return 0;
}

  int main(){
    int i, x, y, sum = 0;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
     scanf("%d", &A[i]);
    }

    scanf("%d", &x);
    for(i = 0; i < x; i++){
      scanf("%d", &y);
      if(binarySearch(y))sum++;
      else continue;}
    
      printf("%d\n", sum);
      return 0;
  }



Measured memory_bytes: 2108
#include <iostream>

int main()
{
	int N, C=0;
	long X, Y, D;
	std::cin >> N >> D;
	for (int i = 0; i < N; i++)
	{
		std::cin >> X >> Y;
		if ((X * X) + (Y * Y) <= D * D) {
			C++;
		}
	}
	std::cout << C;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>
#include<random>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
int d;
int c[30]={};
int s[370][30];
int num=260000;
int koho=5;
int calc(vector<int>const& t,vector<vector<int>>& last_list){
  int res=0;
  vector<int> last(30,0);
  rep1(i,d){
    res+=s[i][t[i]];
    last[t[i]]=i;
    last_list[i]=last;
    int buf=0;
    rep1(j,26){
      buf+=c[j]*(i-last[j]);
    }
    res-=buf;
    //cout<<res<<"\n";
  }
  return res;
}
int change(int nd,int nq,int& res,vector<int>& t,vector<vector<int>>& last_list){
  int flag_t=false;
  int flag_q=false;
  int x=t[nd];
  t[nd]=0;
  res+=s[nd][nq];res-=s[nd][x];
  for(int i=nd;i<=d;++i){
    if(flag_t&&flag_q)break;
    if(t[i]==x||flag_t)flag_t=true;
    else{
      res+=c[x]*(i-last_list[i][x]);
      last_list[i][x]=last_list[i-1][x];
      res-=c[x]*(i-last_list[i][x]);
    }
    if(t[i]==nq||flag_q)flag_q=true;
    else{
      res+=c[nq]*(i-last_list[i][nq]);
      last_list[i][nq]=nd;
      res-=c[nq]*(i-last_list[i][nq]);
    }
  }
  t[nd]=nq;
  return res;
}
vector<int> greedy(int d,vector<vector<int>>& t_koho){
  vector<int> res(d+1,0);
  vector<int> last(30,0);
  rep1(i,d){
    int mx=-inf;
    int mx_ind=0;
    vector<P> kouho(26);
    rep1(j,26){
      int tmp=s[i][j];
      rep1(k,26){
        if(k==j)continue;
        tmp-=c[k]*(i-last[k]);
      }
      if(mx<tmp){
        mx=tmp;
        mx_ind=j;
      }
      kouho[j-1]={tmp,j};
    }
    sort(kouho.begin(),kouho.end());
    reverse(ALL(kouho));
    rep(x,koho){
      t_koho[i][x]=kouho[x].second;
    }
    last[mx_ind]=i;
    res[i]=mx_ind;
  }
  return res;
}
signed main(){
  cin>>d;
  rep1(i,26)cin>>c[i];
  rep1(i,d){
    rep1(j,26)cin>>s[i][j];
  }
  vector<vector<int>> t_koho(d+5,vector<int>(koho+5,0));
  vector<int> t=greedy(d,t_koho);
  vector<vector<int>> last_list(d+1,vector<int>(30,0));
  int res=calc(t,last_list);
  //cout<<res<<"\n";
  int param=1;
  rep(xx,num){
    random_device rand;
    mt19937 mt(rand());
    int dev=koho;
    if(xx>num/2)dev/=2;
    vector<int> nd(param);
    rep(i,param){
      nd[i]=mt()%d;
      if(nd[i]==0)++nd[i];
    }
    vector<int> bq(param);rep(i,param)bq[i]=t[nd[i]];
    int bval=res;
    rep(i,param){
      change(nd[i],t[nd[i]+1],res,t,last_list);
      change(nd[i]+1,bq[i],res,t,last_list);
    }
    int yakinamasi=mt()%100;
    //if(yakinamasi<(20-(xx*30)/num)&&res+res/10000>bval)continue;
    if(bval>res){
      rep(i,param){
        change(nd[i]+1,t[nd[i]],res,t,last_list);
        change(nd[i],bq[i],res,t,last_list);
      }
    }
  }
  rep1(i,d){
    cout<<t[i]<<"\n";
  }
  //cout<<res<<"\n";
  return 0;
}

Measured memory_bytes: 3872
import sys
from collections import deque
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

def main():
    k=int(input().rstrip())
    lunlun=deque([str(i) for i in range(1,10)])
    for _ in range(k-1):
        now=lunlun.popleft()
        last=now[-1]
        if last!="0":
            lunlun.append(now+str(int(last)-1))
        lunlun.append(now+last)
        if last!="9":
            lunlun.append(now+str(int(last)+1))
        
    print(lunlun[0])

if __name__=="__main__":
    main()

Measured memory_bytes: 17004
#include<iostream>
using namespace std;
int e,x,y,MIN,i,j;
int main(){
	while(true){
		MIN=1<<27;
		cin>>e;if(!e){break;}
		for(i=0;i*i*i<=e;i++){
			for(j=0;j*j+i*i*i<=e;j++){
				MIN=min(MIN,i+j+e-(i*i*i+j*j));
			}
		}
		cout<<MIN<<endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main(){
long long a, b, k;
cin >> a >> b >> k;

if(k <= a){
cout << a - k << " " << b <<endl;
}
else if(k <= a+b){
cout << 0 << " " << b - (k-a) <<endl;
}
else{
cout << 0 << " " << 0 <<endl;
}
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main (String[] args)  {
		long[][] comb = new long[51][51];
		for (int i = 1; i <= 50; i++) {
			for (int j = 0; j <= i; j++) {
				if (j == 0 || j == i) {
					comb[i][j] = 1;
				} else {
					comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
				}
			}
		}
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		Arrays.sort(arr);
		long max = arr[n - 1];
		double total = 0;
		long target = arr[n - a];
		for (int i = 0; i < a; i++) {
			total += arr[n - i - 1];
		}
		int count = 0;
		int aCount = 0;
		int bCount = 0;
		int minIdx = 0;
		for (int i = n - 1; i >= 0; i--) {
			if (arr[i] == target) {
				count++;
				if (i >= n - a) {
					aCount++;
				} else if (i >= n - b) {
					bCount++;
				}
			}
		}
		long ans = 0;
		if (target == max) {
			for (int i = 0; i <= bCount; i++) {
				ans += comb[count][aCount + i];
			}
		} else {
			ans = comb[count][aCount];
		}
		System.out.println(java.math.BigDecimal.valueOf(total / a).toPlainString());
		System.out.println(ans);
	}
}


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

using namespace std;

int n, a[1005], b[1005];
long double p, dis[3];

bool obt() {
	if (abs(dis[0]*dis[0] + dis[1]*dis[1] < dis[2]*dis[2])) return 1;
	if (abs(dis[0]*dis[0] + dis[2]*dis[2] < dis[1]*dis[1])) return 1;
	if (abs(dis[2]*dis[2] + dis[1]*dis[1] < dis[0]*dis[0])) return 1;
	return 0;
}

long double act() {
	double coso = ((dis[1] * dis[1]) + (dis[2] * dis[2]) - (dis[0] * dis[0])) / 2 / dis[1] / dis[2];
	double sino = sqrt(1 - coso * coso);
	return (dis[0] / sino);
}

long double circ(int f, int g, int h) {
	dis[0] = sqrt((a[f] - a[g])*(a[f] - a[g]) + (b[f] - b[g])*(b[f] - b[g]));
	dis[1] = sqrt((a[f] - a[h])*(a[f] - a[h]) + (b[f] - b[h])*(b[f] - b[h]));
	dis[2] = sqrt((a[h] - a[g])*(a[h] - a[g]) + (b[h] - b[g])*(b[h] - b[g]));
	if (obt()) return max(dis[0], max(dis[1], dis[2]));
	else return act();
}

int main() {
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i=0; i<n - 2; i++) {
		for (int j=i + 1; j<n - 1; j++) {
			for (int k=j; k<n; k++) {
				p = max(p, circ(i,j,k));
			}
		}
	}
	p /= 2;
	cout << fixed << setprecision(9);
	if (n > 2) cout << p << endl;
	else cout << sqrt((a[1] - a[0])*(a[1] - a[0]) + (b[1] - b[0])*(b[1] - b[0])) / 2 << endl;
}

Measured memory_bytes: 256
#define George_Plover
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define MAXN 3000
#define MAXM 3000000
#define INF 2147483647
using namespace std;
int n,m,tx,ty,tz,T0,T1,T2,T3;
int S,T;
int pre[MAXN],tot=1,to[MAXM],lin[MAXM],cost[MAXM],flow[MAXM],in[MAXN];
LL dis[MAXN];
int bx[MAXN],by[MAXN];
bool vis[MAXN];
queue <int> q;
void add(int x,int y,int v,int f)
{
    tot++;
    lin[tot]=pre[x];
    pre[x]=tot;
    to[tot]=y;
    cost[tot]=v;
    flow[tot]=f;
    
    tot++;
    lin[tot]=pre[y];
    pre[y]=tot;
    to[tot]=x;
    cost[tot]=-v;
    flow[tot]=0;
}
bool SPFA()
{
    for(int i=0;i<MAXN;i++)
    {
        dis[i]=(1ll<<61);
    }
    memset(in,0,sizeof(in));
    dis[S]=0;
    q.push(S);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        vis[u]=0;
        
        for(int i=pre[u];i;i=lin[i])
        {
            int v=to[i];
            if(flow[i]&&dis[v]>dis[u]+cost[i])
            {
                dis[v]=dis[u]+cost[i];
                in[v]=i;
                if(!vis[v])
                {
                    vis[v]=1;
                    q.push(v);
                }
            }
        }
    }
    return dis[T]!=dis[0];
}

LL adjust()
{
    LL ret=2147483647;
    for(int i=T;i!=S;i=to[in[i]^1])
    {
        ret=(ret<flow[in[i]]?ret:flow[in[i]]);
    }
    for(int i=T;i!=S;i=to[in[i]^1])
    {
        flow[in[i]]-=ret;
        flow[in[i]^1]+=ret;
    }
    return ret*dis[T];
}

int main()
{
    scanf("%d",&n);
    S=n+n+2;
    T=S+1;T0=T+1;T1=T0+1;T2=T1+1;T3=T2+1;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d",&tx,&ty,&tz);
        bx[i]=tx;
        by[i]=ty;
        add(S,i,0,tz);
        add(i,T0,tx+ty,INF);
        add(i,T1,-tx+ty,INF);
        add(i,T2,tx-ty,INF);
        add(i,T3,-tx-ty,INF);
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d",&tx,&ty,&tz);
        add(i+n,T,0,tz);
        add(T0,n+i,-tx-ty,INF);
        add(T1,n+i,tx-ty,INF);
        add(T2,n+i,-tx+ty,INF);
        add(T3,n+i,tx+ty,INF);
    }
    
    LL ans=0;
    
    while(SPFA())
    {
        ans+=adjust();
    }
    
    cout<<-ans<<endl;
    return 0;
}


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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
int a[110000];
bool e[33];

signed main() {
    cin>>N;
    for(int i=0;i<N;i++)cin>>a[i];
    int x=0;
    for(int i=0;i<N;i++){
        x^=a[i];
        for(int j=0;j<33;j++){
            if(a[i]%2==1){
                e[j]=true;
                break;
            }
            a[i]/=2;
        }
    }
    bitset<33> xbs(x);
    bool sw=0;
    int ans=0;
    for(int i=32;i>=0;i--){
        if(xbs[i]^sw){
            if(e[i]){
                ans++;
                sw=!sw;
            }else{
                cout<<-1<<endl;
                return 0;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
    int N,D,ans=0;
    cin >> N >> D;
// 一人2D本の木を監視できるので
    if(N%(2*D+1)==0){
        ans = N/(2*D+1);
    }
    else ans = N/(2*D+1)+1;

    cout << ans << endl;

}



Measured memory_bytes: 384
package main

// Solution for https://atcoder.jp/contests/abc174/tasks/abc174_c

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var k int
	con.Scan(&k)
	c, x := 0, 0
	max := 10000000
	for c < max {
		x = x*10 + 7
		x %= k
		c++
		if x == 0 {
			break
		}
	}
	if c == max {
		con.Println(-1)
	} else {
		con.Println(c)
	}
	return nil
}


Measured memory_bytes: 1872
#include <iostream>
#include <cstdlib>

#define MAX 10000

using namespace std;

int main() {
    int n;
    long long C[100001], A[2000001], B[2000001];
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        C[A[i]]++;
    }
    for (int i = 1; i <= MAX; i++) {
        C[i] = C[i] + C[i - 1];
    }
    for (int i = n - 1; i >= 0; i--) {
        B[C[A[i]]] = A[i];
        C[A[i]]--;
    }
    for (int i = 1; i <=n; i++) {
        if (i != 1) cout << " ";
        cout << B[i];
    }
    cout << endl;

    return 0;
}


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

const int MOD = 998244353;

bool p[302][302];

int _pow(int x){
  int v = 1, w = 2;

  while(x > 0){
    if(x & 1) v = 1LL * v * w % MOD;
    w = 1LL * w * w % MOD; x >>= 1;
  }

  return v;
}

int main(){
  int N, M; scanf("%d%d", &N, &M);

  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= M; j++){
      int x; scanf("%d", &x); p[i][j] = x == 1;
    }
  }

  int f = 0;

  for(int i = 1; i <= M; i++){
    int z = 0;

    for(int j = f + 1; j <= N; j++){
      if(p[j][i]){ z = j; break; }
    }

    if(z == 0) continue;

    f++;
    for(int j = 1; j <= M; j++) swap(p[f][j], p[z][j]);

    for(int j = 1; j <= N; j++){
      if(j == f) continue;

      if(p[j][i]){
        for(int k = 1; k <= M; k++) p[j][k] ^= p[f][k];
      }
    }
  }

  int a = _pow(N), b = _pow(N - f), c = _pow(M - 1);
  int ans = 1LL * (a - b < 0 ? a - b + MOD : a - b) * c % MOD;

  printf("%d\n", ans);
  return 0;
}

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

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

    int n,k;
    scanf("%d %d",&n,&k);

    vector<int> p(n);
    for(int i=0;i<n;i++){
        scanf(" %d",&p[i]);
    }

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

    // for(int i=0;i<n;i++){
    //     printf("%d ",p[i]);
    // }

    int sum=0;
    for(int i=0;i<k;i++){
        sum += p[i];
    }

    printf("%d",sum);
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  if (N%10 == 9 || N/10%10 == 9) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  
  return 0;  
}

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

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

    int n;
    cin >> n;
    
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    
    vector<ll> cusum(n);
    cusum[0] = a[0];
    for(int i = 1; i < n; i++){
        cusum[i] = cusum[i - 1] + a[i];
    }
    
    int ans = 1;
    for(int i = n - 2; i >= 0; i--){
        if(cusum[i] * 2 >= a[i + 1]) ans++;
        else break;
    }
    cout << ans << endl;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<char>> a(n, vector<char>(n)), b(m, vector<char>(m));
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cin >> a[i][j];
        }
    }
    for(int i=0; i<m; i++){
        for(int j=0; j<m; j++){
            cin >> b[i][j];
        }
    }

    for(int i=0; i<n-m+1; i++){
        for(int j=0; j<n-m+1; j++){
            bool flag = true;
            for(int k=0; k<m; k++){
                for(int l=0; l<m; l++){
                    if(b[k][l]!=a[i+k][j+l]){
                        flag=false;
                        break;
                    }
                }
                if(!flag){
                    break;
                }
            }
            if(flag){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    vector<int> base(n);
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        vec[i]=a;
        base[i]=b;
    }
    long long c=0;
    for(int i=n-1;i>=0;i--){
        long long k=c+vec[i];
        k%=base[i];
        if(k!=0){
            c += base[i]-k;
        }
    }
    cout<<c<<endl;
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
int MOD=1000000007;
signed main(){
    int n,q;cin>>n>>q;
    string s;cin>>s;
    vector<int> l(q);
    vector<int> r(q);
    rep(i,q)cin>>l[i]>>r[i];
    vector<int> sum(n+1,0);
    for(int i=2;i<=n;i++){
        sum[i]=sum[i-1];
        if(s[i-1]=='C'&&s[i-2]=='A')sum[i]++;
    }
    rep(i,q){
        int res;
        if(l[i]==1){
            res=sum[r[i]];
        }
        else if(s[l[i]-2]=='A'&&s[l[i]-1]=='C')res=sum[r[i]]-sum[l[i]-1]-1;
        else res=sum[r[i]]-sum[l[i]-1];
        cout<<res<<endl;
    }
    //rep1(i,n)cout<<sum[i]<<" ";
    //cout<<endl;
    return 0;
}

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

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

  int n; cin >> n;
  ll ans = 0;

  ll dp[100];
  dp[0] = 2;
  dp[1] = 1;
  for(int i = 2; i <= n; ++i) {
    dp[i] = dp[i-1] + dp[i-2];
  }
  cout << dp[n] << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Bye return 0
#define ll long long

using namespace std;


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

    int cont = 0;

    for (int i=0; i<S.size(); i++)
        if(S[i] != T[i])
            cont++;

    cout<<cont<<endl;

    Bye;
}


Measured memory_bytes: 3852
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>
#include <sstream>
#include <bitset>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
#define MOD ((int)1e9+7)
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

struct Combination {
	const int num=51e4;			//要素数
	const int mod=1e9+7;
	vector<ll> fact,inv,finv; //階乗,逆元,逆元の階乗.
	
	Combination():fact(num),inv(num),finv(num){
		fact[0]=fact[1]=1;
		inv[1]=1;
		finv[0]=finv[1]=1;
		for(int i=2;i<num;++i){
			fact[i]=fact[i-1]*i%mod;
			inv[i]=mod-inv[mod%i]*(mod/i)%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	
	int nCk(int n,int k){
		if(n<k) return 0;
		if(n<0 or k<0) return 0;
		return fact[n]*(finv[k]*finv[n-k]%mod)%mod;
	}
	int big_nCk(int n,int k){ //nが大きいとき
		ll res=1LL;
		for (int i = 0; i < k; i++) {
			res=res*(n-i)%mod;
		}
		res = res*finv[k]%mod;
		return res;
	}
	int nHk(int n,int k){return nCk(n+k-1,n-1);}//重複組み合わせ.
};

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

ll pow_mod(ll n, ll k, ll p) { // n^k(mod p)
	if (k == 0) {
		return 1;
	}
	ll res = pow_mod(n * n % p, k / 2, p);
	if (k & 1) {
		res = res * n % p;
	}
	return res;
}

bool vector_finder(std::vector<int> vec, int number) { // vector 内にnumberがあるかどうか
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance( vec.begin(), itr );
	if (index != vec.size()) { // 発見できたとき
		return true;
	}
	else { // 発見できなかったとき
		return false;
	}
}

int main() {
	int 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: 3640
#include <iostream>
#include <string>

typedef long long ll;
const ll INF = 1e12;

int main(int argc, char* argv[])
{
  ll N;
  std::string S;
  std::cin >> N;
  std::cin >> S;

  ll x   = 0;
  ll ans = 0;
  std::string::iterator it;
  for (it = S.begin(); it != S.end(); it++) {
    x += *it == 'I' ? 1 : -1;
    ans = std::max(ans, x);
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,x,y;
    cin >> a >> b >> c;
    cin >> x >> y;
    
    long long int l,m,n;
    long long int ans;
    
    if(x>=y){
        l = a*x + b*y;
        m = c*2*y + a * (x-y);
        n = c*2*x;
        ans = min({l,m,n});
    }else{
        l = a*x + b*y;
        m = c*2*x + b * (y - x);
        n = c*2*y;
        ans = min({l,m,n});
    }
    cout << ans << endl;
}


Measured memory_bytes: 3620
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 1e5+10
#define mod 1e9 + 7
#define pii pair<int,int>
using namespace std;
const int N = 1e5 + 1;
int n,m,i,j,l,k,x,y,a,b,cnt[3],sum[3];
/***********MAIN**************/
int v[(int)1e5+1][3];
int dp[(int)1e5+1][2][2][2];
int brute(int indx,int a,int b,int c){
	if(indx >= n){
		return 0;
	}
	if(dp[indx][a][b][c] != -1){
		return dp[indx][a][b][c];
	}
	int ans = -1;
	if(a){
		ans = max({ans,brute(indx+1,0,1,0) + v[indx][1],brute(indx+1,0,0,1) + v[indx][2]});
	}
	else if(b){
		ans = max({ans,brute(indx+1,1,0,0) + v[indx][0],brute(indx+1,0,0,1)+ v[indx][2]});
	}
	else if(c){
		ans = max({ans,brute(indx+1,0,1,0)+ v[indx][1],brute(indx+1,1,0,0)+ v[indx][0]});
	}else{
		ans = max({ans,brute(indx+1,1,0,0)+ v[indx][0],brute(indx+1,0,1,0)+ v[indx][1],brute(indx+1,0,0,1)+ v[indx][2]});
	}
	dp[indx][a][b][c] = ans;
	return ans;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>v[i][0]>>v[i][1]>>v[i][2];
	}
	memset(dp,-1,sizeof dp);
	cout<<(brute(0,0,0,0));
    return 0;
}
//.........

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

int main()
{
  int n;
  cin >> n;
  
  int a;
  int max = 0, min = 1001;
  rep(i,n){
    cin >> a;
    if(a > max){
      max = a;
    }
    if(a < min){
      min = a;
    }
  }
  
  cout << max - min << endl;
      
}

Measured memory_bytes: 3536
#pragma GCC optimize("-O3")

#include <bits/stdc++.h>

#define ll long long

using namespace std;


struct RollingHash {
	string text; // text
	int n; // number of characters
	int base1 = 1009;
	int base2 = 1007;
	ll mod1 = (ll)1e9 + 9;
	ll mod2 = (ll)1e9 + 7;
	ll* pow1;
	ll* pow2;
	ll* hash1;
	ll* hash2;
	/* constructor */
	RollingHash(string s) {
		text = s;
		n = text.size();
		hash1 = new ll[n + 1];
		hash2 = new ll[n + 1];
		pow1 = new ll[n + 1];
		pow2 = new ll[n + 1];
		hash1[0] = hash2[0] = 0;
		pow1[0] = pow2[0] = 1;
		for (int i = 0; i < n; ++i) {
			hash1[i + 1] = (hash1[i] + text[i]) * base1 % mod1;
			hash2[i + 1] = (hash2[i] + text[i]) * base2 % mod2;
			pow1[i + 1] = pow1[i] * base1 % mod1;
			pow2[i + 1] = pow2[i] * base2 % mod2;
		}
	}
	/* text[l,l+1,...,r-1]のハッシュ値を計算 */
	pair<ll, ll> get(int l, int r) {
		pair<ll, ll> p;
		p.first = ((hash1[r] - hash1[l] * pow1[r - l] % mod1) + mod1);// % mod1;
		if (p.first >= mod1)p.first -= mod1;
		p.second = ((hash2[r] - hash2[l] * pow2[r - l] % mod2) + mod2);//% mod2;
		if (p.second >= mod2)p.second -= mod2;
		return p;
	}
};


signed main() {
	int n; cin >> n;
	string s; cin >> s;
	RollingHash rh(s);

	int ans = 0;
	for (int l = 0; l < n - 1; ++l) {
		for (int r = l + ans + 1; r < n - ans; ++r) {
			int mx = min(r - l, n - r);
			if (mx <= ans) continue;
			if (rh.get(l, l + mx) == rh.get(r, r + mx)) {
				ans = max(ans, mx);
				continue;
			}
			if (rh.get(l, l + ans) != rh.get(r, r + ans)) {
				continue;
			}
			int mn = ans;
			// mn : ok, mx : ngでにぶたん
			while (mx - mn > 1) {
				int mid = mn + (mx - mn) / 2;
				if (rh.get(l, l + mid) == rh.get(r, r + mid)) {
					mn = mid;
				}
				else {
					mx = mid;
				}
			}
			ans = max(ans, mn);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a;
	cin>>a;
	string s;
	cin>>s;
	int len=a;
	if(a%2){
		cout<<"No"<<endl;
	}
	else{
		int half=a/2;
		int flag=1;
		for(int i=0;i<half;i++){
			if(s[i]!=s[i+half]){
				flag=0;
				break;
			}
		}
		printf("%s",flag?"Yes":"No");
	}
} 

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a) {if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(int a) {if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
void AorB(int a,string b,string c) {if(a){cout<<b<<endl;}else{cout<<c<<endl;}}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    int n,m;
    cin >> n;
    m=n-1;
    Vi ans(n,0),a(m),b(m),c(m);
    vector<vector<Pii>> connect(n);
    REP(i,0,m){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        connect[a[i]].pb(mp(b[i],c[i]));
        connect[b[i]].pb(mp(a[i],c[i]));
    }
    
    REP(i,0,m) if(c[i]%2!=0) goto out;
    REP(i,0,n) cout<<ans[i]<<endl;
    return 0;
    
out:
    queue<Tiii> q;
    q.push(mt(0,-1,0));
    while(!q.empty()){
        int now,past,dnow;
        tie(now,past,dnow)=q.front();
        q.pop();
        if(dnow%2==1) ans[now]=1;
        REP(i,0,connect[now].size()) if(connect[now][i].first!=past) q.push(mt(connect[now][i].first,now,dnow+connect[now][i].second));
    }
    REP(i,0,n) cout<<ans[i]<<endl;
}

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

const int maxN = 1e5; int n, m, k;

int parent[maxN];
int root(int u)
{
  return parent[u] < 0 ? u : parent[u] = root(parent[u]);
}
void merge(int u, int v)
{
  if ((u = root(u)) == (v = root(v))) return;
  if (parent[u] > parent[v]) swap(u, v);
  parent[u] += parent[v];
  parent[v] = u;
}
bool sameSet(int u, int v)
{
  return root(u) == root(v);
}
int setSize(int u)
{
  return -parent[root(u)];
}

set<int> friends[maxN], blocks[maxN];
int ans[maxN];

int unionSize(int u)
{
  int sz = friends[u].size() + blocks[u].size();
  for (int v: blocks[u])
    if (!sameSet(u, v))
      sz --;
  return sz;
}

int main()
{
  while (scanf("%d %d %d", &n, &m, &k) != EOF)
  {
    memset(parent, -1, sizeof(parent));
    for (int i = 0; i < n; i ++)
      friends[i].clear(), blocks[i].clear();

    for (int i = 0; i < m; i ++)
    {
      int u, v; scanf("%d %d", &u, &v); u --, v --;
      friends[u].insert(v), friends[v].insert(u);
      merge(u, v);
    }

    for (int i = 0; i < k; i ++)
    {
      int u, v; scanf("%d %d", &u, &v); u --, v --;
      blocks[u].insert(v), blocks[v].insert(u);
    }

    for (int i = 0; i < n; i ++)
      ans[i] = setSize(i) - unionSize(i) - 1;

    for (int i = 0; i < n; i ++)
      printf("%d%c", ans[i], i < n - 1 ? ' ' : '\n');
  }
  return 0;
}

Measured memory_bytes: 29696
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
ll h ;
ll dfs(ll x)
{
	if(x == 1)  return 1ll ;
	else  return 1ll + 2ll * dfs(x / 2) ;
}
int main()
{
	scanf("%lld" , &h) ;
	printf("%lld\n" , dfs(h)) ;
	return 0 ;
}


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


const int MAX = 200010;
vector<long long> fac(MAX,1),finv(MAX,1),inv(MAX,1);

void init() {
  for(int i = 2;i < MAX;i++) {
    fac.at(i) = fac.at(i-1) * i % MOD;
    inv.at(i) = MOD - inv.at(MOD%i) * (MOD/i) % MOD;
    finv.at(i) = finv.at(i-1) * inv.at(i) % MOD;
  }
}


long long comb(int n,int k) {
    if(n < k || n < 0 || k < 0) return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%MOD)%MOD;
}

int main() {

  int N,K;
  cin >> N >> K;

  vector<long long> A(N);
  for(int i = 0;i < N;i++) cin >> A.at(i);

  sort(A.begin(),A.end());
  init();
  
  long long M = 0,m = 0;
  for(int i = 0;i < N;i++) {
    M += (comb(i,K-1)*A.at(i))%MOD;
    m += (comb(N-i-1,K-1)*A.at(i))%MOD;
    M %= MOD;
    m %= MOD;
  }

  

  cout << (M+MOD-m)%MOD << endl;
}


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

int main(){
  int x,y;
  cin >> x >> y;

  if (x==2 || y==2){
    cout << "No" << endl;
  }
  else{
    int a=0,b=0;

    vector<int> group={4,6,9,11};

    for (int i; i<4; i++){
      if (group.at(i)==x){
        a=1;
      }
      if (group.at(i)==y){
        b=1;
      }
    }
    if (a==b){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 384
import copy
from datetime import datetime

#print(datetime.now())
n,k = map(int ,input().split())
p = [[0] * (2*k) for i in range(2*k)]
ans = 0
for i in range(n):
  x,y,c = input().split()
  x = int(x)
  y = int(y)
  if c == 'B':
    x += k
  p[x%(2*k)][y%(2*k)] += 1
#[print(p[i]) for i in range(2*k)]
#print()
#print(datetime.now())

csum1 = [[0]*(2*k) for i in range(2*k)]
#csum1 = copy.deepcopy(p)
for i in range(2*k):
    for j in range(0, k):
        csum1[i][0] += p[i][j]
    for j in range(1, 2*k):
        csum1[i][j] = csum1[i][j-1] - p[i][j-1] + p[i][(j+k-1)%(2*k)]
#print(datetime.now())
#[print(csum1[i]) for i in range(2*k)]
#print()

csum2 = [[0]*(2*k) for i in range(2*k)]
#csum2 = copy.deepcopy(csum1)
#print(datetime.now())
for j in range(2*k):
    for i in range(0, k):
        csum2[0][j] += csum1[i][j]
    for i in range(1, 2*k):
        csum2[i][j] = csum2[i-1][j] - csum1[i-1][j] + csum1[(i+k-1)%(2*k)][j]

#[print(csum2[i]) for i in range(2*k)]
#print(datetime.now())
for i in range(2*k):
    for j in range(2*k):
        ans = max(ans, csum2[i][j] + csum2[(i+k)%(2*k)][(j+k)%(2*k)])

print(ans)

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

int main(){
    int N,num;
    int aliP=0;int BobP=0;int maxPoint=0;
    
    //入力
	cin>>N;
    vector<int> vec(N);
    for (int i=0; i<N; i++){
        cin >> vec.at(i);
    }
    
    //処理
    //大きい順に並べ替える
    for(int i=0;i<N;i++){
        //i以降で最大をとる
        maxPoint=0;
        num=0;
        for(int j=i;j<N;j++){
            if( maxPoint<vec.at(j) ){
                maxPoint=vec.at(j);
                num=j;
            }
        }
        //入れ替え
        vec.at(num)=vec.at(i);
        vec.at(i)=maxPoint;
    }
    for(int i=0;i<N;i++){
        //cout<<vec.at(i)<<endl;//並びが見れる
    }
    
    //点数を入れる
    for (int i=0; i<N; i++){
        if(i%2==0){
            aliP+=vec.at(i);
        }
        else{
            BobP+=vec.at(i);
        }
    }
    //cout<<aliP<< " "<<BobP<<endl;//両者の特典
    cout<<aliP-BobP<<endl;
}

Measured memory_bytes: 256
///Astalavista Code........~CodeSlayer007
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define pb push_back
#define mp make_pair
#define fe first
#define se second
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl
#define lets_go ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
const int N = 1e6 + 10;
const int IM = 1e15 + 37;
const double PI = 3.1415926535897932384;
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " " ; cout << endl;}
void PVV(vii v) {for (int i = 0 ; i < v.size() ; i++) cout << v[i].fe << " " << v[i].se << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << ' ' ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
inline void PP(int n) { cout << n << " ";}
inline void PP(int n, int m) { cout << n << " " << m << endl;}
inline void PP(int n, int m, int q) {  cout << n << " " << m << " " << q << endl;}
inline void PP(int n, int m, int q, int u) {  cout << n << " " << m << " " << q << " " << u << endl;}
inline void op() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
// <=================================================================================================================================
// <=================================================================================================================================


signed  main() {
   /// op();
    lets_go
    int i, j, x, y, u, l;
    //int t; cin >> t; while (t--)
    {
        i = j = x = y = u = l = 0;


        int n,k;
        cin >> n >> k;
        int a[n + 10];
        for (i = 0; i < n; i++) {
            cin >> x;
            a[i] = x;
        }
        sort(a, a + n);
        for (i = 0; i < k; i++)
            y += a[i];
        PT(y);


        /* */

    }
    return 0;

}


Measured memory_bytes: 3640
#include<iostream>
#include <cstdlib>
#include<list>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
using namespace std;
int main() {
	//cout << 1 / 10 << endl;
	long long n; cin >> n; bool zz = false;
	long long mini=100000000;
	long long hh = sqrt(n) + 1;
	for (long long i =hh; i >=1; i--)
	{
		if (n%i==0) {long long count = 0,zz=0;
		long long d = n / i;
		while (d != 0) {
			//cout << d <<"d"<< endl;
				d = d / 10;
				count++;
			}
			long long z = i;
			while (z != 0) {
			//	cout << z << "s" << endl;
				z =z/10; zz++;
			}//cout << count << endl;
			cout << max(zz, count) << endl; zz = true; break;
		}
		if (zz) { break; }
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 1e5 + 5; 
using namespace std; 

int n, a[N], p[N], ans, res; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	n = read <int> ();
	for(int i = 1; i <= n; i++) p[i] = a[i] = read <int> ();
	for(int i = 1; i < n; i++)
		if(a[i] == i) swap(a[i], a[i + 1]), ans++;
	if(a[n] == n) ans++;
	for(int i = 1; i <= n; i++) a[i] = p[i];
	for(int i = n; i > 1; i--)
		if(a[i] == i) swap(a[i], a[i - 1]), res++;
	if(a[1] == 1) res++; 
	printf("%d\n", min(ans, res)); 
	return 0; 
}


Measured memory_bytes: 4548
#include<bits/stdc++.h>
using namespace std;
#define I_O		ios::sync_with_stdio(false),cin.tie(0)
#define ll		long long
#define ff		first
#define ss		second
#define mod 		1000000007
#define rep(i,n)	for(ll i=1;i<=n;i++)
#define repv(i,a,n)	for(ll i=a;i<=n;i++)
#define pb 		push_back
#define newl		'\n'
#define deb(x)		cout<<x<<" "
int main() 
{  
	I_O;
	char c;	cin>>c;
	if(isupper(c))	cout<<"A";
	else			cout<<"a";
} 


Measured memory_bytes: 3600