akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const int MAX_V = 201000;
class LCA {
public : 
int parent[20][MAX_V];
vector<int>graph[MAX_V];
int depth[MAX_V];
int root;//これを決定しないといけない事に注意。

void add_LCA(int u,int v) {
	graph[u].push_back(v);
	graph[v].push_back(u);
}


void dfsLCA(int v,int p,int d) {
	parent[0][v] = p;
	depth[v]=d;
	for(int i=0; i<graph[v].size(); i++) {
		if(graph[v][i]!=p) dfsLCA(graph[v][i],v,d+1) ;
	}
	
}

void initLCA(int V) {
	dfsLCA(root,-1,0);
	
	for(int k=0; k+1<20; k++) {
		for(int v=0; v<V; v++) {
			if(parent[k][v]<0) parent[k+1][v]=-1;
			else parent[k+1][v] = parent[k][parent[k][v]];
		}
	}
	
}

int solveLCA(int u,int v) {
	int ans = 0;
	if(depth[u]>depth[v]) swap(u,v) ;
	for(int k=0; k<20; k++) {
		if((depth[v]-depth[u])>>k&1) {
			v = parent[k][v];
			ans += (1<<k);
		}
	}
	if(u==v) {
		return ans;
	//	return u;
	}
	for(int k=20-1; k>=0; k--) {
		if(parent[k][u]!=parent[k][v]) {
			u = parent[k][u];
			v = parent[k][v];
			ans += (1<<k) * 2;
		}
	}
	return ans + 2;
//	return parent[0][u];
}

};

	LCA lca;
const int MAXN = 201000;
vector<int> black[MAXN];
vector<int> white[MAXN];
int main() {
	int N, X, Y;
	cin >> N >> X >> Y;
	
	X--;Y--;
	for(int i=0; i<N-1; i++) {
		int p,q;
		cin >> p >> q;
		p--;q--;
		black[p].push_back(q);
		black[q].push_back(p);
	}
	
	for(int i=0; i<N-1; i++) {
		int p,q;
		cin >> p >> q;
		p--;q--;
		white[p].push_back(q);
		white[q].push_back(p);
		lca.add_LCA(p, q);
	}
	lca.root = 0;
	lca.initLCA(N);
	
	vector<int> used(N, 0);
	vector<int> pos(N, -1);
	vector<int> distB(N, 0);
	vector<int> distA(N, 0);
	used[X] = true;
	
	stack<int> sta;
	sta.push(X);
	pos[X] = Y;
	distB[X] = lca.solveLCA(X, Y);
	
	int ans = 0;
	ans = distB[X];
	
	bool good = false;
	distA[X] = 0;
	while(!sta.empty()) {
		int cur = sta.top(); sta.pop();
		for(int i=0; i<black[cur].size(); i++) {
			int u = black[cur][i];
			if(used[u]) continue;
			if(pos[cur] == u) continue;
			
			used[u] = true;
			int prevWhite = pos[cur];
			int nextWhite = -1;
			int minim = N;
			/*
			for(int j=0; j<white[prevWhite].size(); j++) {
				int tmpWhite = white[prevWhite][j];
				int diff = lca.solveLCA(tmpWhite, u);
				if(diff < minim) {
					minim = diff;
					nextWhite = tmpWhite;
				}
				
			}*/
			/*
			pos[u] = nextWhite;
			dist[u] = minim;
			*/
			//cout << u << " " << dist[u] << endl;
			//if(dist[u] >= dist[cur])
//			cout << u << pos[cur] << endl;
			if(lca.solveLCA(cur, u) >= 3)
				good = true;
			
//			cout << u << " " << Y << " " << lca.solveLCA(u,Y) << endl;

			distA[u] = distA[cur] + 1;
			distB[u] = lca.solveLCA(u, Y) - distA[u];
			if(distB[u] > 0) {
				sta.push(u);
				ans = max(ans, lca.solveLCA(u, Y));
			}
			if(distB[u]==0)
				ans = max(ans, lca.solveLCA(u, Y));
		}
	}
	if(good) {
		cout << "-1" << endl;
	}
	else {
		cout << ans * 2 << endl;
	}
	
	
	return 0;
}



Measured memory_bytes: 59008
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s_1,s_2,s_3;
    cin>>s_1>>s_2>>s_3;
    transform(s_1.begin(),s_1.end(),s_1.begin(),::toupper);
    transform(s_2.begin(),s_2.end(),s_2.begin(),::toupper);
    transform(s_3.begin(),s_3.end(),s_3.begin(),::toupper);
    cout<<s_1[0]<<s_2[0]<<s_3[0]<<endl;
}


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

bool is_prime(int num)
{
  bool ret = true;
  for (int i = 2; i * i <= num; i++)
  {
    if (num % i == 0)
    {
      ret = false;
      break;
    }
  }
  return ret;
}

int main()
{
  int n;
  cin >> n;
  int ans = 0;
  int num;
  for (int i = 0; i < n; i++)
  {
    cin >> num;
    if (is_prime(num))
    {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3076
#include <stdio.h>

int abs1(int a, int b)
{
  if(a>=b)
    return a-b;
  else
    return b-a;
}

int sort(int a, int b, int c)
{
  int s;
  s = abs1(a, b);
  s = s + abs1(b, c);
  return s;
}

int main()
{
  int a, b, c;
  int s,min = 300;
  scanf("%d %d %d", &a, &b, &c);
  s = sort(a, b, c);
  if(s<min) min=s;
  s = sort(a, c, b);
  if(s<min) min=s;
  s = sort(b, a, c);
  if(s<min) min=s;
  s = sort(b, c, a);
  if(s<min) min=s;
  s = sort(c, a, b);
  if(s<min) min=s;
  s = sort(c, b, a);
  if(s<min) min=s;
  printf("%d\n", min);
  return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;

class Main {
	static final String YES = "YES";
	static final String NO = "NO";

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		Set<Long> s = new HashSet<>();
		for (int i = 0; i < N; i++) {
			Long a = sc.nextLong();
			if (s.contains(a)) {
				System.out.println(NO);
				return;
			}
			s.add(a);
		}
		System.out.println(YES);
	}
}


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

int main(){
	int n,s;
	string a;
	cin>>n;
	cin>>a;
	cin>>s;
	for(int i=0;i<=a.length();i++){
		if(a[i]!=a[s-1]){
			a[i]='*';
		}
	}
	cout<<a<<"\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int a[15]={0};
 
int main(){
    int n;
    cin >> n;
    int ans = pow(3,n);
    int odd = 1;
    for(int i=0;i<n;++i){
        cin >> a[i];
        if(a[i] % 2 == 0)odd *= 2;
    }
 
    cout << ans - odd << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
    int a[5];

    rep(i,5){
        cin>>a[i];
    }
    int k;
    cin>>k;
    sort(a,a+5);
    if(a[4]-a[0]<=k){
        cout<<"Yay!"<<endl;
    }else{
        cout<<":("<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>
#include<queue>

//const int mod = 1000000007;

int main() {
	int N, M;
	scanf("%d %d", &N, &M);
	std::priority_queue<int> q;
	for (int i = 0; i < N; i++) {
		int a;
		scanf("%d", &a);
		q.push(a);
	}
	for (int i = 0; i < M; i++) {
		int a = q.top();
		q.pop();
		q.push(a / 2);
	}
	long long res = 0;
	for (int i = 0; i < N; i++) {
		res += q.top();
		q.pop();
	}
	printf("%lld", res);
	return 0;
}


Measured memory_bytes: 892
use std::collections::HashSet;
fn main() {
    let n = read::<usize>();
    let v = read_vec::<u32>().into_iter().collect::<HashSet<u32>>();
    if n == v.len() {
        println!("YES");
    } else {
        println!("NO");
    }
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 10036
N = int(input())
List=[int(j) for j in input().split()]
final_ans = 10 ** 10
for i in range(0,N):
    ans=0
    
    while List[i] % 2==0:
        List[i] /=2
        ans +=1

    if final_ans > ans:
        final_ans = ans
print(final_ans)

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

long long N,pre[200010],tmp;
map<long long,long long> bingung;

int main(){
	cin>>N;
	pre[0]=0;
	bingung[0]=1;
	long long total=0;
	for(long long i=0; i<N; i++){
		cin>>tmp;
		pre[i+1]=pre[i]+tmp;
		if(bingung[pre[i+1]]!=0){
			total+=bingung[pre[i+1]];
		}
		bingung[pre[i+1]]++;
	}
	cout<<total<<'\n';
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int MX_N = 1e5+5;

int N;
queue<ii> q;
set<ii> f;
multiset<int> c[MX_N];
int p[MX_N];
int merged = 0;

int findset(int u) { return (p[u] == u) ? u : (p[u] = findset(p[u])); }

void merge(int u, int v) {
    c[u].erase(v);
    c[v].erase(u);
    f.erase({u,v});

    if (SZ(c[u]) > SZ(c[v])) swap(u,v);
    p[u] = v;
    //cout << "MERGE " << u << " to " << v << endl;

    for (int x : c[u]) {
        c[x].erase(u);

        ii e = {v,x};
        if (e.fi > e.sc) swap(e.fi,e.sc);
        //cout<<"UPDATE " << x << " " << u << " to " << e.fi << " " << e.sc << endl;
        if (f.count(e)) q.push(e);
        else {
            c[x].insert(v);
            c[v].insert(x);
            f.insert(e);
        }
    }
    ++merged;
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;
    FOR(i,1,N) p[i] = i;
    FOR(i,1,2*N-2){
        int a,b; cin >> a >> b;
        a = findset(a), b = findset(b);
        assert(a != b);
        if (a > b) swap(a,b);
        if (f.count({a,b})) {
            merge(a,b);
        } else {
            c[a].insert(b);
            c[b].insert(a);
            f.insert({a,b});
        }
    }

    //cout<<SZ(q)<<endl;

    while (!q.empty()){
        ii a = q.front(); q.pop();
        a.fi = findset(a.fi), a.sc = findset(a.sc);
        if (a.fi > a.sc) swap(a.fi,a.sc);
        merge(a.fi,a.sc);
    }

    cout << (merged == N-1 ? "YES" : "NO");
}



Measured memory_bytes: 33536
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static int ENEMY = 0;
    private static int DIFF = 1;
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long D = scan.nextLong();
        long A = scan.nextLong();
        PriorityQueue<Pair> deque = new PriorityQueue<>(new PairComparator());
        for (int i = 0; i < N; i++) {
            deque.add(new Pair(ENEMY, scan.nextLong(), scan.nextLong()));
        }
        long ans = 0;
        long damage = 0;
        while(!deque.isEmpty()) {
            Pair p = deque.poll();
            if (p.type == ENEMY) {
                if (p.H <= damage) {
                    continue;
                }
                long remain = p.H - damage;
                long t = (remain + A - 1) / A;
                ans += t;
                damage += t * A;
                deque.add(new Pair(DIFF, p.X + D * 2, -A*t));
                continue;
            }
            damage += p.H;
        }
        System.out.println(ans);
    }
    class Pair {
        int type;
        long X;
        long H;
        Pair (int type, long X, long H) {
            this.type = type;
            this.X = X;
            this.H = H;
        }
    }
    class PairComparator implements Comparator<Pair> {
        @Override
        public int compare(Pair o1, Pair o2) {
            if (o1.X != o2.X) {
                return Long.compare(o1.X, o2.X);
            }
            if (o1.type != o2.type) {
                return Integer.compare(o1.type, o2.type);
            }
            return Long.compare(o1.H, o2.H);
        }
    }
}


Measured memory_bytes: 124368
import fractions

a, b = map(int, input().split())
gcd = fractions.gcd(a, b)
count = 1
for i in range(2, int(gcd ** 0.5) + 1):
    if gcd % i == 0:
        count += 1
    while gcd % i == 0:
        gcd //= i
if gcd != 1:
    count += 1
print(count)

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<int> a(n);
    ll ans = 0;;
    rep(i, n){
        int a;
        cin >> a;
        ans += a-1;
    } 

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop
import sys
input = sys.stdin.readline

H, W, K = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
c = [[i == '.' for i in input()] for _ in range(H)]

x1, y1, x2, y2 = x1 - 1, y1 - 1, x2 - 1, y2 - 1
INF = 1 << 60
dist = [INF] * (H * W * 2)

def pos(x, y, m) :
  return (x * W + y) * 2 + m
dist[pos(x1, y1, 0)] = dist[pos(x1, y1, 1)] = 0

q = [(0, pos(x1, y1, 0)), (0, pos(x1, y1, 1))]
while q :
  ccost, cpos = heappop(q)
  if ccost > dist[cpos] : continue
  cx = cpos // 2 // W
  cy = cpos // 2 % W
  cmode = cpos % 2
  dir = [
    [(-1, 0), (1, 0)],
    [(0, -1), (0, 1)]
  ]
  for dx, dy in dir[cmode] :
    nx, ny = cx + dx, cy + dy
    ncost = ccost + 1
    if 0 <= nx < H and 0 <= ny < W and c[nx][ny] and ncost < dist[pos(nx, ny, cmode)] :
      heappush(q, (ncost, pos(nx, ny, cmode)))
      dist[pos(nx, ny, cmode)] = ncost
      
  ncost = (ccost + K - 1) // K * K
  if ncost < dist[pos(cx, cy, cmode ^ 1)] :
    dist[pos(cx, cy, cmode ^ 1)] = ncost
    heappush(q, (ncost, pos(cx, cy, cmode ^ 1)))

ans = min(dist[pos(x2, y2, 0)], dist[pos(x2, y2, 1)])
if ans == INF :
  print(-1)
else :
  print((ans + K - 1) // K)

Measured memory_bytes: 145720
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}

signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	
    int n,k;
    cin>>n>>k;
    int A[n]={0};

    for(int i=0;i<k;i++)
    {
        int x;
        cin>>x;
        for(int j=0;j<x;j++)
        {
            int val;
            cin>>val;
            val--;
            A[val]=1;
        }
    }
    int cnt=0;
    for(int i=0;i<n;i++)
    if(!A[i])
    cnt++;

    cout<<cnt;
    

return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,k;
	while(cin>>a>>b>>k){
		for(int i=0;i<k/2;i++){
		if(a&1){
			b+=(a-1)/2;
			a/=2;
		}
		else if(!(a&1)){
			b+=a/2;
			a/=2;
		}
		if(b&1){
			a+=(b-1)/2;
			b/=2;
		} 
		else if(!(b&1)){
			a+=b/2;
			b/=2;
		}	
	}
	if(k%2==1){
		if(a&1){
			b+=(a-1)/2;
			a/=2;
		}
		else if(!(a&1)){
			b+=a/2;
			a/=2;
		}
	}
	cout<<a<<" "<<b<<endl;	
	}
	
} 

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int tag[100000];

vector<vector<int>> g;

void dfs(int t, int to, int from) {
    if(tag[to] != -1) return;
    tag[to] = t;
    for(auto next : g[to]){
        if(next == from) continue;
        dfs(t, next, to);
    }
}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n, m;cin >> n >> m;
    g.resize(n);
    inc(i, 0, n){
        tag[i] = -1;
    }
    inc(i, 0, m){
        int x, y;cin >> x >> y;
        x--;y--;
        int d;cin >> d;
        g[x].pb(y);
        g[y].pb(x);
    }
    inc(i, 0, n){
        if(tag[i] != -1) continue;
        dfs(i, i, -1);
    }
    set<int> st;
    inc(i, 0, n){
        st.insert(tag[i]);
    }
    cout << st.size() << endl;
    return 0;
}


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

int32_t main() {
    
    int n,a,b;
    string s;
    cin >> n >> a >> b >> s;
    
    a=a+b;
    
    int c=0,d=0;
    
    for(int i=0;i<n;i++) {
        if(s[i]=='b' and c<a and d<b) {
        cout << "Yes" << endl;
        c++,d++;
        }
        else if(s[i]=='a' and c<a) {
        cout << "Yes" << endl;     
        c++;
        }
        else
        cout <<"No" << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int nums[3], k;
  std::cin >> nums[0] >> nums[1] >> nums[2] >> k;

  int id = 0;
  for (int j = 1; j < 3; j++)
    if (nums[id] < nums[j]) id = j;

  rep(i, k) { nums[id] *= 2; }

  int cnt = 0;
  rep(i, 3) cnt += nums[i];

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

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    long mod = 2019;
    int[] child,color,count;
    long[] res;
    ArrayList<Integer>[] tree;
    public static void main(String[] args) throws IOException {
        Main main = new Main();
//        out.println(main.solve());
        main.solve();
        out.flush();
    }
    long solve(){
        int n = sc.nextInt(), m = sc.nextInt(), S = sc.nextInt();
        ArrayList<Edge>[] tree = new ArrayList[n];
        for(int i=0;i<n;i++) tree[i] = new ArrayList<>();
        for(int i=0;i<m;i++){
            int u = sc.nextInt()-1, v = sc.nextInt()-1;
            int fee = sc.nextInt();
            long time = sc.nextLong();
            tree[u].add(new Edge(v,fee,time));
            tree[v].add(new Edge(u,fee,time));
        }
        int[] c = new int[n], d= new int[n];
        for(int i=0;i<n;i++){
            c[i] = sc.nextInt(); d[i] = sc.nextInt();
        }
        int s_max = 50*n;
        long[][] dp = new long[n][s_max+1];
        long inf = Long.MAX_VALUE/10;
        for(int i=0;i<n;i++) Arrays.fill(dp[i],inf);
        S = Math.min(S,s_max);
        dp[0][S] = 0;
        PriorityQueue<State> pq = new PriorityQueue<>(5000, Comparator.comparingLong(ele->ele.res));
        pq.add(new State(0,S,0));
        while(pq.size()>0){
            State cur = pq.poll();
            if(dp[cur.pos][cur.coin]<cur.res) continue;
            // first of all, buy one coins here
            int idx = cur.pos;
            if(cur.coin<s_max){
                int target = Math.min(s_max, cur.coin+c[idx]);
                if(dp[idx][target]>cur.res+d[idx]){
                    dp[idx][target] = cur.res+d[idx];
                    pq.add(new State(idx, target, dp[idx][target]));
                }
            }
            // then go to neiboring cities
            for(Edge e:tree[idx]){
                if(e.fee>cur.coin) continue;
                int to = e.to;
                int  left = cur.coin-e.fee;
                if(dp[to][left]<=cur.res+e.time) continue;
                dp[to][left] = cur.res+e.time;
                pq.add(new State(to, left, dp[to][left]));
            }
        }
        for(int t=1;t<n;t++){
            long ans = inf;
            for(int res=0;res<=s_max;res++) ans = Math.min(ans,dp[t][res]);
            out.println(ans);
        }
        return 0;
    }
    class Edge{
        int to,fee;
        long time;
        public Edge(){}
        public Edge(int _to, int _f, long _time){
            to = _to; fee = _f; time = _time;
        }
    }
    class State{
        int pos; int coin; long res;
        public State(int p, int c, long r){
            pos = p; coin = c; res= r;
        }
    }

}



Measured memory_bytes: 53976
#include <stdio.h>
int main(void) {
  char S[5];
  scanf("%s", S);
  switch (S[1]) {
    case 'B':
      printf("%s\n", "ARC");
      break;
    case 'R':
      printf("%s\n", "ABC");
      break;
  }
  return 0;
}

Measured memory_bytes: 1620
N = int(raw_input())
a = map(int, raw_input().strip().split())

identity = sum(xrange(1, N+1))
sum_a = sum(a)
if sum_a % identity:
    print 'NO'
else:
    lv = sum_a / identity
    if a[0]-a[-1] > lv:
        print "NO"
    else:
        for i in xrange(len(a)-1):
            d = a[i+1]-a[i]
            if d > lv or (d-lv) % N:
                print 'NO'
                break
        else:
            print 'YES'

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

int n;
map<char, int> ans;

map<char, int> shape(string s) {
  map<char, int> mp;
  for (auto e: s) {
    mp[e] += 1;
  }
  return mp;
}

void merge(map<char, int> inpt) {
  map<char, int> newans;
  for (auto &e: inpt) {
    if (ans.find(e.first) != ans.end()) {
      newans[e.first] = min(ans[e.first], e.second);
    }
  }
  ans = newans;
}

int main(void) {
    // Here your code !
    scanf("%d\n", &n);
    string fst;
    cin >> fst;
    ans = shape(fst);
    for (int i = 2; i <= n; ++i) {
      string tmp;
      cin >> tmp;
      auto inpt = shape(tmp);
      merge(inpt);
    }

    for (auto &e: ans) {
      for (int i = 0; i < e.second; ++i) {
        printf("%c", e.first);
      }
    }

    printf("\n");

    return 0;
}


Measured memory_bytes: 256
n = int(input())
ans = 0
for i in range(1,n + 1):
  if i % 2 == 0:
    continue
  cnt = 0
  for j in range(1,i + 1):
    if i % j == 0:
      cnt += 1
  if cnt == 8:
    ans += 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}

int main(){
	ll n;
	cin >> n;
	ll min_move = n;
	ll ans;
	for(int i = 1; i <= sqrt(n); i++){
		if(n%i == 0){
			min_move = min(min_move, i + n/i);
			if(i == 1) ans = min_move - 1;
			else ans = min_move - 2;
		}
	}
	cout << ans << endl;
}



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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int dp[50];

int main(){
  int n;cin>>n;
  dp[0]=1;
  dp[1]=1;
  rep1(i, n){
    dp[i+1] = dp[i-1]+dp[i];
  }

  cout<<dp[n]<<endl;

  return 0;
}



Measured memory_bytes: 3104
/* ***************************************
Author        :Scau.ion
Created Time  :2017/03/18 20:11:01 UTC+8
File Name     :ion.cpp
*************************************** */

#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

int main()
{
    IOS;
    int n;
    cin>>n;
    int sq=sqrt(n);
    while (sq*(sq+1)/2<n) ++sq;
    cout<<sq<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#define r(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;

int main(void){
  ll a, b;
  ll n;
  string ans;
  cin >> n;
  ll t=n;
  ll tmp=1;
  int i;
  for(i=(ll)sqrt(n); i>=1; i--){
    if(n%i==0){
      tmp=i;
      b=n/i;
      a=max(b, tmp);
      ans = to_string(a);
      cout << ans.size() << endl;return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
N,Q = map(int, input().split())
to = [[] for _ in range(N+1)]
ans = [0]*N

for _ in range(N-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

for _ in range(Q):
    pa, x = map(int, input().split())
    pa -= 1
    ans[pa] += x

q = [(0, -1)]
while(q):
    v, p = q.pop()
    for nv in to[v]:
        if nv == p: continue
        ans[nv] += ans[v]
        q.append((nv, v))

print(*ans)

Measured memory_bytes: 109440
import java.util.Scanner;

public class Main {
	static long[] b;
	static long[][] dp;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		b = new long[n + 1];
		for (int i = 1; i <= n; i++) {
			b[i] = b[i - 1] + a[i];
		}

		dp = new long[n + 1][n + 1];
		System.out.println(dfs(1, n));
	}

	static long dfs(int l, int r) {
		if (dp[l][r] > 0 || l == r) {
			return dp[l][r];
		}

		long ret = Long.MAX_VALUE;
		for (int i = l; i < r; i++) {
			long val = dfs(l, i) + dfs(i + 1, r) + b[r] - b[l - 1];
			ret = Math.min(ret, val);
		}
		return dp[l][r] = ret;
	}
}


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

const int INF=0x3f3f3f3f;

int v[5000],h[5000];
int t[5000],s[5000];
int dp[5000][5000];

int main(){
	int n,m;cin>>n>>m;
	rep(i,n){
		scanf("%d%d",&v[i],&h[i]);
	}
	rep(i,m){
		scanf("%d%d",&t[i],&s[i]);
	}
	rep(i,m+1)rep(j,n+1)dp[i][j]=-INF;
	dp[0][0]=0;
	rep(i,m){
		int sum=0;
		for(int j=1;j<=n;j++){
			sum+=v[j-1];
			if(sum>t[i])break;
			dp[i+1][j]=max(dp[i+1][j-1]+h[j-1]+(j>=2?abs(h[j-1]-h[j-2]):0),dp[i][j-1]+h[j-1]);
		}
		for(int j=0;j<=n;j++){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			if(dp[i+1][j]<s[i])dp[i+1][j]=-INF;
		}
	}
	int sum=0;
	for(int j=0;j<=n;j++){
		if(dp[m][j]>0){
			cout<<t[m-1]-sum<<endl;
			return 0;
		}
		sum+=v[j];
	}
	puts("-1");
}


Measured memory_bytes: 18980
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n1 = 0;
		int n0 = 0;
		String s = sc.next();
		char a[] = new char[s.length() + 1];
		for (int i = 0; i <= s.length() - 1; i++) {
			a[i + 1] = s.charAt(i);
			if (a[i + 1] == '1') {
				n1++;
			}
		}
n0=s.length()-n1;

int an,mi;

if((n0-n1)>0){
	mi=n0-n1;
}else{
	mi=n0-n1;
	mi=0-mi;
}
an=s.length()-mi;
System.out.println(an);
	}
}

Measured memory_bytes: 26580
fn main() {
  proconio::input! {a:u8,mut b:u8,mut c:u8,k:u8}
  for _ in 0..k {
    if a>=b {
      b*=2;
    } else if b>=c {
      c*=2;
    } else {
      break;
    }
  }
  println!("{}",if a<b && b<c {"Yes"} else {"No"});
}

Measured memory_bytes: 2124
import java.util.*;
public class Main {
	public static void main(String[] args){
    //データ取り込み
		Scanner sc = new Scanner(System.in);
		//String S = sc.next();
    //int B = sc.nextInt();
    //System.out.println();
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(A%2==1 && B%2==1){
				System.out.println("Odd");
		}else{
			System.out.println("Even");
		}
		
	}
}

Measured memory_bytes: 22996
n = int(input())
b = list(map(int, input().split()))
s = b[0]
for i in range(n-1):
    if i == n-2:
        s += b[i]
        break
    if b[i]<b[i+1]:
        s += b[i]
    else:
        s += b[i+1]
print(s)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

bool solve(vector<string> W){
  for(int i = 0; i < W.size() - 1; i++){
    if(W.at(i).back() != W.at(i + 1).front()){
      return false;
    }
  }
  for(int i = 0; i < W.size(); i++){
    for(int j = i + 1; j < W.size(); j++){
      if(W.at(i) == W.at(j)){
        return false;
      }
    }
  }
  return true;
}

int main(){
 int N;
 cin >> N;
 vector<string> W(N);
 for(int i = 0; i < N; i++){
  cin >> W.at(i);
 }
 if(solve(W)){
  cout << "Yes" << endl;
 } else{
  cout << "No" << endl;
 }
}


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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;

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

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

  int ans = 0;
  int pos = 0;
  while(ans <= N) {
    ans++;
    pos = A[pos]-1;
    if (pos == 1) { cout << ans << endl; return 0; }
  }

  cout << -1 << endl;

  return 0;
}



Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    ll r;
    cin >> r;
    if (r < 1200) {
        cout << "ABC" << endl;
    } else if (r < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n,ans;
signed main(){
	ios_base::sync_with_stdio(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	ans+=1+(n-2)*2;
	for(int i=2;i<n;i++){
		if(i*i<n) ans++;
		int tmp=max(0ll,(n-1)/i-i);
		ans+=tmp*2;
	}
	cout<<ans;
	re 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <unordered_map>
#include <iomanip>

#define DEBUG(x) cout << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<pair<T, T> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	long long n, k;
	cin >> n >> k;

	long long curr = n % k;
	cout << min(curr, abs(curr - k)) << "\n";

	// if (k >= 2 * n) {
	// 	cout << n << "\n";
	// }
	// else if (k < 2 * n && k >= n) {
	// 	cout << k - n << "\n";
	// } else {
	// 	if (n - k >= k) {
	// 		cout << n % k << "\n";
	// 	} else {
	// 		long long curr = n % k;
	// 		cout << min(curr, abs(curr - k)) << "\n";
	// 	}
	// }

	return 0;

}

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

int main(){
  int k, s;
  cin >> k >> s;
  int ans = 0;
  for(int x = 0; x <= k; x++){
    for(int y = 0; y <= k; y++){
      int z = s - x - y;
      if(0 <= z && z <= k){
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
P = 10**4
g1 = [1, 1] # 元テーブル 階乗
g2 = [1, 1] #逆元テーブル 逆元の階乗
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, P + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

#a = cmb(n,r,mod)

print(N - K + 1)

for i in range(2, K + 1):
    ans = cmb(K - 1, i - 1, mod) * cmb(N - K + 1, i, mod) % mod
    print(ans)


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

int main() {
    vector<int> vec(3);
    for (int i = 0; i < 3; i++) {
        cin >> vec[i];
    }
    sort(vec.begin(), vec.end());
    int a, b;
    a = vec[2]-vec[0];
    b = vec[2]-vec[1];
    if (a % 2 == 0 && b % 2 == 0) cout << (a+b)/2 << endl;
    else if (a % 2 != 0 && b % 2 != 0) cout << (a+b)/2 << endl;
    else if (a % 2 == 0 && b % 2 != 0) cout << 1+(a/2)+((b+1)/2) << endl;
    else if (a % 2 != 0 && b % 2 == 0) cout << 1+((a+1)/2)+(b/2) << endl;
}

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

const int maxl=3e5+10;

int n,m,ans,cas,k;
int a[maxl],b[maxl];
char s[maxl];
bool in[maxl]; 
int h1,m1,h2,m2; 

inline void prework()
{
	scanf("%d%d%d%d%d",&h1,&m1,&h2,&m2,&k);
} 

inline void mainwork()
{
	ans=(h2-h1)*60+(m2-m1)-k;
	ans=max(0,ans);
}

inline void print()
{
	printf("%d\n",ans);
}

int main()
{
	int t=1;
	//scanf("%d",&t);
	for(cas=1;cas<=t;cas++)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}

Measured memory_bytes: 3832
#include<bits/stdc++.h>
#define L 1000000000000000000
#define ll long long int
#define ld long double
using namespace std;
int main(void){
	ld a,b;
	cin>>a>>b;
	ld ans=a*b;
	ll ans2=(ll)(ans);
	cout<<ans2;
}


Measured memory_bytes: 3780
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define rsort(x) sort(all(x));reverse(all(x))
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/

int main(){
  int n;
  int a[100005];
  int ans=0;
  cin>>n;
  REP(i,1,n+1)if(i!=0)cin>>a[i];
  REP(i,1,n+1)if(i==a[a[i]])ans++;
  cout<<ans/2<<endl;
  return 0;
}


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

typedef long long int lli;
typedef long double lld;
typedef long long ll;
//Datatype
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define vvlli vector<vector<long long int>>
#define ppi pair<int, int>
#define rppi pair<int, pair<int, int>>
#define lppi pair<pair<int, int>, int>
#define vppi vector<pair<int, int>>
#define sppi stack<pair<int int>>
#define qppi queue<pair<int, int>>
//function
#define f first
#define s second
#define pb(x) push_back(x)
#define mkp(i, j) make_pair(i, j)
#define lmkp(i,j,k) make_pair(make_pair(i,j),k)
#define rmkp(i,j,k) make_pair(i,make_pair(j,k))
//loop
#define loop(i,n) for (i = 0; i < n; ++i)
#define loops(i,k,n) for (i = k; i <= n; ++i)
#define looprev(i,k,n) for (i = k; i >= n; --i)
//Const
#define inf (int)1e9
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
//Print
#define prd(n) printf("%d", n)
#define prl(n) printf("%lld", n)
#define prdn(n) printf("%d\n", n)
#define prln(n) printf("%lld\n", n)
#define prf(n) printf("%f", n)
//Scan
#define scd(n) scanf("%d", &n)
#define scd2(a, b) scanf("%d %d", &a, &b)
#define scd3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scl(n) scanf("%lld", &n)
#define scl2(a, b) scanf("%lld %lld", &a, &b)
#define scl3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define scf(n) scanf("%f", &n)

using namespace std;
class Solution{
  public:
    lli knapsack1(lli w[], lli v[], lli N, lli W){
      lli i, j, res;
      vector<vector<lli>> g(N+1, vector<lli>(W+1, 0));
      loop(i, N+1){
          loop(j, W+1){
              if(i == 0 || j == 0){
                  g[i][j] = 0;
              }
              else if(w[i-1] <= j){
                  g[i][j] = max(g[i-1][j], (v[i-1]+g[i-1][j-w[i-1]]));
              }
              else{
                  g[i][j] = g[i-1][j];
              }
          }

      }
      /*loop(i, N+1){
        loop(j, W+1){
            cout<<g[i][j]<<" ";
        }
        cout<<endl;
      }*/
      res = g[N][W];
      return res;
    }
};
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    Solution s;
    lli i, j, k, N, W;
    cin>>N>>W;
    lli w[N], v[N];
    loop(i, N){
        cin>>w[i]>>v[i];
    }
    lli res = s.knapsack1(w, v, N, W);
    cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 83056
#include<bits/stdc++.h>
#define maxn 100005
#define ll long long 
using namespace std;
ll n, ans, a[maxn];
int main()
{
	scanf("%lld", &n);
	for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
	for (int i = 1; i < n; i++)
	{
		if (!(a[i] & 1)) ans += a[i] / 2;
		else 
		if (a[i+1] == 0) ans += a[i] / 2;
		else ans += (a[i] / 2 + 1), a[i+1]--; 
	}
	if (a[n]) ans += a[n] / 2;
	printf("%lld", ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;
const int MOD=1e9+7;

int n;
int cache[N][2];
vector<int> g[N];

int dfs(int k, int par, int col)
{
	int &ans=cache[k][col];
	if(ans!=-1)
		return ans;
	ans=1;
	for(auto &it:g[k])
	{
		if(it==par)
			continue;
		if(!col)
			ans*=(dfs(it, k, 0) + dfs(it, k, 1));
		else
			ans*=dfs(it, k, 0);
		ans%=MOD;
	}
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin>>n;
	for(int i=1;i<=n-1;i++)
	{
		int u, v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int ans=dfs(1, 1, 0) + dfs(1, 1, 1);
	ans%=MOD;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 14208
n = gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
count = 0
i = 0
s = false
while true
  i = 0
  while i < n
    if arr[i].even?
      arr[i] /= 2
    else
      s = true
      break
    end
    i += 1
  end
  break if s
  count += 1
end
p count

Measured memory_bytes: 1788
def main():
  h,w=map(int,input().split())
  s=input()
  a=b=x=y=s[0]=='#'
  d=[(b,a)]
  d_add=d.append
  for i in range(1,w):
    f=s[i]=='#'
    b+=a^f
    a=f
    d_add((b,a))
  for _ in range(h-1):
    s=input()
    f=s[0]=='#'
    y+=x^f
    b=y
    a=x=f
    p=[(b,a)]
    p_add=p.append
    for i in range(1,w):
      f=s[i]=='#'
      b+=a^f
      c,g=d[i]
      c+=f^g
      if b>c:b=c
      a=f
      p_add((b,a))
    d=p
  print(b+1>>1)
main()

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, x;
  while (cin >> n) {
    cin >> m >> x;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= m; j++) {
        if (j == 0) {
          cin >> c[i];
        } else {
          cin >> a[i][j - 1];
        }
      }
    }
    int best = INT_MAX;
    for (int i = 1, end = (1 << n); i < end; i++) {
      int cur = 0, good = 0;
      vector<int> st(m);
      for (int j = 0; j < n; j++) {
        if (i&(1<<j)) {
          cur += c[j];
          for (int k = 0; k < m; k++) {
            if (st[k] < x && st[k] + a[j][k] >= x) {
              good++;
            }
            st[k] += a[j][k];
          }
        }
      }
      if (good == m) {
        best = min(best, cur);
      }
    }
    cout << (best == INT_MAX ? -1 : best) << endl;
  }
}

Measured memory_bytes: 3648
from collections import deque
 
N = int(input())
As = [[]]
iset = [0]*(N+1)
for _ in range(N):
  As.append(list(map(int, input().split())))

cnt = 0
cset = set([i for i in range(1,N+1)])
while len(cset) > 0:
  cnt += 1
  fset = set()
  nex = set()
  f = 1
  for i in cset:
    if i not in fset:
      vis = As[i][iset[i]]
      if As[vis][iset[vis]] == i and vis not in fset:
        iset[i] += 1
        iset[vis] += 1
        fset.add(i)
        fset.add(vis)
        if iset[i] < N-1:
          nex.add(i)
        if iset[vis] < N-1:
          nex.add(vis)
        f = 0
  cset = nex
  if f == 1:
    print('-1')
    exit()
    
print(cnt)

Measured memory_bytes: 85740
using System;
using System.IO;

class Solve
{
    static void Main(string[] args) {
        var arr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int M = arr[1];
        var L = new int[M];
        var R = new int[M];
        for (int i = 0; i < M; i++) {
            var g = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            L[i] = g[0];
            R[i] = g[1];
        }
        Array.Sort(L);
        Array.Sort(R);
        var lMax = L[^1];
        var rMin = R[0];
        var answer = lMax <= rMin ? rMin - lMax + 1 : 0;
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();
    }
}

Measured memory_bytes: 46852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

vector<pair<char, ll>> RunLengthCompression(const string& s) {
  ll cur = 1;
  ll n = SZ(s);
  vector<pair<char, ll>> run;
  REP(i, n - 1) {
    if (s[i] == s[i + 1]) {
      cur++;
      continue;
    }
    run.push_back(make_pair(s[i], cur));
    cur = 1;
  }
  run.push_back(make_pair(s[n - 1], cur));
  return run;
}

int main() {
  string s;
  cin >> s;

  auto run = RunLengthCompression(s);
  ll m = SZ(run);
  ll ans = 0, i = 0;
  if (m == 1) {
    ans = run[0].second * (run[0].second + 1) / 2;
    cout << ans << endl;
    return 0;
  }
  while (i < m) {
    if (i == m - 1 || i == 0 && run[i].first == '>') {
      ans += run[i].second * (run[i].second + 1) / 2;
      i++;
      continue;
    }

    ll maxi = max(run[i].second, run[i + 1].second);
    ll mini = min(run[i].second, run[i + 1].second);
    ans += maxi * (maxi + 1) / 2 + (mini - 1) * (mini) / 2;
    i += 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6648
<?php

class Solver
{
    private $number_of_elements;
    private $nature_numbers = array();

    public function __construct()
    {
        $lines = array();
        while (1) {
            if (!$line = fgets(STDIN)) break;
            $line = trim($line);
            $lines[] = $line;
        }

        $this->number_of_elements = $lines[0];
        $this->nature_numbers = array_slice($lines, 1);
    }

    public function getAnswer()
    {
        $counter = 0;
        foreach ($this->nature_numbers as $nature_number) {
            $counter += $this->isPrimeNumber($nature_number) ? 1 : 0;
        }
        echo $counter, PHP_EOL;
    }

    public function isPrimeNumber($n)
    {
        if ($n == 2) return true;
        elseif ($n % 2 == 0) return false;

        $sqrt_n = sqrt($n);
        for ($i = 3; $i <= $sqrt_n; $i += 2) {
            if ($n % $i == 0) return false;
        }
        return true;
    }
}

$answer = new Solver;
$answer->getAnswer();


Measured memory_bytes: 12056
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define map map<char,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
const double PI=acos(-1);
using namespace std;

int main( ) {
    ll N;
    cin>>N;
    if(N%1000==0) {
        cout<<"0"<<endl;
        return 0;
    }
    cout<<1000*(N/1000+1)-N<<endl;
    }


Measured memory_bytes: 3524
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int h, w, dp[1010][1010];
string s[1010];

signed main() {
	cin >> h >> w;
	rep(i,h) cin >> s[i];
	dp[0][0] = 1;
	rep(i,h) rep(j,w) {
		if (i!=h-1 && s[i+1][j]=='.') (dp[i+1][j] += dp[i][j]) %= mod;
		if (j!=w-1 && s[i][j+1]=='.') (dp[i][j+1] += dp[i][j]) %= mod;
	}
	cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 5248
num = [x for x in range(1, 14)]
mark = ('S', 'H', 'C', 'D')
cards = {m:num[:] for m in mark}
for i in range(int(input())):
    card = input().split()
    cards[card[0]].remove(int(card[1]))
for m in mark:
    lacks = cards[m]
    for c in lacks:
        print(m + ' ' + str(c))

Measured memory_bytes: 7728