akhauriyash/Code-Regression huggingface dataset:
line = readlines
len = line.length
i = 0

while i < len
    line[i] = line[i].chomp.split(' ')
    i += 1
end

N = line[0][0].to_i
X = line[N+1][0]

songs = []
for i in 1..N do
  songs.push(line[i][0])
end
x_id = songs.index(X) + 1

answer = 0
for i in (x_id+1)..N do
  answer += line[i][1].to_i
end

print answer

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

// a^n mod を計算する
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
ll modinv(ll a, ll mod) {
    return modpow(a, mod - 2, mod);
}

const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, A, B, C;
  ll d = pow(10, 9) + 7;
  cin >> N >> A >> B >> C;
  ll Q = 0;
  ll P = 0;
  ll ans = 0;
  COMinit();
  for (int k = 0; k <= N - 1; k++) {
    ll t = N * C * COM(N + k, k) + (N + k) * (100 - C) * COM(N + k - 1, k);
    t %= d;
    ll ta = (modpow(B, k, d) * modpow(A, N, d)) % d;
    ll tb = (modpow(A, k, d) * modpow(B, N, d)) % d;
    t *= modinv(modpow(100 - C, N + k + 1, d), d);
    t %= d;
    ans += t * ((ta + tb) % d);
    ans %= d;
  }
  ans %= d;
  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
#define int long long
using namespace std;
ll p2[61];
ll bt[114514][60];
vector<ll> v;
ll check_bit(ll N,int POS){return (N & (1LL<<POS));}
ll gaussian_elimination()
{
    int n=v.size();
    int ind=0;  // Array index
    for(int bit=log2(v[0]);bit>=0;bit--)
    {
        int x=ind;
        while(x<n&&check_bit(v[x],bit)==0)
          x++;
        if(x==n)
          continue; // skip if there is no number below ind where current bit is 1
        swap(v[ind],v[x]);
        for(int j=0;j<n;j++)
        {
            if(j!=ind&&check_bit(v[j],bit))
                v[j]^=v[ind];
        }
        ind++;
    }
    ll ANS=v[0];
    for(int i=1;i<n;i++)
      ANS=max(ANS,ANS^v[i]);
    return ANS;
}
signed main(){
	int n; cin>>n;
	vector<int> a;
	vector<int> deke;
	int alx=0;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a.pb(x);
		alx = alx^x;
	}
	int ans = 0;
	p2[0]=1;
	for(int i=1;i<=60;i++){
		p2[i]=p2[i-1]*2;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<=59;j++){
			if( a[i] % p2[j+1] >= p2[j])bt[i][j] = 1;
		}
	}
	vector<int> dame;
	for(int i=59;i>=0;i--){
		if( alx % p2[i+1] >= p2[i]){
			ans += p2[i];
		}
		else{
			dame.pb(i);
		}
	}
	for(int i=0;i<=n;i++){
		v.pb(0);
	}
	for(int i=0;i<dame.size();i++){
		int cd = dame[i];
		for(int k=0;k<n;k++){
			if(bt[k][cd]==1)v[k]+=p2[cd];
		}
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	ans += gaussian_elimination()*2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 49652
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main(){
    
    int n;
    cin>>n;
    double ar[n];
    for(int i=0; i< n; i++) cin>>ar[i];
    
    double ans = 0;
    
    sort(ar, ar+n);
    
    for(int i=0; i<(n-1) ;i ++){
        ar[i + 1] = (ar[i] + ar[i+1])/ (double) 2;
    }
    cout<<ar[n-1]<<endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<int> abcd;
vector<int> signs(3);
const int ret = 10000;
int search(int idx,int sign){
	if(idx < 2){
		signs[idx] = 1;
		if(search(idx + 1,1) == ret){
			return ret;
		} else{
			signs[idx] = -1;
			if(search(idx + 1,1) == ret){
				return ret;
			} else{
				return -ret;
			}
		}
	} else{
		if(abcd[0] + signs[0] * abcd[1] + signs[1] * abcd[2] +  abcd[3] == 7){
			signs[2] = 1;
			return ret;
		} else if(abcd[0] + signs[0] * abcd[1] + signs[1] * abcd[2] - abcd[3] == 7){
			signs[2] = -1;
			return ret;
		} else{
			return -ret;
		}
	}
}

int main(){
	string buf,out;
	cin >> buf;
	for(auto b : buf){
		abcd.push_back(b - '0');
	}
	search(0,1);

	for(int i = 0; i < 3; ++i){
		out.push_back(abcd[i]+'0');
		if(signs[i] == 1){
			out.push_back('+');
		} else{
			out.push_back('-');
		}
	}
	out.push_back(abcd[3]+'0');
	out += "=7";

	cout << out << endl;
	return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

dishes = [A, B, C, D, E]

dishes_time = [10 * (i // 10) +  10 if i % 10 != 0 else 10 * (i // 10) for i in dishes]

sum_time = sum(dishes_time)

FinishTime = 0x100000

for i in range(5):
    prov_time = sum_time - dishes_time[i] + dishes[i]
    if sum_time - dishes_time[i] + dishes[i] < FinishTime:
        FinishTime = prov_time

print(FinishTime)

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

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

int main(){
  int n, k; cin >> n >> k;
  int a; rep(i,n) cin >> a;
  cout << (n + k - 3) / (k - 1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int m,nmin,nmax;
  while(cin>>m>>nmin>>nmax,m+nmin+nmax!=0){
    vector<int> point(m);
    for(int i=0;i<m;i++)
      cin>>point[i];
    int max=-1,ans=0;
    for(int i=nmin-1;i<nmax;i++){
      if(max<=(point[i]-point[i+1])){
	max=point[i]-point[i+1];ans=i+1;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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


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

    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    int sum = 0;
    rep(i,m) cin >> a[i], sum += a[i];

    int ans = n - sum;
    cout <<(ans<0?-1:ans)<<endl;
    return 0;
}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
const int MOD = 998244353;
const int INF = INT_MAX / 2;
struct edge { int v, w; };
#define double long double

double d(int x1, int y1, int x2, int y2) {
	double dx = x1 - x2, dy = y1 - y2;
	return sqrt(dx * dx + dy * dy);
}

int main() {
	int N; cin >> N;
	vector<int> x(N), y(N);
	rep(i, N) cin >> x[i] >> y[i];
	int ans = 1;
	rep(t, N) ans = ans * 2 % MOD;
	rep(i, N) rep(j, i) {
		int n = 0;
		rep(k, N) if (k != i && k != j) {
			double d1 = d(x[k], y[k], x[i], y[i]);
			double d2 = d(x[k], y[k], x[j], y[j]);
			double d3 = d(x[i], y[i], x[j], y[j]);
			if (abs(d1 + d2 - d3) < 1e-12) n++;
		}
		int x = 1;
		rep(t, n) x = x * 2 % MOD;
		ans = (ans - x) % MOD;
	}
	ans = (ans - N - 1) % MOD;
	cout << (ans + MOD) % MOD << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.*;
class Main{public static void main(String[]args){
	Scanner cin=new Scanner(System.in);
	for(;;){
		final int a=cin.nextInt();
		final int b=cin.nextInt();
		if(a==0)break;
		System.out.println(IntStream.range(0,a/2+1).asDoubleStream().map(i->Math.abs(b-Math.hypot(i,a-i))).min().getAsDouble());
	}
}}

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

using namespace std;
long long  ans=0;
long long  a[55],b[55];
long long fun(long long n,long long m)
{
    long long ans=0;
    if(n>1)
    {
        if(m>a[n]/2+1 && m!=a[n])
        {
            ans+=b[n-1]+1+fun(n-1,m-a[n]/2-1);
        }
        else if(m==a[n]/2+1)
        {
            ans+=b[n-1]+1;
        }
        else if(m<a[n]/2+1)
        {
            ans+=fun(n-1,m-1);
        }
        else
        {
            ans+=b[n];
        }
    }
    else
    {
        if(m==5)
        {
            ans+=3;
        }
        else if(m>0)
        {
            ans+=m-1;
        }
    }
    return ans;
}
int main()
{
    long long  n,m;
    cin >> n >> m;
    a[0]=b[0]=1;
    for(int i=1; i<=n; i++)
    {
        a[i]=a[i-1]*2+3;
        b[i]=b[i-1]*2+1;
    }
    cout << fun(n,m) << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		//var n=sc.I;
		var s=sc.Ia;
		Console.WriteLine("{0} {1}",(1.0*s[0]*s[1])/2,(s[0]-s[2]==s[2]&&s[1]-s[3]==s[3])?1:0);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2(int b){return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}
	public int[] Ia3(int a,int b){return Array.ConvertAll(((a!=0?b.ToString()+" ":"")+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(int a,int b,int c,int d){return Array.ConvertAll(((a!=0?b.ToString()+" ":"")+Console.ReadLine()+(c!=0?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2(int b){return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}
	public long[] La3(int a,int b){return Array.ConvertAll(((a!=0?b.ToString()+" ":"")+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(int a,int b,int c,int d){return Array.ConvertAll(((a!=0?b.ToString()+" ":"")+Console.ReadLine()+(c!=0?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13140
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int N;
char s[128], t[128];
int sl, tl;

int FRE() {
	int common = 0, nowDeep = 0;
	char *ss, *ts, *fss, *fts, flag;
	ss = &s[N - 1];
	ts = t;
	while((*ts)) {
		nowDeep++;
		if((*ss) == (*ts)) {
			//printf("    DEBUG : %d\n", nowDeep);
			flag = 1;
			for(fts = ts, fss = ss; fts >= t; fts--, fss--) {
				if((*fts) != (*fss)) {
					flag = 0;
					break;
				}
			}
			if(flag) {
				common = nowDeep;
			}
		}
		ts++;
	}
	return common;
	
}
int main (void) {
	int re, tem;
	char *ss, *ts;
	while(~scanf(" %d %s %s", &N, s, t)) {
		//printf("DEBUG : N : %d , s : %s, t : %s,\n", N, s, t);
		//system("pause");
		tem = FRE();
		//printf("DEBUG : tem : %d\n", tem);
		re = N * 2 - tem;
		printf("%d\n", re);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
//define
#define int long long
#define vint vector<int>
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define pb() push_back()
#define mod 100000007
#define elif else if
#define str string
//main
signed main(){
  int N,M,O,Q,count=0,count2=0,count3=0;
  vint A(3);
  cin>>A[0]>>A[1]>>A[2];
  cin>>Q;
  sort(all(A));
  rep(0,Q){
    A[2]*=2;
  }
  cout<<A[0]+A[1]+A[2]<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

struct Edge{
    int to,id;
    ll dist;
    Edge(int to,ll dist=1,int id=0):to(to),dist(dist),id(id){}
};

struct HeavyLightDecomposition{
    vector<vector<Edge>> g;
    vector<int> in,out,head,par,dep,sz;
    int times;
    int root;

    HeavyLightDecomposition(int V,vector<vector<Edge>> &G):
        g(G),in(V),out(V),head(V),par(V),dep(V),sz(V){
            root=0;
            times=0;
            sz_dfs(root,-1);
            hld_dfs(root,-1);
        }
    
    void sz_dfs(int now,int p){
        par[now]=p;
        sz[now]=1;
        if(p==-1) dep[now]=0;
        else dep[now]=dep[p]+1;

        for(auto &e:g[now]){
            if(e.to==p) continue;
            sz_dfs(e.to,now);
            sz[now]+=sz[e.to];
            if(sz[e.to]>sz[g[now][0].to]) swap(e,g[now][0]);
        }
    }

    void hld_dfs(int now,int p){
        in[now]=times++;
        for(auto e:g[now]){
            if(e.to==p) continue;
            head[e.to]=(e.to == g[now][0].to ? head[now] : e.to);
            hld_dfs(e.to,now);
        }
        out[now]=times;
    }

    int lca(int u,int v){
        for(;;v=par[head[v]]){
            if(in[u]>in[v]) swap(u,v);
            if(head[u]==head[v]) return u;
        }
    }

    int distance(int u,int v){
        return dep[u]+dep[v]-2*dep[lca(u,v)];
    }
};


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

  int N;
  cin>>N;
  vector<vector<Edge>> g(N);
  rep(i,N){
      int K;cin>>K;
      rep(j,K){
          int a;cin>>a;
          g[i].push_back(a);
      }
  }

  HeavyLightDecomposition hld(N,g);

  int Q;
  cin>>Q;
  rep(i,Q){
      int a,b;
      cin>>a>>b;
      cout<<hld.lca(a,b)<<endl;
  }

  return 0;
}



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

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

  for(int i=1;i<=100;i++) {
    for(int j=1;j<=100;j++) {
      for(int k=1;k<=100;k++) {
        int val=i*i+j*j+k*k+i*j+j*k+k*i;
        m[val]++;
      }
    }
  }

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


Measured memory_bytes: 5412
#include<stdio.h>
int main(void){
	int H,W,i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0&&W==0){
			break;
		}
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if(i==0||i==H-1){
					printf("#");
				}else if(j==0||j==W-1){
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 300300;
int n, m;
vector<int> g[N];
bool used[N];

void dfs(int v)
{
	used[v] = 1;
	for (int u : g[v])
	{
		if (!used[u])
			dfs(u);
	}
	return;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
	{
		int sz;
		scanf("%d", &sz);
		while(sz--)
		{
			int v;
			scanf("%d", &v);
			v += n - 1;
			g[i].push_back(v);
			g[v].push_back(i);
		}
	}
	dfs(0);
	bool ok = true;
	for (int i = 0; i < n; i++)
		ok &= used[i];
	if (ok)
		printf("YES\n");
	else
		printf("NO\n");

	return 0;
}

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

int main(){
    string s, t;
    int a, b;
    string u;

    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
	
    if (u == s){
        a = a - 1;
    }
    else if (u == t){
        b = b - 1;
    }

    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
n = parseInt(readline())
x = parseInt.(split(readline()))

ans = 100000000000000000000
tmp = 0
for i in 1:100
    tmp = 0
    for j in 1:n
        tmp += (x[j] - i)^2
    end
    if tmp < ans
        ans = tmp
    end
end
println(ans)


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

int main() {
    string a, b;
    cin >> a >> b;
    int an = a.size(), bn = b.size();
    if (an > bn) {
        cout << "GREATER" << endl;
        return 0;
    }
    else if (an < bn) {
        cout << "LESS" << endl;
        return 0;
    }
    else if (a == b) {
        cout << "EQUAL" << endl;
        return 0;
    }
    for (int i=0; i<an; ++i) {
        if (a[i] > b[i]) {
            cout << "GREATER" << endl;
            return 0;
        }
        else if (a[i] < b[i]) {
            cout << "LESS" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	count := 0
	var s string
	fmt.Scan(&s)

	for i,j:=0, len(s)-1; i<j; i, j = i+1, j-1{
		if s[i] != s[j]{
			count++
		}
	}

	fmt.Println(count)
}

Measured memory_bytes: 1768
#include <stdio.h>
#include <math.h>

int main(void){
  double N, K;
  double P, S;
  scanf("%lf %lf", &N, &K);
  S=0;
  for(double i=1; i<=N; i++){
    if(i>=K) S=S+1;
    else S=S+pow(0.5, ceil(log2(K/i)));
  }
  P=S/N;
  printf("%.15f", P);
  return(0);
}

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

int main() {
  int h, w, k, bCount;
  cin >> h >> w >> k;
  string str[h];
  for(int i = 0; i < h; i++) {
    cin >> str[i];
  }
  int res = 0;
  for(int bitH = 0; bitH < (1<<h); bitH++) {
    for(int bitW = 0; bitW < (1<<w); bitW++) {
      bCount = 0;
      for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
          if((bitH & (1<<i)) && (bitW & (1<<j))) {
              if(str[i].at(j) == '#') bCount++;
          }
        }
      }
      if(k == bCount) res++;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=4e5+5,mod=1e9+7;
ll f[N],invf[N];
ll C(int n,int m)
{
    return f[n]*invf[n-m]%mod*invf[m]%mod;
}
int n,k;
int main()
{
    f[0]=invf[0]=f[1]=invf[1]=1;
    for(int i=2;i<N;i++) f[i]=f[i-1]*i%mod,invf[i]=(mod-mod/i)*invf[mod%i]%mod;
    for(int i=2;i<N;i++) invf[i]=invf[i-1]*invf[i]%mod;
    scanf("%d%d",&n,&k);
    k=min(n,k);
    ll ans=0;
    for(int i=0;i<=min(n-1,k);i++)
        ans=(ans+C(n,i)*C(n-1,n-i-1)%mod)%mod;
    ans=(ans+mod)%mod;
    printf("%lld\n",ans);
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  cout << min((2*a+b)/4,b/2) << endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int N,X;
  cin >> N >> X;
  int L[N];
  int A[N+1];
  A[0] = 0;
  for(int i=0; i<N; i++){
    cin >> L[i];
    if(i==0){
      A[i+1] = L[i];
      // cout << A[i+1] << endl;
    }else{
      A[i+1] = A[i] + L[i];
      // cout << A[i+1] << endl;
    }
  }

  int ans = 0;

  for(int i=0; i<=N; i++){
    if(A[i] <= X){
      ans = i;
    }
  }

  cout << ans + 1 << endl;
}


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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int main() {
    str s;
    cin >> s;
    ll ans = 0;
    int mlen = s.length() - 1;
    for(int bit = 0; bit < (1 << mlen); bit++) {
        bitset<9> b(bit);
        int pos = 0;
        REP(i, mlen) {
            if(b[i]) {
                ans += stoll(s.substr(pos, i + 1 - pos));
                pos = i + 1;
            }
        }
        ans += stoll(s.substr(pos));
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
h, w, n = map(int, input().split())
sr, sc = map(int, input().split())
s = input()
t = input()
l, u = 1, 1
r = w
d = h
for i in range(n-1, -1, -1):
    if t[i] == 'L':
        r = min(w, r+1)
    if t[i] == 'R':
        l = max(1, l-1)
    if t[i] == 'U':
        d = min(h, d+1)
    if t[i] == 'D':
        u = max(1, u-1)
    if s[i] == 'L':
        l += 1
    if s[i] == 'R':
        r -= 1
    if s[i] == 'U':
        u += 1
    if s[i] == 'D':
        d -= 1
    if l > r or u > d:
        print("NO")
        quit()
print("YES" if l<=sc<=r and u<=sr<=d else "NO")

Measured memory_bytes: 3788
n,c1 = map(int, input().split())
d = []
c = []
for i in range(c1):
    di = list(map(int, input().split( )))
    d.append(di)


for i in range(n):
    ci = list(map(int, input().split( )))
    c.append(ci)
    for j in range(n):
        c[i][j]-=1

"""
for cij in range(n):
        cij-=1
だとリストの内容は変化しない
"""

cost_c = [[0]*c1 for i in range(3)]

for t in range(n*n):
    i = t//n
    j = t%n
    md = (i+j)%3
    for cy in range(c1):
        try:
            cx = c[i][j]
            cost = d[cx][cy]
            cost_c[md][cy]+= cost
        except:
            print(d,cx,cy)
ans = 10**10
for x in range(c1):
    for y in range(c1):
        if x==y:
            continue
        for z in range(c1):
            if x==z or y==z:
                continue
            ans = min(ans, cost_c[0][x]+cost_c[1][y]+cost_c[2][z])
print(ans)
        
    

Measured memory_bytes: 46300
#include <bits/stdc++.h>
#define N 30010
using namespace std;
typedef long long ll;
inline ll read()
{
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
struct edge
{
	int u,v,next;
}vs[N*30*2];
int n,st[N*7],ee,las,id[N],nd[N*7],idx[N];
ll X[N],Y[N],V[N];
int dfn[N*7],low[N*7],tim,vis[N*7],op[N],tot,bl[N*7];
stack <int> St;

inline void addedge(int u,int v)
{
	vs[++ee].v=v;vs[ee].next=st[u];st[u]=ee;
}

inline bool cmp(const int a,const int b)
{
	return V[a]<V[b];
}
void built(int l,int r,int rt)
{
	nd[rt]=++las;
	if(l==r)
	{
		addedge(nd[rt],op[l]);
		return ;
	}
	int mid=(l+r)>>1;
	built(l,mid,rt<<1);
	built(mid+1,r,rt<<1|1);
	addedge(nd[rt],nd[rt<<1]);
	addedge(nd[rt],nd[rt<<1|1]);
}
void linkedge(int L,int R,int x,int l,int r,int rt)
{
	if(L<=l&&r<=R)
	{
		addedge(x,nd[rt]);
		return ;
	}
	int mid=(l+r)>>1;
	if(mid>=L) linkedge(L,R,x,l,mid,rt<<1);
	if(mid<R) linkedge(L,R,x,mid+1,r,rt<<1|1);
}
void dfs(int rt)
{
	vis[rt]=1; dfn[rt]=low[rt]=++tim;
	St.push(rt);
	for(int i=st[rt];i;i=vs[i].next)
	{
		if(vis[vs[i].v])
		{
			low[rt]=min(low[rt],dfn[vs[i].v]);
		}
		else if(!dfn[vs[i].v])
		{
			dfs(vs[i].v);
			low[rt]=min(low[rt],low[vs[i].v]);
		}
	}
	if(low[rt]==dfn[rt])
	{
		++tot;
		while(St.top()!=rt)
		{
			bl[St.top()]=tot;
			vis[St.top()]=0;
			St.pop();
		}
		St.pop(); bl[rt]=tot; vis[rt]=0;
	}
}
bool check(ll x)
{
	memset(st,0,sizeof st);
	ee=0; las=n+n; tim=0;
	built(1,n+n,1);
	for(int i=1;i<=n+n;i++)
	{
		int pr=upper_bound(V+1,V+1+n+n,V[i]-x)-V;
		int nx=lower_bound(V+1,V+1+n+n,V[i]+x)-V-1;
		if(pr<i) linkedge(pr,i-1,i,1,n+n,1);
		if(nx>i) linkedge(i+1,nx,i,1,n+n,1);
	}
	for(int i=1;i<=las;i++) vis[i]=dfn[i]=low[i]=0;
	for(int i=1;i<=las;i++) if(!dfn[i]) dfs(i);
	for(int i=1;i<=n+n;i++) if(bl[i]==bl[op[i]]) return 0;
	return 1;
}
int main()
{
	//freopen("read.in","r",stdin);
	n=read();
	for(int i=1;i<=n;i++)
		X[i]=read(),Y[i]=read(),
		V[++V[0]]=X[i],id[V[0]]=V[0],
		V[++V[0]]=Y[i],id[V[0]]=V[0];
	sort(id+1,id+1+n+n,cmp);
	for(int i=1;i<=n+n;i++) idx[id[i]]=i;
	for(int i=1;i<=n+n;i++) op[i]=idx[(id[i]&1)? id[i]+1: id[i]-1];
	sort(V+1,V+1+n+n);
	ll l=0,r=1000000000,ans;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid)) ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 17664
s = input()
k = int(input())

if len(set(list(s)))==1:
    print(len(s)*k//2)

elif s[0] != s[-1]:
    cnt = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s = s[:i]+'.'+s[i+1:]
    print(s.count('.')*k)
else:
    a,b = 0,0
    c = s[0]
    rev_s = s[::-1]
    for i in range(len(s)):
        if s[i]==c:
            a += 1
        else:
            break
    for i in range(len(s)):
        if rev_s[i]==c:
            b += 1
        else:
            break
    cnt = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s = s[:i]+'.'+s[i+1:]
    print(s.count('.')*k - (a//2 + b//2 - (a+b)//2)*(k-1))

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <bitset>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define rg register
#define LL long long
#define __space putchar(' ')
#define __endl putchar('\n')
template <typename qwq> inline void read(qwq & x)
{
    x = 0;
    rg int f = 1;
    rg char c = getchar();
    while (c < '0' || c > '9')
    {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    x *= f;
}
template <typename qaq> inline void print(qaq x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    if (x > 9) print(x / 10);
    putchar(x % 10 + '0');
}
struct node
{
	int val,data;
}a[233333];
int n;
LL ans;
bitset<1000000005> s;
inline bool cmp(node x,node y)
{
	return x.val < y.val;
}
int main()
{
	read(n);
	ans = n;
	for (rg int i = 1;i <= n;++i)
	{
		read(a[i].val);
		a[i].data = i;
	}
	stable_sort(a + 1,a + 1 + n,cmp);
	for (rg int i = 1;i <= n;++i)
	{
		if (s[a[i].val]) continue;
		rg bool odd_i = i & 1,odd_data = a[i].data & 1;
		if (odd_i == odd_data) s[a[i].val] = true,--ans;
	}
	print(ans >> 1);
}

Measured memory_bytes: 123128
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N;
    in1(N);

    vll X(N), Y(N), H(N);
    rep(i, N) in3(X[i], Y[i], H[i]);

    int count = 0;
    int pos = 0;
    rep(i, N)
    {
        if (H[i] == 0) continue;

        count++;
        pos = i;
    }

    if (count == 1)
    {
        cout << X[pos] << " " << Y[pos] << " " << H[pos] << endl;
        return 0;
    }

    repse(x, 0, 100)
    {
        repse(y, 0, 100)
        {   
            bool flg = true;

            ll h = -1;

            rep(i, N)
            {
                if (H[i] == 0) continue;

                ll tmp = H[i] + abs(X[i] - x) + abs(Y[i] - y);

                if (h > 0 && tmp != h)
                {
                    flg = false;
                    break;
                }

                h = tmp;
            }

            if (flg)
            {
                cout << x << " " << y << " " << h << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3632
// Copyright (C) 2017 Sayutin Dmitry.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.

#include <iostream>
#include <vector>
#include <stdint.h>
#include <algorithm>
#include <set>
#include <map>
#include <array>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <string>
#include <assert.h>
#include <iterator>
#include <cstdint>
#include <cinttypes>
#include <string.h>
#include <random>
#include <numeric>
#include <tuple>


using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::min;
using std::abs;
using std::max;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

#define pb push_back
#define eb emplace_back


int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    // code here.
    int n, a, b;
    cin >> n >> a >> b;

    if ((b - a) % 2 == 0)
        cout << "Alice\n";
    else
        cout << "Borys\n";
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<double,double>
#define pb push_back
#define f first
#define s second
#define ll long long int
#define vi vector<ll>
#define rs resize
int main()
{
     std::ios::sync_with_stdio(false);
     ll n,i,a,h=INT_MIN,z=INT_MAX;
     cin>>n;
     rep(i,0,n){
       cin>>a;
       h = max(h,a);
       z = min(z,a);
     }
     cout<<h-z;
     return 0;
}


Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=int(input())
x=(10**9-s%(10**9))%(10**9)
y=(s+x)//(10**9)
print(0, 0, 10**9,1,x,y)
# print(10**9,1)
# print(10**9-s%(10**9),s//(10**9))

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <map>
#define S str[ima]
using namespace std;
map <string,int> mp;
int ima;
string str;

int check(char ch){
  if('A'<=ch && ch<='Z') return 1;
  if('a'<=ch && ch<='z') return 2;
  if('0'<=ch && ch<='9') return 3;
  if(ch == '(') return 4;
  return 5;
}

int formula(){
  int res=0;
  while(S != '\0'){
    int num=0;
    if(check(S) == 1) {
      string a="";
      a+=S;
      ima++;
      while(check(S)==2) a+=S,ima++;
      if(mp.count(a) != 1) return -1;
      while(check(S)==3) num*=10,num+=S-'0',ima++;
      res += (mp[a]*max(1,num));
    }
    else if(check(S)==4){
      ima++;
      int b =formula();
      if(b == -1) return -1;
      ima++;
      while(check(S)==3) num*=10,num+=S-'0',ima++;
      res += (b*max(1,num));
    }
    else break;
  }
  return res;
}

int main(){
  while(1){
    int n;
    cin >> str;
    if(str == "END_OF_FIRST_PART")break;
    cin >> n;
    mp[str]=n;
  }
  while(1){
    cin >> str;
    if(str=="0") break;
    ima=0;
    int res = formula();
    if(res==-1 || res==0) cout <<"UNKNOWN"<<endl;
    else cout << res <<endl;
  }
  return 0;
}

Measured memory_bytes: 1228
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long n){
    string s1 = "24579";
    string s2 = "0168";
    if(s1.find(n % 10 + '0') != string::npos)
        cout << "hon" << endl;
    else if(s2.find(n % 10 + '0') != string::npos)
        cout << "pon" << endl;
    else
        cout << "bon" << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

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

    int a[N][3];
    for(int i=0; i<N; i++){
        for(int j=0; j<3; j++){
            cin >> a[i][j];
        }
    }

    int h[N][3];
    h[0][0] = a[0][0];
    h[0][1] = a[0][1];
    h[0][2] = a[0][2];
    
    for(int i=1; i<N; i++){
        for(int j=0; j<3; j++){
            if (j==0){
                h[i][0] = max(h[i-1][1] + a[i][0], h[i-1][2] + a[i][0]);
            }
            else if (j==1){
                h[i][1] = max(h[i-1][0] + a[i][1], h[i-1][2] + a[i][1]);    
            }
            else {
                h[i][2] = max(h[i-1][0] + a[i][2], h[i-1][1] + a[i][2]);
            }
        }
    }

    cout << max(h[N-1][0], max(h[N-1][1], h[N-1][2]));
}

Measured memory_bytes: 2560
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	ll n, k;
	while(scanf("%lld%lld", &n, &k)==2)
	{
		ll ans=n%k;

		ans=min(ans, abs(ans-k));
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	LL N, K;
	cin >> N >> K;
	vector<int> B(60);
	vector<LL> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		LL ter = A[i];
		for (int j = 0; j < 60; ++j) {
			B[j] += (ter & 1);
			ter /= 2;
		}
	}
	LL X = 0;
	LL base = (LL)1 << 59;
	for (int i = 59; i >= 0; --i) {
		if (X + base <= K) {
			LL bit1 = B[i];
			LL bit0 = N - B[i];
			LL H = N / 2;
			if (bit0 > H) {
				X += base;
			}
		}
		base >>= 1;
	}
	LL ans = 0;
	for (int i = 0; i < N; ++i) {
		ans += (X ^ A[i]);
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

map<int,map<int,int> >pop;
int x[123456],y[123456];

int main(){
  int N;
  cin>>N;
  for(int i=0;i<N;i++){
    int w;
    cin>>x[i]>>y[i]>>w;
    pop[y[i]][x[i]]=w;
  }
  int ans=0;
  for(int i=0;i<N;i++){
    for(int j=-1;j<=0;j++){
      for(int k=-1;k<=0;k++){
	int c=0;
	for(int l=0;l<2;l++){
	  for(int m=0;m<2;m++){
	    c+=pop[y[i]+j+l][x[i]+k+m];
	  }
	}
	ans=max(ans,c);
      }
    }
  }
  cout<<ans<<" / 1"<<endl;
}

Measured memory_bytes: 72300
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll n;
    cin >> n;
    vector<ll> h(n, 0);
    rep1(i, n) cin >> h[i];
    bool judge = true;
    rep1(i, n-1){
        if (h[i]>h[i+1]) judge = false;
        else{
            if (h[i]!=h[i+1]) h[i+1]--;
        }
    }
    if (judge) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
#if LOCAL
#include "../cout.hpp"
#endif
using namespace std;

#define forn(i,n) for (unsigned i = 0; i < n; ++i)

int bins[26];

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

    string s;
    cin >> s;

    forn(i, s.length()) {
	bins[s[i] - 'a']++;
    }

    forn(i, 26) {
	if(bins[i] == 0) {
	    cout << (char)('a' + i);
	    return 0;
	}
    }
    cout << "None";
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };

void err() {
	cout << "No" << endl;
	exit(0);
}

int main() {
	int n;
	cin >> n;
	vector<int>check(101010,0);

	int k = 1;
	int c;
	while (1) {
		c = k*(k + 1) / 2;
		if (c >= 101010)break;
		else {
			check[c] = k;
		}
		k++;
	}

	if (check[n] == 0)err();
	cout << "Yes" << endl;


	int num = check[n] + 1;
	vector<vector<int>>s(num);

	cout << num << endl;

	int p = 1;
	rep(i,0,num) {
		rep(j, i + 1, num) {
			s[i].pb(p);
			s[j].pb(p);
			p++;
		}
	}

	rep(i, 0, num) {
		cout << num-1;
		rep(j, 0, num-1) {
			cout << " " <<s[i][j];
		}
		cout << endl;
	}
	

	return 0;
}

Measured memory_bytes: 2688
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
sumA = sum(A)

dic = Counter(A)

Q = int(input())

for _ in range(Q):
    b, c = map(int, input().split())
    if b in dic.keys():
        sumA += ((c-b)*dic[b])

        #変更後の数字は既にいる？
        if c in dic.keys():
            #個数を保持
            #bの個数をcに追加し、bを削除
            dic[c] += dic[b]
            del dic[b]
        else:
            dic[c] = dic[b]
            del dic[b]
        # print("C", C)
        
        
        
        # print(dic)
    # else:
    #     ans = sumA
    print(sumA)

Measured memory_bytes: 21284
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <bitset>
//#include <boost/math/common_factor_rt.hpp>

#define ll long long
#define max 100000
using namespace std;
ll l = 1000000007;

float a[105] = {};


int main()
{	
	int n;
	float min = 150;
	int ans = 0;
	float ave = 0;
	float sum = 0;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
	}
	ave = sum / n;

	for (int i = 0; i < n; i++)
	{
		float x = 0;
		x = abs(a[i] - ave);

		if (x < min) {
			min = x;
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}



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

int main() {
	int K;
	int sum = 0;
	cin >> K;
	for (int i = 1; i <= K; i += 2) {
		for (int j = 2; j <= K; j += 2) {
			sum++;
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}
ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
void solve()
{
	int a, b;
	cin >> a >> b;
	cout << max(a - b, max(a + b, a * b));
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;

const int MAXN=1e5+5;

int n;
char s[MAXN];
vector<int> E[MAXN];

int main(){
    scanf("%s",s+1);
    int n=strlen(s+1);
    if(s[1]=='0'||s[n]=='1') return puts("-1"),0;
    for(int i=1;i<=n/2;i++)
        if(s[i]!=s[n-i]) return puts("-1"),0;
    printf("1 2\n");
    int last=2;
    for(int i=2;i<n;i++){
        if(s[i]=='0') printf("%d %d\n",last,i+1);
        else printf("%d %d\n",last,i+1),last=i+1;
    }
}



Measured memory_bytes: 3840
n,m = list(map(int, input().split()))
flag = 0

if n%2!=0:
    for i in range(m):
        print(i+1,n-i)
else:
    for i in range(m):
        if ((n-i)-(i+1))<=n-((n-i)-(i+1)):
            flag = 1
        if flag==0:
            print(i+1,n-i)
        else:
            print(i+1,n-i-1)

Measured memory_bytes: 9280
h,w=map(int,input().split())
ans=min(h,w)
if h%3==0 or w%3==0:
  print(0)
  exit(0)
for hi in range(1,h):
  mi=min(w*hi,w//2*(h-hi),(w-w//2)*(h-hi))
  ma=max(w*hi,w//2*(h-hi),(w-w//2)*(h-hi))
  ans=min(ans,ma-mi)
for wi in range(1,w):
  mi=min(h*wi,h//2*(w-wi),(h-h//2)*(w-wi))
  ma=max(h*wi,h//2*(w-wi),(h-h//2)*(w-wi))
  ans=min(ans,ma-mi)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb2l(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
#define  mat vector<vector<ll>>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n;
    cin>>n;
    map<ll,ll>mp;
    ll x;
    vll v(n);
    fr(i,0,n){
        cin>>x;
        v[i]=x;
        mp[x]++;
    }
    ll ans=0;
    for(auto xx:mp){
       ll k=xx.ss;
      ans+=(k*(k-1))/2;
    }
    for(auto xx:v){
        ll k=mp[xx];
      ans-=(k*(k-1))/2;
      k--;
      ans+=(k*(k-1))/2;
      cout<<ans<<endl;
      ans-=(k*(k-1))/2;
      k++;
      ans+=(k*(k-1))/2;
      
    }
}
int main(){
    ll t=1;
   // cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
    return 0;
}

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

using namespace std;
const int mod = 1000000007;
const int N = 200005;

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

	int n;
	cin>>n;
	int arr[n];
	vector<int> ans(n,INT_MAX);
	for(int i=0;i<n;i++)
		cin >> arr[i];
	ans[0] = 0;
	for(int i=0;i<n-1;i++){
		ans[i+1] = min(ans[i+1],ans[i]+abs(arr[i] - arr[i+1]));
		if(i+2 < n)
		ans[i+2] = min(ans[i+2],ans[i]+abs(arr[i] - arr[i+2]));
	}
	cout<<ans[n-1];
	return 0;
}

Measured memory_bytes: 1024