akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bitset>

using namespace std;

int main() {
    int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    int n, s, sum, cnt;

    while (cin >> n >> s) {
        if (!n && !s) { break; }
        cnt = 0;
        for (int i = 0; i < (1 << 10); i++) {
            sum = 0;
            for (int j = 0; j < 10; j++) {
                // if (bitset<10>(i).test(j)) {
                if ((i >> j) & 1) {
                    sum += a[j];
                }
            }
            if (sum == s && bitset<10>(i).count() == n) { cnt++; }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 2996
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define INF ((1LL<<62)-(1LL<<31))
#define min(p,q)((p)<(q)?(p):(q))

//辺の情報を個別に持つタイプ
typedef struct edge{ll s,g,c;}E;
typedef struct graph{
	ll vcnt,ecnt;
	E  e[100010];//適宜変える
	ll id[100010];//適宜変える
}G;
int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}

G g;
void readgraph(){
	//適宜変える
	ll n,m;
	scanf("%lld%lld",&n,&m);
	rep(i,0,m){
		ll x,y,c;
		scanf("%lld%lld%lld",&x,&y,&c);
		x--,y--;
		g.e[i].s=x;
		g.e[i].g=y;
		g.e[i].c=-c;
	}
	g.vcnt=n;
	g.ecnt=m;
	qsort(g.e,g.ecnt,sizeof(E),esort);

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//一応番兵
}

//ベルマンフォード
//グラフと始点を引いて単一始点最短経路を返す
//O(EV)、負辺ありでもOK
ll d[10010];
void berumanfoodo(G g,ll s){
	rep(i,0,g.vcnt)d[i]=i==s?0:INF;
	rep(nnnn,0,g.vcnt-1)rep(i,0,g.ecnt)if(d[g.e[i].s]!=INF)d[g.e[i].g]=min(d[g.e[i].g],d[g.e[i].s]+g.e[i].c);
	rep(nnnn,0,g.vcnt)rep(i,0,g.ecnt)if(d[g.e[i].s]!=INF){
		if(d[g.e[i].g]>d[g.e[i].s]+g.e[i].c)d[g.e[i].g]=-INF;
	}
}

int main(){
	readgraph();
	berumanfoodo(g,0);
	if(d[g.vcnt-1]==-INF)puts("inf");
	else printf("%lld\n",-d[g.vcnt-1]);
	return 0;
}

Measured memory_bytes: 3452
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int a[3];

    cin >> a[0] >> a[1] >> a[2];

    int min = 32767;

    for(int i = 0; i < 3; i++){
        for(int n = 0; n < 3; n++){
            if(n == i) continue;
            for(int m = 0; m < 3; m++){
                if(n == m) continue;
                if(m == i) continue;
                if(min > abs(a[i] - a[n]) + abs(a[n] - a[m])){
                    min = abs(a[i] - a[n]) + abs(a[n] - a[m]);
                }
            }
        }
    }

    cout << min << endl;
}

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

void solve()
{
    int n,m,x;
  cin>>n>>m>>x;
  vector<vector<int>>a(n,vector<int>(m));
  vector<int>c(n);
  
  for(int i=0;i<n;i++)
  {
    cin>>c[i];
    for(int j=0;j<m;j++)
      cin>>a[i][j];
    
    
  }
  int all=1<<n;
  int ans=INT_MAX;
  for(int mask=0;mask<all;mask++)
  {
      vector<int>level(m);
       int cost=0;
   for(int i=0;i<n;i++)
   { 
       
      if(mask>>i&1)
      {
        cost+=c[i];
        for(int j=0;j<m;j++)
        {  
          level[j]+=a[i][j];
        }
        
      }
   
   }
    bool ok=true;
      for(int k=0;k<m;k++)
      {
        if(level[k]<x)
          ok=false;
      }
      if(ok)
        ans=min(ans,cost);
     
    
  }
  if(ans==INT_MAX)
    cout<<-1<<endl;
  else
cout<<ans<<endl;
      
 }

int main()
{
solve();
}


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

int main(){
    int T,i,j;
    char ch;
    scanf("%c",&ch);

    map<char,char> mp;

    mp['A']='T';
    mp['T']='A';
    mp['G']='C';
    mp['C']='G';

    printf("%c\n",mp[ch]);

return 0;
}


Measured memory_bytes: 3752
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>
using std::cout;
using std::cin;
using std::endl;

int main(void){
    std::string s;
    cin >> s;
    long long answer = s.size() * (s.size() - 1) / 2;
    //cout << "first answer:" << answer << endl;

    for (char i = 'a'; i <= 'z'; i++)
    {
        long long count = 0;
        for (int j = 0; j < s.size();j++){
            if(s[j]==i){
                count++;
            }
        }
            answer -= count * (count - 1) / 2;
    }
    cout << answer+1 << endl;

    return 0;
}


Measured memory_bytes: 832
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>

using namespace std;

int n;
int num[10];
string edge[10][10];
string tmp;

main(){
  vector<string> in;
  set<string> data;
  while(cin >> n && n){
    in.clear();
    data.clear();
    for(int i=0;i<n;i++){
      string str;
      cin >> str;
      in.push_back(str);
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(i == j) continue;
        if(in[i].size() >= in[j].size()){
          for(int k=0;k+in[j].size()<=in[i].size();k++){
            if(in[i].substr(k, in[j].size()) == in[j]) data.insert(in[j]);
          }
        }
      }
    }
    for(set<string>::iterator i=data.begin();i!=data.end();i++){
      for(vector<string>::iterator ite=in.begin();ite!=in.end();ite++){
        if(*ite == *i){
          in.erase(ite);
          n--;
          break;
        }
      }
    }
    for(int i=0;i<in.size();i++){
      for(int j=0;j<in.size();j++){
        if(i == j){
          continue;
        }
        int size = min(in[i].size(),in[j].size());
        for(int k=size;k>=0;k--){
          if(in[i].substr(in[i].size()-k, k) == in[j].substr(0, k)){
            edge[i][j] = in[j].substr(k);
            break;
          }
        }
      }
    }
    int valm = 100000;
    string ans = in[0];
    for(int i=0;i<10;i++) num[i] = i;
    do{
      tmp = in[num[0]];
      for(int i=1;i<n;i++){
        tmp += edge[num[i-1]][num[i]];
      }
      if(tmp.size() < valm){
        ans = tmp;
        valm = tmp.size();
      }else if(tmp.size() == valm){
        ans = min(ans, tmp);
      }
    }while(next_permutation(num, num+n));
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 932
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  string S,T;
  cin >> S >> T;
  int A,B;
  cin >> A >> B;
  string U;
  cin >> U;
  if(U==S)
  {
    A--;
  }
  else
  {
    B--;
  }
  
  cout << A << " " << B << endl;
  return 0;
}


Measured memory_bytes: 256
//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
//use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
//take care of precedence rule of operators 
//do not forget to change the sizes of arrays and value of contants and other things after debugging  

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define ld long double
#define pi acos(-1.0)
 
#define SZ(x)  (ll)(x.size())
 
//comment the below if not required

/*

#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second
*/
 
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

const ll M = 5e5+1;

ll f[M],mi[M];

ll modinv(ll num)
{
    ll ans=num,res=1,i;

    for(i=mod-2;i>=1;i=i/2,ans=(ans*ans)%mod)
    {
        if(i%2)
            res = (res*ans)%mod;
    }

    return res;

}

int main()
{

    IOS;


    ll n,m,i,ans,tot,s,temp;

    cin>>n>>m;

    f[0]=1;

    rep(i,1,m+1)
        f[i] = (f[i-1]*i)%mod;


    mi[m]=modinv(f[m]);

    for(i=m-1;i>=0;--i)
            mi[i] = (mi[i+1]*(i+1))%mod;


    ans = (f[m]*mi[m-n])%mod;

    tot = ans;

    for(i=1,s=-1;i<=n;++i,s*=-1)
    {
        temp = (f[n]*mi[i])%mod;

        temp = (temp*f[m-i])%mod;

        temp = (temp*mi[n-i])%mod;

        temp = (temp*mi[m-n])%mod;

        temp = (s*temp)%mod;

        temp = (temp+mod)%mod;

        tot = (tot+temp)%mod;

    }

    ans = (ans*tot)%mod;

    cout<<ans<<"\n";

    return 0;
}

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

class ABC170
{
    static void Main()
    {
        // A - Five Variables
        string[] sarr = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
        int ans = 1;
        foreach (string temps in sarr)
        {
            if (Int32.Parse(temps) == 0)
            {
                Console.WriteLine(ans);
                //System.Diagnostics.Debug.WriteLine(ans);
                break;
            }
            ans++;
        }
    }
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    rep(i,0,n) cin >> a.at(i);
    rep(i,0,n) a.at(i)--;
    rep(k,0,n){
        b.at(a.at(k)) = k;
    }
    rep(i,0,n) cout << b.at(i)+1 << " ";
}

//  a 1 2 0
//  b 2 0 1

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> 	pii;
typedef long long 		ll;
typedef vector<int> 	vi;
#define PI 				3.14159265
#define int				long long
#define f 				first
#define s 				second
#define umap 			unordered_map
#define pb 				push_back
#define eb 				emplace_back
#define ins 			insert
#define all(a) 			a.begin(),a.end()
#define mtup 			make_tuple
#define nl 				'\n'
#define FLASH 			ios_base::sync_with_stdio(false);cin.tie(NULL);
#define maxheap 		priority_queue<ll>
#define minheap 		priority_queue<ll,vector<ll> ,greater<ll>>
#define rep(i,s,e)		for (int i = s; i <= e; i++)
#define repr(i,s,e) 	for (int i = s; i >= e; i--)
#define mem0(a)			memset(a, 0, sizeof(a))
#define mem1(a)			memset(a, -1, sizeof(a))
#define beg(a)			a.begin()
#define sz(x) 			((int)(x.size()))
#define len(str)		((int)(str.length()))
const ll inf = 1e18 + 1;
const int mod = 998244353;
const int maxn = 3e5;
ll modpow(ll a,ll b,int mod = inf) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) {return __gcd(a,b);}
vi g[maxn];int n, m, a, b, seen[maxn], dp[maxn], ans = 0;

void dfs(int v){
	seen[v] = 1;
	for (int u : g[v]) {
		if (!seen[u]) dfs(u);
		dp[v] = max(dp[v], 1 + dp[u]);
	}
}

signed main(){
	FLASH
	cin >> n >> m;
	mem0(seen), mem0(dp);
	rep(i, 1, m) cin>>a>>b, g[a].eb(b);
	rep(i, 1, n) if (!seen[i]) dfs(i);
	rep(i, 1, n) ans = max(ans, dp[i]);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 17152
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int N, ans = 0;
	int A[100] = { 0 };
	int B[100] = { 0 };
	int C[100] = { 0 };
	cin >> N;
	for (int i = 1; i < N+1; i++) {
		cin >> A[i];
	}
	for (int i = 1; i < N+1; i++) {
		cin >> B[i];
	}
	for (int i = 1; i < N; i++) {
		cin >> C[i];
	}
	for (int i = 1; i < N+1; i++) {
		ans += B[A[i]];
		if (A[i]-1==A[i-1]&&i!=1) {
			ans += C[A[i]-1];
		}
	}
	
	cout << ans << endl;
	

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    
    ll x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    ll ans = 0;
    vector <ll> p,q,r;
    for(ll i=0;i<a;i++){
        ll tmp;
        cin >> tmp;
        p.push_back(tmp);
    }
    for(ll i=0;i<b;i++){
        ll tmp;
        cin >> tmp;
        q.push_back(tmp);
    }
    for(ll i=0;i<c;i++){
        ll tmp;
        cin >> tmp;
        r.push_back(tmp);
    }
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    sort(q.begin(), q.end());
    reverse(q.begin(), q.end());
    vector <ll> ansList;
    for(ll i=0;i<x;i++){
        ansList.push_back(p[i]);
    }
    for(ll i=0;i<y;i++){
        ansList.push_back(q[i]);
    }
    for(ll i=0;i<c;i++){
        ansList.push_back(r[i]);
    }
    sort(ansList.begin(), ansList.end());
    reverse(ansList.begin(), ansList.end());
    for(ll i=0;i<x+y;i++){
        ans += ansList[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 8304
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]

for i in range(n-3):
  if a[i] == a[i+1]:
    for j in range(i+2, n):
      if a[j] == a[j+1]:
        print(a[i] * a[j])
        exit()

print(0)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long ans,dp[110][N],val,w,n,W;

int main(){
  scanf("%lld%lld",&n,&W);
  for(int i = 1; i <= n; ++i){
  	scanf("%lld%lld",&w,&val);
    for(int j = 0; j <= W; ++j){
    	dp[i][j] = dp[i-1][j];
        if(j >= w)dp[i][j] = max(dp[i][j],dp[i-1][j-w]+val);
    }
  }
  printf("%lld",*max_element(dp[n],dp[n]+W+1));
  return 0;
}

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

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

    vector<int> s(N,0);
    int a;
    for(int i=0;i<N-1;i++){
        cin>>a;
        s[a-1]++;
    }

    for(auto p:s){
        cout<<p<<endl;
    }

    return 0;
}

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

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

  string ans = "";
  if (n <= 26) {
    char ch = 'a' + n - 1;
    cout << ch << endl;
    return 0;
  }

  ll l = n - 26;
  ll d = 1;
  ll mn = 26;
  for (int i = 2;; i++) {
    ll p = (ll)pow(26, i);
    d++;
    if (l <= p) {
      break;
    }
    l -= p;
    mn += p;
  }
  mn++;
  //  cout << d << ' ' << mn << endl;

  ll m = n - mn;
  ll p26 = 1;
  ans += ('a' + m % 26);
  for (int i = 0; i < d - 1; i++) {
    ll pp = (ll)pow(26, p26);
    ll cnt = m / pp % 26;
    ans += ('a' + cnt);
    p26++;
  }

  reverse(ans.begin(), ans.end());

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


Measured memory_bytes: 3996
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 1e9+7;
ll arr[200200];
ll power(ll a, ll b)
{
    ll ret = 1;
    while(b>0) {
        if(b%2==1) ret = (ret*a)%mod;
        b/=2;
        a=(a*a)%mod;
    }
    return ret;
}
int main()
{
    int n,i,j,k,x,y,ans,curr,temp,m;
    int tc;
    ll sum = 0;
    cin >> n;
    for(i=1;i<=n;i++) {
        cin >> arr[i];
        sum += arr[i];
    }
    ll chaeng = 0;
    for(i=1;i<=n;i++) {
        ll sisa = sum - arr[i];
        sisa %= mod;
        chaeng += sisa*arr[i];
        chaeng %= mod;
    }
    chaeng = chaeng * power(2, mod - 2);
    chaeng %= mod;
    cout<<chaeng<<endl;
    return 0;
}


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

using namespace std;

#define LL long long int

struct edge{
    LL next;
    LL cost;
};

vector<vector<edge>> vec(100001);
vector<LL> total(100001,0);
vector<bool> close(100001,false);

void dfs(int r){
    close[r] = true;
    for(int i = 0; i < vec[r].size(); i++){
        if(!close[vec[r][i].next]){
            total[vec[r][i].next] = total[r] + vec[r][i].cost;
            dfs(vec[r][i].next);
        }
    }
}

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

    cin >> n;

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

    int q,k;

    cin >> q >> k;

    vector<int> qx(q),qy(q);

    for(int i = 0; i < q; i++){
        cin >> qx[i] >> qy[i];
    }

    dfs(k);

    for(int i = 0; i < q; i++){
        cout << total[qx[i]] + total[qy[i]] << "\n";
    }

    return 0;
}

Measured memory_bytes: 15104
#include <vector>
#include <queue>
#include <string>
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;

int gen;
int vis[1 << 24];
int dpt[1<<24];
char ch[1<<24];
queue<int> q;
inline void addq(int d2, int d1, int y2, int x2, int y1, int x1){
	int st = (d2 & 3) << 22 | (d1 & 3) << 20 | y2 << 16 | x2 << 10 |
	         y1 << 6 | x1;
	if(vis[st] != gen){
		vis[st] = gen;
		q.push(st);
	}
}

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

	int dy[] = {-1, 0, 1, 0};
	int dx[] = {0, -1, 0, 1};
	int h, w;
	while(cin >> w >> h, h){
		++gen;
		vector<string> v(h);
		int kd = -1, ky = -1, kx = -1, md = -1, my = -1, mx = -1;
		for(int i = 0; i < h; ++i){
			cin >> v[i];
		}
		for(int i = 0; i < h; ++i)
		for(int j = 0; j < w; ++j){
			for(int j = 0; j < w; ++j){
				if(v[i][j] == 'K'){
					for(kd = 0; v[i + dy[kd]][j + dx[kd]] == '#'; ++kd);
					ky = i;
					kx = j;
				}
				else if(v[i][j] == 'M'){
					for(md = 0; v[i + dy[md]][j + dx[md]] == '#'; ++md);
					my = i;
					mx = j;
				}
			}
		}
		int d2 = kd, d1 = kd, y2 = ky, x2 = kx, y1 = ky, x1 = kx;
		addq(d2 + 1, d1, y2, x2, y1, x1);
		addq(d2 + 3, d1, y2, x2, y1, x1);
		while(v[y2][x2] != '#'){
			addq(d2, d1, y2, x2, y1, x1);
			y2 += dy[d2];
			x2 += dx[d2];
		}
		addq(0, d1, 0, 0, y1, x1);
		int ans = 0;
		while(!q.empty()){
			int st = q.front();
			q.pop();

			d2 = st >> 22 & 3;
			d1 = st >> 20 & 3;
			y2 = st >> 16 & 15;
			x2 = st >> 10 & 63;
			y1 = st >> 6 & 15;
			x1 = st & 63;

			while(v[y1 + dy[d1]][x1 + dx[d1]] != '#'){
				y1 += dy[d1];
				x1 += dx[d1];
			}

			if(y1 == my && x1 == mx){
				ans |= 1;
				if(y2 == my && x2 == mx && (d2 + 2 & 3) == md){
					ans = 3;
				}
			}

			if(y2){
				if(v[y2 + dy[d2 + 1 & 3]][x2 + dx[d2 + 1 & 3]] == '#'){
					int ny2 = y2, nx2 = x2;
					while(v[ny2][nx2] != '#'){
						addq(d2 + 3, d1 + 3, ny2, nx2, y1, x1);
						ny2 += dy[d2 + 3 & 3];
						nx2 += dx[d2 + 3 & 3];
					}
				}
				if(v[y2 + dy[d2 + 3 & 3]][x2 + dx[d2 + 3 & 3]] == '#'){
					int ny2 = y2, nx2 = x2;
					while(v[ny2][nx2] != '#'){
						addq(d2 + 1, d1 + 1, ny2, nx2, y1, x1);
						ny2 += dy[d2 + 1 & 3];
						nx2 += dx[d2 + 1 & 3];
						if(y1 == my && x1 == mx && ny2 == my && nx2 == mx && (d2 + 3 & 3) == md){
							ans = 3;
						}
					}
				}
			}
			else{
				addq(0, d1 + 1, 0, 0, y1, x1);
				addq(0, d1 + 3, 0, 0, y1, x1);
			}
		}
		
		if(ans == 3){
			puts("He can accomplish his mission.");
		}
		else if(ans == 1){
			puts("He cannot return to the kitchen.");
		}
		else{
			puts("He cannot bring tea to his master.");
		}
	}
}

Measured memory_bytes: 52592
N = int(input())
A = list(map(int, input().split()))
 
ans = 'APPROVED'
for i in range(N):
  if A[i] % 2 == 0:
    if A[i] % 3 != 0 and A[i] % 5 != 0:
      ans = 'DENIED'
      break
      
print(ans)

Measured memory_bytes: 9176
#include<bits/stdc++.h>
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,M,p;
    cin >> N >> M >> p;
    vector<ll> d(N,INF);
    d[0] = 0;
    vector<pair<ll,P>> edge(M);
    for(int i=0; i<M; i++){
        ll a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        edge[i] = make_pair(p-c,make_pair(a,b));
    }
    vector<bool> dist(N,false);
    vector<bool> dist2(N,false);
    dist2[N-1] = true;
    dist[0] = true;
    queue<int> que;
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            if(dist[edge[j].second.first]) dist[edge[j].second.second] = true;
            if(dist2[edge[j].second.second]) dist2[edge[j].second.first] = true;
        }
    }
    for(int i=0; i<N*3; i++){
        for(int j=0; j<M; j++){
            auto now = edge[j];
            if(d[now.second.second] > d[now.second.first] + now.first){
                d[now.second.second] = d[now.second.first] + now.first;
                if(i > N-1 and dist[now.second.first] and dist2[now.second.second]){
                    cout << -1 << enld;
                    return 0;
                }
            }
        }
    }
    if(d[N-1] > 0){
        cout << 0 << enld;
    }else{
        cout << -d[N-1] << enld;
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vct vector
#define vi vct<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vct<vi>
#define vll vct<ll>
#define vvll vct<vll>
#define vpii vct<pii>
#define vpll vct<pll>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define ft cout<<"for test"<<endl;
#define read(v,a,n) for(int i=a; i<n; i++)cin>>v[i];
#define print(v) for(auto it:v)cout<<it<<' ';cout<<endl;
#define PI 2*acos(0.0)
#define yes cout<<"Yes"<<endl
#define no cout<<"-1"<<endl
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test,cs=1;cin>>test;while(test--)
///................function.....................///
#define siz(s) (int)(s.size())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
///....................-_-......................///
///................Graph's Move.................
///const int dx[] = {+1,-1,+0,+0}; ///Rock's Move
///const int dy[] = {+0,+0,+1,-1}; ///Rock's Move
///const int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
///const int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int dx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's Move
///const int dy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's Move
///*.....................-_-........................*///
#define mod 1000000007
int main()
{
    FIO;
    ///freopen("in.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    int n,m,i,j;
    cin>>n>>m;
    string s[n+2];
    for(i=0; i<n; i++)
        cin>>s[i];
    vvi dp(n+2, vi(m+2));
    dp[0][0]=1;
    for(j=1; j<m; j++)
        if(s[0][j]=='.')
            dp[0][j]=dp[0][j-1];
        else
            dp[0][j]=0;
    for(i=1; i<n; i++)
        if(s[i][0]=='.')
            dp[i][0]=dp[i-1][0];
        else
            dp[i][j]=0;
    for(i=1; i<n; i++)
    {
        for(j=1; j<m; j++)
        {
            if(s[i][j]=='.')
                dp[i][j] = (dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
            else
                dp[i][j]=0;
        }
    }
    /**for(i=0; i<n; i++)
    {
        for(j=0; j<m; j++)
            cout<<dp[i][j]<<' ';
        cout<<endl;
    }**/
    cout<<dp[n-1][m-1]%mod<<endl;
}





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

int main() {
	int n,m;
	cin >> n >> m;
	cout << (n%3!=0 && m%3!=0 && (n+m)%3!=0 ? "Impossible":"Possible") << endl;
}


Measured memory_bytes: 256
import Data.List
import Data.Char

foo :: [Int] -> Int
foo ints
  | length ints <= 2 = 0
  | otherwise = bar ints
    where
      bar (a:b:c:cs) =
        if (a < b && b < c) || (a > b  && b > c) then 1 + foo (b:c:cs)
        else foo (b:c:cs)

main = do
  _ <- getLine
  ints <- map read . words <$> getLine :: IO [Int]
  print $ foo ints



Measured memory_bytes: 508
class Dice:
        def __init__(self, strList):
                self.label = strList[:]
                self.label[0] = int(self.label[0])
                self.label[1] = int(self.label[1])
                self.label[2] = int(self.label[2])
                self.label[3] = int(self.label[3])
                self.label[4] = int(self.label[4])
                self.label[5] = int(self.label[5])
        def reset(self, strList):
                self.label = strList[:]
                self.label[0] = int(self.label[0])
                self.label[1] = int(self.label[1])
                self.label[2] = int(self.label[2])
                self.label[3] = int(self.label[3])
                self.label[4] = int(self.label[4])
                self.label[5] = int(self.label[5])
        def rollE(self):
                temp = self.label[3]
                self.label[3] = self.label[5]
                self.label[5] = self.label[2]
                self.label[2] = self.label[0]
                self.label[0] = temp
        def rollN(self):
                temp = self.label[0]
                self.label[0] = self.label[1]
                self.label[1] = self.label[5]
                self.label[5] = self.label[4]
                self.label[4] = temp
        def rollA(self):
                temp = self.label[3]
                self.label[3] = self.label[4]
                self.label[4] = self.label[2]
                self.label[2] = self.label[1]
                self.label[1] = temp
        def printDice(self):
                print(self.label)
        def check(self, x, y):
                if x == self.label[0] and y == self.label[1]:
                        return True
                else:
                        return False

strDice = input()
diceList = strDice.split()
dice = Dice(diceList)

num = int(input())

for i in range(num):
        list = input().split()
        a = int(list[0])
        b = int(list[1])
        dice.reset(diceList)
        for j in range(6):
                for k in range(4):
                        dice.rollA()
                        if dice.check(a, b):
                                print(dice.label[2])
                if j % 2 == 0:
                        dice.rollE()
                else:
                        dice.rollN()


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

int main(){
  int N,Y,sum;
  cin >> N >> Y;
  int a=-1;
  int b=-1;
  int c=-1;
  for(int i=0;i<=N;i++){
    for(int j=0;j+i<=N;j++){
      int k=N-i-j;
      sum = 10000*i +5000*j + 1000*k;
      if(sum == Y){
        a=i;
        b=j;
        c=k;
      }
    }
  }
  cout << a << " " << b << " "<< c << endl;
}


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

#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl

void solve() {
  ll n;
  cin >> n;
  ll sm = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0 || i % 5 == 0)
      continue;
    sm += i;
  }
  cout << sm << '\n';
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll test = 1;
  // cin >> test;
  while (test--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

// using
using namespace std;

// typedef
typedef long long ll;
typedef unsigned long long ull;

// assert
template <typename T>
void assert_between(T val, T min, T max)
{
    assert(min <= val && val <= max);
}

// math
// 最大公約数(Gratest Common Divisor)を求める.
template <typename T>
T gcd(T a, T b)
{
    assert(a > 0 && b > 0);
    T num1 = max(a, b);
    T num2 = min(a, b);
    T mod = num1 % num2;
    return (mod == 0) ? num2 : gcd(num2, mod);
}

// 最小公倍数(Least Common Multiple)を求める.
template <typename T>
T lcm(T a, T b)
{
    return (a * b) / gcd(a, b);
}

int main ()
{
    int n, x;
    scanf("%d %d", &n, &x);
    assert_between<int>(n, 1, pow(10, 5));
    assert_between<int>(x, 1, pow(10, 9));

    int c[n];
    for (size_t i = 0; i < n; i++)
    {
        scanf("%d", &c[i]);
        assert_between<int>(c[i], 1, pow(10, 9));
    }

    int ans = abs(c[0] - x);
    for (size_t i = 1; i < n; i++)
    {
        ans = min(ans, gcd(ans, abs(c[i] - x)));
    }

    printf("%d\n", ans);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define st first
#define nd second
#define PQ priority_queue

using ll = long long ;
using namespace std;
using pii = pair<int,int>;
const int N = 1e3 + 10;


struct O{
	int x;
	int y;
	int val;
	bool operator < (const O &o) const{
		return val > o.val;
	}
};
int dp[N][N];
char s[N][N];
int n, m;
bool ch(int x, int y){
	return x >= 1 && x <= n && y >= 1 && y <= m && s[x][y] == '.' && dp[x][y] == -1;
}
int main(){
	pii beg, tar;
	scanf("%d %d", &n, &m);
	scanf("%d %d", &beg.st, &beg.nd);
	scanf("%d %d", &tar.st, &tar.nd);
	for(int i = 1; i <= n; i++){
		scanf("%s", s[i] + 1);
		for(int j = 1; j <= m; j++) dp[i][j] = -1;
	}
	PQ<O> pq;
	pq.push({beg.st, beg.nd, 0});
	while(!pq.empty()){
		O p = pq.top();
		pq.pop();
		if(dp[p.x][p.y] != -1) continue;
		dp[p.x][p.y] = p.val;
		if(p.x == tar.st && p.y == tar.nd) return !printf("%d", p.val);
		for(int i = -2; i <= 2; i++){
			for(int j = -2; j <= 2; j++){
				if(ch(p.x + i, p.y + j)) {
					int val = p.val + (abs(i) + abs(j) == 1 ? 0 : 1);
					pq.push({p.x + i, p.y + j, val});
				}
			}
		}
	}
	printf("-1");

}

Measured memory_bytes: 9936
#include<iostream>

using namespace std;

int main()
{
	string s;

	int alphabet[26];

	cin >> s;

	for(int i=0;i<26;i++)
	{
		alphabet[i] = 0;
	}

	for(int i=0;i<s.size();i++)
	{
		int index = s[i] - 'a';
		alphabet[index]++;
	}

	for(int i=0;i<26;i++)
	{
		if(alphabet[i] == 0)
		{
			char out = 'a'+i;
			cout << out << endl;
			return 0;
		}
	}

	cout << "None" << endl;

	return 0;
}

Measured memory_bytes: 512
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};

fn main() {
    input! {
        n: usize,
        ab: [(i64, i64); n],
    }
    // println!("{:?}", ab);
    let mut ab = ab;
    ab.sort_by_key(|x| x.1);

    let mut sum = 0;
    for i in ab {
        sum += i.0;
        if i.1 < sum {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


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

int main() {
    int A, B, K;
    cin >> A >> B >> K;

    int cnt = 0;
    for(int i=100; i>=1; i--){
        if(A%i==0 && B%i==0) cnt++;
        if(cnt == K){
            cout << i << endl;
            return 0;
        }         
    }
    return 0;
}


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

int main(void){
    char c;
    int b,ans;
    
    cin >> ans;
    while(1){
        cin >> c;
        
        if(c == '=') break;
        cin >> b;
        switch(c){
            case '+':
                ans += b;
                break;
                
            case '-':
                ans -= b;
                break;
                
            case '*':
                ans *= b;
                break;
                
            case '/':
                ans /= b;
                break;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long x; 
    double p;
    cin>>x>>p;
  if(x%2){cout<<setprecision(20)<<(((double)x+1)/2)/p*100<<endl;}
  else{ cout<<setprecision(20)<<(((double)x)/2)/p*100<<endl;}
}


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

int main()
{
    int n;
    cin >> n;
    double ans = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        ans += 1.0 / a;
    }
    cout << 1.0 / ans << endl;
    return 0;
    
}

Measured memory_bytes: 256
N = int(input())
direction = list(input())
change = [0]*(N+1)
# print(direction)
change[0] = direction.count("E")
# print(change)
for i in range(N):
    f_n = 0
    f_p = 0
    if direction[i] == "E":
        f_n = 1
    else:
        f_p = 1
    change[i+1] = change[i] - f_n + f_p
# print(change)
print(min(change))

Measured memory_bytes: 17484
#include <bits/stdc++.h>
using namespace std;
 
int main(){
   long long n,a,b,c,d,e,ans1;
   cin>>n>>a>>b>>c>>d>>e;
   ans1=min(min(min(a,b),min(c,d)),e);
   ans1=4+(n+ans1-1)/ans1;
    cout<<ans1;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        String result = c + " " + a + " " + b;

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 21844
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    map<int, ll> nums;
    REP(i, n){
        nums[a[i]]++;
    }
    ll sum = accumulate(a.begin(), a.end(), 0LL);
    int q;
    cin >> q;
    REP(i, q){
        int b, c;
        cin >> b >> c;
        sum += (nums[b] * c - nums[b] * b); 
        nums[c] += nums[b];
        nums[b] = 0;
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 9488
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	vector<string> a(n),b(m);
	for(int i = 0;i < n; i++)
		cin>>a[i];
	for(int j = 0; j< m ; j++)
		cin>>b[j];
	if(m>n)
	{
		cout<<"No"<<endl;
		return 0;
	}
	int flag = 0;
	for(int i = 0;i<=n-m; i++)
	{
		int ans = 0;
		for(int j = 0; j<=n-m;j++)
		{
			if(a[i].substr(j,m)==b[0])
			{
				for(int y = i,h2=0;y<min(n,i+m);y++,h2++)
				{
					if(a[y].substr(j,m)==b[h2])
						ans++;
					else
						ans=0;
				}
			}
		}
		if(ans>=m)
		{
			flag = 1;
		}

	}
	if(flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

ll power(ll a, ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans*=a;
        a*=a;
        n>>=1;
    }
    return ans;
}

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

int main()
{
    IOS;
    ll n;
    cin>>n;
    ll a[n];
    repf(i,0,n) cin>>a[i];
    ll dp[n][n];
    // repf(i,0,n)
    // {
    //     repf(j,0,n)
    //     {
            
    //     }
    // }
    repb(i,n-1,0)
    {
        repf(j,i,n)
        {
            if(i==j) dp[i][j]=(n%2?a[i]:-a[i]);
            else if(i+1==j) dp[i][j]=max(a[i]-a[j],a[j]-a[i]);
            else
            {
                ll x=a[i]+min(-a[i+1]+dp[i+2][j],-a[j]+dp[i+1][j-1]);
                ll y=a[j]+min(-a[i]+dp[i+1][j-1],-a[j-1]+dp[i][j-2]);
                dp[i][j]=max(x,y);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
    return 0;  
}

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pi;
#define PI 3.1415926

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    int a, b, h, m;
    cin >> a >> b >> h >> m;

    cout.precision(19);
    long double angle = abs(m*6-(h*30+m*0.5))*M_PI/180;
    long double c = sqrt(a*a+b*b-2*a*b*cos(angle));
    cout << c << endl;

    return 0;
}


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

struct Record {
  string city;
  int point;
  int idx;
};

int main() {
  int N;
  cin >> N;
  vector<Record> records;
  string s;
  int p;
  for(int i = 1; i <= N; ++i) {
    cin >> s >> p;
    records.push_back({s, p, i});
  }
  sort(records.begin(), records.end(), [](const auto& lhs, const auto& rhs) {
    if(lhs.city == rhs.city) {
      return lhs.point > rhs.point;
    } else {
      return lhs.city.compare(rhs.city) < 0;
    }
  });
  for(auto r : records) {
    cout << r.idx << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0; i < n; i++)
#define REPR(i, n) for(long long i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(long long i = m; i <= n; i++)
#define FORR(i, m, n) for(long long i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;


int main(){FIN

    char s;cin>>s;
    if(s=='A') cout<<'T';
    else if(s=='T') cout<<'A';
    else if(s=='G') cout<<'C';
    else cout<<'G';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> tmp;
    vector<vector<int>> bra(n, tmp);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        bra[a-1].push_back(b-1);
        bra[b-1].push_back(a-1);
    }
    int res=0;
    queue<P> q;
    q.push(make_pair(0, 0));
    while(!q.empty()){
        P now = q.front();
        q.pop();
        if((now.second>>now.first)%2==0){
            now.second += 1<<now.first;
            if (now.second == (1 << n) - 1) {
              res++;
            }
            int len = bra[now.first].size();
            rep(i, len){
                q.push(make_pair(bra[now.first][i], now.second));
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
using namespace std;
 
int main(){
    int x,y,res;
    cin >> x >> y;
    while(1){
        if(x >= y){
            x = x%y;
            if(x == 0){
                res = y;
                break;
            }
        }
        else{
            y = y%x;
            if(y == 0){
                res = x;
                break;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3060
import java.util.*;
import java.io.*;

class Main {
    final private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    final private static StringBuilder sb = new StringBuilder();

    public static void main(final String[] args) throws IOException {
        final String line = in.readLine();
        
        for (int i = line.length() - 1;  0 <= i; --i) {
            sb.append(line.charAt(i));
        }
        System.out.println(sb);
    }
}

Measured memory_bytes: 16848
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#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 <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

void solve() {
    const int N = 8;
    vector<ll> X(N+1);
    for(int i=0; i<N+1; i++) {
        int v; scanf("%x", &v);
        X[i] = v;
    }

    ll ans = 0;
    for(int i=0; i<32; i++) {
        int a = (X[N] >> i & 1);
        int b = (accumulate(X.begin(), X.begin() + N, 0LL) >> i & 1);
        if(a != b) {
            ans |= (1LL << i);
            for(int j=0; j<N; j++) X[j] ^= (1LL << i);
        }
    }

    printf("%llx\n", ans);
}

int main() {
    int N; cin >> N;
    while(N--) solve();
    return 0;
}



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

int main(){
    int n,m;
    cin>>n>>m;
    priority_queue<long long> pq;
    for(int i=0;i<n;++i){
        long long temp;
        cin>>temp;
        pq.push(temp);
    }

    for(int i=0;i<m;++i){
        long long temp=pq.top();
        pq.pop();
        pq.push(temp/2);
    }

    long long ans=0;
    while(!pq.empty()){
        ans+=pq.top();
        pq.pop();
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 4252
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))

n = int(input())
for i in range(ceil(sqrt(n)), 0, -1):
    f = n / i
    j = floor(f)
    if f - j > 0: continue
    print(i + j - 2)
    sys.exit()

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

int main()
{
    int n, d;

    cin >> n >> d;

    vector<vector<int>>list(n, vector<int>(d));

    rep(i , n)
    {
        rep(j , d)
        {
            cin >> list.at(i).at(j);
        }
    }

    int ans = 0;

    rep(i ,n)
    {
        rep(j , i)
        {
            int sq = 0;
            rep(k, d)
            {
                int s = list.at(i).at(k) - list.at(j).at(k);
                sq += s * s;
            }
            int s = sqrt(sq) + 0.5;
            if(s * s == sq)
            {
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <array>

using namespace std;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) {
	return ist >> right.first >> right.second;
}
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) {
	return ost << right.first << ' ' << right.second;
}

#if 1
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

int N;
int sum;
int main() {
	cin >> N;
	REP(i, 0, N) {
		int a, b;
		cin >> a >> b;
		sum += b - a + 1;
	}
	cout << sum << endl;
	return 0;
}

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

vector<long> sump(51);
vector<long> sumb(51);
vector<long> suma(51);

long burger(long index, long x)
{
    if (suma[index] / 2 + 1 == x)
    {
        return sump[index] / 2 + 1;
    }
    else if (1 == x)
    {
        return 0;
    }
    else if (suma[index] == x)
    {
        return sump[index];
    }
    else if (suma[index] / 2 + 1 < x)
    {
        return sump[index] / 2 + 1 + burger(index - 1, x - suma[index] / 2 - 1);
    }
    else
    {
        return burger(index - 1, x - 1);
    }
}

int main()
{
    long N, X;
    cin >> N >> X;

    sump[0] = 1;
    sumb[0] = 0;
    for (int i = 1; i < N + 1; i++)
    {
        sump[i] = 2 * sump[i - 1] + 1;
        sumb[i] = 2 * sumb[i - 1] + 2;
        suma[i] = sump[i] + sumb[i];
    }

    //cout << sump[N] << "\n";

    cout << burger(N, X) << "\n";
}

Measured memory_bytes: 256
#include <cstdio>

const int MN = 200005;

int N, A[MN];

int stkp[MN], stkv[MN], tp;
inline bool check(int M) {
	tp = 0;
	for (int i = 1; i <= N; ++i) {
		if (A[i] <= A[i - 1]) {
			while (stkp[tp] > A[i]) --tp;
			int pos = A[i];
			while (pos) {
				if (stkp[tp] != pos || stkv[tp] != M - 1) {
					if (stkp[tp] != pos)
						stkp[++tp] = pos,
						stkv[tp] = 0;
					++stkv[tp];
					break;
				} else --tp, --pos;
			}
			if (!pos) return 0;
		}
	}
	return 1;
}

int main() {
	int ok = 1;
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) {
		scanf("%d", &A[i]);
		if (A[i] <= A[i - 1]) ok = 0;
	}
	if (ok) return puts("1"), 0;
	int lb = 2, rb = N, mid = 0, ans = 0;
	while (lb <= rb) {
		mid = (lb + rb) >> 1;
		if (check(mid)) ans = mid, rb = mid - 1;
		else lb = mid + 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

// powのll番
ll pow(ll a,ll b) {
    ll k = 1;
    REP(_,b) k*=a;
    return k;
}


void solve() {
    ll A,B,C,K;
    cin >> A >> B >> C >> K;
    REP(r,K+1)
    REP(g,K+1-r)
    REP(b,K+1-r-g) {
                auto rc = A * pow(2ll, (ll)r);
                auto gc = B * pow(2ll,(ll) g);
                auto bc = C * pow(2ll, (ll)b);
                if (bc > gc && gc > rc) {
                    cout << "Yes" << endl;
                    return;
                }
    }
    cout << "No" << endl;
}

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

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




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

string s;
cin >> s;

vector<string> t = {"Sunny","Cloudy","Rainy","Sunny"};

rep(i,3) if(s == t[i]) cout << t[i+1] << endl;

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll a, b;std::cin >> a >> b;
  if(a==1) a+=13;
  if(b==1) b+=13;
  std::cout << (a==b?"Draw":a>b?"Alice":"Bob") << '\n';
  return 0;
}


Measured memory_bytes: 384