akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <memory.h>
using namespace std;

#define eprintf(...) fprintf(stderr, __VA_ARGS__)

const int MOD = 1000 * 1000 * 1000 + 7;

const int N = 1000500;
int pw3[N];

int stup(int n, int m, int k) {
    const int N = 21;
    int D[3][N][N][N];
    memset(D, 0, sizeof(D));
    for (int s = 0; s < 3 * N; s++) {
        for (int x = 0; x <= min(s, N - 1); x++) {
            for (int y = 0; x + y <= s && y <= N - 1; y++) {
                int z = s - x - y;
                if (z < 0 || z > N - 1)
                    continue;
                for (int w = 0; w < 3; w++) {
                    int g[] = {x, y, z};
                    if (g[w] == 0) {
                        if (w == 0)
                            D[w][x][y][z] = pw3[y + z];
                        else
                            D[w][x][y][z] = 0;
                    } else {
                        g[w]--;
                        D[w][x][y][z] = (1ll * D[0][g[0]][g[1]][g[2]] + D[1][g[0]][g[1]][g[2]] + D[2][g[0]][g[1]][g[2]]) % MOD;
                    }
                }
            }
        }
    }
    return D[0][n][m][k];
}

int powmod(int x, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = 1ll * res * x % MOD;
        x = 1ll * x * x % MOD;
        b >>= 1;
    }
    return res;
}

inline int inv(int x) {
    return powmod(x, MOD - 2);
}

int F[N], iF[N];

int C(int x, int y) {
    if (y < 0 || y > x || x < 0)
        return 0;
    return 1ll * F[x] * iF[y] % MOD * iF[x - y] % MOD;
}

int D[N];

int n, m, k;
int get(int x) {
    /*int res = 0;
    for (int i = 0; i <= m; i++) {
        int j = x - i;
        if (j < 0 || j > k)
            continue;
        res += C(x, i);
        if (res >= MOD)
            res -= MOD;
    }
    return res;*/
    if (x == 0)
        D[x] = 1;
    if (D[x] != -1)
        return D[x];
    D[x] = 2ll * D[x - 1] % MOD;
    if (x >= m + 1 && x < k + 1) {
        D[x] = (D[x] + MOD - C(x - 1, x - m - 1)) % MOD;
    } else if (x >= k + 1) {
        D[x] = (D[x] + 2ll * MOD - C(x - 1, x - m - 1) - C(x - 1, x - k - 1)) % MOD;
    }
    return D[x];
}

int main() {
    memset(D, -1, sizeof(D));
    pw3[0] = 1;
    for (int i = 1; i < N; i++) {
        pw3[i] = (pw3[i - 1] * 3ll) % MOD;
    }
    F[0] = 1;
    for (int i = 1; i < N; i++) {
        F[i] = 1ll * F[i - 1] * i % MOD;
    }
    iF[N - 1] = inv(F[N - 1]);
    for (int i = N - 2; i >= 0; i--)
        iF[i] = 1ll * iF[i + 1] * (i + 1) % MOD;

    scanf("%d %d %d", &n, &m, &k);
    if (m > k)
        swap(m, k);
    int ans = 0;
    for (int l = n; l <= n + m + k; l++) {
        int cur1 = C(l - 1, n - 1);
        int cur2 = get(l - n);
        int cur3 = pw3[n + m + k - l];
        ans += 1ll * cur1 * cur2 % MOD * cur3 % MOD;
        if (ans >= MOD)
            ans -= MOD;
    }

    printf("%d\n", ans);
    if (n <= 20 && m <= 20 && k <= 20) {
        int s = stup(n, m, k);
        eprintf("stup = %d\n", s);
        assert(s == ans);
    }

}


Measured memory_bytes: 16000
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

int A, B;

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

    cin >> A >> B;
    if (A > 8 || B > 8) {
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    }
    return 0;
}


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

int main()
{
    string a , b ;
    cin>>a;
    cin>>b ;
    if(a.length() > b.length())
        cout<<"GREATER\n" ;
    else if(a.length() < b.length())
        cout<<"LESS\n";
    else
    {
    if(a > b)
      cout<<"GREATER\n"  ;
    else if (a < b)
        cout<<"LESS\n";
    else
    cout<<"EQUAL\n";
    }
    return 0;
}

Measured memory_bytes: 256
N, D = map(int, input().split())
ans = 0
X = []
for i in range(N):
  x = [int(i) for i in input().split()]
  X.append(x)
for i in range(N-1):
  for j in range(i+1,N):
    tmp = 0
    for k in range(D):
      tmp += (X[i][k] - X[j][k])**2
    if ((tmp)**(1/2))%1 != 0:
      continue
    else:
      ans += 1
print(ans)

Measured memory_bytes: 3064
N,K = map(int,input().split())
A = list(map(int,input().split()))

bit = [0 for _ in range(40)]

for i in range(N):
    s = format(A[i],'040b')
    for j in range(40):
        bit[j] += int(s[j])
        
x = 0
ans = 0

for j in range(40):
    if N-bit[j] > bit[j] and 2**(39-j)+x <= K:
        x += 2**(39-j)
    
for i in range(N):
    ans += x^A[i]
    
print(ans)

Measured memory_bytes: 14700
package main

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

func main() {
	protagonist(os.Stdin, os.Stdout)
}

func protagonist(r basicIO.Reader, w basicIO.Writer) {
	io := NewIO(r, w)
	N, _ := io.nextInt()

	gv := 0
	total := 0
	for i := 0; i < N; i++ {
		if h, _ := io.nextInt(); gv <= h {
			total++
			gv = h
		}
	}
	io.PutInt(total)
}

type IO struct {
	Scanner *bufio.Scanner
	Writer  basicIO.Writer
}

func NewIO(r basicIO.Reader, w basicIO.Writer) *IO {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	return &IO{
		Scanner: s,
		Writer:  w,
	}
}

func (io *IO) nextString() string {
	io.Scanner.Scan()
	return io.Scanner.Text()
}

func (io *IO) nextInt() (int, error) {
	io.Scanner.Scan()
	i, err := strconv.Atoi(io.Scanner.Text())
	return i, err
}

func (io *IO) PutInt(v int) {
	fmt.Fprintf(io.Writer, "%d\n", v)
}

func (io *IO) PutString(s string) {
	fmt.Fprintf(io.Writer, "%s\n", s)
}


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

int main() {
  int N, ans=0;
  cin >> N;
  for(int i=int(N/1.08)-2; i<=N; i++){
    if(int(i*1.08)==N){
      ans=i;
      break;
    }
  }
  if(ans!=0) cout << ans << endl;
  else cout << ":(" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        while (true)
        {
            string S = N.ToString();
            bool frag = true;
            for (int i = 0; i < S.Length-1; i++)
            {
                if (S[i] == S[i + 1]) continue;
                frag = false;
            }

            if (frag)
            {
                WriteLine(S);
                return;
            }
            N++;
        }
    }
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int coll(int n) {
  if (n % 2 == 0) {
    return n / 2;
  } else {
    return 3 * n + 1;
  }
}

int main() {
  int s;
  cin >> s;
  vector<int> v(1000001);
  v[0] = s;
  for (int i = 1;; i++) {
    if (contains(v, coll(v[i - 1]))) {
      cout << i + 1;
      return 0;
    }
    v[i] = coll(v[i - 1]);
  }
}


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

int main() {
	int n;
	cin >> n;
	vector<int> h;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		h.push_back(tmp);
	}

	for (int i = 0; i < n-1; i++) {

		if (i == 0) { //第1項目
			if (h[i] > h[i + 1] + 1) {//ひとつ右と比較して、2つ以上大きかったらNoを出力
				cout << "No" << endl;
				return 0;
			}
			else {//下げておいて損することはない
				h[i]--;
			}
		}

		else {//i=1以降n-2まで
			if (h[i] > h[i + 1] + 1) {//ひとつ右と比較して、2つ以上大きかったらNoを出力
				cout << "No" << endl;
				return 0;
			}
			else if (h[i] == h[i + 1] + 1 && h[i] == h[i - 1]) {//ひとつ右と比較して、1つだけ大きいが、ひとつ左と同じ高さなので下げることができず、Noを出力
				cout << "No" << endl;
				return 0;
			}
			else if (h[i] <= h[i+1]+1 && h[i] > h[i-1] ) {//ひとつ右と比較して、最大で1大きく、自身をひとつ下げることが可能
				h[i]--;
			}
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		char temp=s[i];
		temp+=n;
		if(temp>90)
		{
			temp-=26;
		}
		s[i]=temp;
	}
	cout<<s;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
void N(int a[], int t) {
	t = a[1];
	a[1] = a[2];
	a[2] = a[6];
	a[6] = a[5];
	a[5] = t;
}

void S(int a[], int t) {
	t = a[1];
	a[1] = a[5];
	a[5] = a[6];
	a[6] = a[2];
	a[2] = t;
}

void E(int a[], int t) {
	t = a[1];
	a[1] = a[4];
	a[4] = a[6];
	a[6] = a[3];
	a[3] = t;
}

void W(int a[], int t) {
	t = a[1];
	a[1] = a[3];
	a[3] = a[6];
	a[6] = a[4];
	a[4] = t;
}

int main(void) {
	int a[10],t=0;
	char NEWS[100];
	a[0] = 0;
	for (int i = 1; i <= 6; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < 99; i++) {
		NEWS[i] = 0;
	}

	scanf("%s", NEWS);
	for (int i = 0; i < strlen(NEWS); i++) {
		if (NEWS[i] == 'N') {
			N(a, t);
		}
		if (NEWS[i] == 'E') {
			E(a, t);
		}
		if (NEWS[i] == 'W') {
			W(a, t);
		}
		if (NEWS[i] == 'S') {
			S(a, t);
		}
	}
	printf("%d\n", a[1]);
}


Measured memory_bytes: 2704
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    ll ans = 0;
    int tmp;
    int n, x;
	cin >> n >> x;
	vector<int> a(n+2);
	a[0] = 0, a[n+1] = 0;
	REP1(i, n) cin >> a[i];
	for (int i = 0; i <= n; i++)
	{
		if(a[i] + a[i+1] > x){
			ans += a[i] + a[i+1] - x;
			a[i+1] -= a[i] + a[i+1] - x;
		}
	}
	
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		vector<ll>      vll;
#define     fi              first
#define     print(v)        for(ll i:v) cout<<i<<ss
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;



int main()
{
    string s;
    cin>>s;
    ll ans=0;
    for(ll i=0,j=zz(s)-1; i<j; i++,j--)
    {
        if(s[i]!=s[j]) ans++;
    }
    cout<<ans<<nn;



}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/






Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,a,b) for(auto i=(a);i<(b);i++)
#define per(i,a,b) for(auto i=(a);i>=(b);i--)
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define int_inf 0x3f3f3f3f
#define int_max 2147483647
#define ll_max 9223372036854775807
#define ull_max 18446744073709551615
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lowbit(x) (x)&(-x)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll mod=1e9+7;
template<class T>
inline T read()
{
	T x=0,f=1;char s=getchar();
	while(s<'0'||s>'9') {if(s=='-')f=-1;s=getchar();};
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();};
	return x*f;
}
template<typename T>
inline void wri(T x)
{
	if(x<0){x=-x;putchar('-');};
	if(x/10) wri(x/10);
	putchar(x%10+48);
}
template<typename T>
inline void print(T x,char s)
{
	wri(x);
	putchar(s);
}
template<typename T>
T gcd(T a,T b)
{
	return b==0?a:gcd(b,a%b);
}
//关闭流同步就不能手写读入优化啦
int n;
ll a[100010];
ll b[100010];//节点
ll sum[100010];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n;
    rep(i,0,n+1){
    	cin>>a[i];
    	if(i==0) sum[i]=a[i];
    	else sum[i]=a[i]+sum[i-1];
	}
	if(a[0]>1){
		cout<<-1<<endl;
	}
	else if(a[0]==1&&n!=0){
		cout<<-1<<endl;
	}
	else if(a[0]==1&&n==0){
		cout<<1<<endl;
	}
	else{
		b[0]=1;
		int flag=0;
		rep(i,1,n+1){
			if(a[i]>2*b[i-1]){
				flag=1;
				break;
			}
			else b[i]=min(2*b[i-1]-a[i],sum[n]-sum[i]);
		}
		if(flag){
			cout<<-1<<endl;
		}
		else{
			ll sum=0;
			rep(i,0,n+1) {
				sum+=(b[i]+a[i]);
			}
			cout<<sum<<endl;
		}
	}
    return 0;
}


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

using namespace std;

int c[1010], s[1010], f[1010], ans[1010], n;

int work(int idx) {
    int now = 0;
    for (int i = idx; i < n - 1; i++) {
        now = max(now, s[i]);
        if (now % f[i]) {
            now = now / f[i] * f[i] + f[i];
        }
        now += c[i];
    }
    return now;
}


int main() {
    while (scanf("%d", &n) != EOF) {
        for (int i = 0; i < n - 1; i++)
            scanf("%d %d %d", &c[i], &s[i], &f[i]);
        ans[n - 1] = 0;
        for (int i = 0; i < n - 1; i++) {
            ans[i] = work(i);
        }
        for (int i = 0; i < n; i++)
            printf("%d\n", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 256
import collections
S = input()

s = list(S.split("><"))
ans = 0
for i in range(len(s)):
    table = collections.defaultdict(int)
    for y in s[i]:
        table[y] += 1

    if i == 0 and len(table) != 0:
        table["<"] -= 1
    if i == len(s)-1 and len(table) != 0:
        table[">"] -= 1
    table = list(table.values())
    if len(table) == 2:
        table.sort()
        ans += max((table[1]+1)*(table[1]+2) // 2, 0)
        ans += max((table[0]+1)*table[0] // 2, 0)

    elif len(table) == 1:
        ans += max((table[0]+1)*(table[0]+2) // 2, 0)
    else:
        ans += 1
print(ans)


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

const int N = 200005;

int a, b, c, d;

int solve() {
  scanf("%d %d %d %d", &a, &b, &c, &d);
  int turn = 0;
  while (a > 0 && c > 0) {
    turn ^= 1;
    if (turn) {
      c -= b;
    } else {
      a -= d;
    }
  }

  if (a <= 0) printf("No\n");
  else printf("Yes\n");
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  for (int tc = 0; tc < t; ++tc) {
    // printf("Case #%d: ", tc+1);
    solve();
  }
  return 0;
}


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

map<long long, int> prime_number_factor(long long n) {
    map<long long, int> res;
    for (long long i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

long long pow(long long a, long long n) {
    if (n == 0) return 1;
    
    if (n == 1) return a;
    
    if (n % 2 == 0) {
        long long half = pow(a, n / 2);
        return half * half;
    }
    else return pow(a, 1) * pow(a, n - 1);
}

int main() {
    long long n, p;
    cin >> n >> p;

    map<long long, int> prime = prime_number_factor(p);

    long long ans = 1;
    for (auto v: prime) {
        if (v.second / n == 0) continue;
        
        ans *= pow(v.first, v.second / n);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int N, M;
char table[256];
char buf[10];

int main() {
  for (;;) {
    fgets(buf, 10, stdin);
    sscanf(buf, "%d", &N);
    if (N == 0) { break; }

    for (int i = 0; i < 256; i++) {
      table[i] = i;
    }

    for (int i = 0; i < N; i++) {
      fgets(buf, 10, stdin);
      table[(int)buf[0]] = buf[2];
    }

    scanf("%d ", &M);

    for (int i = 0; i < M; i++) {
      fgets(buf, 10, stdin);
      printf("%c", table[(int)buf[0]]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1016
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct edge{
	int s,t,nxt;
}e[4005];
int last[2005],e_cnt;
void ins(int a,int b){
	e[e_cnt]=(edge){a,b,last[a]};
	last[a]=e_cnt++;
}
char s[2005];
int fa[2005],dep[2005],sum,l[2005],r[2005],size[2005];
void merge(int a,int b){
	l[a]=(l[a]<=l[b]&&l[b]<=r[a])||(l[b]<=l[a]&&l[a]<=r[b])?
			(l[b]^l[a])&1:max(l[a]-r[b],l[b]-r[a]);
	r[a]=r[a]+r[b];
}
void dfs(int x){
	size[x]=(s[x]=='1');
	sum+=dep[x]*(s[x]=='1');
	l[x]=r[x]=0;
	for(int i=last[x];i!=-1;i=e[i].nxt)if(e[i].t!=fa[x]){
		fa[e[i].t]=x;
		dep[e[i].t]=dep[x]+1;
		dfs(e[i].t);
		size[x]+=size[e[i].t];
		l[e[i].t]+=size[e[i].t];
		r[e[i].t]+=size[e[i].t];
		merge(x,e[i].t);
	}
}
int main(){
	int n;
	scanf("%d",&n);
	scanf("%s",s+1);
	memset(last,-1,sizeof(last));
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		ins(u,v);
		ins(v,u);
	}
	int ans=1e9;
	for(int i=1;i<=n;i++){
		fa[i]=dep[i]=sum=0;
		dfs(i);
		if(l[i]==0)ans=min(ans,sum/2);
	}
	printf("%d\n",(ans>=1e9?-1:ans));
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<queue>
#include<string>// 加法 S.size() s.substr(l,r=s.size()-l) -> l文字目からr文字分
#include<cmath>//三角関数,rad
#include<algorithm>　//__gcd()　lower_bound(a+l,a+r,x)-a でindex
// vector -> min/max({vector}) 
// 配列   -> *min_element(a+l,a+r)  *忘れず lとrで[l,r) 
//reverse(a+l,a+r)   配列aの[l,r)を逆順に strはreverse(S.begin(),S.end())
//sort(a+l,a+r,greater <int>()) 配列aの[l,r)昇順sort,大きい順はgreater<type>()
//vectorならv.begin(),v.end()
#include<ctime>//"clock()/CLOCKS_PER_SEC で秒数
#include<vector>//v.push_back(x),v.pop_back()
#include<queue>//q.push(x),front()で先頭を返す,pop()で削除, size(),empty()
#include<functional>//vector,queueと併用でpriority_queue
//宣言は priority_queue< Type, vector<Type>, greater<Type>> Q1; 
// pq.push(x),top()で参照 pop()で削除   greaterで最小 lessで最大がtopに
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main(){
    int k,t,d;d=-1;cin>>k>>t;int v[t];rep(i,t){int y;cin>>y;if(y>k/2){d=y;}v[i]=y;}
    if (d!=-1){cout<<2*d-k-1<<endl;}else{cout<<0<<endl;}
}

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

ll n,a[200000],b[200000];

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

	cin>>n;
	REP(i,n) cin>>a[i];
	REP(i,n) cin>>b[i];

	int ans=0;
	REP(i,30) {
		ll c[n],cnt=0,mod=(1<<i);
		REP(j,n) c[j]=b[j]%(2*mod);
		sort(c,c+n);
		REP(j,n) {
			ll tar=a[j]%(2*mod);
			if(tar<mod) cnt+=lower_bound(c,c+n,mod-tar)-c;
			cnt+=(lower_bound(c,c+n,3*mod-tar)-lower_bound(c,c+n,2*mod-tar));
		}
		if((n*n-cnt)&1) ans|=mod;
	}
	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

int g[8][8];

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u][v] = true;
		g[v][u] = true;
	}

	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		p[i] = i;
	}
	int ans = 0;
	do {
		if (p[0] != 0) continue;
		bool ok = true;
		for (int i = 0; i < n - 1; i++) {
			if (!g[p[i]][p[i + 1]]) {
				ok = false;
			}
		}
		if (ok) {
			ans++;
		}
	} while (next_permutation(p.begin(), p.end()));
	cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();
		
		char ch[] = s.toCharArray();
		
		ch[k-1] = (char)(ch[k-1] - 'A'+'a');
		
		System.out.println(ch);
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cstring>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;

const int N_MAX = 1000000;
int a[N_MAX];

int calc_num(int st, int en, int k, int n){
  int left_time = (st - 0)/(k-1) + (st%(k-1) != 0);
  int right_time = (n-1 - en)/(k-1) + ((n-1-en)%(k-1) != 0);
  /*
  cout << " st: " << st;
  cout << " en: " << en;
  cout << " left_time: " << left_time;
  cout << " right_time: " << right_time;
  cout << endl;*/
  return left_time + right_time + 1;
}

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

  int min_ele = N_MAX;
  int min_ix = -1;
  
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n){
    if(a[i] < min_ele){
      min_ele = a[i];
      min_ix = i;
    }
  }
  
  int lower_st = max(0, min_ix + 1 - k);
  int ans = INT_MAX;
  rep(st, lower_st, min_ix+1){
    ans = min(ans, calc_num(st, st+k-1, k, n));
  }
  cout << ans << endl;
  /*
  int rightlen = n - min_ix - 1; // not include min element
  int right_time = rightlen/(k-1) + (rightlen%(k-1) != 0);

  // if(rightlen == k) right_time = 1;

  int hamide =  k - rightlen%(k-1) - 1;
  if(rightlen%(k-1)==0) hamide = 0;
  int leftlen = max(0, min_ix - hamide);
  int left_time = leftlen/(k-1) + (leftlen%(k-1) != 0);
  */

  
  /*
  cout << "rightlen: " << rightlen << endl;
  cout << "leftlen: " << leftlen << endl;
  cout << "right_time: " << right_time << endl;
  cout << "left_time: " << left_time << endl;
  */
  //cout << right_time + left_time << endl;
  return 0;
}


Measured memory_bytes: 640
n = int(input())
a = list(map(int, input().split()))

a = sorted(a, reverse=True)
ans = a[0]

for i in range((n-2)//2):
    ans += a[i+1]*2
    # print(ans)
if (n) % 2 == 1:
   # print(a[i+2], i+2)
    ans += a[i+2]
print(ans)


Measured memory_bytes: 31580
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll LLmaxn = 2e18;
const int N = 100005;
int par[N];
void init(int n)
{
        for (int i = 0; i <= n; i++)
        {
                par[i] = i;
        }
}
int find(int x)
{
        return par[x] == x ? x : par[x] = find(par[x]);
}
void unite(int x, int y)
{
        x = find(x);
        y = find(y);
        if (x != y)
        {
                par[x] = y;
        }
}
int num[N];
int where[N];
int a, b;
int main()
{
        int n;
        int m;
        cin >> n;
        cin >> m;
        init(n);
        int anser = 0;
        for (int i = 1; i <= n; i++)
        {
                cin >> num[i];
                where[num[i]] = i;
        }
        for (int i = 1; i <= m; i++)
        {
                cin >> a >> b;
                unite(a,b);
        }
        for (int i = 1; i <= n; i++)
        {
                if (find(where[i]) == find(i))
                {
                        anser++;
                }
        }
        cout << anser << endl;
        return 0;
}


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

int dp[100010];

int pow(int x, int n) {
    if (n == 1) return x;
    
    if (n % 2 == 0) return pow(x, n / 2) * pow(x, n / 2);
    else return pow(x, 1) * pow(x, n - 1);
}

int main() {
    int n;
    cin >> n;
    for(int i = 0; i < 100010; i++)
    {
        dp[i] = i;
        
    }
    
    int m;
    for(int i = 1; i <= n; i++)
    {
        m = 1;
        while ((i - pow(6, m)) >= 0) {
            dp[i] = min(dp[i], (dp[i - (int)pow(6, m)] + 1));
            m++;
        }
        m = 1;
        while ((i - pow(9, m)) >= 0) {
            dp[i] = min(dp[i], (dp[i - (int)pow(9, m)] + 1));
            m++;
        }
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int N, A;

int main()
{
	in >> N >> A;
	out << N*N - A << std::endl;
	return 0;
}

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

int main() {
  int A, B, X;
  cin >> A >> B;
  
  for (int i=0; i<=B-A; i++) {
    int n;
    n=B-i;
      if (n/10000 == n%10 && n/1000%10 == n/10%10) {
        X++;
      }
      else {
        continue;
      }
  }
  cout << X <<endl;
}


Measured memory_bytes: 256
X,N = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
diff = 100000
ans = 0
for i in range(-200, 200):
  if i not in p:
    if abs(X-i) < diff:
      diff = abs(X-i)
      ans = i
print(ans)

Measured memory_bytes: 9184
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;

int main()
{
	int K, X;
	cin >> K >> X;
	int minX, maxX;
	minX = max(-1000000, X - (K - 1));
	maxX = min(1000000, X + (K - 1));
	for (int i = minX; i <= maxX; i++) {
		cout << i << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3144
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll l;
    ll r;
    ll d;
    cin >> l >> r >> d;
    ll ans = {(r/d) - ((l-1)/d)};
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 3152
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
    struct node *right;
    struct node *left;
    struct node *parent;
    int key;
};
typedef struct node * Node;

Node root;

Node treeMinimum(Node x){ 

    // 小さい方へどんどん降りていく
    while(x->left != NIL)
        x = x->left;
    return x;
}

Node treeSearch(Node u, int k){

    if(u == NIL) return NIL;

    // 見つかった
    if(u->key == k) return u;

    // 右か左か
    if(k < u->key) return treeSearch(u->left, k);
    if(k > u->key) return treeSearch(u->right, k);
}

// 節点xに節点があればそれを返す
// xが木の中で最大ならNILを返す
Node treeSuccessor(Node x){

    Node y;

    // 右の子から最小を探索
    if(x->right != NIL) return treeMinimum(x->right);

    // 左の子から最大を検索でも良い
    // if(x->left != NIL) return treeMaximum(x->left);

    // 右の子が存在しなければ、既に探索した節点ではない右の子が存在するノードが見つかるまで親の節点を探索
    y = x->parent;

    // 上へ上がっていく
    while(y != NIL && x == y->parent){
        x = y;
        y = y->parent;
    }
    return y;
}

void treeDelete(Node z){
    Node y; // node to be deleted
    Node x; // child of y

    // zの子が一つ以下なら削除し子供と置き換える
    if(z->left == NIL || z->right == NIL) y = z;
    //子を2つ持つ場合
    else y = treeSuccessor(z);

    if(y->left != NIL) x = y->left;
    else x = y->right;

    // yの親とxのポインタを変更しyを削除する
    // yが子を一つ持つ場合
    if(x != NIL) x->parent = y->parent;

    // yが根の時の境界条件を処理
    if(y->parent == NIL) root = x;

    // yが左の子の場合?
    else if(y == y->parent->left) y->parent->left = x;

    // yが右の子の場合?
    else if(y == y->parent->right) y->parent->right = x;

    // zの次節点が削除された時にyの内容をzに移動する
    if(y != z) z->key = y->key;
}

void insert(int k){
    Node y = NIL;
    Node x = root;
    Node z;

    // node生成
    z = malloc(sizeof(struct node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL) {
        // 下に降りていく
        y = x;
        if(z->key < x->key) x = x->left;
        else x = x->right;
    }

    z->parent = y;

    // 根
    if(y == NIL) root = z;

    // yよりzが小さければ左の子に
    else if(z->key < y->key) y->left = z;

    // yよりzが大きければ右の子に
    else y->right = z;
}

void inorder(Node u){
    if(u->left != NIL) inorder(u->left);
    printf(" %d", u->key);
    if(u->right != NIL) inorder(u->right);
}

void preorder(Node u){
    printf(" %d", u->key);
    if(u->left != NIL) preorder(u->left);
    if(u->right != NIL) preorder(u->right);
}


int main(){
    int n, i, x;
    char com[20];
    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
        scanf("%s", com);

        // find
        if ( com[0] == 'f' ){
            scanf("%d", &x);
            Node t = treeSearch(root, x);
            if ( t != NIL ) printf("yes\n");
            else printf("no\n");
        } 

        // insert
        else if ( com[0] == 'i' ){
            scanf("%d", &x);
            insert(x);
        } 

        // print
        else if ( com[0] == 'p' ){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } 

        else if ( com[0] == 'd' ){
            scanf("%d", &x);
            treeDelete(treeSearch(root, x));
        } 
    }

    return 0;
}

Measured memory_bytes: 19364
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
using namespace std;
int mx[]={1,0,-1,0},my[]={0,1,0,-1};
bool check(int x,int y,vector<vector<char> > &map,int count){
    if(count == 0){
        return true;
    }
    REP(i,4){
        int nx = x + mx[i];
        int ny = y + my[i];
        if(nx == -1 || nx == map[0].size() || ny == -1 || ny == map.size() || !map[ny][nx])continue;
        map[ny][nx] = false;
        if(check(nx,ny,map,count - 1)){
            return true;
        }
        map[ny][nx] = true;
    }
    return false;
}
int main(){
    int H,W,S,T;
    cin >> H >> W >> S >> T;
    --S;
    --T;
    while(S > 3){
        S -= 2;
        H -=2;
    }
    while(T > 3){
        T -= 2;
        W -= 2;
    }
    while(H - S > 3){
        H -= 2;
    }
    while(W - T > 3){
        W -= 2;
    }
    vector<vector<char> > map(H,vector<char>(W));
    REP(i,H){
        REP(j,W){
            map[i][j] = true;
        }
    }
    map[S][T] = false;
    cout << (check(S,T,map,H*W-1)?"Yes":"No")<< endl;
    return 0;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std ;
int main () {
  int N , M , X ;
  cin >> N >> M >> X ;
  int a = 0 , b = 0 ;
  for(int i = 0 ; i < M ; i++ ){
    int x ;
    cin >> x ;
    if(x < X ) a++ ;
    if(x > X ) b++ ;
  }
  cout << min(a,b) << endl ;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>))
import Control.Monad (replicateM, unless)
import Data.List (sortBy)
import Data.Vector.Unboxed (Vector, (!), (//))
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    solve <$> replicateM n (toRecord <$> getLine) >>= mapM_ print
    main

solve :: [Record] -> [Int]
solve rs = f 0 (V.replicate 1001 0) [] (sortRecord rs)
  where f :: Int -> Vector Int -> [Int] -> [Record] -> [Int]
        f _ _ as [] = reverse as
        f 26 _ as _ = reverse as
        f ct gv as (Record i u _ _ : rcs) | ct < 10 = if gv ! u < 3 then f (ct+1) (V.accum (+) gv [(u,1)]) (i:as) rcs
                                                      else f ct gv as rcs
                                          | ct < 20 = if gv ! u < 2 then f (ct+1) (V.accum (+) gv [(u,1)]) (i:as) rcs
                                                      else f ct gv as rcs
                                          | otherwise = if gv ! u < 1 then f (ct+1) (V.accum (+) gv [(u,1)]) (i:as) rcs
                                                      else f ct gv as rcs

data Record = Record Int Int Int Int deriving Show

sortRecord :: [Record] -> [Record]
sortRecord = sortBy f
  where f (Record i1 u1 a1 p1) (Record i2 u2 a2 p2) | a1 == a2 && p1 == p2 = compare i1 i2
                                                    | a1 == a2 = compare p1 p2
                                                    | otherwise = compare a2 a1

toRecord :: String -> Record
toRecord s = Record i u a p
  where [i,u,a,p] = map read . words $ s



Measured memory_bytes: 5024
#include <iostream>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	for (int i = 1; i <= 10000; i++){
		if ((int)(i*0.08) == a and (int)(i*0.1) == b){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# input
N = int(input())
H = list(map(int, input().split()))

# solve
l = list()
for i in range(N - 1):
    l.append(H[i + 1] - H[i])
tmp = 0
ans = 0
for i in range(len(l)):
    if l[i] <= 0:
        tmp += 1
        ans = max(ans, tmp)
    else:
        tmp = 0

# output
print(ans)


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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Yes or No
void yesno(bool ok, string yes = "Yes", string no = "No") {
  cout << (ok ? yes : no) << endl;
}

// Paste snippets here!!

//

void solve(std::string S) {
  ll ret = 0LL;
  for(char c : S){
    if(c=='+') ret++;
    else ret--;
  }
  cout << ret << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 3596
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = read().decode().rstrip()

if (S[2] == S[3]) & (S[4] == S[5]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) x.begin(), x.end()
using namespace std;
int main(){
  int n,m,c;
  cin>>n>>m>>c;
  vector<int> b(m);
  vector<vector<int>> a(n,vector<int>(n));
  rep(i,m) cin>>b[i];
  rep(i,n){
    rep(j,m){
      cin>>a[i][j];
    }
  }
  int ans=0;
  rep(i,n){
    int sum=0;
    rep(j,m){
      sum+=a[i][j]*b[j];
    }
    if(sum+c>0) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3588
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  string S;
  cin >> S;
  int N = S.size();
  char before = S[0];
  int ans = 0;
  REP(i, N) {
    if (S[i] != before) ans++;
    before = S[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
using namespace std;

class Node
{ 
    public:
    Node *l, *r;
    int key;
};

void insert(Node **root, int key)
{
    Node **cur = root, *node = new Node;
    node->l = NULL; node->r = NULL;
    node->key = key;
    while (NULL != *cur) {
        if (node->key < (*cur)->key) cur = &((*cur)->l);
        else cur = &((*cur)->r);
    }
    *cur = node;
    return;
}

void inorder(Node *cur)
{
    if (cur == NULL) return;
    inorder(cur->l);
    cout << " " << cur->key;
    inorder(cur->r);
}

void preorder(Node *cur)
{
    if (cur == NULL) return;
    cout << " " << cur->key;
    preorder(cur->l);
    preorder(cur->r);
}

int main()
{
    Node *root = NULL;
    int n, key;
    string command;
    cin >> n;
    while (n--) {
        cin >> command;
        if ("insert" == command) {
            cin >> key;
            insert(&root, key);
        }
        if ("print" == command) {
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 18748
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
	int a,b;
	std::cin >> a >> b;
	int c = a+b;
	if(c&1) {
		print("IMPOSSIBLE");
		return 0;
	}
	print(c/2);
	return 0;
}


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

int main(){

    int n;
    cin >> n;
    int c[n];
    int s[n];
    int f[n];

    for(int i=0; i<n-1; i++){
        cin >> c[i] >> s[i] >> f[i];
    }

    c[n-1] = 0;
    s[n-1] = 0;
    f[n-1] = 0;



    for(int i=0; i<n; i++){
        int time = 0;
        for(int j=i; j<n-1; j++){
            if(s[j] > time){
                time = s[j] + c[j];
            }else{
                if((time-s[j])%f[j]==0){
                    time += c[j];
                }else{
                    time += f[j] - time%f[j] + c[j]; 
                }
            }
        }
        cout << time << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
// constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

class UnionFind {
    struct UFNode {
        int par;
        int rank;
        UFNode() {}
    };
    vector<UFNode> nodes;
public:
    UnionFind(int n): nodes(n) {
        for (int i = 0; i < n; i++) {
            nodes[i].par = i;
            nodes[i].rank = 0;
        }
    };
    int root(int x) {
        //return nodes[x].par == x ? x : nodes[x].par = root(nodes[x].par);
        return nodes[x].par == x ? x : root(nodes[x].par);
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (nodes[x].rank < nodes[y].rank) {
            nodes[x].par = y;
        } else {
            nodes[y].par = x;
            if (nodes[x].rank == nodes[y].rank) nodes[x].rank++;
        }
    }
    //~UnionFind() {cout << nodes.size() << endl;}
};

void solve() {
    LL n,m;
    cin >> n >> m;
    UnionFind u(n);
    VI p(n);
    REP(i,0,n) cin >> p[i];
    int x,y;
    REP(i,0,m) {
        cin >> x >> y;
        u.unite(x,y);
    }
    VI v(n);
    int cnt = 0;
    REP(i,0,n) {
        if (u.same(i+1, p[i])) ++cnt;
    }
    cout << cnt << endl;
}

int main() {
    solve();
    
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<int> vi;
typedef pair<int, int> pi;
#define SQ(a) (a) * (a)
#define deb(x) cout << #x << " = " << x << '\n'
#define deb2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"

int dp[1000005];
list<int> *adj;
int n;
void addEdge(int v, int w)
{
    adj[v].push_back(w);
    adj[w].push_back(v);
     // Add w to v’s list.
}

bool BFS(int s)
{
    int V=n;
    // Mark all the vertices as not visited
    bool *visited = new bool[V];
    for (int i = 0; i < V; i++)
        visited[i] = false;

    // Create a queue for BFS
    list<int> queue;

    // Mark the current node as visited and enqueue it
    visited[s] = true;
    queue.push_back(s);

    // 'i' will be used to get all adjacent
    // vertices of a vertex
    list<int>::iterator i;

    while (!queue.empty())
    {
        // Dequeue a vertex from queue and print it
        s = queue.front();
        //cout << s << " ";
        queue.pop_front();

        // Get all adjacent vertices of the dequeued
        // vertex s. If a adjacent has not been visited,
        // then mark it visited and enqueue it
        for (i = adj[s].begin(); i != adj[s].end(); ++i)
        {
            if (!visited[*i])
            {
                visited[*i] = true;
                dp[*i]=s;
                queue.push_back(*i);
            }
        }
    }
    for(int i=0;i<n;i++){
        if(visited[i]==0){
            cout<<"No";return true;
        }
    }
    return false;
}
int main(int argc, char const *argv[])
{

#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int m;
    cin>>n>>m;
    memset(dp,0,sizeof dp);
    
    adj = new list<int>[n];

    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        addEdge(x-1,y-1);
    }
    if(BFS(0)) return 0;
    cout<<"Yes"<<endl;
    for(int i=1;i<n;i++){
        cout<<dp[i]+1<<endl;
    }

    return 0;
}

Measured memory_bytes: 25584
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
typedef long long ll;

int main() {
  string s, t;
  cin >> s >> t;
  vector< vector<ll>> v(26);
  for(int i = 0; i<s.size(); i++) {
     v[s[i] - 'a'].push_back(i);
  }
  ll cnt = -1;
  ll ans = 0;
  for(int i = 0; i<t.size(); i++) {
    char c = t[i];
    if(v[c-'a'].size() == 0) {
      cout << -1 << endl;
      return 0;
    }
    auto id = lower_bound(ALL(v[c-'a']), cnt+1);
    if(id == v[c-'a'].end()) {
      cnt = v[c-'a'][0];
      ans += (ll)s.size();
    }
    else {
      cnt = *id;
    }
    // cout << "cnt: " << cnt << " ans: " << ans << endl;
  }
  cout << ans + cnt + 1<< endl;
  return 0;
}


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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP				make_pair

typedef pair<int, int> P;

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

const int INF = 1e9;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int dp[MAX_N];

signed main() {
	int N, M; cin >> N >> M;

	dp[0] = dp[1] = 1;
	REP( i, M ) {
		int t; cin >> t;
		if( t != 1 ) {
			dp[t] = INF;
		} else {
			dp[t] = 0;
		}
	}

	FOR( i, 2, N + 1 ) {
		if( dp[i] != INF ) dp[i] = dp[i - 1] + dp[i - 2];
		else dp[i] = 0;
		dp[i] %= MOD;
	}

	cout << dp[N] << endl;
}

Measured memory_bytes: 1152