akhauriyash/Code-Regression huggingface dataset:
using System.Collections.Generic;
using System.Linq;
using System;

public class C
{
    public const int INF = 99999;
    public const int MINF = -99999;
}

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var m = int.Parse(line[1]);
            if (n == 0 && m == 0) break;
            var s = new int[n];
            for (int i = 0; i < m; i++)
            {
                var x = Console.ReadLine().Trim();
                if (x == "A") doA(s, n, 1);
                else if (x == "B") doB(s, n, 2);
                else if (x == "C") doC(s, n, 3);
                else doD(s, n, 4);
            }
            display(s);
        }

    }
    public static void display(int[] s)
    {
        foreach (var x in s)
            if (x == 1) Console.Write("A");
            else if (x == 2) Console.Write("B");
            else if (x == 3) Console.Write("C");
            else if (x == 4) Console.Write("D");
            else Console.Write("#");
        Console.WriteLine();
    }
    public static void doA(int[] s, int n, int A)
    {
        for (int i = 0; i < n; i++)
            if (s[i] == 0) { s[i] = A; break; }
    }
    public static void doB(int[] s, int n, int B)
    {
        if (n == 1) { s[0] = B; return; }
        if ( n-2 >= 0 &&  s[n - 1] == 0 && s[n - 2] != 1) { s[n - 1] = B; return; }
        for (int i = n - 2; i >= 1; i--)
            if (s[i] == 0 && s[i + 1] != 1 && s[i - 1] != 1) { s[i] = B; return; }
        if (s[0] == 0 && s[1] != 1) { s[0] = B; return; }
        doA(s, n, B);
    }
    public static void doC(int[] s, int n, int C)
    {
        if (n == 1) { s[0] = C;  return; }
        if (s.Sum() == 0)
        {
            if (n % 2 == 0) s[n / 2 ] = C;
            else s[(n + 1) / 2 -1] = C;
            return;
        }
        for (int i = 0; i < n; i++)
        {
            if (s[i] != 0 && (i + 1 < n) && s[i + 1] == 0) { s[i + 1] = C; return; }
            else if (s[i] != 0 && (i - 1 >= 0) && s[i - 1] == 0) { s[i - 1] = C; return; }
        }
    }
    public static void doD(int[] s, int n, int D)
    {
        if (s.Sum() == 0) { s[0] = D; return; }
        var abc = new List<int>();
        if (s[0] == 0) abc.Add(C.MINF);
        else abc.Add(0);
        for (int i = 1; i < n - 1; i++)
            if (s[i] != 0) abc.Add(i);
        if (s[n - 1] == 0) abc.Add(C.INF);
        else abc.Add(n - 1);
        var maxp = -1; var wL = 0; var maxL = -1;
        for (int i = 1; i < abc.Count(); i++)
        {
            var t = (abc[i] + abc[i - 1]) / 2;
            if (t < 0) { maxp = 0; maxL = abc[i] - 1; }
            else if (t > n - 1)
            {
                wL = n - 2 - abc[i - 1];
                if (wL > maxL) { maxL = wL; maxp = n - 1; }
            }
            else
            {
                if (t == i - 1) continue;
                wL = t - abc[i - 1] - 1;
                if (wL > maxL) { maxL = wL; maxp = t; }
            }
        }
        s[maxp] = D;
    }
}

Measured memory_bytes: 9288
package main

import (
	"bufio"
	"errors"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	for stdin.Scan() {
		in := stdin.Text()
		out, _ := do(in)
		fmt.Println(out)
	}

}

func do(in string) (string, error) {
	num, _ := strconv.Atoi(in)
min:
	for i := num; i < 4*num; i++ {
		for j := 2; j < int(math.Sqrt(float64(num))+1); j++ {
			if i%j == 0 {
				continue min
			}
		}
		return strconv.Itoa(i), nil
	}
	return "0", errors.New("foo")
}


Measured memory_bytes: 640
#include<stdio.h>
int x[5],sum,z[5],z2[5],i;
int func(int w){
	//	printf("sum=%d\n",sum);
	if(w==3){
		if(sum==7){
			for(i=0;i<3;i++){
				z2[i]=z[i];
			}
		}
	}
	else{
		z[w]=0;
		sum+=x[w+1]; func(w+1); sum-=x[w+1];
		z[w]=1;
		sum-=x[w+1]; func(w+1); sum+=x[w+1];
	}
}
int main(void)
{
	int a,s;
	char n[]="+-";
	scanf("%d",&a);
	s=1000;
	for(i=0;i<4;i++){
		x[i]=a/s;
		a-=x[i]*s;
		s/=10;
	}
	sum=x[0];
	func(0);
	// for(i=0;i<5;i++) printf("%d\n",z2[i]);
	printf("%d%c%d%c%d%c%d=7\n",x[0],n[z2[0]],x[1],n[z2[1]],x[2],n[z2[2]],x[3]);
	return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parents[self.find(x)]


################################
N, M, K = map(int, input().split())
uf = UnionFind(N + 1)
friends = [set() for _ in range(N + 1)]
blocks = [set() for _ in range(N + 1)]

for _ in range(M):
    a, b = map(int, input().split())
    friends[a].add(b)
    friends[b].add(a)
    uf.union(a, b)

for _ in range(K):
    c, d = map(int, input().split())
    blocks[c].add(d)
    blocks[d].add(c)

ans = []

for i in range(1, N + 1):
    group_size = uf.size(i)
    friend_cnt = len(friends[i])
    block_cnt = 0
    for j in blocks[i]:
        if uf.same(i, j):
            block_cnt += 1
    suggest_cnt = group_size - friend_cnt - block_cnt - 1
    ans.append(suggest_cnt)

print(*ans)


Measured memory_bytes: 152388
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };



class UnionFind {
public:
	int n;
	vi par; //親
	vi ran; //木の深さ
	vi num; //要素数

	UnionFind(int _n) {
		n = _n;
		par.resize(n); ran.resize(n); num.resize(n);
		for (int i = 0; i < n; i++) {
			par[i] = i; ran[i] = 0; num[i] = 1;
		}
	}

	//木の根を求める
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	//xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		int numsum = num[x] + num[y];
		if (x == y) {
			return;
		}
		if (ran[x]<ran[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (ran[x] == ran[y]) {
				ran[x]++;
			}
		}
		num[x] = num[y] = numsum;
	}

	//xとyが同じ集合に属するか否か
	bool same(int x, int y) {
		return find(x) == find(y);
	}

};




int main() {
	int n, i, j;
	cin >> n;
	UnionFind uf1(n), uf2(n);
	int k, l;
	cin >> k >> l;
	for (i = 0; i < k; i++) {
		int p, q;
		cin >> p >> q;
		p--; q--;
		uf1.unite(p, q);
	}
	for (i = 0; i < l; i++) {
		int p, q;
		cin >> p >> q;
		p--; q--;
		uf2.unite(p, q);
	}
	vector<pii> p(n);
	map<pii, int> num;
	for (i = 0; i < n; i++) {
		p[i] = pii(uf1.find(i), uf2.find(i));
		num[p[i]]++;
	}
	for (i = 0; i < n; i++) {
		cout << num[p[i]] << " ";
	}
	cout << endl;
}

Measured memory_bytes: 18048
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
tentosu1=0
mod=10**9+7
for i in range(N):
    for j in range(N):
        if i<j and A[i]>A[j]:
            tentosu1+=1
tentosu1%=mod
D=dict()
for i in range(N):
    if A[i] in D:
        D[A[i]]+=1
    else:
        D[A[i]]=1
difftento=0
S=(K*(K-1))//2
S%=mod
for i in D:
    for j in D:
        if i>=j:
            continue
        difftento+=S*D[i]*D[j]
        difftento%=mod
print((((tentosu1*K)%mod)+difftento)%mod)


Measured memory_bytes: 42204
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define rg register
#define LL long long
#define __space putchar(' ')
#define __endl putchar('\n')
#define debug printf("Time Test: %d\n", clock())
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');
}
int n, emm;
int a[233333];
int main()
{
	read(n);
	for (rg int i = 1; i <= n; ++i) read(a[i]), emm ^= a[i];
	if (!emm) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 640
import bisect

n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))

ans = 0
for i in t:
    ind = bisect.bisect_left(s, i)
    if ind<n and s[ind]==i:
        ans += 1
print(ans)


Measured memory_bytes: 16736
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    if ((A + B) > (C + D)) cout << "Left" << endl;
    else if ((A + B) < (C + D)) cout << "Right" << endl;
    else cout << "Balanced" << endl;
}

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

int main() {
	int d,n;
	cin >> d >> n;
	if(n==100){
		n++;
	}
	if(d==0){
		cout << n << endl;
	}
	else if(d==1){
		cout << 100*n << endl;
	}
	else{
		cout << 10000*n << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;
public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		HashSet<Integer> list = new HashSet<Integer>();
		list.add(0);
		for(int i = 0; i < n; i++) {
			int l = sc.nextInt();
			if(!list.contains(l)) {
				list.add(l);
			}else{
				break;
			}
		}
		if(list.size() == n+1)pw.print("YES");
		else pw.print("NO");
		pw.close();
	}
	static  class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

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

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

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

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

using namespace std;


int main(){
  int N=0;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin>>N;
  string str=to_string(N);
  if(str.find("7")!=string::npos)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3724
#include <stdio.h>
int a, b, c, x;
int main() {
	scanf("%d%d%d", &a, &b, &c);
	if (a == b)x++;
	if (b == c)x++;
	if (c == a)x++;
	if (x == 1)printf("Yes\n");
	else printf("No\n");
}

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

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;



int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	int n;
	cin >> n;
	set <string> st;
	while (n--) {
		string s;
		cin >> s;
		st.insert(s);
	}
	cout << st.size();
}


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

int main() {
    int n;
    cin >> n;
    vector<long long> a(n);
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
        sum += a.at(i);
    }

    long long left = 0;
    long long mini = 1000000000000000ll;
    for (int i = 0; i < n; i++) {
        left += a.at(i);
        sum -= a.at(i);

        mini = min(mini, abs(left - sum));
    }
    cout << mini << endl;
}

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

int main () {
  	int n;
  	cin >> n;
  	int c = 1;
  	for (int i = 0; i < n; ++i) {
    	int a;
      	cin >> a;
      	if (a == c) ++c;
    }
  	int ret = (c>1) ? n - c + 1 : -1;
  	cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N;
  string S;
  cin >> S;
  if(S.size() == 3){
    reverse(S.begin(),S.end());
    cout << S << endl;
  }else
    cout << S << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int K;

template<typename T>
T gcd(T a, T b){
    if(b > a) swap(a, b);
    T tmp;
    while(b != 0){
        tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

signed main(){
    cin >> K;
    ll ans = 0;
    for(int i=1; i<=K; i++){
        for(int j=1; j<=K; j++){
            for(int k=1; k<=K; k++){
                ans += gcd(i, gcd(j, k));
            }
        }
    }
    cout << ans << endl;
}

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

int main(){
        int n, m;
        std::cin >> n;
        std::map<std::string, int> dict;
        std::string s;
        for(int i=0; i<n; i++){
                std::cin >> s;
                dict[s]++;
        }
        std::cin >> m;
        for(int i=0; i<m; i++){
                std::cin >> s;
                dict[s]--;
        }
        int ans = 0;
        for(auto p: dict) ans = std::max(ans, p.second);
        std::cout << ans << std::endl;
        return 0;
}

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

int main(){
	int N,M,X;
	cin >> N >> M >> X;
	vector<vector<int>> A(N,vector<int>(M+1));
	vector<int> V(M+1);

	for(int i=0; i<N; i++){
		for(int j=0; j<M+1; j++){
			cin >> A[i][j];
		}
	}

	ll ans = 1e9; 
	for(int bit=0; bit<(1<<N); bit++){
		bool f=true;
		ll t=0;
		vector<int> v(M);
		for(int i=0; i<N; i++){
			if(bit & (1<<i)){
				for(int j=1; j<=M; j++){
					v[j-1] += A[i][j];
				}
				t += A[i][0];
			}
		}
		for(int i=0; i<M; i++){
			if(v[i]<X)f = false;
		}
		if(f)ans = min(ans,t);
	}
	if(ans == 1e9)cout << -1 << endl;
	else cout << ans << endl;;
	


	

	return 0;
}



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

int main()
{
	int a, b;
	string sa;
	string sb;

	cin >> a >> b;

	for (int i = 0; i < b; i++) {
		sa += (char)(a + '0');
	}
	for (int i = 0; i < a; i++) {
		sb += (char)(b + '0');
	}

	if (sa <= sb) cout << sa << endl;
	else  cout << sb << endl;
	
	return 0;
}

Measured memory_bytes: 256
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,p = map(int,input().split())
s = list(map(int,input().split()))
x,y,ans = 0,0,0
for i in s:
    if i%2 == 0:
        x += 1
    else:
        y += 1

if p == 1:
    k = 0
    for i in range(1,y+1,2):
        k += comb(y,i)
    g = 0
    for i in range(x+1):
        g += comb(x,i)
    print(k*g)
else:
    g = 0
    for i in range(x+1):
        g += comb(x,i)
    k = 0
    for i in range(0,y+1,2):
        k += comb(y,i)
    print(k*g)

Measured memory_bytes: 9236
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <climits>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<string> check={"AC","WA","TLE","RE"};
  int num[4]={0};
  vector<string>::iterator itr;
  int ind=0;
  for(int i=0;i<n;i++){
    string tmp;
    cin >> tmp;
    itr=find(check.begin(),check.end(),tmp);
    ind=distance(check.begin(),itr);
    num[ind]++;
  }
  for(int i=0;i<4;i++){
    cout << check.at(i) << " x " << num[i] << endl;
  }
}

Measured memory_bytes: 3592
eval'N,M,A,*B='+`dd`.split*?,
s=[x=0]*9*M
B.map{|b|c=b;A>b&&b+=M;x+=t=b-A
[0,M].map{|m|s[m-~A]+=1;s[m+b]-=t;s[m-~b]+=t-1}
A=c}
2.times{c=0;s=s.map{|s|c+=s}}
p x-s.max

Measured memory_bytes: 56008
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];

  ll ans = 0, keta = 1;
  rep(i, 30) {
    vector<int> am(n), bm(n);
    rep(j, n) {
      am[j] = a[j] % (keta * 2);
      bm[j] = b[j] % (keta * 2);
    }
    sort(bm.begin(), bm.end());

    ll res = 0;
    rep(j, n) {
      res += lower_bound(bm.begin(), bm.end(), keta * 2 - am[j]) - lower_bound(bm.begin(), bm.end(), keta - am[j]);
      res += lower_bound(bm.begin(), bm.end(), keta * 4 - am[j]) - lower_bound(bm.begin(), bm.end(), keta * 3 - am[j]);
      res %= 2;
    }
    if (res) ans += keta;
    keta *= 2;
  }

  cout << ans << endl;


  
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  set<char> st;
  vector<int> board(26);
  for(int i = 0; i < (int)s.size(); i++) {
    if(st.count(s[i]) == 0) {
      st.insert(s[i]);
      board[s[i] - 'a'] = 1;
    }
    if((int)st.size() == 26) {
      cout << "None" << endl;
      return 0;
    }
  }
  string ans = "";
  rep(i, 26) {
    if(board[i] == 0) {
      ans = i + 'a';
      cout << ans << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int MOD = 1000000007;
const int N = 21;

int n, i, j, k, act, prevv, t[N], w, tab[1<<N][N], ind[1<<N];
LL res[2][1<<N];

int main() {
scanf("%d", &n);
for (i=0;i<n;i++) {
	t[i] = 0;
	for (j=0;j<n;j++) {
		scanf("%d", &w);
		t[i] = t[i] * 2 + w;
	}
}
for (i=0;i<(1<<n);i++) {
	ind[i] = 0;
	for (j=0;j<n;j++) if (i & (1<<j)) tab[i][ind[i]++] = j;
}

for (i=0;i<(1<<n);i++) res[0][i] = __builtin_popcount(t[0] & i);
for (j=1;j<n;j++) {
	act = j % 2;
	prevv = 1 - act;
	for (i=0;i<(1<<n);i++) {
		res[act][i] = 0;
		for (k=0;k<ind[i];k++) if ((t[j] & (1<<tab[i][k]))) {
			res[act][i] = res[act][i] + res[prevv][i - (1<<tab[i][k])];
		}
		res[act][i] = (res[act][i] % MOD);
		//cout << j << " " << i << " " << res[act][i] << endl;
	}
}
printf("%d\n", res[act][(1<<n) - 1] % MOD);
return 0;
}

Measured memory_bytes: 213248
N, M =map(int, input().split())
L = []
R = []
for i in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
if min(R)-max(L)>=0:
  print(min(R)-max(L)+1)
else:
  print(0)

Measured memory_bytes: 10996
#include <stdio.h>

int main(){
  int n;
  scanf("%d\n",&n);
  
  switch(n % 10){
      case 2:
      case 4:
      case 5:
      case 7:
      case 9:
        puts("hon");
        break;
      case 0:
      case 1:
      case 6:
      case 8:
        puts("pon");
        break;
      case 3:
        puts("bon");
        break;
  }
  return 0;
}


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)

int dx[4]={1, -1, 0, 0};
int dy[4]={0, 0, 1, -1};

int main(void) {
    int n, y, t, sum;
    cin >> n >> y;
    REP(i, n+1){
        REP(j, n+1){
            t = n - (i + j);
            sum = i * 10000 + j * 5000 + t * 1000;
            if(t >= 0  && sum == y) {
                printf("%d %d %d\n", i, j, t);
                return 0;
            }
        }
    }
    printf("-1 -1 -1\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
long long n,m,nr,k,ans;
long long p[100001];
bool l[100001];
string s;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>nr>>s;
        if(l[nr]==1) continue;
        if(s=="WA")
            p[nr]++;
        else
        {
            l[nr]=1;
            k++;
            ans+=p[nr];
        }
    }
    cout<<k<<" "<<ans;
	return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <iostream>
#include <string>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    set<string> us;
    int n;
    cin >> n;
    rep (i, n) {
        string s;
        cin >> s;
        us.insert(s);
    }
    int m;
    cin >> m;
    bool f = false;
    rep (i, m) {
        string s;
        cin >> s;
        if (us.count(s)) {
            cout << (f ? "Closed" : "Opened") << " by " << s << endl;
            f = !f;
        }
        else {
            cout << "Unknown " << s << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1232
//shara's here
//SPEEEEEEEEEED IS KEEEEEEEEEEY
//REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAD
#include <bits/stdc++.h>
using namespace std;
typedef string s;
typedef long long ll;
typedef long double ld;
#if !defined(ONLINE_JUDGE)
#include "C:\debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define ins insert
#define vl vector<ll>
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
int main(){
    ll n , sum = 0;
    cin >> n;
    for( ll i = 1; i <= n; i++ ){
        if(i%5&&i%3)sum+=i;
    }
    cout << sum << endl;































return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define MP make_pair
#define pb push_back
#define read2(a, b) (read(a), read(b))
#define read3(a, b, c) (read(a), read(b), read(c))
#define lop(i,a,b) for(register int i = (a); i <= (b); ++i)
#define dlop(i,a,b) for(register int i = (a); i >= (b); --i)
#define eps (1e-7)
#define fir first
#define sec second

const int inf = 0x3f3f3f3f-1;
const int MAXN = 1e6+7;
typedef long long LL;
typedef long double LF;
typedef pair<int,int> pii;
typedef unsigned long long ULL;
typedef unsigned int uint;
template<class T> void read(T & x) {
  register int c = getchar(), f = 1; x = 0;
  while(!isdigit(c)) {if (c == '-') f = -f; c = getchar();}
  while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x *= f;
}
int n, m;

char str[300006];
int prew[300006];
int main(void) {
  #ifdef LOCAL_DEBUG
  // freopen("data.in", "r", stdin);
  #endif
  int cnt;
  cin >> cnt;
  scanf("%s", str+1);
  int ans = 0x3f3f3f3f;
  int len = strlen(str+1);
  for(int i = 1; i <= len; ++i) 
    prew[i] = prew[i-1] + (str[i] == 'W');
  for(int i = 1; i <= len; ++i) {
    int cnt1 = prew[i-1], cnt2 = len-i-(prew[len] - prew[i]);
    ans = min(cnt1+cnt2, ans);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <tuple>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
    ll x, y;
    cin >> x >> y;
    ll ans = max(0ll, (4 - x) * 100000) + max(0ll, (4 - y) * 100000);
    cout << ans + 400000 * (x * y == 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pll = pair<ll, ll>;
const ll mod = 1000000007;
const ll inf = 1000000000000;//10の12乗
long long keta(long long x){
  int y=0;
  while(x!=0){
    y++;
    x/=10;
  }
  return y;
}

int main() {
  int n;
  cin >> n;
  int nt=0,nx=0,ny=0;
  rep(i,n){
    int t,x,y;
    cin >> t >> x >> y;
    int cost=abs(nx-x)+abs(ny-y);
    if((t-nt-cost)%2!=0){
      cout << "No" << endl;
      return 0;
    }
    if(t-nt<cost){
      cout << "No" << endl;
      return 0;
    }
    nx=x;
    ny=y;
    nt=t;
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3632
fn main() {
    let mut sc = Scanner::new();
    let a: (f64, f64) = (sc.read(), sc.read());
    let b: (f64, f64) = (sc.read(), sc.read());
    let c: (f64, f64) = (sc.read(), sc.read());

    let ab = dist(a, b);
    let bc = dist(b, c);
    let ca = dist(c, a);

    let s = (ab + bc + ca) / 2.0;
    let t = (s * (s - ab) * (s - bc) * (s - ca)).sqrt();
    let r = t / s;

    let m = max(ab, max(bc, ca));
    let x = r / (2.0 * r / m + 1.0);
    println!("{}", x);
}

fn max(a: f64, b: f64) -> f64 {
    if a > b {
        a
    } else {
        b
    }
}

fn dist(a: (f64, f64), b: (f64, f64)) -> f64 {
    let (x, y) = a;
    let (z, w) = b;
    let dx = x - z;
    let dy = y - w;
    (dx * dx + dy * dy).sqrt()
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


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

int D, G;
int minQ;
vector<int> p;
vector<int> c;
string checked = "          ";

/*中途半端に解く配点は 1 種類以下であり、それ以外の配点は完全に解くかまったく解かない。
  中途半端に解く配点があるなら、それは完全に解く配点以外の配点の中で最も高い配点である。*/
void minQuestion(int max, int q, int n) {
  if(max <= 0) {
//cout << checked << "," << q << "," << n << endl;
    if (q < G) {
      int i;
      for (i = D - 1; i >= 0; i--) {
        if (checked.at(i) == '0') {
          break;
        }
      }
      if (i < 0) {
        return;
      }
      for (int j = 1; j < p.at(i); j++) {
        q += 100 * (i + 1);
        if (q >= G) {
          minQ = min(minQ, n + j);
          return;
        }
      }
    }
    else {
      minQ = min(minQ, n);
    }
    return;
  }
  max--;
  checked.at(max) = '1';
  int num = p.at(max);
  minQuestion(max, q + 100 * (max + 1) * num + c.at(max), n + num);
  checked.at(max) = '0';
  minQuestion(max, q, n);
}

int main() {

  cin >> D >> G;

  for (int i = 0; i < D; i++) {
    int pi, ci;
    cin >> pi >> ci;
    p.push_back(pi);
    c.push_back(ci);
  }

  minQ = 1001;

  minQuestion(D, 0, 0);

  cout << minQ << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <functional>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 3000000;

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


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


// テーブルを作る前処理
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;
    }
}

// 二項係数計算
long long 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;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
            prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
} 

vector<ll> divisor;
void list_divisor(ll n) {
    divisor.clear();
    for(int i = 1; i*i <= n; i++) {
        if(n % i == 0) {
            divisor.push_back(i);
            if(i*i != n) divisor.push_back(n/i);
        }
    }
    sort(divisor.begin(), divisor.end());
}

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

    list_divisor(M);
    ll ret = 1;
    for(ll i = 0; i < (ll)divisor.size(); i++) {
        if(divisor[i] * N > M) break;
        ret = divisor[i];
    }

    cout << ret << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i=0;i<N;i++) {
    cin >> d.at(i);
  }
  
  int premax=0, k=0;
  
  for(int i=0;i<N;i++) {
    
  int max=0, maxnum=0;      

 	for(int i=0;i<N;i++) {
  	  if(d.at(i)>max) {
        max=d.at(i);
        maxnum=i;
      }
  	}
    
    if(max!=premax) k++;
    
    premax=max;
    d.at(maxnum)=0;

  }
  
  cout << k << endl;
  
}

Measured memory_bytes: 3604
// atcoder ARC? C

#include <bits/stdc++.h>

#define MOD 1000000007

#define ll long long

using namespace std;
ll n, m, i, j, k, cf[200005], now, a[200005], ans = 1, sum, check1, check2;
char s[200005];

ll read() {
    char ch = getchar();
    ll s = 0;
    while (ch < '0' || ch > '9')
        ch = getchar();
    while (ch >= '0' && ch <= '9') {
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s;
}

int main() {
    n = read();
    scanf("%s", s + 1);
    for (i = 1; i <= 2 * n; i++)
        if (s[i] == 'W' && (now & 1) == 0 || s[i] == 'B' && (now & 1) == 1) {
            a[i] = 2;
            now ^= 1;
            check1++;
        } else {
            a[i] = 1;
            now ^= 1;
            check2++;
        }
    for (i = 1; i <= 2 * n; i++) {
        if (a[i] == 1)
            sum++;
        else {
            ans = ans * sum % MOD;
            sum--;
        }
    }
    if (check1 != check2) {
        cout << 0 << endl;
        return 0;
    }
    for (i = 1; i <= n; i++)
        ans = ans * i % MOD;
    printf("%lld\n", ans);
    return 0;
}


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

int main()
{
    int i = 1;
    while (true)
    {
        int x;
        scanf("%d", &x);
        if (x == 0)
            break;
        printf("Case %d: %d\n", i, x);
        i++;
    }
}


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

class bigint {
	deque<uint8_t> val;

public:
	bigint( const string& s ) {
		for( auto c: s ) {
			val.push_front( c - '0' );
		}
	}

	void add( const bigint& b ) {
		int x = 0;
		int i = 0;

		for( ; i < b.val.size(); ++i ) {
			if( i >= val.size() ) {
				val.push_back( 0 );
			}

			x += val[i] + b.val[i];
			val[i] = x % 10;
			x /= 10;
		}

		for( ; x > 0; ++i ) {
			if( i >= val.size() ) {
				val.push_back( 0 );
			}

			x += val[i];
			val[i] = x % 10;
			x /= 10;
		}
	}

	int length() const {
		return (int)val.size();
	}

	void print() const {
		for( int i = (int)val.size()-1; i >= 0; --i ) {
			cout << (int)val[i];
		}

		cout << '\n';
	}
};

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

	int N;
	cin >> N;

	for( int i = 0; i<N; ++i ) {
		string a, b;
		cin >> a >> b;

		bigint x( a );
		x.add( b );

		if( x.length() <= 80 ) {
			x.print();
		}
		else {
			cout << "overflow" << '\n';
		}
	}
}



Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll N;scanf("%lld",&N);
    char S[N],T[N];
    scanf("%s %s",S,T);
    ll ans;char now;
    rep(i,N){
        if(i==0){
            if(S[i]==T[i])ans=3,now='X';
            else ans=6,now='Y',i++;
        }
        else if(S[i]==T[i]){
            if(now=='X')ans*=2;
            else now='X';
        }
        else{
            if(now=='X')ans*=2,now='Y',i++;
            else ans*=3,i++;
        }
        ans%=MOD;
    }
    printf("%lld %s",ans,"\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

class dice
{
	int ue,mae,migi,hidari,sita,usiro;
	public:
	dice(int a,int b,int c,int d,int e,int f)
	{
		ue = a;
		mae = b;
		migi = c;
		hidari = d;
		sita = f;
		usiro = e;
	}
	void N()
	{
		swap(ue,mae);
		swap(mae,sita);
		swap(sita,usiro);
	}
	void S()
	{
		swap(ue,usiro);
		swap(usiro,sita);
		swap(sita,mae);
	}
	void E()
	{
		swap(ue,hidari);
		swap(hidari,sita);
		swap(sita,migi);
	}
	void W()
	{
		swap(ue,migi);
		swap(migi,sita);
		swap(sita,hidari);
	}
	int top()
	{
		return ue;
	}
};

int main()
{
	int a,b,c,d,e,f;
	cin >> a >> b >> c >> d >> e >>f;
	string s;
	cin >> s;
	dice D = dice(a,b,c,d,e,f);
	int n = s.size();
	for(int i = 0;i<n;i++)
	{
		if(s[i]=='N')D.N();
		else if(s[i]=='S')D.S();
		else if(s[i]=='E')D.E();
		else if(s[i]=='W')D.W();
	}
	cout<<D.top()<<endl;
	return 0;
}


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

using namespace std;

struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> size;

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

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

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

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

int main()
{
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a, b);
    }

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans = max(ans, uf.size[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 4844
#include <cstdio>
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main()
{
    int s;
    char t[10];
    map<string, int> res;
    while( scanf( "%d,%s", &s, t ) != -1 ) {
        ++res[t];
    }

    cout << res["A"] << endl
         << res["B"] << endl
         << res["AB"] << endl
         << res["O"] << endl;
}

Measured memory_bytes: 1220
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

int main(){

    int N;
    cin >> N;

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

    i = 0;
    int j = N-1;
    
    unsigned long former = A.at(i);
    unsigned long latter = A.at(j);

    while(j-1 != i){
        if(former <= latter){
            i++;
            former += A.at(i);
        }
        else{
            j--;
            latter += A.at(j);
        }
    }

    unsigned long ans;
    if(former >= latter) ans = former - latter;
    else ans = latter - former;

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1792
#ifndef VS
#include<bits/stdc++.h>
#endif

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int main() {
	map<char, LL> in;
	int N;
	cin >> N;
	for (int i : range(N)) {
		string p; cin >> p;
		in[p[0]]++;
	}
	string s = "MARCH";
	sort(ALL(s));
	set<string> x;
	do {
		string t = s.substr(0, 3);
		sort(ALL(t));
		x.insert(t);
	} while (next_permutation(ALL(s)));
	LL ret = 0;
	for (auto &it : x) {
		ret += in[it[0]] * in[it[1]] * in[it[2]];
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
def solve() :
    n = int(input())
    a = list(map(int, input().split()))

    hsum = 0
    hmax = a[0]
    for i in range(len(a)-1) :
        if hmax >= a[i+1] :
            hsum += hmax - a[i+1]

        else :
            hmax = a[i+1]

    print(hsum)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 105068
#include<bits/stdc++.h>
//#define REP(i,n) for (int i = 0; i < n; i++)
//#define REP(j,m) for (int j = 0; j < m; j++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define lli long long int
#define INF 1000000000
#define endl '\n'
#define ll 	long long
#define pi acos(-1.0)
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;

using namespace std;

int main()
{
	int a,b;
	cin>>a>>b;
	
	cout<<6-(a+b)<<"\n";
}

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

int main(){
    int input = 1;
    vector<int> data(10000);
    bool isFinish=false;
    int i=0;
    for(;isFinish!=true;i++){
        cin >> data[i];
        if(data[i]==0){
            isFinish = true;
        }
    }
    for(int j=0;j<i-1;j++){
        cout << "Case " << j+1 << ": " << data[j] << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF=1e9;

template<typename T,bool directed>//directedは有向のこと
struct Fordfulkerson{
  struct edge{
    int to,cap,rev;
    edge(){}
    edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
  };

  vector<vector<edge> > G;
  vector<int> used;

  Fordfulkerson(){}
  Fordfulkerson(int n):G(n),used(n){}//n個の頂点

  void add_edge(int from,int to,T cap){
    G[from].emplace_back(to,cap,G[to].size());//edgeのrevには逆辺の番号が入る
    G[to].emplace_back(from,directed?0:cap,G[from].size()-1);//有向グラフならcapは0
  }

  T dfs(int v,int t,T f){//v->tにfの流量を道が見つかり次第通していく感じ　通った量が返り値
    if(v==t) return f;//ゴール
    used[v]=true;//通った確認
    for(int i=0;i<(int)G[v].size();i++){
      edge &e = G[v][i];
      if(!used[e.to]&&e.cap>0){//まだ通ってなくてcap的にいける場所があるなら
        T d=dfs(e.to,t,min(f,e.cap));//そこからtまで通せるだけ通そうとして見る
        if(d>0){//dだけ通った
          e.cap-=d;//流量を減らす
          G[e.to][e.rev].cap+=d;//逆辺の流量を増やす
          return d;//d通せた
        }
      }
    }
    return 0;
  }

  int flow(int s,int t,T lim){
    T fl=0;
    while(1){
      fill(used.begin(),used.end(),0);//usedの初期化
      T f=dfs(s,t,lim);//sからtまで逆辺を考慮しつつ通す
      if(f==0) break;//全く通らないなら終了
      fl+=f;//通ってるなら流量を増やす
      lim-=f;//初期流量を減らす
    }
    return fl;
  }

  int flow(int s,int t){//全力で流す
    return flow(s,t,numeric_limits<T>::max()/2);
  }

};

signed main(){
  int N,M,S,T,U,V;cin>>N>>M>>S>>T>>U>>V;
  Fordfulkerson<int,0> fl(123456),fl2(123456);
  while(M--){
    int u,v;cin>>u>>v;
    fl.add_edge(u,v,1);
    fl2.add_edge(u,v,1);
  }
  fl.add_edge(123400,S,INF);
  fl.add_edge(123400,U,INF);
  fl.add_edge(T,123401,INF);
  fl.add_edge(V,123401,INF);
  fl2.add_edge(123400,S,INF);
  fl2.add_edge(123400,V,INF);
  fl2.add_edge(T,123401,INF);
  fl2.add_edge(U,123401,INF);
  cout<<min(fl.flow(123400,123401),fl2.flow(123400,123401))<<endl;
}



Measured memory_bytes: 26240
package main

import (
	"fmt"
)

func main(){
	var n int
	var word string
	var is_end bool
	fmt.Scan(&n)
	list := make([]string, n)
	fmt.Scan(&list[0])
	for i:=1; i<n; i++{
		fmt.Scan(&word)
		if word[0] != list[i-1][len(list[i-1])-1]{
			is_end = true
			break
		}
		for j:=0; j<i; j++{
			if word == list[j]{
				is_end = true
			}
		}
		list[i] = word
		if is_end{
			break
		}
	}
	if is_end{
		fmt.Println("No")
	}else{
		fmt.Println("Yes")
	}
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
using R = double;

const int limit = 100010;

using edge = struct { int to; ll cost; };

vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d) {
	depth[v] = d;
	for (auto &e : tree[v]) {
		if (e.to == p)continue;
		dfs(e.to, v, d + e.cost);
	}
}	

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

	for (int i = 0; i < n - 1; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		tree[a].push_back({ b,c });
		tree[b].push_back({ a,c });
	}

	int q, k;
	cin >> q >> k;
	k--;

	dfs(k, -1, 0);
	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		cout << depth[x] + depth[y] << endl;
	}


}

Measured memory_bytes: 14336