akhauriyash/Code-Regression huggingface dataset:
a,b,c=[list(input()) for _ in range(3)]
x=a[0]
while True:
    if x=="a":
        if a==[]:
            ans="A"
            break
        else:
            x=a.pop(0)
    elif x=="b":
        if b==[]:
            ans="B"
            break
        else:
            x=b.pop(0)
    else:
        if c==[]:
            ans="C"
            break
        else:
            x=c.pop(0)
print(ans)


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
"""
Created on Tue May 14 15:12:42 2019

@author: avina
"""

N,M = map(int, input().split())
k = list(map(int, input().split()))
k = set(k[1:])
for i in range(N-1):
  l = list(map(int, input().split()))
  k = k & set(l[1:])
print(len(k))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define faster() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define mx_int_prime 999999937
#define mem(a,b) memset(a, b, sizeof(a) )
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef long double ld;
const int mx=2e5+125;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
ll p[mx],a[mx],b[mx];
void solve()
{
    string s,t;
    cin>>s>>t;
    int c=0;
    int mx=0;
    int len1=s.size();
    int len2=t.size();
    int w=(len1-len2)+1;
    int i,j;
    int ck=0;
    while(w--)
    {
        c=0;
        for(i=ck,j=0; j<len2; j++,i++)
        {
            if(s[i]==t[j])
                c++;
        }
        mx=max(c,mx);
        ck++;
    }
    cout<<len2-mx<<endl;


}
int main()
{
    faster();
    int tc;
    tc=1;
    while(tc--)
        solve();
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <sstream>
#include <vector>
#include <map>
using namespace std;

int main()
{
	int n;

	cin >> n;

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

	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int r,g,b,sum;
    scanf("%d %d %d",&r,&g,&b);
    sum=r*100+g*10+b;
    if(sum%4==0){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}



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

int main(){
  int N, c, t;
  cin >> N;
  t = N;
  c = 0;
  //tが0以上なら継続
  while(t > 0){
    c += t % 10; 
    t = t / 10;
  }
  if (N % c == 0){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	string s;
	cin>>s;
	a=s[0]-'0';
	b=s[1]-'0';
	c=s[2]-'0';
	d=s[3]-'0';
	if(a+b+c+d==7)
	{
		cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7";
		return 0;
	}
	if(a+b+c-d==7)
	{
		cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7";
		return 0;
	}
	if(a+b-c+d==7)
	{
		cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7";
		return 0;
	}
	if(a+b-c-d==7)
	{
		cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7";
		return 0;
	}
	if(a-b+c+d==7)
	{
		cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7";
		return 0;
	}
	if(a-b+c-d==7)
	{
		cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7";
		return 0;
	}
	if(a-b-c+d==7)
	{
		cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7";
		return 0;
	}
	if(a-b-c-d==7)
	{
		cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7";
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] x = new int[n];
    int[] y = new int[n];
    for (int i = 0;i<n;i++){
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
    }
    double ans = 0;
    for (int i = 0;i<n-1;i++){
      for (int j = i+1;j<n;j++){
        ans += Math.sqrt(Math.pow(x[i]-x[j],2)+Math.pow(y[i]-y[j],2));
      }
    }
    ans = ans/(n*(n-1)/2)*(n-1);
    System.out.println(ans);
  }
}

Measured memory_bytes: 22996
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

//#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

class UnionFindTree {
public:
    vector<ll> m_parents; // 親ノードの番号を格納。-1なら自分自身が親(root)

                          // 頂点数で初期化。最初は全てのノードが非連結。
    UnionFindTree(ll x) : m_parents(x, -1) {}

    // xがどのグループに属しているかを調べる。
    ll root(ll x) {
        if (m_parents[x] < 0) {
            return x;
        }
        m_parents[x] =
            root(m_parents[x]); // 高速化のため、親を根に繋ぎかておく。
        return m_parents[x];
    }

    // 自分の属するグループの頂点数を調べる。
    ll size(ll x) { return -m_parents[root(x)]; }

    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) {
            return false; // すでにくっついているからくっつけない。
        }

        // ノード番号の大きい方(x)に小さい方(y)をくっつけたい。
        if (size(x) < size(y))
            swap(x, y);

        // xのサイズを更新。
        m_parents[x] += m_parents[y];
        // yの親をxにする。
        m_parents[y] = x;
        return true;
    }

    // 同じグループか？
    bool is_same_group(ll x, ll y) { return root(x) == root(y); }
};

int main() {
    ll N, M; cin >> N >> M;
    vector<ll> A(M), B(M);
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
    }

    UnionFindTree uf(N);
    ll ans = 0;
    for (int i = 0; i < M; i++) {
        UnionFindTree uf(N);
        for (int j = 0; j < M; j++) {
            // 辺i以外の辺を使ってみる。
            if (j != i) {
                uf.merge(A[j], B[j]);
            }
        }

        int root_num = 0;
        for (int i = 0; i < N; i++) {
            if (uf.root(i) == i) {
                root_num++;
            }
        }
        // グラフ全体が連結なら根は1つ。非連結なら2つ以上。
        // 辺iを含まないことで非連結なグラフになっている -> 辺iは橋だったということがわかる
        if (1 < root_num) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))

e = []
for v in p:
    if v % 2 == 0:
        e.append(((v+1)*(v//2)) / v)
    else:
        e.append(((v+1)*(v//2) + (v+1) // 2) / v)

e_sum = [0]

for i in range(len(e)):
    e_sum.append(e_sum[i] + e[i])

ans = 0

for i in range(k, len(e_sum)):
    ans = max(ans, e_sum[i] - e_sum[i-k])

print(ans)


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

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

int main() {
	int N1, N2, N3, N4;
	cin >> N1 >> N2 >> N3 >> N4;
	if(((1 << N1) | (1 << N2) | (1 << N3) | (1 << N4)) == ((1 << 1) | (1 << 9) | (1 << 7) | (1 << 4)))
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void solve() {
  int w, h;
  cin >> w >> h;
  int minW = 0;
  int maxW = w;
  int minH = 0;
  int maxH = h;
  int n; cin >> n;
  for(int i = 0; i < n; ++i) {
    int x, y, op;
    cin >> x >> y >> op;
    if(op == 1) {
      minW = max(minW, x);
    } else if(op == 2) {
      maxW = min(maxW, x);
    } else if(op == 3) {
      minH = max(minH, y);
    } else {
      maxH = min(maxH, y); 
    }
  }
  // cout << minW << " " << maxW << " " << minH << " " << maxH << endl;
  int ansW = maxW-minW;
  int ansH = maxH-minH;
  if(ansW <= 0 || ansH <= 0)cout << "0\n";
  else cout << ansW*ansH << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tc = 1;
  // cin >> tc;
  for(int i = 1; i <= tc; ++i) {
    // cout << "Case #" << i <<": ";
    solve();
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	static String S;
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
			 S = sc.next();

		sc.close();
		int z = S.length()-1;

		String plus = "";
		int result = 0;
		long ans = 0;
		int tmp = 0 ;

		String [] pp = new String[9];

		for(int i = 1 ; i < Math.pow(2, S.length()-1) ; i++){
			String bin = Integer.toBinaryString(i);
			plus = String.format("%0"+z+"d", Integer.parseInt(bin));

	        for (int j = 0; j < plus.length(); j++) {
	            result = plus.indexOf("1", j);
	            if (result != -1) {
	                ans += Integer.parseInt(S.substring(j,result+1));
	                tmp = result;
	                j = result;
	            }
	        }

	        ans += Integer.parseInt(S.substring(tmp+1,S.length()));

		}
		ans += Long.parseLong(S);
		System.out.println(ans);

	}
}

Measured memory_bytes: 22100
#include "bits/stdc++.h"

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;

void solve() {
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif
	int n;
	cin >> n;
	vector<ll> v(n);

	rep(k, n) cin >> v[k];

	sort(all(v));

	int ans = 0, i = 0;
	ll sum = 0;
	while (i < n){
		sum += v[i];
		int j = i + 1;
		while (j < n - 1) {
			if (sum * 2 >= v[j]) {
				sum += v[j++];
			}  else
				break;
		}
		if (j == n - 1) {
			ans = n - i;
			break;
		}
		i = j;
	}

	
	cout << ans << endl;
}




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


	solve();
#ifdef _WIN32
	system("PAUSE");
#endif
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"

signed main()
{
    FAST;
    
    int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
    int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
    int left=0,up=0,down=0,start=0,end=0,r=0,qq=0,total=0;
    int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
    int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
    
    cin>>i>>j;
    if(j>=i) cout<<"unsafe"<<endl;
    
    else cout<<"safe"<<endl;
    
    
    
    
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

int main() {
    string s; cin >> s;
    int n = sz(s);
    vector<int> rec;
    int cnt = 0;
    rep(i, n-1) {
        if (s[i] == 'R' && s[i+1] == 'L') {
            rec.push_back(i);
        }
    }
    vector<int> ans(n);
    for (int x : rec) {
        int l = 1; int r = 1;
        int y = x;
        while (y > 0 && s[y-1] == 'R') {
            y--;
            if ((x-y) % 2 == 1) {
                l++;
            }
            else {
                r++;
            }
        }
        y = x+1;
        while (y+1 < n && s[y+1] == 'L') {
            y++;
            if ((y-x) % 2 == 1) {
                l++;
            }
            else {
                r++;
            }
        }
        ans[x] = r;
        ans[x+1] = l;
    }

    rep(i, n) {
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 1280
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <limits>
using namespace std;
typedef long long ll;

const double pi = atan(1) * 4;

struct Pt {
	double x, y, z;
	Pt(double r, double a, double b){
		// aが上下
		// bが回転
		if(a < 0)a += 360;

		a = (a / 360) * 2 * pi;
		b = (b / 360) * 2 * pi;

		y = r * sin(a);

		double t = r * cos(a);

		x = t * cos(b);
		z = t * sin(b);
	}
};

double getDist(Pt a, Pt b){
	double dx = a.x - b.x;
	double dy = a.y - b.y;
	double dz = a.z - b.z;

	return sqrt(dx * dx + dy * dy + dz * dz);
}

const double r = 6378.1;
const double k = 2 * r * r;

int main(){
	double a, b, c, d;

	while(cin >> a >> b >> c >> d){
		if(a == -1 && b == -1 && c == -1 && d == -1)break;

		Pt A(r, a, b), B(r, c, d);

		double D = getDist(A, B);

		double theta = acos((D * D - k) / -k);
		double dist = r * theta;

		int dist_a = (int)(dist + 0.5);
		int dist_b = (int)(2 * pi * r - dist + 0.5);

		cout << min(dist_a, dist_b) << endl;

	}
	return 0;
}

Measured memory_bytes: 1272
def judge(my, another):
    if my == another:
        return 0
    elif my == 'g':
        return -1
    else:
        return 1

s = input()

g, p = 0, 0
point = 0
for c in s:
    if p >= g:
        #print("自分の手はグー")
        point += judge('g', c)
        g += 1
    else:
        #print("自由に選べる")
        if c == 'g':
            point += 1
            p += 1
        else:
            p += 1

        
print(point)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod=1000000007;
constexpr ll INF=(1ll<<60);
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}

int main(){
    ll n;cin>>n;string s;cin>>s;
    if(n%2){
        cout<<"No"<<endl;
        return 0;
    }
    bool yes=true;
    rep(i,n/2){
        if(s[i]!=s[i+n/2]) yes=false;
    }

    if(yes){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;

void solve(){
    int n, l;
    cin >> n >> l;
    vector <string> v(n);
    
    for(int i = 0; i < n; i++) cin >> v[i];
    sort(all(v));
    
    for(int i = 0; i < n; i++) cout << v[i];
}

 
int main() {
    barsik;
    int q = 1;
    //cin >> q;
    while(q--) solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int n,max_int,second_max_int;
    cin >> n;

    vector<int> v_a(n);
    vector<int> v_b(n);
    for(int i=0; i<n; i++) cin >> v_a[i];

    v_b = v_a;

    sort(v_b.begin(), v_b.end());
    reverse(v_b.begin(), v_b.end());

    for(int j = 0; j < n; j++){
        if (v_a[j] != v_b[0]){
            cout << v_b[0] << '\n' ;
        } else {
            cout << v_b[1] << '\n' ;
        }
    }
  
  return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 16;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

vector <int> conn[55];
int ans = 0;
int par[55];
int dep[55];
int low[55];
bool dchk[55];
void DFS(int n) {
	low[n] = dep[n];
	dchk[n] = true;
	for (auto it : conn[n]) {
		if (it == par[n]) continue;
		if (dchk[it]) {
			low[n] = min(low[n], dep[it]);
			continue;
		}
		par[it] = n;
		dep[it] = dep[n] + 1;
		DFS(it);
		if (low[it] > dep[n]) ans++;
		low[n] = min(low[n], low[it]);
	}
}
int main() {
	int N, M, i, j;
	scanf("%d %d", &N, &M);
	for (i = 1; i <= M; i++) {
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		conn[t1].push_back(t2);
		conn[t2].push_back(t1);
	}
	DFS(1);
	return !printf("%d\n", ans);
}

Measured memory_bytes: 256
def actual(x1, y1, x2, y2):
    a = x2 - x1
    b = y2 - y1

    x3, y3 = x2 - b, y2 + a
    x4, y4 = x3 - a, y3 - b

    # return f'{x3} {y3} {x4} {y4}'
    return '{} {} {} {}'.format(x3, y3, x4, y4)

x1, y1, x2, y2 = map(int, input().split())
print(actual(x1, y1, x2, y2))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define N 100009
using namespace std;

int n,tot,fa[N],fst[N],pnt[N<<1],nxt[N<<1]; bool tg[N];
void gg(){
	puts("First"); exit(0);
}
void add(int x,int y){
	pnt[++tot]=y; nxt[tot]=fst[x]; fst[x]=tot;
}
void dfs(int x){
	int i,y;
	for (i=fst[x]; i; i=nxt[i]){
		y=pnt[i];
		if (y!=fa[x]){
			fa[y]=x; dfs(y);
			if (tg[x]&&tg[y]) gg();
			tg[x]|=tg[y];
		}
	}
	tg[x]^=1;
	if (x==1 && tg[x]) gg();
}
int main(){
	scanf("%d",&n);
	int i,x,y;
	for (i=1; i<n; i++){
		scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
	}
	dfs(1);
	puts("Second");
	return 0;
}


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

const int inf = 1e9;
const ll linf = 1e18;

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

    int h, w, d; cin >> h >> w >> d;
    vector<pair<int, int>> v(h*w);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int a; cin >> a; a--; // 0-indexed
            v[a] = make_pair(i, j);
        }
    }

    vector<vector<int>> s(d, vector<int>(1, 0));
    for (int i = d; i < h * w; i++) {
        int x, y, nx, ny;
        tie(x, y) = v[i - d], tie(nx, ny) = v[i];
        s[i % d].push_back(s[i % d].back() + abs(nx - x) + abs(ny - y));
    }

    int q; cin >> q;
    for (int i = 0; i < q; i++) {
        int l, r; cin >> l >> r; l--, r--; // 0-indexed
        int mod = l % d;
        cout << s[mod][r / d] - s[mod][l / d] << endl;
    }

    return 0;
}

Measured memory_bytes: 6144
#include<stdio.h>
#include<string.h>
int main()
{
    char str[105];
    gets(str);
    int len,i;
    len=strlen(str);
    for(i=0;i<len;i+=2)
    {
        if(str[i]=='L'||str[i+1]=='R')
        {
             printf("No\n");
             return 0;
        }
    }
    printf("Yes\n");

}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
int n;
int sg(int x, int k) {
    if (x % k == 0) return x / k;
    int t = x % k;
    return sg(x-max(1, t/((x/k)+1))*((x/k)+1), k);
}

int main() {
    int ans = 0;
    cin >> n;
    while (n --) {
        int a, k;
        cin >> a >> k;
        ans ^= sg(a, k);
    }
    printf("%s\n", (!ans)?"Aoki":"Takahashi");
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path;
//***********//
int main() {
	cin >> N >> M;
	vl A(N);
	vl B(N);
	for (i = 0; i < N; i++) {
		B[i] = 0;
	}
	if (N == 1) {
		A[0] = 0;
	}
	else {
		A[0] = 1;
		for (i = 1; i < N; i++) {
			A[i] = 0;
		}
	}
	for (i = 0; i < M; i++) {
		ll s, c;
		cin >> s >> c;
		if (B[s-1] == 0 || A[s-1] == c) {
			A[s - 1] = c;
			B[s-1] = 1;
		}
		else {
			cout << -1;
			exit(0);
		}
	}
	if (N != 1 && A[0] == 0) {
		cout << -1;
		exit(0);
	}
	for (i = 0; i < N; i++) {
		cout << A[i];
	}
}


Measured memory_bytes: 256
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let _: usize = scan(tokens);
    let s: String = scan(tokens);
    let mut d1 = vec![false; 10];
    let mut d2 = vec![vec![false; 10]; 10];
    let mut d3 = vec![vec![vec![false; 10]; 10]; 10];
    for b in s.bytes() {
        let k = (b - b'0') as usize;
        for i in 0..10 {
            if d1[i] {
                for j in 0..10 {
                    if d2[i][j] {
                        d3[i][j][k] = true;
                    }
                }
                d2[i][k] = true;
            }
        }
        d1[k] = true;
    }
    let mut ans = 0;
    for i in 0..10 {
        for j in 0..10 {
            for k in 0..10 {
                if d3[i][j][k] {
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int la,lb;
    cin>>la>>lb;
    char stra[2002],strb[2002];
    ++la;++lb;
    for(int i=1;i<la;++i){
        cin>>stra[i];
    }
    for(int i=1;i<lb;++i){
        cin>>strb[i];
    }
    int ***dp;
    dp=new int**[la+1];
    for(int i=0,nmax=la+1;i<nmax;++i){
        dp[i]=new int*[lb+1];
        for(int j=0,mmax=lb+1;j<mmax;++j){
            dp[i][j]=new int[2]{0};
        }
    }
    int ans=0;
    for(int i=0;i<la;++i){
        for(int j=0;j<lb;++j){
            if(stra[i+1]=='I'){
                dp[i+1][j][1]=max(dp[i+1][j][1],dp[i][j][0]+1);
            }else{
                dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][1]==0?0:dp[i][j][1]+1);
            }
            if(strb[j+1]=='I'){
                dp[i][j+1][1]=max(dp[i][j+1][1],dp[i][j][0]+1);
            }else{
                dp[i][j+1][0]=max(dp[i][j+1][0],dp[i][j][1]==0?0:dp[i][j][1]+1);
            }
        }
    }
    for(int i=0;i<la;++i){
        for(int j=0;j<lb;++j){
            for(int k=0;k<2;++k){
                ans=max(ans,dp[i][j][k]);
            }
        }
    }
    if(ans!=0&&ans%2==0){
        --ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 159712
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            String x =Console.ReadLine();
            String[] xArray = x.Split(' ');
            int tate = int.Parse(xArray[0]);
            int yoko = int.Parse(xArray[1]);

            int menseki = tate*yoko;
            int syuu = (tate+yoko)*2;
            Console.WriteLine("{0} {1}", menseki, syuu);
           
        }
    }
}

Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
void rcmb(ll *x,ll s,ll r,function<void(ll *)>f){if(r==0){f(x);}else{if(s<0)return;rcmb(x,s-1,r,f);x[r-1]=s;rcmb(x,s-1,r-1,f);}}
void cmb(ll n,ll k,function<void(ll *)>f){ll x[k];rcmb(x,n-1,k,f);}
void prm(ll n,function<void(ll *)>f){ll x[n];for(ll i=0;i<n;i++)x[i]=i;do{f(x);}while(next_permutation(x,x+n));}
void prm(ll n,ll k,function<void(ll *)>f){cmb(n,k,[&](ll *c){prm(k,[&](ll *p){ll x[k];for(ll i=0;i<k;i++){x[i]=c[p[i]];}f(x);});});}
// prm(4, 2, [](ll *x){ cout << x[0] << "," << x[1] << "\n"; });


int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
	vector<pair<ll ,ll>> AB(N);
    for(int i = 0 ; i < N ; i++){
		ll A, B;
		cin >> A >> B;
		AB[i].first = A;
		AB[i].second = B;
    }

	ll res = 0;
	ll c = 0;
	ASC(AB);
	REP(i, N) {
		if (c < M) {
			ll need = AB[i].second;
			chmin(need, M-c);
			res += AB[i].first * need;
			c += need;
		} else break;
	}
	cout << res << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD=1000000007;
const ll INF=1000000000LL;
const int MAX=100001;
const double EPS=1e-10;
struct edge{int to,cost;};
typedef pair<int,int> P;
int V;
vector<edge> G[214514];
int d[214514];
void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>>que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();
        que.pop();
        int v=p.second;
        if(d[v]<p.first){
            continue;
        }
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(){
    int n,m;
    cin>>n>>m;
    V=n;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;a--;b--;
        G[a].push_back({b,1});
        G[b].push_back({a,1});
    }
    dijkstra(0);
    if(d[n-1]==2){
        cout<<"POSSIBLE"<<endl;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
    }
}

Measured memory_bytes: 15464
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    string s;
    cin >> s;

    if (s[2] == s[3]  and s[4] ==  s[5] ) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

using namespace std;

int a, b, c, d, e;

int main()
{
    cin >> a >> b >> c >> d >> e;
    if(a==0)
        cout << 1 << endl;
    else if(b==0)
        cout << 2 << endl;
    else if(c==0)
        cout << 3 << endl;
    else if(d==0)
        cout << 4 << endl;
    else if(e==0)
        cout << 5 << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int arr[100005][4];
int dp[100005][2][2][2];

int fun(int n,int op1,int op2,int op3)
{
    if(n==0) return 0;
    if(dp[n][op1][op2][op3]!=-1) return dp[n][op1][op2][op3];
    int ans1=0,ans2=0,ans3=0;
    if(op1) ans1=arr[n][1]+fun(n-1,0,1,1);
    if(op2) ans2=arr[n][2]+fun(n-1,1,0,1);
    if(op3) ans3=arr[n][3]+fun(n-1,1,1,0);
    return dp[n][op1][op2][op3]=max({ans1,ans2,ans3});
}

int main()
{
   int n;cin>>n;
   for(int i=1;i<=n;i++)
    for(int j=1;j<=3;j++)  cin>>arr[i][j];
   for(int i=1;i<=n;i++)
    for(int j=0;j<2;j++)
    for(int k=0;k<2;k++)
    for(int m=0;m<2;m++)  dp[i][j][k][m]=-1;
   int ans=fun(n,1,1,1);
   cout<<ans<<"\n";
}





Measured memory_bytes: 12800
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        s: String
    };

    let res = "x".repeat(s.len());
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2224
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll N;
  cin >> N;

  vll A(N);
  ll sum = 0;
  rep(i, N) {
    cin >> A[i];
    sum += A[i];
  }

  vll ans(N);
  ll X1 = sum;
  rep(i, N) {
    if (i % 2 == 0) {
      continue;
    }
    X1 -= 2 * A[i];
  }
  ans[0] = X1;

  rep(i, N) {
    if (i == 0) {
      continue;
    }
    ans[i] = 2 * A[i - 1] - ans[i - 1];
  }

  rep(i, N) {
    if (i == 0) {
      cout << ans[i];
    } else {
      cout << " " << ans[i];
    }
  }
  ENDL;

  return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>

int main(){
	
	int j,c;
	char s[100001],i;
	
	scanf("%s",&s);
	
	for(i='a';i<='z';i++){
		c=1;
		for(j=0;j<strlen(s);j++){
			if(s[j]==i){
				c=0;
				break;
			}
		}
		if(c==1)break;
	}
	
	if(c==1)printf("%c\n",i);
	else printf("None\n");
	
	return 0;
}



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

int main(){

  int cnt_s, cnt_r, b[3];

  cnt_s = 0;
  cnt_r = 0;
  while(scanf("%d, %d, %d", &b[0], &b[1], &b[2]) != EOF){
    if(b[0] * b[0] + b[1] * b[1] == b[2] * b[2]){
      if(b[0] != b[1]){
        cnt_s++;
      }
    }
    else if(b[0] == b[1]){
      cnt_r++;
    }
  }

  cout << cnt_s << endl << cnt_r << endl;

  return 0;

}

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

int n,q;
vector<int>G[(int)2e6];
vector<int>E((int)2e6,0);
vector<int>flag((int)2e6,0);

void dfs(int x){
    flag[x]=1;
    REP(i,G[x].size()){
        if(flag[G[x][i]])continue;
        E[G[x][i]]+=E[x];
        dfs(G[x][i]);
    }
}

void solve() 
{
    cin>>n>>q;
    REP(i,n-1){
        int a,b;cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    REP(i,q){
        int p,x;cin>>p>>x;
        E[p]+=x;
    }
    dfs(1);
    REP(i,n)cout<<E[i+1]<<" ";cout<<endl;
}

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

Measured memory_bytes: 80512
c1 = list(map(int, input().split()))
c2 = list(map(int, input().split()))
c3 = list(map(int, input().split()))

flag = 0
if c1[0]-c1[1] != c2[0]-c2[1] or c1[0]-c1[1] != c3[0]-c3[1]:
    flag = 1
if c1[0]-c1[2] != c2[0]-c2[2] or c1[0]-c1[2] != c3[0]-c3[2]:
    flag = 1
if c1[2]-c1[1] != c2[2]-c2[1] or c1[2]-c1[1] != c3[2]-c3[1]:
    flag = 1
if c1[0]-c2[0] != c1[1]-c2[1] or c1[0]-c2[0] != c1[2]-c2[2]:
    flag = 1
if c1[0]-c3[0] != c1[1]-c3[1] or c1[0]-c3[0] != c1[2]-c3[2]:
    flag = 1
if c3[0]-c2[0] != c3[1]-c2[1] or c3[0]-c2[0] != c3[2]-c2[2]:
    flag = 1

if flag:
    print('No')
else:
    print('Yes')


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

n = int(input())
s = []
h = []
c = []
d = []

for i in range(13):
    s.append(i + 1)
    h.append(i + 1)
    c.append(i + 1)
    d.append(i + 1)

for j in range(n):
    x = list(input().split())
    if x[0] is 'S':
        s.remove(int(x[1]))
    elif x[0] is 'H':
        h.remove(int(x[1]))
    elif x[0] is 'C':
        c.remove(int(x[1]))
    elif x[0] is 'D':
        d.remove(int(x[1]))

if len(s) != 0:
    for i in range(len(s)):
        print('{0} {1}'.format('S', s[i]))

if len(h) != 0:
    for i in range(len(h)):
        print('{0} {1}'.format('H', h[i]))

if len(c) != 0:
    for i in range(len(c)):
        print('{0} {1}'.format('C', c[i]))

if len(d) != 0:
    for i in range(len(d)):
        print('{0} {1}'.format('D', d[i]))


Measured memory_bytes: 5616
#include<cstdio>
int n,a[200001];
long long ans=0;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	if(a[1]!=0){
		puts("-1");return 0;
	}
	for(int i=1;i<n;i++){
		if(a[i+1]-a[i]>1){
			puts("-1");return 0;
		}
		if(a[i+1]-a[i]==1) ans++;
		else ans+=1ll*a[i+1];
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
using namespace std;
bool palin(string s){
	for(int i=0;i<s.length()/2;i++){
    	if(s[i]!=s[s.length()-i-1]) return false;
    }
  return true;
}
int main(){
	string s;
  cin>>s;
  string s1=s.substr(0,(s.length()-1)/2);
  string s2=s.substr(((s.length()+3)/2)-1,s.length()+1-(s.length()+3)/2);
//   cout<<s1<<" "<<s2<<"\n";
  if(palin(s) && palin(s1) && palin(s2)) cout<<"Yes\n";
  else cout<<"No\n";
}

Measured memory_bytes: 256
N,*A=`dd`.split.map &:to_i;r=[0]*(N*N);B=[*1..N].sort_by{|i|r[A[i-1]-1]=i;A[i-1]};H={};s=Hash.new 0
z=[];N.times{|i|H[A[i]-1]=i+1;n=B[N-i-1];z=[n]*~-n+z+[B[i]]*(N-B[i])}
(N*N).times{|i|r[i]=z.shift if r[i]==0}
puts (N*N).times.any?{|i|s[r[i]]+=1;H[i]&&H[i]!=s[r[i]]}?:No:"Yes\n"+r*' '

Measured memory_bytes: 86752
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))

const int INF = 1000000009;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);

const int MAX = 2e5;

ll N, K;
ll I, O, T, J, L, S, Z;

int main() {
  cin >> I >> O >> T >> J >> L >> S >> Z;
  ll ans = (I/2+J/2+L/2)*2;
  if (I>0 && J>0 && L>0) ans = max(ans, 3+((I-1)/2+(J-1)/2+(L-1)/2)*2);
  cout << O+ans << endl;

  return 0;
}

Measured memory_bytes: 256
#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 INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
	int n;
	cin >> n;
    vector<int> v(n);
    REP(i, n) cin >> v[i];
    int ans = 1;
    int tmp = v[0];

    REP(i, n){
        if(tmp > v[i]){
            tmp = v[i];
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int N = 51;

int c[N][N][N];

int n, m;
int ans = 0;

void eval(vector<int> a) {
	int cur = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			cur += c[i][j][a[j] - a[i]];
		}
	}
	ans = max(ans, cur);
}

void gen(int pos, int lst, vector<int> &a) {
	if (pos == n) {
		eval(a);
	} else {
		for (int i = lst; i <= m; i++) {
			a.push_back(i);
			gen(pos + 1, i, a);
			a.pop_back();
		}
	}
}

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

	int q;
	cin >> n >> m >> q;
	while (q--) {
		int aa, bb, dl, dd;
		cin >> aa >> bb >> dl >> dd;
		aa--;
		bb--;
		c[aa][bb][dl] += dd; 
	}
	vector<int> a;
	gen(0, 1, a);
	cout << ans << endl;
}


Measured memory_bytes: 3228
#include <iostream>

using namespace std;

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    int ans = 0;
    for (int i = 100; i > 0; i-- ) {
        if (A % i == 0 && B % i == 0) {
            ans++;
            if(ans == K){
                cout << i << endl;
            }
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin>>vec[i];}
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";}
#define S second
#define F first
const int  MOD = 1e9 + 7;
const int MSK = (1<<22);
const int  N = 25;
ll n , g[N][N] , dp[N][MSK];

ll rec(ll i , ll msk){
    if(dp[i][msk] != -1) return dp[i][msk];
    if (i == n){
        if (msk == (1<<n) - 1) {
            return 1;
        } else return 0;
    }
    dp[i][msk] = 0;
    for(int j = 0 ; j < n; j++){
        if (g[i][j] && !(msk & (1<<j) ) ) dp[i][msk] = (dp[i][msk] + rec ( i+1, msk|(1<<j) ) ) %MOD;
    }
    return dp[i][msk];
}

//  a d f j k  l  ;
int main(){
    ios::sync_with_stdio(0);  cin.tie(0);
    cin>>n;
    for(int i = 0 ; i < n; i++){
        for(int j = 0 ; j < n; j++){
            cin>>g[i][j];
        }
    }
    memset(dp,-1,sizeof dp);
    cout<<rec(0,0)<<endl;

    return 0;
}

Measured memory_bytes: 819456
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>


typedef long long ll;

using namespace std;

int main() 
{ 

	string s;
	cin >> s;

	if (s[0] == s[1] && s[1] == s[2]){
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}

	return 0; 
} 


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
#include<cassert>
using namespace std;
#include<atcoder/all>
using namespace atcoder;


#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

/////////////////////////////////////


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

	dsu d(N);
	repn(q, Q) {
		ll t, u, v;
		cin >> t >> u >> v;
		if (t == 0) {
			d.merge(u, v);
		}
		if (t == 1) {
			if (d.same(u, v)) { cout << 1 << endl; }
			else { cout << 0 << endl; }
		}
	}
}


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

int main(void) {

	int n;
	cin >> n;

	int b,f,r,v;
	int a[4][3][10] = {};

	for(int i=0;i<n;i++) {
		cin >> b >> f >> r >> v;
		a[b-1][f-1][r-1] += v;
	}

	for(int i=0;i<4;i++) {
		for(int j=0;j<3;j++) {
			for(int k=0;k<10;k++) {
				cout << " " << a[i][j][k];
			}
			cout << endl;
		}
		if(i != 3) {
			cout << "####################" << endl;
		}

	}

	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC032
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] h = Console.ReadLine().Split(' ').Select(z => int.Parse(z)).ToArray();

            List<int> a = h.ToList();
            List<int> list = new List<int>();
            for (int i = 0; i < N; i++)
            {
                int j = 0;
                for (j = N-i - 1; j >= 0; j--)
                {
                    int k = a[j];
                    if (k == j + 1)
                    {
                        list.Add(k);
                        a.RemoveAt(j);
                        break;
                    }                    
                }
                if (j < 0)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
            list.Reverse();
            foreach (int r in list)
            {
                Console.WriteLine(r);
            }
        }
    }
}


Measured memory_bytes: 13396
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			for(int i = 0 ; i < n ; i++){
				int pm = sc.nextInt();
				int pe = sc.nextInt();
				int pj = sc.nextInt();
				if(pm == 100 || pe == 100 || pj == 100){
					System.out.println("A");
				}else if(90 <= (pm+pe)/2){
					System.out.println("A");
				}else if(80 <= (pm+pe+pj)/3){
					System.out.println("A");
				}else if(70 <= (pm+pe+pj)/3){
					System.out.println("B");
				}else if(50 <= (pm+pe+pj)/3 && 80 <= pm || 80 <= pe){
					System.out.println("B");
				}else{
					System.out.println("C");
				}
			}
		}
		sc.close();
	}

}

Measured memory_bytes: 28260
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>


int main() {
	int x, y, z; std::cin >> x >> y >> z;
	int n, m, s, t; std::cin >> n >> m >> s >> t; --s; --t; t += n;
	std::vector<std::pair<int, int>> sands;
	for (auto i = 0; i < n; ++i) {
		int sand, katsu; std::cin >> sand >> katsu;
		sands.emplace_back(--sand, --katsu + x);
	}
	for (auto i = 0; i < m; ++i) {
		int katsu, curry; std::cin >> katsu >> curry;
		sands.emplace_back(--katsu + x, --curry + x + y);
	}
	std::vector<std::vector<int>> pair(x + y + z);
	for (const auto p : sands) {
		pair[p.first].push_back(p.second);
		pair[p.second].push_back(p.first);
	}
	std::vector<int> distance(x + y + z, -2);
	std::queue<int> stack;
	distance[sands[s].first] = distance[sands[s].second] = 0;
	stack.push(sands[s].first); stack.push(sands[s].second);
	while (!stack.empty()) {
		const auto top = stack.front(); stack.pop();
		for (const auto next : pair[top]) if (distance[next] == -2) {
			distance[next] = distance[top] + 1;
			stack.push(next);
		}
	}
	std::cout << ((distance[sands[t].first] != distance[sands[t].second]) ? std::max(distance[sands[t].first], distance[sands[t].second]) : distance[sands[t].first] + 1) << std::endl;
}


Measured memory_bytes: 19480