akhauriyash/Code-Regression huggingface dataset:
class UnionFind(object):
    def __init__(self, n):
        self.parent={i:i for i in range(1,n+1)}
        self.size={i:1 for i in range(1,n+1)}
    def find(self, a):
        if self.parent[a]!=a:
            self.parent[a]=self.find(self.parent[a])
        return self.parent[a]
    def getsize(self, a):
        return self.size[self.find(a)]
    def unite(self, a, b):
        a=self.find(a)
        b=self.find(b)
        if a==b:return
        if self.size[a]>self.size[b]:
            self.size[a]+=self.size[b]
            self.parent[b]=a
        else:
            self.size[b]+=self.size[a]
            self.parent[a]=b
    def isunited(self, a, b):
        return self.find(a)==self.find(b)

N, M = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(M)]
ans = []
uft = UnionFind(N)

c = 0
ans.append(N*(N-1)//2)
for a, b in l[1:][::-1]:
    if not uft.isunited(a, b):
        ba, bb = uft.getsize(a), uft.getsize(b)
        pa, pb = ba*(ba-1)//2, bb*(bb-1)//2
        
        uft.unite(a, b)

        bc = uft.getsize(a)
        pc = bc*(bc-1)//2
        c += pc - pa - pb
    ans.append(N*(N-1)//2-c)

for i in ans[::-1]:
    print(i)

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

int n,k,a,b,c;
string s,t;

int main() {
  cin >> a >> b >> c;
  bool ok=a+b+c-max({a,b,c})-min({a,b,c})==c;
  if(ok)
  cout << "Yes" << endl;
  else 
  cout << "No" << endl;
}

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

int main(){
	int n;
	scanf("%d",&n);
	int arr[n];
	int sa[n];
	int i = 0;
	for(i=0;i<n;i++){
		int a, b;
		scanf("%d %d",&a,&b);
		arr[i] = a%b;
		sa[i] = b;
	}
	long long int count= 0;
	long long int sum = 0;
	for(i=n-1;i>=1;i--){
		int x;
		if (arr[i] == 0)
		{
			x = 0;
		}
		else{
			x = sa[i] - arr[i];
		}
		// printf("%d\n", x);
		sum = sum+x;
		count = count + x;
		arr[i-1] = (arr[i-1] + count)%sa[i-1];

		// int j= 0;
		// for(j=0;j<i;j++){
		// 	arr[j] = (arr[j] + x)%sa[j];
		// }
	}
	if (arr[0] != 0)
	{
		sum = sum + (sa[i] - arr[i]);
	}
	
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 1024
// #pragma GCC optimize("Ofast,unroll-all-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define all(v) v.begin(), v.end()
#define len(v) ((int)(v).size())
#define pb push_back
#define kek pop_back
#define pii pair<int, int>
#define mp make_pair
#define int ll

#define debug(x) cout << #x << " = " << x << endl;

const int INF = (is_same<int, ll>::value ? 1e18 + 666 : 1e9 + 666);

// const int MEM_SIZE = 1e8;
// char mem[MEM_SIZE];
// int cur_mem_ptr = 0;

// void* operator new(size_t n) {
//     cur_mem_ptr += n;
//     return mem + cur_mem_ptr - n;
// }

// void operator delete(void*) noexcept {}
// void operator delete(void*, size_t) noexcept {}

template<class t1, class t2>
bool cmin(t1 &a, const t2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class t1, class t2>
bool cmax(t1 &a, const t2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#ifndef LOCAL
void UseFiles(const string &s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
#else
void UseFiles(const string&) {}
#endif

void run();

signed main() {
    // UseFiles("squads");
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
}

void run() {
    string s;
    cin >> s;
    s[1] ^= 'R' ^ 'B';
    cout << s << endl;
}

Measured memory_bytes: 3644
from math import sqrt
from sys import stdin, stdout
out = lambda o: stdout.write("{}\n".format(o))


def solve(a):
    a.sort()
    size = a[-1] + 1

    seive = [1] * size

    seen = set()
    for item in a:
        if item in seen:
            seive[item] = 0
        seen.add(item)

    for item in a:
        for j in range(2 * item, size, item):
            seive[j] = 0

    return sum(map(lambda x: seive[x], a))


if __name__ == "__main__":
    n = int(stdin.buffer.readline())
    a = [int(x) for x in stdin.buffer.readline().split()]
    out(solve(a))

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

const ll INF = 1ll << 60;
ll MOD = 998244353;

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; }

ll f(ll x, int c, int d)
{
    ll res = x;
    res -= x / c;
    res -= x / d;
    res += x / lcm(c, d);
    return res;
}
int main()
{

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = f(b, c, d) - f(a - 1, c, d);
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
P = [int(x) for x in input().split()]

p0 = P[0]
p1 = P[1]

cnt = 0
for i in range(2, n):
    p2 = P[i]
    if p1 != max(p0, p1, p2) and p1 != min(p0, p1, p2):
        cnt += 1 
    p0, p1 = p1, p2

print(cnt)


Measured memory_bytes: 3060
s=input()
mod=10**9+7
a,ab,abc=0,0,0
q=0
for c in s:
  if c=='A':
    a=(a+pow(3,q,mod))%mod
  elif c=='B':
    ab=(a+ab)%mod
  elif c=='C':
    abc=(ab+abc)%mod
  else:
    a,ab,abc=(3*a+pow(3,q,mod))%mod,(3*ab+a)%mod,(3*abc+ab)%mod
    q+=1
print(abc)

Measured memory_bytes: 40944
#include<bits/stdc++.h>
#define ll long long

const int N = 1000010;

struct edge{
	int next, to;
	ll w;
};

edge e[N << 1];
int n, deg[N], first[N], e_cnt = 1;
ll a[N];
ll orz[N];

void addedge(int u, int v){
	e[++ e_cnt] = {first[u], v};
	first[u] = e_cnt;
	e[++ e_cnt] = {first[v], u};
	first[v] = e_cnt;
}

void dfs(int i, int fa){
	for (int j = first[i]; j; j = e[j].next){
		int x = e[j].to;
		++ deg[i];
		if (x != fa){
			dfs(x, i);
		}
	}
}

void solve(int i, int fa){
	for (int j = first[i]; j; j = e[j].next){
		int x = e[j].to;
		if (x == fa){
			continue;
		}
		solve(x, i);
		if (deg[x] > 1){
			e[j].w = e[j ^ 1].w = 2 * a[x] - orz[x];
		}
		else{
			e[j].w = e[j ^ 1].w = a[x] - orz[x];
		}
		if (e[j].w < 0 || e[j].w > a[i] || e[j].w > a[x]){
			printf("NO\n");
			exit(0);
		}
		orz[i] += e[j].w;
	}
}

int main(){
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i){
		scanf("%lld", &a[i]);
	}
	for (int i = 0, u, v; i < n - 1; ++ i){
		scanf("%d%d", &u, &v);
		addedge(u, v);
	}
	if (n == 2){
		return printf(a[1] == a[2] ? "YES\n" : "NO\n"), 0;
	}
	dfs(1, 0);
	for (int i = 1; i <= n; ++ i){
		if (deg[i] > 1){
			solve(i, 0);
			ll sum = 0;
			for (int j = first[i]; j; j = e[j].next){
				sum += e[j].w;
			}
			if (sum != 2 * a[i]){
				return printf("NO\n"), 0;
			}
			break;
		}
	}
	return printf("YES\n"), 0;
}

Measured memory_bytes: 12416
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve();
			Console.Out.Flush();
		}

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve()
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int a = vs[0];
			int b = vs[1];
			int ans = 0;
			if (a > b) {
				ans = a - 1;
			} else {
				ans = a;
			}
			Console.WriteLine(ans);

		}
	}
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, n;
    cin >> x >> n;
    vector<int> dist(102, 0);
    for(int i=0; i<n; i++)
    {
        int p;
        cin >> p;
        dist.at(p) = 1;
    }

    pair<int, int> ans(99999, -1);
    for(int i=0; i<102; i++)
    {
        if(dist.at(i) == 1) continue;
        int dif = abs(x - i);
        ans = min(ans, pair<int, int>(dif, i));
    }
    cout << ans.second << endl;

    return 0;
}

Measured memory_bytes: 3656
def main():
    N, W = map(int, input().split())
    values, weights = [], []
    for i in range(N):
        v, w = map(int, input().split())
        values.append(v)
        weights.append(w)

    INF = 10 ** 11
    MAX_VALUE = 100 * N
    dp = [[INF for i in range(MAX_VALUE + 1)] for j in range(N + 1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(MAX_VALUE + 1):
            if values[i] > j:
                dp[i + 1][j] = dp[i][j]
            else:
                dp[i + 1][j] = min(dp[i][j], dp[i][j - values[i]] + weights[i])

    ans = 0
    for i in range(MAX_VALUE + 1):
        if dp[N][i] <= W:
            ans = i

    print(ans)


main()



Measured memory_bytes: 17568
import numpy as np

LIM = int(10e5)
time = [0] * (LIM + 1)
N, C = list(map(int, input().split(" ")))
schs = []
for _ in range(N):
    s, t, c = list(map(int, input().split(" ")))
    schs.append((s,t,c))
schs.sort(key = lambda x:x[0])

schs.sort(key = lambda x:x[2])

# print(schs)
for i,temp in enumerate(schs):
    s,t,c = temp

    s_p,t_p,c_p = schs[i-1]
    if i != 0 and c_p == c and t_p == s:
        time[t_p + 1] += 1
        time[t + 1] -= 1

    else:
        time[s] += 1
        time[t + 1] -= 1
# print(time[:100])
ruiseki = np.cumsum(time)

# print(ruiseki[:10])x
print(np.max(ruiseki[1:]))

Measured memory_bytes: 50420
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P=pair<int,int>;
int main(){
  string S;
  cin>>S;
  
  int N=S.size();
  string ans="Yes";
  for(int i=0;i<(N-1)/2;i++){
    if(S[i]!=S[N-1-i]){
      ans="No";
      break;
    }
  }
  
  for(int i=0;i<(N-1)/2;i++){
     if(S[i]!=S[(N-1)/2-1-i]){
      ans="No";
      break;
    }
  }
  for(int i=0;i<(N-1)/2;i++){
     if(S[(N+1)/2+i]!=S[N-1-i]){
      ans="No";
      break;
    }
  }
 
  cout<<ans<<endl;

}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		char[] c=ir.next().toCharArray();
		c[3]='8';
		String s="";
		for(int i=0;i<c.length;i++)
			s+=Character.toString(c[i]);
		out.println(s);
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 21204
#include <iostream>
#include <cstdlib>
using namespace std;
string a;
int i,n;
int main()
{
    cin>>a;
    n=a.length();
    if(a[0]==a[n-1])
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int s[1000000];

int main() {
    int n,q,a,v,i,j,maxa,maxv;

    scanf("%d %d",&n,&q);

    for(i=0;i<q;i++){
        scanf("%d %d",&a,&v);
        s[a-1]+=v;
        if(i==0){
            maxa=a;
            maxv=s[a-1];
            printf("%d %d\n",maxa,maxv);
            continue;
        }

        if(v>0){
            if((maxv<s[a-1])||((maxv==s[a-1])&&(maxa>a))){
                maxa=a;
                maxv=s[a-1];
            }
        }else{
            if(maxa==a){
                maxa=n+1;
                maxv=0;
                for(j=0;j<n;j++){
                    if((maxv<s[j])||((maxv==s[j])&&(maxa>a))){
                        maxa=j+1;
                        maxv=s[j];
                    }
                }
            }
        }
        printf("%d %d\n",maxa,maxv);
    }

    return 0;
}

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

using namespace std;

int main(void){
//	int a, b, c, ans;
//	cin >> a >> b >> c;
//	if(a > b){
//		int tmp = a;
//		a = b;
//		b = tmp;
//	}
//	if(b > c){
//		int tmp = b;
//		b = c;
//		c = tmp;
//	}
//	if(a > c){
//		int tmp = c;
//		c = a;
//		a = tmp;
//	}
//	ans =  c-b+b-a;
//	int z = a + b;
//	if(ans > a+b){
//		ans = a+b;
//	}
//	cout << a+b << endl;
	int a[4];
	cin >> a[1] >> a[2] >> a[3];
	for(int i = 1; i <= 3;i++){
		for(int j = i+1; j <= 3; j++){
			if(a[i]>a[j]){
				int tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
	int tmp = a[3];
	cout << a[3]-a[1] << endl; 
} 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

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


Measured memory_bytes: 764
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

ll dp[50][1 << 18];
// i番目まで見て、直前がjで、XYZが出現しない場合の数

ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}

int main() {
    int N, C[3];
    cin >> N >> C[0] >> C[1] >> C[2];
    int sm = C[0] + C[1] + C[2] - 1;
    int mx = 1 << sm;

    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < mx; j++) {
            if (dp[i][j] == 0) continue;

            vector <int> vec;
            int tmp = 1;
            for (int k = 0; k < sm; k++) {
                if (j & (1 << k)) {
                    vec.push_back(tmp);
                    tmp = 1;
                } else {
                    tmp++;
                }
            }

            for (int k = 1; k <= 10; k++) {
                if (k <= C[2]) {
                    int idx = 2;
                    int tmp = C[2] - k;
                    if (tmp == 0) {
                        idx--;
                        tmp = C[idx];
                    }

                    bool ng = false;
                    for (int x : vec) {
                        if (tmp - x > 0) {
                            tmp -= x;
                        } else if (tmp == x) {
                            idx--;
                            if (idx == -1) {
                                ng = true;
                                break;
                            } else {
                                tmp = C[idx];
                            }
                        } else {
                            break;
                        }
                    }

                    if (ng) continue;
                }

                ll nxt = (j * 2 + 1) * pow_mod(2, k-1, mx) % mx;

                dp[i+1][nxt] += dp[i][j];
                dp[i+1][nxt] %= MOD;
            }
        }
    }

    ll ans = pow_mod(10, N, MOD);
    for (int j = 0; j < mx; j++) {
        ans += MOD - dp[N][j];
        ans %= MOD;
    }

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

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

int combination(int n, int r)
{
  if(n>=r){
    if (r == 0 || r == n){
        return (1);
    }
    else if (r == 1){
        return (n);
    }else{
    return (combination(n - 1, r - 1) + combination(n - 1, r));
    }
  }else {
    return(0);
  }
}

int main(){
  int n,m,a,b,d;
  cin >> n;
  cin >> m;
  if(m%2 != 0){
   b=combination(n,2);
   d=combination(m,2);
   a=b+d;
   }else{
   b=combination(n,2);
   d=combination(m,2);
   a=b+d;
  }
  cout << a;
}

Measured memory_bytes: 256
n = int(input())
num = int(n/2)
d_n = list(map(int, input().split()))
d_n.sort()

d_n_min_max = d_n[num-1]
d_n_max_min = d_n[num]

delta = d_n_max_min - d_n_min_max
print(delta)

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
#define INF 1e8
typedef long long ll;
typedef long double ld;

int main() {
    int n, k;
    cin >> n >> k;
    vector<long double> p(n), s(n+1), a(n);
    s[0] = 0;
    rep(i, n){
        long double temp;
        cin >> temp;
        p[i] = (1+temp)/2;
    }
    for(int i = 1; i < n+1; i++){
        s[i] = s[i-1] + p[i-1];
    }
    long double ans = 0;
    for(int i = 0; i < n-k+1; i++){
        ans = ans > s[i+k] - s[i] ? ans : s[i+k] - s[i];
    }
    //rep(i,n) cout << a[i] << endl;
    cout << fixed << setprecision(12);
    cout << ans << endl;
}



Measured memory_bytes: 9600
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
struct UnionFind
{
    vector<int> par,num; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N),num(N,1)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        num[ry]+=num[rx];
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k,l;
    cin>>n>>k>>l;
    UnionFind tree(n);
    rep(i,k){
        ll x,y;
        cin>>x>>y;
        x--;y--;
        tree.unite(x,y);
    }
    UnionFind tree2(n);
    rep(i,l){
        ll x,y;
        cin>>x>>y;
        x--;y--;
        tree2.unite(x,y);
    }
    map<P,ll> mp;
    rep(i,n){
        mp[{tree.root(i),tree2.root(i)}]++;
    }
    rep(i,n){
        cout<<mp[{tree.root(i),tree2.root(i)}]<<endl;
    }
 //   cout<<endl;
}


Measured memory_bytes: 15104
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskC {
        private final static int MOD = (int) (1e9 + 7);

        private long Sum(long a) {
            long sum = 1;
            for (long i = 1; i <= a; i++) {
                sum = sum * i % MOD;
            }
            return sum;
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int m, n;
            m = in.nextInt();
            n = in.nextInt();
            if (Math.abs(n - m) >= 2) {
                out.println(0);
            } else if (Math.abs(n - m) == 1) {
                out.println(Sum(n) * Sum(m) % MOD);
            } else {
                out.println(2 * Sum(n) * Sum(m) % MOD);
            }
        }

    }
}



Measured memory_bytes: 23636
#include <iostream>
using namespace std;
int main()
{
	int num, height, width, a, b, count = 0;
  	cin >> num >> height >> width;
  	for (int i = 0; i < num; i++){
    	cin >> a >> b;
      	if (a >= height && b >= width){
        	count++;
        }
    }
  	cout << count;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n,res=0;
    scanf("%d",&n);
    int a[n+1],b[n+1],c[n];
    for(int i=1;i<n+1;i++)scanf("%d",&a[i]);
    for(int i=1;i<n+1;i++)scanf("%d",&b[i]);
    for(int i=1;i<n;i++)scanf("%d",&c[i]);
    for(int i=1;i<n+1;i++){
        res+=b[i];
    }
    for(int i=1;i<n;i++){
        if(a[i+1]==a[i]+1)res+=c[a[i]];
    }
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long count = 0;
		int price = 1;
		for (int i = 0; i < n; i++) {
		    int x = sc.nextInt();
		    if (x == price) {
		        price++;
		        continue;
		    }
		    int d = (x - 1) / price;
		    count += d;
		    if (price == 1) {
		        price++;
		    }
		}
		System.out.println(count);
	}
}
	


Measured memory_bytes: 49428
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

int main()
{
    long long n;
    std::cin >> n;

    long long sum = 0;
    for (int i = 0; i < n; i++) {
        long long temp;
        std::cin >> temp;

        sum += temp - 1;
    }

    std::cout << sum << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s,m="aaa";
    cin>> s;
    m.at(0)=s.at(0);
    m.at(1)=s.at(1);
    m.at(2)=s.at(2);
    cout << m <<endl;
}


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

int d()
{
    long long a, b, n;
    std::cin >> a >> b >> n;
    
    long long ans = 0;
    long long num = 0;
    if(b <= n)
    {
        num = b - 1;
    }
    else
    {
        num = n;
    }
    
    ans = ((a * num) / b) - (a * (num / b));
    
    std::cout << ans << std::endl;
    
    return 0;
}

int main(int argc, const char * argv[])
{
    d();
    return 0;
}

Measured memory_bytes: 3636
n = gets.to_i
nums = gets.split.map(&:to_i)
count = 0
for c in 0..(n-2) do #01234
  for d in 0..n-c-2 do #0=>0123 1=>012 3=>0
    if nums[d] > nums[d+1]
      nums[d], nums[d+1] = nums[d+1], nums[d]
      count += 1
    end
  end
end
puts nums.join(" ")
puts count


Measured memory_bytes: 8880
// 工夫0の山登り
#include<iostream>
#include<set>
#include<random>
#include<chrono>
using namespace std;
typedef long long ll;

int main(){
    auto start = std::chrono::system_clock::now(); 
    random_device rnd;
    mt19937 mt(rnd());
    uniform_int_distribution<int> randd(1,365);
    uniform_int_distribution<int> randq(1,26);
    
    int d;
    cin >> d;
    int c[27];
    for(int i = 1; i <= 26; i++) cin >> c[i];
    int s[365+1][27];
    for(int i = 1; i <= d; i++){
        for(int j = 1; j <= 26; j++){
            cin >> s[i][j];
        }
    }
    set<int> h[27];
    for(int i = 1; i <= 26; i++) h[i].insert(0), h[i].insert(d+1);
    int t[365+1];
    int last[27] = {};
    ll now = 0;
    for(int i = 1; i <= 365; i++){
        t[i] = randq(mt);
        h[t[i]].insert(i);
        now += s[i][t[i]];
        last[t[i]] = i;
        ll dec = 0;
        for(int j = 1; j <= 26; j++)    dec += c[j]*(i-last[j]);
        now -= dec;
    }

    while(1){
        auto nowt = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now()-start).count();
        if(nowt > 1900)  break;
        int d = randd(mt), q = randq(mt);
        ll diff = 0;
        int bef = t[d];
        diff -= s[d][bef];
        h[bef].erase(d);
        {
            int from = *(--h[bef].lower_bound(d));
            int to = *(h[bef].lower_bound(d));
            diff -= (ll)c[bef]*(to-d)*(d-from);
        }
        t[d] = q;
        diff += s[d][q];
        h[q].insert(d);
        {
            int from = *(--h[q].lower_bound(d));
            int to = *(h[q].upper_bound(d));
            diff += (ll)c[q]*(to-d)*(d-from);
        }
        if(diff < 0){
            int bef = t[d];
            h[bef].erase(d);
            t[d] = q;
            h[q].insert(d);
        }else{
            now += diff;
        }
    }

    for(int i = 1; i <= d; i++) cout << t[i] << endl;
    
    return 0;
}

Measured memory_bytes: 3700
#include<iostream>
#include<vector>
using namespace std;
int main(void){
	int n, d;

	while (1){
		n = 0;
		d = 0;
		cin >> n;
		if (n == 0)
			break;
		vector<int> p(n), d1(n), d2(n), dsum(n);

		for (int i = 0; i < n; i++){
			cin >> p.at(i) >> d1.at(i) >> d2.at(i);
			dsum.at(i) = d1.at(i) + d2.at(i);
		}

		for (int i = 0; i < n;i++){
			if (dsum.at(0) < dsum.at(i)){
				swap(dsum.at(0), dsum.at(i));
				swap(p.at(0), p.at(i));
			}
		}

		cout << p.at(0) << " " << dsum.at(0) << endl;
	}
	return 0;
}


Measured memory_bytes: 3184
#include<stdio.h>
#include<algorithm>
using namespace std;
int c[30];
int from[4][11]={
{0,1,2,18,19,20,14,15,27,28,29},
{0,3,6,15,16,17,20,9,23,26,29},
{6,7,8,9,10,11,17,12,21,22,23},
{2,5,8,12,13,14,11,18,21,24,27}
};
int to[4][11]={
{27,28,29,20,19,18,15,14,0,1,2},
{23,26,29,17,16,15,9,20,0,3,6},
{21,22,23,11,10,9,12,17,6,7,8},
{21,24,27,14,13,12,18,11,2,5,8}
};
int d[30];
int chk(){
	for(int i=1;i<9;i++)if(d[0]!=d[i])return 0;
	for(int i=10;i<12;i++)if(d[9]!=d[i])return 0;
	for(int i=13;i<15;i++)if(d[12]!=d[i])return 0;
	for(int i=16;i<18;i++)if(d[15]!=d[i])return 0;
	for(int i=19;i<21;i++)if(d[18]!=d[i])return 0;
	for(int i=22;i<30;i++)if(d[21]!=d[i])return 0;
	return 1;
}
int main(){
	int a;
	scanf("%d",&a);
	while(a--){
		for(int i=0;i<30;i++){
			scanf("%d",c+i);
			d[i]=c[i];
		}
		int ret=8;
		if(chk()){
			ret=0;
		}
		for(int i=0;i<(1<<14);i++){
			for(int j=0;j<30;j++)d[j]=c[j];
			for(int j=0;j<7;j++){
				int t=(i/(1<<(j*2)))%4;
				for(int k=0;k<11;k++)if(from[t][k]<to[t][k]){
					swap(d[from[t][k]],d[to[t][k]]);
				}
				if(chk()){
					ret=min(ret,j+1);break;
				}
			}
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1024
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 105;
const ll mm = 1e+18;
void solve()
{
    int a,b;
    cin>>a>>b;
    if(a==1) a=15;
    if(b==1) b=15;
    if(a>b) cout<<"Alice";
    else if(a<b) cout<<"Bob";
    else cout<<"Draw";
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

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

using namespace std;

int main() {
    int n, m;
    vector<pair<int, int> > students, points;

    cin >> n >> m;

    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        students.push_back(make_pair(a, b));
    }

    for (int i = 0; i < m; i++) {
        int c, d;
        cin >> c >> d;
        points.push_back(make_pair(c, d));
    }

    for (int i = 0; i < n; i++) {
        int min_num = INT_MAX;
        int min_dis = INT_MAX;
        pair<int, int> spos = students[i];
        for (int j = 0; j < m; j++) {
            pair <int, int> cpos = points[j];
            int cur_dis = abs(spos.first - cpos.first) +
                abs(spos.second - cpos.second);

            if (cur_dis < min_dis) {
                min_dis = cur_dis;
                min_num = j;
            }
        }
        cout << min_num+1 << endl;;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#define int long long
using namespace std;

int b[100];
signed main() {
	int a;
	cin >> a;
	for (int c = 0; c < a; c++) {
		cin >> b[c];
	}
	int S = 1 << 29;
	for (int i = -10000; i <= 10000; i++) {
		int sum = 0;
		for (int j = 0; j < a; j++) {
			sum += (b[j]-i)*(b[j]-i);
		}
		S = min(S, sum);
	}
	cout << S << endl;
}

Measured memory_bytes: 256
n = gets.to_i
a = n.times.map{gets.to_i}
x = Array.new(n, 0)

n.times{|i|
  #idxより大きい
  if a[i] > i
    p -1
    exit
  end
}

ans = 0
for i in 1...n
  if a[i-1]+2 <= a[i] 
    p -1
    exit
  end
  
  if a[i] == a[i-1]+1
    ans += 1
  else
    ans += a[i]
  end
end

p ans


Measured memory_bytes: 5428
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int a, b, c, k;
int ans;

signed main() {
	cin >> a >> b >> c >> k;
	ans += min(a, k);
	k -= min(a, k);
	k -= min(b, k);
	ans -= min(c, k);
	cout << ans << endl;
}

Measured memory_bytes: 3624
S = input()
ACGT_counter = [0]*len(S)

for ii in range(len(S)):
    if ii == 0 and (S[ii] == 'A' or S[ii] == 'C' or S[ii] == 'G' or S[ii] == 'T'):
        ACGT_counter[ii] = 1
    elif S[ii] == 'A' or S[ii] == 'C' or S[ii] == 'G' or S[ii] == 'T':
        ACGT_counter[ii] = ACGT_counter[ii-1] + 1
    else:
        ACGT_counter[ii] = 0
        
print(max(ACGT_counter))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
#define int long long
#define MOD 1000000007
typedef pair<int,int> P;
typedef pair<int,P>PP;

vector<int> g[1000],x(1000);

int rec(int v){
  int INF=111111111;
  vector<vector<int> > dp(2,vector<int>(5010,INF));
  if(g[v].size()==0){
    return 0;
  }
  for(int i=0;i<g[v].size();i++){
    int ii=i%2;
    int ni=(i+1)%2;
    dp[ni]=vector<int>(5010,INF);
    int b=x[g[v][i]];
    int w=rec(g[v][i]);
    if(w==-1)return w;
    if(i==0){
	 if(w<=5000)dp[1][w]=b;
	 if(b<=5000)dp[1][b]=w;
	 continue;
    }
    for(int j=5000;j>=0;j--){
	 if(dp[ii][j]==INF)continue;
	 if(j+w<=5000)dp[ni][j+w]=min(dp[ni][j+w],dp[ii][j]+b);
	 if(j+b<=5000)dp[ni][j+b]=min(dp[ni][j+b],dp[ii][j]+w);
    }
  }
  int w=INF;
  for(int i=x[v];i>=0;i--){
    w=min(w,dp[(g[v].size())%2][i]);
  }
  if(w==INF)return -1;
  return w;
}

signed main(){
  int n;
  cin>>n;
  for(int i=1;i<n;i++){
    int p;
    cin>>p;
    g[--p].pb(i);
  }
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  if(rec(0)==-1)cout<<"IM";
  cout<<"POSSIBLE"<<endl;
  return 0;
}


Measured memory_bytes: 33956
# -*- coding: utf-8 -*-
"""
Created on Tue Jan  1 12:22:07 2019

@author: Yamazaki Kenichi
"""

N = int(input())
a = [int(input()) for i in range(N) ]

for i in range(N):
    if a[i] % 2 == 0:
        ans = 'second'
    else:
        ans = 'first'
        break

print(ans)

Measured memory_bytes: 7072
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

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

  int a, p;
  cin >> a >> p;

  int frag = 3*a+p;
  cout << frag/2 << endl;
    
  
  return 0;
}


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

class Dice{
public:
  vector<int> d;
  void spin(string s){
    if(s == "S"){
      swap(d[0],d[4]);
      swap(d[4],d[1]);
      swap(d[4],d[5]);
    }
    if(s == "E"){
      swap(d[0],d[3]);
      swap(d[2],d[3]);
      swap(d[3],d[5]);
    }
    if(s == "N"){
      swap(d[0],d[1]);
      swap(d[1],d[5]);
      swap(d[4],d[5]);
    }
    if(s == "W"){
      swap(d[0],d[2]);
      swap(d[2],d[5]);
      swap(d[3],d[5]);
    }
  }
};


int main(){

  Dice saikoro;
  vector<int> in(6);
  for(int i=0; i<6; i++){
    cin >> in[i];
  }
  saikoro.d = in;

  map<pair<int,int>,int > cashe; // ????????? --> ???
  
  string s = "EEESEEESEEESSEEEESEEESEEESEEESEEEESEEEEEESEEESEEESEEESSEEESEEESEEESEEEESEEEESEEESEEESEEESSEEESEEESEEES";
  for(int i=0; i<s.size(); i++){
    cashe[make_pair(saikoro.d[0],saikoro.d[1])] = saikoro.d[2];
    //    cout <<saikoro.d[0] << " "  << saikoro.d[1] << " " <<  saikoro.d[2] << endl;
    saikoro.spin(s.substr(i,1));
  }  
  int q; cin >> q;
  for(int i=0; i<q; i++){
    int a,b; cin >> a >> b;
    cout << cashe[make_pair(a,b)] << "\n";
  }

}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>

using namespace std;
// template for creating 2d vector
template<typename T>
vector<vector<T>> make_2d_vector(size_t rows, size_t cols, T init)
{ return vector< vector<T> >(rows, vector<T>(cols, init)); }



#define debug(x) cout << #x << "==" << x << endl;

const int inf = 100000000;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;


  int odds = 0;
  for(int i = 0; i < N; i++) {
    int n;
    cin >> n;
    if( n % 2 == 1 ) { odds++; }
  }

  cout << ( odds % 2 == 0 ? "YES" : "NO") << "\n";

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define per(i,n,a) for(ll i=n-1;i>=a;i--)
#define nl "\n"
#define LLMAX 1e18
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define fastread cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);

const ll MOD=1e9+7;

int main(){
  fastread;

  ll n;
  cin >> n;
  double a[n+1];
  rep(i,0,n)
    cin >> a[i];

  double dp[n+1][n];
  
  rep(i,0,n+1)
    if(i==0)
      dp[i][0]=1-a[0];
    else if(i==1)
      dp[i][0]=a[0];
    else
      dp[i][0]=0;

  rep(i,1,n){
    dp[0][i]=(1-a[i])*(dp[0][i-1]);
  }

  rep(i,1,n+1){
    rep(j,1,n){
      dp[i][j]=a[j]*dp[i-1][j-1]+(1-a[j])*dp[i][j-1];
    }
  }

  // rep(i,0,n+1){
  //   rep(j,0,n)
  //     cout << dp[i][j] << " ";
  //   cout << nl;
  // }

  cout << std::fixed;
  cout << setprecision(10);

  double res=0;
  rep(i,n/2+1,n+1)
    res+=dp[i][n-1];
  cout << res << nl;

  return 0;
}


Measured memory_bytes: 70528
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
    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)));
        String S = scan.next();
        String T = scan.next();
        char[] data = S.toCharArray();
        int length = data.length;
        char[] hint = T. toCharArray();
        int hint_length = hint.length;
        if (length < hint_length) {
            System.out.println("UNRESTORABLE");
            return;
        }
        List<Integer> candidate = new ArrayList<>();
        for (int i = 0; i < length; i++) {
            if (length < i+hint_length) {
                break;
            }
            boolean found = true;
            for (int j = 0; j < hint_length; j++) {
                if (data[i+j] == '?') {
                    continue;
                }
                if (data[i+j] != hint[j]) {
                    found = false;
                    break;
                }
            }
            if (found) {
                candidate.add(i);
            }
        }
        if (candidate.isEmpty()) {
            System.out.println("UNRESTORABLE");
            return;
        }
        candidate.sort(Comparator.reverseOrder());
        int f = candidate.get(0);
        for (int i = 0; i < hint_length; i++) {
            data[f + i] = hint[i];
        }
        for (int i = 0; i < length; i++) {
            if (data[i] == '?') {
                data[i] = 'a';
            }
        }
        System.out.println(data);
    }
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

vector<int> color(100010, -1);
vector<pair<ll, ll> > g[100010];

void dfs(ll now, ll dist) {
  color[now] = dist % 2;

  // 自分の所から移動可能な頂点に移動
  for (int i = 0; i < g[now].size(); i++) {
    pair<ll, ll> res = g[now][i];

    if (color[res.first] == -1) {  // 初めてなら
      dfs(res.first, dist + res.second);
    }
  }
}

// ====================================================================

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

  ll u, v, w;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v >> w;
    u--;
    v--;
    g[u].push_back(make_pair(v, w));
    g[v].push_back(make_pair(u, w));
  }

  dfs(0, 0);

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


Measured memory_bytes: 9856
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int n, m, x[1002], j[1002];

int main() {

	while (true) {
		cin >> n >> m;
		if (n == 0 && m == 0) break;
		REP(i, 1, n + 1)cin >> x[i];
		REP(i, 1, m + 1)cin >> j[i];
		int cnt = 1, ans = 0;
		REP(i, 1, m + 1) {
			cnt += j[i];
			ans++;
			if (cnt >= n)break;
			cnt += x[cnt];
			if (cnt >= n)break;
		}
		cout << ans << endl;
	}
	

	return 0;
}


Measured memory_bytes: 3092
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n,k,ans,a[100005],b[100005],sum[100005],top;
int main(){
	in(n);in(k);
	for(int i=1;i<=n;i++)scanf("%1d",&a[i]);
	for(int i=1;i<=n;i++)b[i]=(a[i]^a[i-1]);
	for(int i=1;i<=n;i++){
		sum[i]=sum[i-1]+b[i];
	}
	int now=0;
	for(int i=1;i<=n;i++){
		now^=b[i];
		int g=upper_bound(sum,sum+n+1,k*2-(!now)+sum[i])-sum;
		ans=max(ans,g-i);
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
  double d;
  while(cin>>d){
    if(d<=48.00)
      cout<<"light fly"<<endl;
    else if(d<=51.00)
      cout<<"fly"<<endl;
    else if(d<=54.00)
      cout<<"bantam"<<endl;
    else if(d<=57.00)
      cout<<"feather"<<endl;
    else if(d<=60.00)
      cout<<"light"<<endl;
    else if(d<=64.00)
      cout<<"light welter"<<endl;
    else if(d<=69.00)
      cout<<"welter"<<endl;
    else if(d<=75.00)
      cout<<"light middle"<<endl;
    else if(d<=81.00)
      cout<<"middle"<<endl;
    else if(d<=91.00)
      cout<<"light heavy"<<endl;
    else
      cout<<"heavy"<<endl;
  }
}

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

int main(){
    long long N;
    vector<long long> A(5);
    cin >> N;
    for(int i = 0; i < 5; ++i) cin >> A[i];
    sort(A.begin(),A.end());
    if( N <= A[0]) cout << 5 << endl;
    else{
        long long s = N / A[0];
        long long r = N % A[0];
        if(r == 0) cout <<  5 + (s - 1) << endl;
        else cout << 5 + s << endl;
    }
}

Measured memory_bytes: 256