akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

ll pow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll func(ll n) {
	if (n <= 0) return 0;

	ll ref = 1;
	ll beki = 0;
	while (true) {
		if (ref*2 > n) break;
		beki++;
		ref *= 2;
	}

	ll ret = 0;
	ref = 0;
	for (ll ii = beki; ii > 0; --ii){
		ll dummy = n;
		if ((n>>ii) & 1){
			ref += pow(2, ii);
			ll num = n - (ref - 1);
			if (num % 2 == 1){
				ret += pow(2, ii);
			}
		}
	}

	//0桁目は別途計算
	ll oneNum = (n+1)/2;
	if (oneNum % 2 == 1){
		ret += 1;
	}

	return ret;
}


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

	ll ans = func(B) ^ func(A-1);
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 4120
#include <bits/stdc++.h>
            #include <ext/pb_ds/assoc_container.hpp>
            #include <ext/pb_ds/tree_policy.hpp>
            using namespace std;
            using namespace __gnu_pbds;
            #define rep(i,a,b) for(ll i =a; i<b;++i)
            #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
            #define nl "\n"
            #define pb push_back
            #define F first
            #define S second
            #define print(a)       for(auto x : a) cout << x << " "; cout << endl
            #define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
            #define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl
            #define mk(x,y)  make_pair(x,y)
            typedef long long int ll;
            const ll N =  1e6+ 5 ;
            const ll mod = 1e9+7;
            const ll inf = 1e18;
            ll   n  , m , a[N]  ,u,v , xors , sum , fact[N] , inv_fact[N] ;

    ll pow_mod_m(ll a , ll n)
    {
        if(!n)
            return 1;
        ll pt =  pow_mod_m(a,n/2);
        pt *= pt , pt %= mod; ;
        if(n&1)
            pt *= a  , pt %= mod;
        return pt;
    }

    ll nPr(ll n, ll r)
    {
        return (fact[n] * inv_fact[n-r])% mod;
    }

    ll nCr(ll n, ll r)
    {
        if(n < r  or n <0 or r < 0)
            return 0;
        return ((fact[n] * inv_fact[n-r])% mod * inv_fact[r]) % mod;
    }

    int main()
    {
         IOS;
         int ts =1;
       ///  cin >> ts ;
         while(ts--)
         {
            fact[0] = 1;
            inv_fact[0] = pow_mod_m(fact[0] , mod-2);
            rep(i, 1, 5e5+1)
            {
                fact[i] =  (fact[i-1] * i) % mod;
                inv_fact[i] = pow_mod_m(fact[i] , mod-2);
            }
            cin >> n >> m;
            ll tot = nPr(m,n) , one = 0  , cur = 1;
            for(int i = 0 ; i <= n; i++)
            {
                one += cur * nCr(n,i) * nPr(m-i ,n-i);
                cur = - cur;
                one += mod;
                one %= mod;
            }
            tot *= one;
            tot %= mod;
            cout << tot << endl;
         }
    }


Measured memory_bytes: 11468
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

constexpr ll INF = 1LL << 60;

struct state {
    int pos; ll cost;
    state() {}
    ~state() {}
    state(int pos, ll cost): pos(pos), cost(cost) {}
    bool operator < (const state& o) const {
        return cost > o.cost;
    }
};

struct edge {
    int to; ll cost;
    edge() {}
    ~edge() {}
    edge(int to, ll cost): to(to), cost(cost) {}
};

vector<ll> shortest_paths(vector<vector<edge>> graph, int start) {
    int V = graph.size();

    priority_queue<state> pq;
    pq.emplace(start, 0);

    vector<ll> res(V, INF);
    res[start] = 0;

    while (!pq.empty()) {
        state st = pq.top(); pq.pop();
        if (st.cost > res[st.pos]) continue;
        for (edge& e : graph[st.pos]) {
            if (st.cost + e.cost < res[e.to]) {
                res[e.to] = st.cost + e.cost;
                pq.emplace(e.to, res[e.to]);
            }
        }
    }

    return res;
}

int N, M, S, T;

vector<vector<edge>> graph1, graph2;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> M >> S >> T; --S; --T;
    graph1.resize(N);
    graph2.resize(N);
    for (int i = 0; i < M; ++i) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        --u; --v;
        graph1[u].emplace_back(v, a);
        graph1[v].emplace_back(u, a);

        graph2[u].emplace_back(v, b);
        graph2[v].emplace_back(u, b);

    }

    auto r1 = shortest_paths(graph1, S);
    auto r2 = shortest_paths(graph2, T);

    vector<ll> ans(N, INF);
    ans[N-1] = r1[N-1] + r2[N-1];
    for (int i = N-2; i >= 0; --i)
        ans[i] = min(ans[i+1], r1[i] + r2[i]);

    for (int i = 0; i < N; ++i)
        cout << (1000000000000000LL - ans[i]) << endl;

    return 0;
}


Measured memory_bytes: 26684
import sys
h,w = map(int,input().split())
A = []
for i in range(h):
    A.append(list(input()))
dx = [1,0,]
dy = [0,1,]
B = [[0,0]]
while B:
    S = B.pop()
    cnt = 0
    if S == [w-1,h-1]:
        A[h-1][w-1] = "."
        for L in A:
            if L.count("#") != 0:
                print("Impossible")
                sys.exit()
        else:
            print("Possible")
            break
    for i in range(2):
        x = S[0] + dx[i]
        y = S[1] + dy[i]
        if 0 <= x <= w-1 and 0 <= y <= h-1 and A[y][x] == "#":
            B.append([x,y])
            cnt += 1
    else:
        if cnt != 1:
            print("Impossible")
            break
        else:
            A[S[1]][S[0]] = "."
        
        
            


Measured memory_bytes: 3064
#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 int long long

signed main(){
    int r; cin >> r;
    cout << 3*r*r << endl;
}

Measured memory_bytes: 256
class Dice(object):
    
    def __init__(self, line):
        self.top = 1
        self.bottom = 6
        self.south = 2
        self.east = 3
        self.west = 4
        self.north = 5
        self.convert = [int(s) for s in line.split()]
    
    def move(self, direction):
        if 'N' == direction:
            self.top, self.north, self.bottom, self.south = self.south, self.top, self.north, self.bottom
        elif 'S' == direction:
            self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top
        elif 'W' == direction:
            self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top
        elif 'E' == direction:
            self.top, self.east, self.bottom, self.west = self.west, self.top, self.east, self.bottom
    
    def rv(self, key):
        index_list = {
            'top' : self.top,
            'bottom' : self.bottom,
            'south' : self.south,
            'east' : self.east,
            'west' : self.west,
            'notrh' : self.north
        }
        return self.convert[index_list[key] - 1]
    
    def search(self, dice):
        
        for direction in 'NNNNWNNNN':
            self.move(direction)
            if self.rv('south') == dice.rv('south'):
                break
        
        if self.rv('south') != dice.rv('south') or self.rv('notrh') != dice.rv('notrh'):
            return 'No'            
        
        for direction in 'WWWW':
            self.move(direction)
            if self.rv('top') == dice.rv('top'):
                break
        
        if self.rv('top') != dice.rv('top'):
            return 'No'
        if self.rv('bottom') != dice.rv('bottom'):
            return 'No'
        if self.rv('east') != dice.rv('east'):
            return 'No'
        if self.rv('notrh') != dice.rv('notrh'):
            return 'No'
        
        return 'Yes'
    
dice = Dice(input())
dice2 = Dice(input())
print(dice.search(dice2))

Measured memory_bytes: 7900
#include<iostream>
#include<algorithm>
#include<queue>

using namespace std;

queue<long long int> q;

int main(void)

{
    long long int n, i, a, total = 0;
    cin>>n;
    long long int ara[n];
    for(i = 0; i < n; i++)cin>>ara[i];
    sort(ara, ara+n, greater<int>());
    q.push(ara[0]);
    for(i = 1; i < n; i++){
        q.push(ara[i]);
        q.push(ara[i]);
        a = q.front();
        total += a;
        q.pop();
    }
    cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 6308
def main():
    S = input()
    n = len(S)
    condA = False
    condB = False
    condC = True
    countC = 0
    for i in range(n):
        if(i == 0 and S[i] == "A"):
            condA = True
        elif(i >= 2 and i <= n-2):
            if(S[i] == "C"):
                countC += 1
        else:
            condC = condC and S[i].islower()
    if(countC == 1):
        condB = True

    if(condA and condB and condC):
        print("AC")
    else:
        print("WA")

            

main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=110000;
const int inf=10000000000000000;
int n,m,v,p;
int a[maxn];
int check(int pos)
{
	int cost=0;
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]<=a[pos]||a[i]>a[pos]+m)
		{
			cost+=m;
			if(a[i]>a[pos]+m) cnt++;
		}
		else cost+=a[pos]+m-a[i];
		
	}
	if(cost>=m*v) return cnt;
	for(int i=n;i>=1;i--)
	{
		if(a[i]<=a[pos]||a[i]>a[pos]+m) continue;
		cost+=a[i]-a[pos];
		cnt++;
		if(cost>=m*v) break;
	}
	return cnt;
}
signed main()
{
	scanf("%lld%lld%lld%lld",&n,&m,&v,&p);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	int l=1,r=n,best=-1;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(check(mid)+1<=p) best=mid,r=mid-1;
		else l=mid+1;
	}
	if(best==-1) printf("0\n");
	else printf("%lld\n",n-best+1);
	return 0;
}

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

int main() {

  int H,N;
  cin >> H >> N;

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

  
  vector<long long> HP(H+10,1LL<<60);
  HP.at(0) = 0;
  for(int i = 1;i < H+10;i++) {
    long long m = HP.at(i);
    for(int j = 0;j < N;j++) {
      if(i <= A.at(j)) m = min(m,B.at(j));
      else m = min(m,B.at(j)+HP.at(i-A.at(j)));
    }
    HP.at(i) = m;
  }

  cout << HP.at(H) << endl;

  
}


Measured memory_bytes: 384
from collections import defaultdict
from bisect import bisect_right
import sys
input=sys.stdin.readline


def solve():
    N, K = map(int, input().split())
    *A, = map(int, input().split())

    dd = defaultdict(list)
    cc = defaultdict(list)

    for i, j in enumerate(A):
        dd[j].append(i)

    pos, loop = 0, 1
    ans = []

    while pos < N:
        num = A[pos]
        pp = bisect_right(dd[num], pos)
        if pp < len(dd[num]):
            pos = dd[num][pp]+1
        else:
            pos = dd[num][0]+1            
            loop += 1
        cc[loop].append(pos)

    pos = cc[K%loop][0] if cc[K%loop] else 0
    while pos < N:
        num = A[pos]
        pp = bisect_right(dd[num], pos)
        if pp < len(dd[num]):
            pos = dd[num][pp]+1
        else:
            ans.append(num)
            pos += 1
    print(*ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 171908
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int flip[10][10];
int f[10][10];
int ans[10][10];
int dx[5]={0,0,0,1,-1};
int dy[5]={0,1,-1,0,0};
int n;
int color(int x,int y)
{
	int res=f[x][y];
	for(int i=0;i<5;i++)
	{
		int nx=x+dx[i],ny=y+dy[i];
		if(nx<0||nx>=10||ny<0||ny>=10)continue;
		res+=flip[nx][ny];
	}
	return res%2;
}
int culc()
{
	for(int i=1;i<10;i++)
	{
		for(int j=0;j<10;j++)
		{
			if(color(i-1,j)==1)flip[i][j]=1;
		}
	}
	for(int i=0;i<10;i++)if(color(9,i)==1)return -1;
	return 1;
}
int main()
{
	scanf("%d",&n);
	for(int s=0;s<n;s++)
	{
		for(int i=0;i<10;i++)
		{
			for(int j=0;j<10;j++)
			{
				cin >> f[i][j];
			}
		}
		for(int i=0;i<(1<<10);i++)
		{
			memset(flip,0,sizeof(flip));
			for(int j=0;j<10;j++)flip[0][j]=(i>>j)&1;
			int num=culc();
			if(num<0)continue;
			else goto end;
		}
		end:;
		for(int i=0;i<10;i++)
		{
			for(int j=0;j<10;j++)
			{
				cout << flip[i][j];
				if(j!=9)cout << ' ';
				else cout << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1240
n, c, k = map(int, input().split())
t = [int(input()) for _ in range(n)]
t = sorted(t, reverse=True)

ti = t.pop()
limit = ti + k
np = 1
ans = 1
while len(t):
    ti = t.pop()
    if np == c or limit < ti:
        limit = ti + k
        ans += 1
        np = 0
    np += 1
print(ans)


Measured memory_bytes: 8280
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		sc.next();
		String s = sc.next();
		sc.next();
		System.out.println("A" +s.charAt(0) + "C");
		sc.close();
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

vector<vector<int> > person(15,vector<int>(15));
int main(){
    int n;
    cin>>n;
    for(int i=0;i<15;i++){
        for(int j=0;j<15;j++){
            person[i][j]=-1;
        }
    }
    for(int i=0;i<n;i++){
        int b;
        cin>>b;
        for(int j=0;j<b;j++){
            int x,y;
            cin>>x>>y;
            x--;
            person[i][x]=y;
        }
    }

    int ans=0;
    for(int i=0;i<(1<<n);i++){
        vector<int> a(n);
        for(int j=0;j<n;j++){
            if(i>>j & 1)a[j]=1;
        }
        bool ok=true;
        for(int j=0;j<n;j++){
            if(a[j]){
                for(int k=0;k<n;k++){
                    if(person[j][k]==-1)continue;
                    if(person[j][k]!=a[k])ok=false;
                }
            }
        }
        if(ok) ans=max(ans,__builtin_popcount(i));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<stdio.h>
   int main(void){
  
       int a,b,menseki,nagasa;
 
       scanf("%d %d",&a,&b);
       if(a>=1 && b<=100){
           menseki = a*b;
           nagasa = a*2 + b*2;
          printf("%d %d\n",menseki,nagasa);
      }
      return 0;
  }

Measured memory_bytes: 596
using System;
class Program
{
    public static void Main()
    {
        char[] s = Console.ReadLine().ToCharArray();
        Array.Sort(s);
        bool f = false;
        for (int i = 0; i < s.Length - 1; i++)
            f = f || s[i] == s[i + 1];
        Console.WriteLine(f ? "no" : "yes");
    }
}

Measured memory_bytes: 11348
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ios>//左右揃え
#include<iomanip>//setwで幅指定

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007LL

long POW(long a, long n) {
    long ret = 1;
    for (; n > 0; n >>= 1, a = a * a % MOD) {
        if (n % 2 == 1) ret = ret * a % MOD;
    }
    return ret;
}

long C(long n, long r) {
    long X = 1, Y = 1;
    rep(i, r) {
        X = X * (n - i) % MOD;
        Y = Y * (i + 1) % MOD;
    }
    return X * POW(Y, MOD - 2) % MOD;
}

int main(void) {
    int n, m;
    cin >> n >> m;
    cout << C((long)n, 2) + C((long)m, 2) << endl;
}

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

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

    string s;
    cin >> s;
    int num = 0;
    for(auto i : s)
    {
        num = (num + i - '0')%9;
    }
    if(num)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
}

Measured memory_bytes: 3784
#include <iostream>
using namespace std;
int main(){
  string a, b;
  cin >> a >> b;
if( a == "H" && b == "H" ){ cout << "H" << endl;}
else if( a == "H" && b == "D"){ cout << "D" << endl;} 
else if( a == "D" && b == "H"){ cout << "D" << endl;} 
else if( a == "D" && b == "D"){ cout << "H" << endl;} 
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int f[3005][3005],l1,l2,p[3005][3005];
char s1[3005],s2[3005];
inline void print(int x,int y)
{
	if(!x&&!y)
		return;
	if(p[x][y]==1)
	{
		print(x-1,y-1);
		printf("%c",s1[x]);
	}
	else if(p[x][y]==3)
		print(x,y-1);
	else
		print(x-1,y);
}
int main()
{
	scanf("%s%s",s1+1,s2+1);
	l1=strlen(s1+1),l2=strlen(s2+1);
	for(int i=1;i<=l1;i++)
		p[i][0]=2;
	for(int j=1;j<=l2;j++)
		p[0][j]=3;
	for(int i=1;i<=l1;i++)
		for(int j=1;j<=l2;j++)
		{
			if(s1[i]==s2[j])
				f[i][j]=f[i-1][j-1]+1,p[i][j]=1;
			if(f[i-1][j]>f[i][j])
				f[i][j]=f[i-1][j],p[i][j]=2;
			if(f[i][j-1]>f[i][j])
				f[i][j]=f[i][j-1],p[i][j]=3;
		}
	print(l1,l2);
}

Measured memory_bytes: 70656
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N,K = mint()
R,S,P = mint()
T = input()
win = [False]*K
ans = 0
score = {'r':P, 's':R, 'p':S}
for i in range(N):
    if win[i] and T[i]==T[i-K]:
        win.append(False)
    else:
        win.append(True)
        ans += score[T[i]]
print(ans)

Measured memory_bytes: 82424
#include<stdio.h>
void init(int[4][13]);
int toSuitInt(char);
char toSuitChar(int);
void showMissing(int[4][13]);
int main(void)
{
  char c;
  int i,n,x;
  int isHere[4][13];
  init(isHere);
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf(" %c %d",&c,&x);
      isHere[toSuitInt(c)][x-1]=1;
    }
  showMissing(isHere);
  return 0;
}
void init(int isHere[4][13])
{
  int i,j;
  for(i=0;i<4;i++)
    for(j=0;j<13;j++)
      isHere[i][j]=0;
}
int toSuitInt(char c)
{
  switch(c)
    {
    case 'S':
      return 0;
    case 'H':
      return 1;
    case 'C':
      return 2;
    case 'D':
      return 3;
    }
  return -1;
}
char toSuitChar(int x)
{
  switch(x)
    {
    case 0:
      return 'S';
    case 1:
      return 'H';
    case 2:
      return 'C';
    case 3:
      return 'D';
    }
  return '\0';
}
void showMissing(int isHere[4][13])
{
  int i,j;
  for(i=0;i<4;i++)
    for(j=0;j<13;j++)
      if(isHere[i][j]==0) printf("%c %d\n",toSuitChar(i),j+1);
}


Measured memory_bytes: 2040
#include<iostream>
#include<vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <limits>
#include <map>
#include <bitset>

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

using namespace std;
using p = pair<int, int>;
using ll = long long;



int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;

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

	return 0;
}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n); i++)
using namespace std;
int main(void){
  int n;
  int mi=1000;
  int ma=0;
  cin >> n;
  vector<int> d(n);
  rep(i,n) {
      cin >> d[i];
      mi = min(mi, d[i]);
      ma = max(ma,d[i]);
  }
  
  int result = 100001000;
  for(int j=mi; j<=ma; j++){
    int ans = 0;
    rep(i,n) {
      ans += (j - d[i])*(j - d[i]);
     }
    result = min(result, ans);
  }
  
  cout << result << endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
 

int main() {
    int D;
    long long G;
    cin >> D >> G;
    int p[D], c[D];
    rep(i,D) cin >> p[i] >> c[i];

    // {0, 1, ..., n-1} の部分集合の全探索
    long long score;
    int num;
    int res = 1e8;
    for (int bit = 0; bit < (1<<D); ++bit) {
        score = 0;
        num = 0;
        for (int i = 0; i < D; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                score += p[i]*(i+1)*100 + c[i];
                num += p[i];
            }
        }
        if (score > G) res = min(res,num);
        else{
            for (int i = D-1; i >= 0; --i){
                if (bit & (1<<i)) continue;
                for (int j = 0; j < p[i]; j++){
                    if (score >= G) break;
                    score += 100*(i+1);
                    num++;
                    }
                }
                res = min(res,num);
                
            }
        }
    cout << res << endl;
}

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

int main() {
    string S, T;
    bool a;
    a = false;
    cin >> S >> T;
    for (int i = 0; i < S.size(); i++){
        if(S.at(i) != T.at(i))a = true;
    }
    if(a) cout << "No" << endl;
    else  cout << "Yes" << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>

using namespace std;


void SolveA()
{
	int a;
	string s;

	cin >> a >> s;

	if (3200 <= a)
		cout << s << endl;
	else
		cout << "red" << endl;
}


/*
void SolveB()
{
	int N;

	cin >> N;

	vector<unsigned long long int> A(N);

	for (int i = 0; i < N; ++i)
		cin >> A[i];

	unsigned long long int denominator = 1; // 分子
	unsigned long long int numerator = A[0]; // 分母

	for (int i = 1; i < N; ++i ) {
		if (numerator == A[i]) {
			denominator += 1;
		}
		else if (numerator < A[i] && A[i] % numerator == 0) {
			denominator += A[i] / numerator;
			numerator = A[i];
		}
		else if (A[i] < numerator && numerator % A[i] == 0) {
			denominator += numerator / A[i];
		}
		else {
			denominator = denominator * A[i] + numerator;
			numerator = numerator * A[i];
		}

		for( int j = 100; 1 < j; --j )
			if (denominator % j == 0 && numerator % j == 0) {
				denominator /= j;
				numerator /= j;
			}

		cout << denominator << " / " << numerator << endl;
	}

	cout << fixed;
	cout << setprecision(6) << (long double)numerator / denominator << endl;
}
/**/


void CorrectSolveB()
{
	int N;

	cin >> N;

	vector<unsigned long long int> A(N);

	for (int i = 0; i < N; ++i)
		cin >> A[i];

	double numerator = 0; // 分母

	for (int i = 0; i < N; ++i)
		numerator += 1.0 / A[i];

	cout << fixed;
	cout << setprecision(6) << 1.0 / numerator << endl;
}


int main()
{
	//SolveA();
	CorrectSolveB();

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
  ll ans=1;
  for(int i=1;i<=n;i++)
       ans*=a;
    return ans;
}

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

 ll n,ans=0,ok=0;
 cin>>n;
 for(int i=0;i<n;i++)
 {
     cin>>A[i];
 }
 sort(A,A+n);
 for(int i=n-1;i>=0;i--)
 {
     if(i==n-1)
     {
         ok++;
        ans+=A[i];
     }
     else
     {
         ans+=A[i];
         ok++;
         if(ok==n-1)
            break;
         ans+=A[i];
         ok++;
         if(ok==n-1)
            break;
     }
     if(ok==n-1)
        break;
 }
 cout<<ans<<endl;
return 0;
}



Measured memory_bytes: 5204
import java.util.Scanner;

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

        for(int i = 1; i <= 5; i++){
            if(sc.nextInt() == 0){
                System.out.println(i);
                return;
            }
        }
    }
}

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class D, class Op> struct SimpleSeg {
    D e;
    Op op;
    int sz, lg;  //(2^lgに拡張後の)サイズ, lg
    V<D> d;

    SimpleSeg(const V<D>& v, D _e, Op _op) : e(_e), op(_op) {
        int n = int(v.size());
        lg = 1;
        while ((1 << lg) < n) lg++;
        sz = 1 << lg;
        d = V<D>(2 * sz, e);
        for (int i = 0; i < n; i++) d[sz + i] = v[i];
        for (int i = sz - 1; i >= 0; i--) {
            update(i);
        }
    }

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }

    void set(int p, D x) {
        p += sz;
        d[p] = x;
        for (int i = 1; i <= lg; i++) update(p >> i);
    }

    D single(int p) { return d[p + sz]; }

    D sum(int a, int b, int l, int r, int k) {
        if (b <= l || r <= a) return e;
        if (a <= l && r <= b) return d[k];
        int mid = (l + r) / 2;
        return op(sum(a, b, l, mid, 2 * k), sum(a, b, mid, r, 2 * k + 1));
    }
    D sum(int a, int b) { return sum(a, b, 0, sz, 1); }
};

template <class D, class Op>
SimpleSeg<D, Op> get_simple_seg(V<D> v, D e, Op op) {
    return SimpleSeg<D, Op>(v, e, op);
}



V<int> lis(V<int> v) {
    int n = int(v.size());
    auto seg = get_simple_seg(V<int>(n, -1), -1, [&](int a, int b) { return max(a, b); });
    V<int> dp;
    for (int d: v) {
        int u = seg.sum(0, d) + 1;
        dp.push_back(u);
        seg.set(d, u);
    }
    return dp;
}


static random_device rd;
static mt19937 gen(rd());
ll rand_int(ll l, ll r) { //[l, r]
    return uniform_int_distribution<ll>(l, r)(gen);
}

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

    int n;
    cin >> n;
    auto seg = get_simple_seg(V<ll>(n, 0), -TEN(18), [&](ll a, ll b) { return max(a, b); });

    V<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i]; h[i]--;
    }
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        seg.set(h[i], seg.sum(0, h[i] + 1) + a);
    }
    cout << seg.sum(0, n) << endl;
    return 0;
}


Measured memory_bytes: 5888
#include <stdio.h>

int Array[500000];
int H;

void maxHeapify(int i){
    int left = 2*(i+1)-1;
    int right = 2*(i+1);
    int largest;
    // select the node which has the maximum value
    if ( left <= H && Array[left] > Array[i])
        largest = left;
    else 
        largest = i;
    if ( right <= H && Array[right] > Array[largest])
        largest = right;

    if ( largest != i ){
        int temp = Array[i];
        Array[i] = Array[largest];
        Array[largest] = temp;
        maxHeapify(largest); // call recursively
    }
}

//void buildMaxHeap(A)
//2    for i = H/2 downto 1
//3        maxHeapify(A, i)

int main(){
    scanf("%d\n",&H);
    for ( int ix = 0 ; ix < H ; ix++){
        if ( ix == H-1) scanf("%d\n",&Array[ix]);
        else scanf("%d ",&Array[ix]);
    }
    for ( int ix = (H/2)-1 ; ix >= 0 ; ix--)
        maxHeapify(ix);
    
    for ( int ix = 0 ; ix < H ; ix++)
        printf(" %d",Array[ix]);
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n; cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    ll sum = a[0];
    ll cnt = 1;
    ll ans = n;
    REP(i,1,n){
        if(a[i] > 2*sum){
            ans -= cnt;
            cnt = 1;
        }else{
            cnt++;
        }
        sum += a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

public static void main(String[] args) {

 Scanner in = new Scanner(System.in);

 String str = in.next();
 if(str.charAt(0) == str.charAt(2)){
	 System.out.println("Yes");
 }
 else{
	 System.out.println("No");
 }
 in.close();
}
}

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

using ll = long long;
static const ll MOD = 1e9 + 7;

// 組合せを素数で割った値を求める
const int MAX = 1000005;
long long inv[MAX];

// テーブルを作る前処理
void COMinit() {
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  map<ll, ll> mp;
  for (int i = 0; i < n; i++) {
    ll now = a.at(i);
    for (int j = 2; j * j <= a.at(i); j++) {
      ll count = 0;
      while (now % j == 0) {
        now /= j;
        count++;
      }
      mp[j] = max(mp[j], count);
    }
    if (now > 1) mp[now] = max<ll>(mp[now], 1);
  }
  
  ll lcm = 1;
  for (auto i : mp) {
    if (i.second > 0) {
      lcm *= pow(i.first, i.second);
      lcm %= MOD;
    }
  }
  
  COMinit();
  
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += lcm * inv[a.at(i)];
    ans %= MOD;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 8832
(def a (read))
(def b (read))
(def c (read))
(def d (read))

(def solve
  (if (<= (Math/abs(- a c)) d)
    (println "Yes")
    (if (and (<= (Math/abs (- a d))d) (<= (Math/abs (- b c)) d))
      (println "Yes")
      (println "No"))))

Measured memory_bytes: 61264
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
#include<map>
#include<set>
#include<utility>
#include<tuple>
using namespace std;
#define ull unsigned long long
#define llong long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()

int main() {
	string s;
	cin >> s;
	int n = 4;
	vector<int>a(n, 0);
	rep(i, n)a[i] = s[i] - '0';
	rep(i, 1 << 3) {
		int ans = a[0];
		rep(j, 3)ans = (i & 1<<j) ? ans - a[j+1] : ans + a[j+1];
		if (ans == 7) {
			string f = "0-0-0-0=7";
			rep(k, 4)f[k * 2] = a[k] + '0';
			rep(k, 3)f[k * 2 + 1] = (i >> k & 1) ? '-' : '+';
			cout << f << endl;
			return 0;
		}
	}
	return 0;
}





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

#define all(v) v.begin(), v.end()
typedef long long ll;

int main() {
    string s; cin >> s;
    ll cnt = 0;
    for(int i = 1; i < s.size(); i++){
        if(s[i - 1] != s[i]) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 512
#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>;

struct UnionFind{
    vector<int> par;

    UnionFind(int n) : par(n, -1){}

    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<set<int>> dame(n);
    UnionFind uf(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--, b--;
        dame[a].insert(b);
        dame[b].insert(a);
        uf.merge(a, b);
    }
    rep(i,k){
        int c, d;
        cin >> c >> d;
        c--, d--;
        if(!uf.issame(c, d)) continue;
        dame[c].insert(d);
        dame[d].insert(c);
    }

    rep(i,n){
        int mem = uf.size(i) - 1;
        mem -= dame[i].size();
        cout << mem << ' ';
    }
}

Measured memory_bytes: 26996
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
void err() {
  cout << -1 << '\n';
  exit(0);
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  string s;
  cin >> s;
  int n = (int) s.size();
  s = '.' + s;
  for (int i = 1; i <= n; i++) {
    if (i == 1 && s[i] == '0') err();
    if (i == n && s[n] == '1') err();
    if (i < n && s[i] != s[n - i]) err();
  }
  int k = n;
  for (int i = n - 1; i >= 1; i--) {
    cout << k << " " << i << '\n';
    if (s[i] == '1') k = i;
  }
  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

bool check1 (vector < ll > &A, ll t) {
    REP(i,A.size()) {
        t -= t % A[i];
    }
    if (t <= 2) return true;
    return false;
}

bool check2 (vector < ll > &A, ll t) {
    REP(i,A.size()) {
        t -= t % A[i];
    }
    if (t >= 2) return true;
    return false;
}

bool check( vector < ll > &A, ll t) {
    REP(i,A.size()) {
        t -= t % A[i];
    }
    if (t != 2) return false;
    return true;
}

int main() {

    int K; cin >> K;
    vector < ll > A(K);
    REP(i,K) cin >> A[i];

    ll low = 0, high = 1e18;
    while (high - low > 1) {
        ll mid = (high + low) / 2;
        if (check1(A, mid)) low = mid;
        else high = mid;
    }

    ll ans_max = low;

    low = 0, high = 1e18;
    while (high - low > 1) {
        ll mid = (high + low) / 2;
        if (check2(A, mid)) high = mid;
        else low = mid;
    }

    ll ans_min = high;

    if (!(check(A,ans_min) && check(A,ans_max))) {
        cout << -1 << endl;
        return 0;
    }

    cout << ans_min << " " << ans_max << endl;


    return 0;
}

Measured memory_bytes: 1024
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

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

        int N = sc.nextInt();
        
        Set<String> set = new HashSet<>();
        for(int i= 0;i<N;i++) {
            set.add(sc.next());
        }
        sc.close();


        System.out.println(set.size());
    }

}


Measured memory_bytes: 77004
#include<algorithm>//everybody dies in their nightmares
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<string>
#include<vector>
#include<sstream>
#include<cmath>
#include<unordered_set>
#include<unordered_map>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const ll mod = 1e18 + 7;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 2e5 + 5;
int t;
int a[N], b[N], c[N];
int main()
{
	int x, y, n, m, k;
	while (cin>>x>>y>>n>>m>>k)
	{
		f(i, 1, n)scanf("%d", &a[i]);
		f(i, 1, m)scanf("%d", &b[i]);
		f(i, 1, k)scanf("%d", &c[i]);
		ll sum = 0;
		sort(a + 1, a + 1 + n, greater<int>());
		sort(b + 1, b + 1 + m, greater<int>());
		sort(c + 1, c + 1 + k, greater<int>());
		vector<int> v;
		f(i, 1, x) {
			sum += a[i];
			v.emplace_back(a[i]);
		}
		f(i, 1, y) {
			sum += b[i];
			v.emplace_back(b[i]);
		}
		sort(v.begin(), v.end());
		f(i, 1, k)
		{
			int j = c[i];
			if (j > *v.begin())
			{
				sum += j - *v.begin();
				v.erase(v.begin());
			}
			else break;
		}
		cout << sum<< endl;
	}
	return 0;
}



Measured memory_bytes: 2552
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

vector<pll> g[N + 1];
ll d[N + 1];

void bfs(ll st, ll n) {
	for(int i = 1; i <= n; i++) d[i] = -1;
	d[st] = 0;
	queue<ll> que;
	que.push(st);
	while(!que.empty()) {
		ll i = que.front();
		que.pop();
		for(auto p : g[i]) {
			if(d[p.first] != -1) continue;
			d[p.first] = d[i] + p.second;
			que.push(p.first);
		}
	}
}

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

	for(int i = 0; i < n - 1; i++) {
		ll u, v, w;
		cin >> u >> v >> w;
		g[u].push_back(pll(v, w));
		g[v].push_back(pll(u, w));
	}
	
	bfs(1, n);
	for(int i = 1; i <= n; i++) {
		if((d[i] - d[1]) % 2 == 0) {
			cout << 0 << endl;
		}
		else {
			cout << 1 << endl;
		}
	}
}


Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
using T3 = tuple<int,int,int>;

struct UnionFind {
  vector<int> p;
  vector<int> r;

  UnionFind(int n=1) {
    init(n);
  }

  void init(int n=1) {
    p.resize(n);
    r.resize(n);
    for(int i=0; i<n; i++)
      p[i]=i, r[i]=1;
  }

  int root(int x) {
    if (p[x] == x)
      return x;
    return p[x] = root(p[x]);
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }

  void merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return;
    if(r[x] < r[y])
      swap(x,y);
    p[y] = x;
    r[y] += r[x];
    return;
  }
};

struct Edge {
    int a,b,ct;

    bool operator<(const Edge& o) const {
      return ct < o.ct;
    }
};

bool cpX(T3 a,T3 b) {
  return get<0>(a) < get<0>(b);
}

bool cpY(T3 a, T3 b) {
  return get<1>(a) < get<1>(b);
}

struct Graph {
  int N;
  vector<Edge> Es;

  int kruskal() {
    UnionFind uf(N);
    sort(Es.begin(), Es.end());
    int m=0,i;

    for(i=0; i<Es.size(); i++) {
      Edge e = Es.at(i);
      if(!uf.issame(e.a, e.b)) {
        m += e.ct;
        uf.merge(e.a, e.b);
      }
    }

    return m;
  }
};

int main() {
    int i;
    Graph G;
    cin >> G.N;
    vector<T3> vt(G.N);

    for(i=0; i<G.N; i++) {
      T3 t;
      cin >> get<0>(t) >> get<1>(t);
      get<2>(t) = i;
      vt.at(i) = t;
    }

    sort(vt.begin(), vt.end(), cpX);

    for(i=0; i<G.N-1; i++) {
      Edge e;
      e.a = get<2>(vt.at(i));
      e.b = get<2>(vt.at(i+1));
      e.ct = get<0>(vt.at(i+1))-get<0>(vt.at(i));
      G.Es.push_back(e);
    }

    sort(vt.begin(), vt.end(), cpY);

    for(i=0; i<G.N-1; i++) {
      Edge e;
      e.a = get<2>(vt.at(i));
      e.b = get<2>(vt.at(i+1));
      e.ct = get<1>(vt.at(i+1))-get<1>(vt.at(i));
      G.Es.push_back(e);
    }

    cout << G.kruskal() << endl;
}

Measured memory_bytes: 6004
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second 
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout); 
	ll n;
	cin>>n;
	string s="";
	while(n>0){
		n--;
		s+=('a'+n%26);
		n/=26;
	}
	reverse(all(s));
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
    int n = ri();
    int a[n];
    INPUT(a);
    int b[n];
    INPUT(b);
    
    int aa[n];
    aa[0] = a[0];
    FROMTO(i,1,n-1) aa[i] = aa[i-1]+a[i];
    
    int bb[n];
    bb[n-1] = b[n-1];
    for (int i = n-2; i >= 0; i--)
        bb[i] = bb[i+1] + b[i];
        
    int res = 0;
    FOR(i,n) {
        res = max(res, aa[i]+bb[i]);
    }
    
    cout << res << endl;
 return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
a,b,c,d = map(int, input().split())

list = [a,b,c]

disAB = abs(list[1] - list[0])
disBC = abs(list[2] - list[1])
disAC = abs(list[2] - list[0])

if disAC <= d:
 print("Yes")
else:
 if disAB <= d and disBC <= d:
  print("Yes")
 else:
  print("No")

Measured memory_bytes: 3060
using System;

namespace _0062
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                int[,] a = new int[10, 10];
                string s = Console.ReadLine();
                if(s==null)
                {
                    break;
                }
                for (int i = 0; i < 10; i++)
                {
                    a[0, i] = int.Parse(s[i].ToString());
                }
                for (int i = 1; i < 10; i++)
                {
                    for (int j = 0; j < 10 - i; j++)
                    {
                        a[i, j] = (a[i - 1, j] + a[i - 1, j + 1]) % 10;
                    }
                }
                Console.WriteLine(a[9, 0]);
            }
        }
    }
}

Measured memory_bytes: 9072
#! usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    h, w = map(int, input().split())
    g = [list(input()) for i in range(h)]

    r = []
    for i in range(h):
        if "#" not in g[i]:
            r.append(i)

    cnt = 0
    for i in r:
        g.pop(i-cnt)
        cnt += 1

    c = []
    for i in range(w):
        for j in range(h-len(r)):
            if g[j][i] == "#":
                break
        else:
            c.append(i)

    for i in range(h-len(r)):
        cnt = 0
        for j in c:
            g[i].pop(j-cnt)
            cnt += 1

    for i in range(h-len(r)):
        print("".join(g[i]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188