akhauriyash/Code-Regression huggingface dataset:
#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;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1, 0), b(m + 1, 0);
  rep(i, n) cin >> a[i + 1];
  rep(i, m) cin >> b[i + 1];

  rep(i, n) a[i + 1] += a[i];
  rep(i, m) b[i + 1] += b[i];
  int ans = 0;
  rep(i, n + 1) {
    if (k - a[i] < 0) break;
    int res = upper_bound(b.begin(), b.end(), k - a[i]) - b.begin() - 1;
    res += i;
    chmax(ans, res);
  }
  cout << ans << '\n';

  




  
  return 0;
}

Measured memory_bytes: 6336
n = int(input())

def chrinc(s,n):
  return chr(ord(s)+1)

def dfs(s,mx):
  if len(s) == n:
    print(s)
  else:
    c = 'a'
    while c <= mx:
      dfs(s+c, chrinc(mx,1) if c==mx else mx)
      c = chrinc(c,1)

dfs('','a')

Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define foo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define min3(a,b,c)         min(a,min(b,c))
#define max3(a,b,c)         max(a,max(b,c))
#define min4(a,b,c,d)       min(a,min(b,min(c,d)))
#define max4(a,b,c,d)       max(a,max(b,max(c,d)))
#define max5(a,b,c,d,e)     max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)     min(min3(a,b,c),min(d,e))
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void DFS(int n);
bool isprime(ll n);
ll gcd(ll a,ll b);
void rstgraph(int n);

const int mod = pow(10,9)+7;
const int N = 3e5, M = N;

//=======================================================================================
vi g[N];
int vis[N];
int nodes=0;

void iluzn() {
ll a,b;
cin>>a>>b;
cout<<(a*b)/gcd(a,b);
}

 
int main() {
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t=1,i;
    // cin>>t;
     while(t--) iluzn();
    return 0;
}
int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}
bool isprime(ll n){
    if(n<=1)
        return false;
    if(n==2)
        return true;
    if(n%2==0)
        return false;
    ll rt = sqrt(n);
    for(ll i=3;i<rt;i+=2){
        if(n%i==0)
            return false;
    }
    return true;
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
void ipgraph(int m){
  int u, v;
  while(m--){
    cin>>u>>v;
    g[u].pb(v);
    // g[v].pb(u);
  }
}

void DFS(int n)
{  ++nodes;
    vis[n] = 1;
    for(vector<int>::iterator i = g[n].begin(); i != g[n].end() ; i++)
    {
        if(!vis[*i])
            DFS(*i);
    }
}
void rstgraph(int n){
  int i;
  fo(i,n+1){
    g[i].clear();
    vis[i]=0;
  }
  nodes=0;
}

Measured memory_bytes: 10696
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int M=998244353,N=100005;
int n,m;
signed main(){
	scanf("%lld",&n);int ans=1e12;
	for (int i=1;i<=1000000;i++)
		if (n%i==0)ans=min(ans,n/i+i);
	printf("%lld\n",ans-2);	
}

Measured memory_bytes: 384
// ref: https://img.atcoder.jp/abc113/editorial.pdf
// ref: https://atcoder.jp/contests/abc113/submissions/3540482


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    const int mod = 1000000007;
    
    int H, W, K; cin >> H >> W >> K;
    vector<vector<int>> dp(H+1, vector<int>(W, 0)); dp[0][0] = 1;
    
    for(int hi=0; hi<H; ++hi){
        for(int wi=0; wi<W; ++wi){
            for(int ls=0; ls< 1<<(W-1); ++ls){ // lines: ls
                
                bool isConnected=false; // check if the two horizontal lines are connected.
                for(int i=0; i<W-2; ++i){
                    if( (ls>>i)&1 && (ls>>(i+1))&1 ){ isConnected=true; break; }
                }
                if(isConnected){ continue; }
                
                if( wi>=1 && (ls>>(wi-1))&1 ){
                    dp[hi+1][wi-1] += dp[hi][wi];
                    dp[hi+1][wi-1] %= mod;
                }else if( wi<=W-2 && (ls>>wi)&1 ){
                    dp[hi+1][wi+1] += dp[hi][wi];
                    dp[hi+1][wi+1] %= mod;
                }else{
                    dp[hi+1][wi+0] += dp[hi][wi];
                    dp[hi+1][wi+0] %= mod;
                }
            }
        }
    }
    cout << dp[H][K-1] << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector <int> vec[(1<<16)+1];
long long n,i,j,a[101][101],sum[(1<<16)+1],f[(1<<16)+1],tt,cnt,d[(1<<16)+1];
void BFS(int s)
{
    queue <int> q;
    cnt++;
    q.push(s); d[s]=cnt;
    while(q.size()>0)
    {
        int u=q.front(); q.pop();
        for(int i=0;i<vec[u].size();i++)
        {
            int v=u+(1<<vec[u][i]);
            if(d[v]<cnt)
            {
                q.push(v); d[v]=cnt;
             //   cerr<<f[s]+sum[v-s]<<'\n';
                f[v]=max(f[v],f[s]+sum[v-s]);
            }
        }
    }
}
int main()
{
    //freopen("group.inp","r",stdin);
    //freopen("group.out","w",stdout);
    cin>>n;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++) cin>>a[i][j];
    for(tt=0;tt<(1<<n);tt++)
    {
        for(i=0;i<n;i++)
            if(!((tt>>i)&1)) vec[tt].push_back(i);
        for(i=0;i<n;i++)
            for(j=i+1;j<n;j++)
                if(((tt>>i)&1) && ((tt>>j)&1)) sum[tt]+=a[i][j];
    }
    f[tt]=0;
    for(tt=0;tt<(1<<n);tt++) BFS(tt);
    cout<<f[(1<<n)-1];
}


Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,w=100000;
    cin>>n;
    double num,ans;
    cin>>ans;
    ans/=w;
    for(int i=1;i<n;i++){
        cin>>num;
        num/=w;
        ans+=num;
    }
    ans/=n;
    int kawa=ans*w;
    cout<<kawa<<endl;
}

Measured memory_bytes: 1228
n = int(input())

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

sum = 0

prev = -1

for now in a:
    sum += b[now-1]

    if(now == prev + 1):
        sum += c[prev-1]

    prev = now

print(sum)

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

using namespace std;

int main() {

	ios_base :: sync_with_stdio(0); cin.tie(NULL);
	

	int n, k;
	cin >> n >> k;

	vector<int> P(n);
	for(int &x : P) cin >> x;

	vector<int> sum(n);
	for(int i = 0; i < n; ++i) {
		sum[i] = P[i];
		if (i) sum[i] += sum[i - 1];
	}

	int mx = 0;
	for(int i = k - 1; i < n; ++i) {
		int last = sum[i];
		int start = (i - k < 0 ? 0 : sum[i - k]);

		mx = max(last - start, mx);
	}

	double ans = (mx + k) / 2.0;

	cout << fixed << setprecision(10) << ans << '\n';
	
	


	return 0;
}

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

int main(){
  string s,t;
  cin>>s>>t;
  bool ad=false;
  for(int i=0;i<s.size();i++){
    if(s==t){
      ad=true;
    }
    s=s.back()+s.substr(0,s.size()-1);
  }
  if(ad) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
// Problem : D - Prediction and Restriction
// Contest : AtCoder Beginner Contest 149
// URL : https://atcoder.jp/contests/abc149/tasks/abc149_d
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using ld = long double;
#define all(x) (x).begin(),(x).end()
#define io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const int MN = 1e5+3;
char s[MN];
char took[MN];
int main () {
	int n,k,r,sc,p;
	scanf ("%d %d %d %d %d",&n,&k,&r,&sc,&p);
	scanf ("%s",s+1);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (s[i] == 'r' && (i < k || took[i-k] != 'p')) ans += p, took[i] = 'p';
		else if (s[i] == 'p' && (i < k || took[i-k] != 's')) ans += sc, took[i] = 's';
		else if (s[i] == 's' && (i < k || took[i-k] != 'r')) ans += r, took[i] = 'r';
	}
	printf ("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007
#define maxn 100005
#define IN freopen("nocross.in","r",stdin)
#define OUT freopen("nocross.out","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define ROF(i,a,b) for(i=a ; i>=b ; i--)
#define DBG pf("Hi\n")
#define INF 2000000000000000000LL
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
// #define off 1000000
#define sq(x) ((x)*(x))

using namespace __gnu_pbds;
using namespace std ;

template <class T>  inline void smax(T &x,T y){ x = max((x), (y)); }
template <class T>  inline void smin(T &x,T y){ x = min((x), (y)); }

// typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

char s[100005] ;

int pal(int i ,int j)
{
    if( i==j || i>j ) return 0 ;

    if( s[i]==s[j] ) return pal(i+1,j-1) ;

    if( s[i]=='x' )
    {
        int ret = pal(i+1,j) ;
        if(ret==-1) return ret ;
        else return ret+1 ;
    }
    if(s[j]=='x')
    {
        int ret = pal(i,j-1) ;
        if(ret==-1) return ret ;
        else return ret+1 ;
    }
    return -1 ;
}

int main()
{
    int i , j , k , l , m , n ;

    scanf("%s",s) ;

    l = strlen(s) ;

    printf("%d\n",pal(0,l-1)) ;

    return 0 ;
}


Measured memory_bytes: 1920
#include <iostream>
#include <queue>
using namespace std;
priority_queue<int>p;
int n, x, ans;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> x;
		p.push(x);
		cin >> x;
		p.push(x);
	}
	for (int i = 1; i <= n; i++)
	{
		p.pop();
		ans += p.top();
		p.pop();
	}
	cout << ans;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define PI acos(-1)
#define ll long long

ll sum(ll n)
{
    if(n == 1)
        return 1;
    else
        return (pow(n, n) + sum(n-1));
}
void printFun(int test)
{
    if(test < 1)
        return;
    else
    {
        cout << test << " ";
        printFun(test - 1);
        cout << test << " ";
        return;
    }
}
int baseToDecimal(string x, int base)
{
    int res = 0, coef = 1, len = x.length();
    for(int i = len-1; i >= 0; i--)
    {
        res += (x[i] - '0')*coef;
        coef *= base;
    }
    return res;
}
int baseToDecimalAlternate(string x, int base)
{
    int res = 0;
    int len = x.length();
    for(int i = 0; i < len; i++)
    {
        res = (res*base) + (x[i] - '0');
    }
    return res;
}

int main()
{
    int s, w;
    cin >> s >> w;
    if(w >= s)
    {
        cout << "unsafe" << endl;
    }
    else
    {
        cout << "safe" << endl;
    }
    //cout << baseToDecimalAlternate(x, base) << endl;
    //cout << baseToDecimal(x, base) << endl;
    return 0;
}


Measured memory_bytes: 3676
def binarySearch(A, n, key):
	
	left = 0
	right = n
	while (left < right):
		mid = (left + right) // 2
		if (key == A[mid]):
			return 1
		if (key > A[mid]):
			left = mid + 1
		elif (key < A[mid]):
			right = mid
	
	return 0

if __name__ == '__main__':
	
	n = int(input())
	L = list(map(int, input().split()))

	q = int(input())
	Key = list(map(int, input().split()))

	cnt = 0
	for i in range(q):
		if (binarySearch(L, n, Key[i])):
			cnt += 1

	print(cnt)


Measured memory_bytes: 16712
#include <stdio.h>
int main(void) {
   int a,b,i,temp;
   while(scanf("%d %d",&a,&b)!=EOF){
   if(a>b){temp=a;a=b;b=temp;}
   for(i=a;i>=1;i--){
	   if(a%i==0 && b%i==0){printf("%d ",i);break;}
   }
   printf("%d\n",a/i*b);
   }
   return 0;
}



Measured memory_bytes: 1980
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007
const int N = 1e6 + 5;
ll cnt[N];
ll gcd(ll a, ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b , a%b);
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;
    ll a[n];
    for(int i = 0 ; i < n; i++){
        cin>>a[i];
    }
    ll gc = a[0];
    for(int i = 1; i < n; i++){
        gc = gcd(gc, a[i]);
    }
    if(gc > 1){
        cout<<"not coprime";
        return 0;
    }
    for(int i = 0; i < n; i++){
        ll t = a[i];
        for(int j = 2; j*j <= t; j++){
            if(t % j == 0){
                while(t % j == 0){
                    t /= j;
                }
                cnt[j]++;
            }
        }
        if(t > 1){
            cnt[t]++;
        }
    }
    bool flag = 1;
    for(auto it : cnt){
        if(it > 1){
            flag = 0;
            break;
        }
    }
    if(flag){
        cout<<"pairwise coprime";
    }else{
        cout<<"setwise coprime";
    }
}

Measured memory_bytes: 19156
#include<stdio.h>
#include<stdlib.h>
#define TYPE int
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int main() {
	int A[3];
	int ans = 0;
	scanf("%d%d%d", &A[0], &A[1], &A[2]);
	qsort(A, 3, sizeof(int), cmp);
	//printf("%d %d %d", A[0], A[1], A[2]);
	if (A[0] == A[1] && A[1] == A[2]) {
		printf("%d\n", ans);
		return 0;
	}
	while (A[0] != A[1] || A[0] != A[2])
	{
		qsort(A, 3, sizeof(int), cmp);
		if (A[0] + 2 <= A[2])
		{
			A[0] += 2;;
		}
		else
		{
			A[0] += 1;
			A[1] += 1;
		}
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using BI = System.Numerics.BigInteger;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		if(lA.Contains(0)){
			Console.WriteLine(0);
			return;
		}
		BI UL = (BI)(long) 1e18;
		
		BI p = 1;
		for(int i=0;i<N;i++){
			p *= A[i];
			if(p > UL){
				Console.WriteLine(-1);
				return;
			}
		}
		Console.WriteLine(p);
	}
	int N;
	BI[] A;
	long[] lA;
	public Sol(){
		N = ri();
		lA = rla();
		A = new BI[N];
		for(int i=0;i<N;i++){
			A[i] = lA[i];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 45084
#include <iostream>
using namespace std;
int main(){
	string a;
	cin>>a;
	for(int i=0;i<a.length();i++){
		if(i%2==0){
			if(a[i]=='L'){
				cout<<"No";
				return 0;
			}
		}
		if(i%2==1){
			if(a[i]=='R'){
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
}


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

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

    string s;
    cin >> s;

    int a_pos = 0;
    int z_pos = 0;
    for (auto itr = s.begin(); itr != s.end(); ++itr, ++a_pos)
    {
        if (*itr == 'A')
        {
            break;
        }
    }

    for (auto itr = s.end(); itr != s.begin(); --itr, ++z_pos)
    {
        if (*itr == 'Z')
        {
            break;
        }
    }

    cout << s.length() - a_pos - z_pos + 1 << endl;

    return 0;
}

Measured memory_bytes: 832
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using graph = vector<vector<int>>;
using wgraph = vector<vector<pair<int, long long int>>>;
long long int INF = 1001001001001001LL;
int inf = 100100100;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(int i = s; i < t; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

string func(string s, int k) {
  string ret = "";
  ret = ret + s[0];
  for(int i = 0; i < s.size() - 1; i++) {
    if(s[i] == 'a' or
       s[i] == 'i' or 
       s[i] == 'u' or 
       s[i] == 'e' or 
       s[i] == 'o') {
        ret = ret + s[i + 1];
    }
  }
  
  if(ret.size() < k) return ret;
  
  string rett = "";
  for(int i = 0; i < k; i++) rett = rett + ret[i];
  return rett;

}

int main(){
  
  while(1) {
    
    int n; cin >> n;
    if(n == 0) break;
    vector<string> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];
    int ans = -1;
    for(int k = 1; k < 53; k++) {
      vector<string> zip(n);
      for(int i = 0; i < n; i++) zip[i] = func(v[i], k);

      bool ok = true;
      for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) {
        if(zip[i] == zip[j]) {
          ok = false;
          break;
        }
      }

      if(ok) {
        ans = k;
        break;
      }
    }

    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3216
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;
typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<' '<<y<<endl
#define p3(x,y,z)               out<<x<<' '<<y<<' '<<z<<endl
#define p4(x,y,z,w)             out<<x<<' '<<y<<' '<<z<<' '<<w<<endl
#define pl(x)                   out<<x
#define pll(x)                  out<<x<<' '
#define range(v)                v.begin(),v.end()
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

#define EACH(x, a) for (auto& x: a)
template<class T> void read_v(T& x, std::istream& in) {
    in >> (x);
}
template<class A> void read_vec(vector<A>& x, std::istream& in) {
    EACH(a, x)
        read_v(a, in);
}

bool sortpairbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
template <typename T>
T factmod(T a, T modulus){ int res = 1, i; for (i = 2; i <= a; i++){ res *= i; res%=modulus;} return res; }
template <typename T>
int powmod(T a,T b,int m){ int ans=1; while(b>0){if(b&1){ans*=a;ans%=m;}a*=a;a%=m;b>>=1;} return ans; }
template <typename T>
int power(T a, T b){ int ans=1; while(b>0){if(b&1){ans*=a;}a*=a;b>>=1;}return ans;}

const ll CMOD = 1e9 + 7;
void ssolve(std::istream& in, std::ostream& out){
    int n; s(n);
    vector<ll> a(n);
    vector<ll> cs(n + 1, 0);
    f(i, 0, n){
        s(a[i]);
        cs[i + 1] = (cs[i] + a[i]);
    }
    ll ans = 0;
    f(i, 0, n - 1){
        ans += ((a[i] * ((cs[n] - cs[i + 1])%CMOD))%CMOD);
        ans %= CMOD;
    }
    p(ans);
}

class CSumOfProductOfPairs {
public:
void solve(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in.tie(nullptr);out.tie(nullptr);
    int t;
    int READ = 0;
    if(READ) s(t);
    else t = 1;
    while(t--){
        ssolve(in, out);
    }
}
};

integer main() {
    CSumOfProductOfPairs solver;
    std::istream& in(std::cin);
     std::ostream& out(std::cout);
     solver.solve(in, out);
}

Measured memory_bytes: 6372
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N+1);
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j*i <= N; j++) {
            A[i*j]++;
        }
    }
    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        ans += A[i]*i;
    }

    cout << ans << ln;
}

Measured memory_bytes: 81328
import java.util.Scanner;

class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long count = 0;
		long countIncrease = 0;
		
		if(N%2==1) {
			System.out.println(0);
			return;
		}

		for(long i = 10;i<=N;i *=5) {

			countIncrease = N/i;
			count += countIncrease;
		}
		System.out.println(count);
	}
		

}







Measured memory_bytes: 21844
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    string s;
    cin >> s;
    if (s == "keyence") {
        cout << "YES" << endl;
        return 0;
    }
    rep(i, (int)s.size()) {
        for (int j = i; j < (int)s.size(); ++j) {
            string t = "";
            rep(k, s.size()) {
                if (k >= i && k <= j) continue;
                t += s[k];
            }
            //cout << t << endl;
            if (t == "keyence") {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
int main(){
  int N;
  int d[110];

  std::cin >> N;
  for (int i = 0; i<N; ++i){
    std::cin >> d[i];
  }

  int num[110] = {0};
  for (int i=0; i<N; ++i){
    num[d[i]]++;
  }

  int res=0;
  for (int i =1; i<=100; ++i){
    if (num[i]){
      ++res;
    }
  }

  std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin>>N;
    vint A(N);
    for (size_t i = 0; i < N; i++)
    {
        cin>>A[i];
    }
    vint acc(N+1),racc(N+1);
    acc[0]=0;
    racc[0]=0;
    for (size_t i = 0; i < N; i++)
    {
        acc[i+1]=gcd(acc[i],A[i]);
        racc[i+1]=gcd(racc[i],A[N-i-1]);
    }
    int ans = 0;
    for (size_t i = 0; i < N; i++)
    {
        chmax(ans,gcd(acc[i],racc[N-1-i]));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4552
#include<bits/stdc++.h>
using namespace std;
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; 
//order_of_key(k)= # of items strictly smaller than 'k'  //find_by_order(x)= iterator to x'th largest element (counting from ZERO) //erase("iterator") [log(n)] //end(<name>)
//os.find_by_order(os.order_of_key(x)=iterator to 'x' in the rb tree
template<class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target ("avx2")
//#pragma GCC optimize ("O3")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef priority_queue<ll> pq;                                        //min-heap-> multiply the values by '-1'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define forr(i,a,b) for (ll i = a; i < b; i++)
#define test ll t;cin>>t;while(t--)
#define summ(a,n) accumulate(a,a+n,0)
#define bsrch(v,n) lower_bound(v.begin(), v.end(), n)
#define minindex(v) distance(v.begin(),min_element(v.begin(),v.end()))         //returns index of minimum(/max) element in the vector
#define bp(x) _builtin_popcount(x)
#define inf 1000000000000
#define PI = 3.1415926535897932384626
#define mod 1000000007

ll dp[3005][3005], a[3005];
ll n;

ll solve(ll i, ll j)
{
    if(dp[i][j]) return dp[i][j];
    return dp[i][j]=max(a[i]-solve(i+1,j), a[j]-solve(i,j-1));
}

int main()
{
    cin>>n;
    forr(i,1,n+1) 
    {
        cin>>a[i];
        dp[i][i]=a[i];
    }
    cout<<solve(1,n);
}

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

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    int a, b;
    cin >> a >> b;

    Cout(a * b - a - b + 1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl;
#define all(x) (x).begin(),(x).end()

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

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

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main()
{
    ll n,k,r,s,p,ans = 0;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    vector<bool> c(n,false);
    rep0(i, n){
        if(i >= k){
            if(t[i] != t[i - k] || !c[i - k]){
                c[i] = true;
                if(t[i] == 'p')ans += s;
                else if(t[i] == 's')ans += r;
                else ans += p;
            }
        }else{
            c[i] = true;
            if(t[i] == 'p')ans += s;
            else if(t[i] == 's')ans += r;
            else ans += p;
        }
    }
    pf(ans)
    return 0;
}


Measured memory_bytes: 512
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define P pair<int,int>
//P pa(114,514);   ,vector<P>vec(N,0);
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
ll llmin(ll a,ll b){
  if(a>b) return b;
  else return a;
}

//cout << setprecision(123);
int main(){
  int a,b,ans=0;
  cin>>a>>b;
  if(a>=13) ans+=b;
  else if(a>=6) ans+=b/2;
  cout << ans <<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <utility>

using namespace std;

typedef pair<int, int> P;

int my_abs(int x) {
  if (x >= 0) {
    return x;
  } else {
    return (-1)*x;
  }
}

int main() {
  int i;
  int N;
  int t[100010];
  scanf("%d", &N);
  P point[100010]; 
  for (i = 1; i < N+1; i++) {
    int x, y;
    scanf("%d %d %d", &t[i], &x, &y);
    point[i].first = x;
    point[i].second = y;
  }
  point[0].first = 0;
  point[0].second = 0;
  t[0] = 0;
  bool ans = true;
  for (i = 1; i < N+1; i++) {
    int dist = my_abs(point[i].first - point[i-1].first) + my_abs(point[i].second - point[i-1].second);
    int time_dist = t[i] - t[i-1];
    if (dist > time_dist || (dist - time_dist) % 2 != 0) {
      ans = false;
      break;
    }
  }
  if (ans) {
    printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 1280
import sys


def tran(A):
    temp = []
    for i in range(len(A)):
        if i == 0:
            temp += [A[i]]
        elif A[i] != A[i - 1]:
            temp += [A[i]]
    return temp


def find(A):
    # assume consecutive elements
    dp = [1] * len(A) + [1]

    current_dic = {}

    MOD = 10**9 + 7

    for i in range(len(A)):

        if i == 0:
            current_dic[A[i]] = 1
        else:
            temp = dp[i - 1]
            if A[i] in current_dic:
                temp += current_dic[A[i]]
                temp %= MOD
                current_dic[A[i]] += dp[i - 1]
                current_dic[A[i]] %= MOD
            else:
                current_dic[A[i]] = dp[i - 1]

            dp[i] = temp
    # print(dp)
    return dp[-2] % MOD


N = int(input())
A = []
for i in range(N):
    A += [int(input())]



print(find(tran(A)))


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


int main() {
    string s;
    cin >> s;

    int w;
    cin >> w;

    REP(i,s.size()) if(i%w==0) p(s[i])
    pl("")

    return 0;
}

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

using namespace std;

#define LL long long
#define ULL unsigned LL
#define LD long double
#define debug(x) cerr << #x << " " << x << endl;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int x[n][3]; // a, b, c
	int dp[n+1][3];
	for(int i=0; i<3; i++)
		dp[0][i] = 0;
	for(int i=0; i<n; i++)
		cin>>x[i][0]>>x[i][1]>>x[i][2];
	for(int i=1; i<=n; i++) {
		for(int j=0; j<3; j++) {
			dp[i][j] = 0;
			for(int z=0; z<3; z++) {
				if(z!=j)
					dp[i][j] = max(dp[i][j], dp[i-1][z]);
			}
			dp[i][j]+=x[i-1][j];
		}
	}
	cout<<max(dp[n][0], max(dp[n][1], dp[n][2]));
}


Measured memory_bytes: 2560
#include<iostream>

using namespace std;

int main(){

	int N,M,dis,ans; cin >> N >> M;
	int A[50],B[50],C[50],D[50],num[50];
	dis =0;
	//Input of Students
	for(int i=0; i < N; i++)
		cin >> A[i] >> B[i];
	//Input of Check Point
	for(int i=0; i < M; i++)
		cin >> C[i] >> D[i];
	//Caluculation of Mahattan distance
	for(int i=0; i < N; i++){
		ans = 1000000000;
		for(int j=0; j< M; j++){
			dis = abs(A[i]-C[j]) + abs(B[i]-D[j]);
			if(dis < ans)	{
				ans = dis;
				num[i] = j+1;
			}
		}
	}
	for(int i=0; i < N; i++)
		cout << num[i] <<endl;

	return 0;
}


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

bool Check(int X) {
    bool flg = true;
    for (int i = 2; i < X; i++) {
        if ((X % i) == 0) {
            flg = false;
            break;
        }
    }
    return flg;

}

int main(){
    int X;
    
     cin >> X;
    while (1) {
        if (Check(X)) {
            break;
        }
        X++;
    }

    cout << X;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N, A, B;
  cin >> N >> A >> B;
  
  long c1 = N/(A+B) * A;
  long c2 = min(N%(A+B), A);
  cout << c1 + c2 << endl;
}

Measured memory_bytes: 256
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
using namespace std;
 
#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);
 
#define csh(a,n) memset(a,n,sizeof(a));

int main(){
	int n,d,x;
	cin>>n>>d>>x;
	
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		x+=(d+a-1)/a;
	}
	cout<<x<<endl;
} 

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    char x,y;
    char a[3];
    int n[3] = {1,0,0};
    int i;
    while(scanf("%s",a) != EOF){
        x = a[0];
        y = a[2];
        n[x - 'A'] ^= n[y - 'A'];
        n[y - 'A'] ^= n[x - 'A'];
        n[x - 'A'] ^= n[y - 'A'];
    }
    if(n[0] == 1) printf("A\n");
    if(n[1] == 1) printf("B\n");
    if(n[2] == 1) printf("C\n");
    return 0;
}

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

#define int long long
#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef pair < ll , ll > pp;
const int mod = 1e9 + 7;
const int N   = 52;

pair < double , pp > P[N];
int dp[N*N*N],val[N],W[N],par[N],n,d,budget,K,i,j,k,l;
deque < pp > Q;

int kesv,kesw,ans,cur,valmax,t;

bool cmp(pp a, pp b){
    return a.st * b.nd > b.st * a.nd;
}

signed main(){

    cin >> n >> budget >> d >> W[1];
    for(i=2;i<=n;i++) cin >> W[i] >> par[i];
    for(i=n; i ;i--) { W[ par[i] ] += W[i]; val[ par[i] ] += ++val[i]; }

    K = min(d , n);
    valmax = n * n * K;

    memset(dp , 11 , sizeof dp);
    dp[0] = 0;
    for(i=1;i<=n;i++){
        for(j=0;j<val[i];j++){
            Q.clear();
            for(l=0,k=j;k<valmax;k+=val[i],l--){
                t = dp[k];
                if(Q.size() && Q.front().nd - l == K+1) Q.pop_front();
                if(Q.size()) dp[k] = min(dp[k] , Q.front().st - l * W[i]);

                for(; Q.size() && Q.back().st > t+l*W[i] ;) Q.pop_back();
                Q.pb(mp(t+l*W[i] , l));
            }
        }
    }

    for(i=1;i<=n;i++) P[i] = mp(1.0*val[i]/W[i],mp(val[i] , W[i]));
    sort(P+1 , P+n+1);
    reverse(P+1 , P+n+1);
    cur = 1;
    for(i=valmax; i>=0 ;i--){
        if(dp[i] + kesw > budget) continue;
        for(; P[cur].nd.st != n && (budget - dp[i] - kesw) >= P[cur].nd.nd * (d - K); cur++){
            kesw += P[cur].nd.nd * (d - K);
            kesv += P[cur].nd.st * (d - K);
        }

        ans = max(ans , i + kesv + (budget - dp[i] - kesw) / P[cur].nd.nd * P[cur].nd.st);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り 0:ON 1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}

	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		boolean flag = false;
		for (int i = 0; i < num.get(1); i++) {
			if ((i * num.get(1) + num.get(2)) % num.get(0) == 0) {
				System.out.println("YES");
				flag = true;
				break;
			}
		}
		if (!flag) {
			System.out.println("NO");
		}
	}
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
using graph = vector<vector<int>>;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define all(x) (x).begin(),(x).end()
#define size(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000

#define pb push_back
#define mp make_pair
#define f first
#define s second

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

#define h(i,j) find(all(b),a[i][j])!=b.end()
int main(){
	vector<vector<int>> a(3,vector<int>(3));
	rep(i,3){
		rep(j,3){
			cin>>a[i][j];
		}
	}
	int n;cin>>n;
	vector<int> b(n);
	rep(i,n)cin>>b[i];

	rep(i,3){
		if(h(0,i)&&h(1,i)&&h(2,i)){cout<<"Yes"<<endl;return 0;}
	}
	rep(i,3){
		if(h(i,0)&&h(i,1)&&h(i,2)){cout<<"Yes"<<endl;return 0;}
	}
	if(h(0,0)&&h(1,1)&&h(2,2)){ cout<<"Yes"<<endl;return 0;}
	if(h(2,0)&&h(1,1)&&h(0,2)){ cout<<"Yes"<<endl;return 0;}


	cout<<"No"<<endl;
}





Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair 
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#define FILE_NAME "a"

const int MAXN = 1e5 + 10;

int n;
vi g[MAXN];
int a[MAXN];

bool read() {
	if  (scanf("%d", &n) < 1) {
		return 0;
	}
	forn(i, n) {
		g[i].clear();
		scanf("%d", &a[i]);
	}
	forn(i, n - 1) {
		int v, u;
		scanf("%d%d", &v, &u);
		--v;
		--u;
		g[v].pb(u);
		g[u].pb(v);
	}
	return 1;
}

ll dfs(int v, int p) {
	if  (sz(g[v]) == 1) {
		return a[v];
	}

	// printf("in v=%d\n", v + 1);

	vll sons;
	ll sum = 0;
	for (int to : g[v]) {
		if (to == p) {
			continue;
		}

		ll x = dfs(to, v);
		// printf("to=%d, x=%lld\n", to + 1, x);
		if  (x == -1) {
			return -1;
		}
		sum += x;
		sons.pb(x);
	}

	ll up = 2 * a[v] - sum;
	if  (up < 0) {
		return -1;
	}

	sort(all(sons));
	if  (sz(sons) == 1) {
		if  (sons[0] != up) {
			return -1;
		}
		return up;
	}

	ll Up = up;

	ll neg = min(Up, sons.back() - sons[sz(sons) - 2]);
	sons.back() -= neg;
	Up -= neg;

	ll s = accumulate(all(sons), 0ll);

	if  (Up == 0) {
		if  (s & 1) {
			return -1;
		}
		s -= sons.back();
		if  (s < sons.back()) {
			return -1;
		}
		return up;
	}

	if  (s - Up >= 0 && (s - Up) % 2 == 0) {
		return up;
	}
	
	return -1;
}

bool solve() {
	int r = -1;
	forn(v, n) {
		if  (sz(g[v]) > 1) {
			r = v;
			break;
		}
	}

	// printf("r=%d\n", r + 1);

	if  (r == -1) {
		if  (n == 2) {
			return a[0] == a[1];
		} else {
			assert(0);
		}
	}

	ll up = dfs(r, -1);
	return up == 0;
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		puts(solve() ? "YES" : "NO");

		// break;
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


Measured memory_bytes: 16768
from sys import stdin
import numpy as np
mod = 10**9+7
X, Y = [int(x) for x in stdin.readline().rstrip().split()]


def mul(a, b):
    return ((a % mod) * (b % mod)) % mod


def div(a, b):
    return mul(a, pow(b, mod-2, mod))


def fact(n):
    f = 1
    for i in range(1, n+1):
        f *= i
        f %= mod
    return f


A = np.matrix([[2, 1], [1, 2]])
Y = np.matrix([[X], [Y]])
if np.linalg.matrix_rank(np.c_[A, Y]) == np.linalg.matrix_rank(A):
    x, y = np.linalg.solve(A, Y)
    x = float(x)
    y = float(y)
    if x < 0 or y < 0:
        print(0)
    elif (not x.is_integer()) or (not y.is_integer()):
        print(0)
    else:
        x = int(x)
        y = int(y)
        ans = fact(x+y)
        ans = div(ans, fact(x))
        ans = div(ans, fact(y))
        print(ans % mod)
else:
    print(0)

Measured memory_bytes: 19616