akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define LONGMAX 1e18
#define MOD 1000000007
#define mp make_pair
#define endl "\n"
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define fr(a,n) for(int i=a;i<n;i++)

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

	int n,w;
	cin>>n>>w;

	vector<ll> dp(w+1,0);

	ll val,wt=0;
	for(int i=0;i<n;i++)
	{
		cin>>wt>>val;

		for(int x=w-wt;x>=0;x--)
		{
			dp[x+wt]=max(dp[x+wt],dp[x] + val);
		}
	}

	ll ans=0;
	for( int i=0;i<w+1;i++)
	{
		ans=max(ans,dp[i]);
	}
	cout<<ans;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> q(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> q[i];
  }
  vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    v[i] = i + 1;
  }
  int cnt = 1;
  int x = 0;
  int y = 0;
  do {
    if (v == p) {
      x = cnt;
    }
    if (v == q) {
      y = cnt;
    }
    ++cnt;
  } while (next_permutation(v.begin(), v.end()));
  cout << abs(x - y) << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define M 50
using namespace std;

int n,q;
int c[300100],x;

int main(){
  scanf("%d%d",&n,&q);
  int lim = 0;
  for(int i=0;i<n;i++){ scanf("%d",&c[i]); lim = max(lim,c[i]); }
  sort(c,c+n);
  int m[M+1] = {0};
  for(int i=1;i<=M;i++){
    for(int j=0;j<n;j++)m[i] = max(m[i],c[j]%i);
  }

  for(int i=0;i<q;i++){
    scanf("%d",&x);
    if(x<=M)printf("%d\n",m[x]);
    else{
      int res = 0;
      for(int j=1;j*x<=lim;j++){
	int tmp = lower_bound(c,c+n,j*x) - c;
	if(tmp)res = max(res,c[tmp-1]%x);
      }
      printf("%d\n",res);
    }
  }
}

Measured memory_bytes: 2212
import java.util.Scanner;

public class Main {

    private static final int N = 100;
    private static Scanner scanner = new Scanner(System.in);
    private static int[][] Mat = new int[N][N];
    private static int[] Start = new int[N];
    private static int[] Finish = new int[N];

    private static int n;
    private static int time = 1;



    public static void main(String[] argss){

        graph_input();

        for (int i = 0; i < n; i++) {
            if (Finish[i] == 0)
                dfs_recursive(i);
        }

        print_answer();
    }

    private static void dfs_recursive(int u) {

        Start[u] = time++;

        for (int v = 0; v < n; v++) {
            if (Mat[u][v] == 1 && Start[v] == 0){
                dfs_recursive(v);
            }
        }

        Finish[u] = time++;

    }

    private static void print_answer() {
        for (int i = 0; i < n; i++) {
            System.out.print((i+1) + " ");
            System.out.print(Start[i] + " ");
            System.out.print(Finish[i] + "\n");
        }
    }


    private static void graph_input() {

        n = scanner.nextInt();

        int u, k, v;
        for (int i = 0; i < n; i++) {
            u = scanner.nextInt();
            k = scanner.nextInt();
            for (int j = 0; j < k; j++) {
                v = scanner.nextInt();
                Mat[u-1][v-1] = 1;
            }
        }
    }
}

Measured memory_bytes: 28448
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>

using namespace std;

int main(){

    int N, K;
    cin >> N >> K;
    vector<bool> D(10);

    int d;
    for(int i = 0; i < K; i++){
        cin >> d;
        D[d] = true;
    }

    for(int i = N; i < 100000; i++){
        int temp = i;
        bool isOk = true;
        while(temp > 0){
            int digit = temp % 10;
            if(D[digit]){
                isOk = false;
                break;
            }
            temp /= 10;
        }

        if(isOk){
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    int n,m;
    cin >> n >>m;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(m);
    vector<int> d(m);
    for(int i=0;i<n ;i++){
        cin >> a[i] >>b[i] ;
    }
    for(int i=0;i<m ;i++){
        cin >> c[i] >>d[i] ;
    }
    for(int i=0;i<n;i++){
        int dis=pow(10,9);
        for(int j=0;j<m;j++){
            dis = min(dis,(abs(a[i]-c[j])+abs(b[i]-d[j])));
        }
        for(int j=0;j<m;j++){
            if(dis==(abs(a[i]-c[j])+abs(b[i]-d[j]))){
                cout<< j+1 <<endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

long N,ans=0;
scanf("%ld",&N);

long A[N];
for (int i = 0; i < N; i++){
    scanf("%ld",&A[i]);
}

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


printf("%ld",ans);


return 0;

}

Measured memory_bytes: 3248
#include <iostream>
#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>
#include <functional>
#include <random>

using namespace std;
 
#define mod 998244353
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
long X[400001];
bool S[200000];
void Calc(){
	int N = rei();
	string S0 = res();
	for(int i=0;i<N;i++){
		S[i] = S0[i] == '1';
	}
	for(int i=1;i<=2*N;i++){
		if((2*N) % i == 0){
			if(N % i == 0){
				continue;
			}
			else{
				int c = i / 2;
				long count = 0;
				for(int j=0;j<c;j++){
					count *= 2;
					if(S[j]){
						count++;
					}
					count %= mod;
				}
				bool OK = true;
				for(int j=c;j<N;j++){
					if(S[j-c] && S[j]){
						break;
					}
					if(!S[j-c] && !S[j]){
						OK = false;
						break;
					}
				}
				if(OK){
					count++;
				}
				count %= mod;
				X[i] = count;
			}
		}
	}
	for(int i=1;i<=2*N;i++){
		if((2*N)%i == 0){
			for(int j=2;j*i<=2*N;j++){
				X[j*i] += mod - X[i];
				X[j*i] %= mod;
			}
		}
	}
	long ans = 0;
	for(int i=1;i<=2*N;i++){
		if((2*N)%i == 0){
			ans += i*X[i]%mod;
		}
	}
	ans %= mod;
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 3988
#include<iostream>
#include<deque>

using namespace std;

int main()
{
	for(;;){
		int a,b;
		int map[20][20] = {0};
		int kouji[40][2];
		int n;
		bool flg = 0;
		
		cin >> a;
		cin >> b;
		if(a == 0 && b == 0){
			break;
		}
		cin >> n;
		//a >> x, b >> y
		map[0][0] = 0;
		map[1][0] = 1;
		map[0][1] = 1;
		
		for(int i = 0; i < n; i++){
			cin >> kouji[i][0] >> kouji[i][1];
		}
		
		int i, j;
		for(i = 0; i < b; i++){
			for(j = 0; j < a; j++){
				for(int k = 0; k < n; k++){
					if(j == kouji[k][0]-1 && i == kouji[k][1]-1){
						map[i][j] = 0;
						flg = 1;
						break;
					}
				}
				if(flg != 1){
					if(i == 0 && j == 0){
						map[i][j] = 1;
					}
					else if((i == 1 && j == 0)||(i == 0 && j == 1)){
						map[i][j] = 1;
					}
					else{
						if(i == 0){
							map[i][j] = map[i][j-1];
						}
						else if(j == 0){
							map[i][j] = map[i-1][j];
						}
						else{
							
							map[i][j] = map[i-1][j] + map[i][j-1];
						}
					}
				}
				flg = 0;
			//	printf("%d\t",map[i][j]);
			//	printf("map[%d][%d] >> %d\n",i,j,map[i][j]);
			}
//			puts("");
		}
		printf("%d\n",map[b-1][a-1]);
	}
}

Measured memory_bytes: 0
#include <deque>
#include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
struct state { long long a, b; };
inline bool operator<(const state& s1, const state& s2) { return s1.a < s2.a; }
int N; long long D, A[33], B[33];
long long sa1[32777], sb1[32777], sa2[32777], sb2[32777]; // bit-dp sum
int cnt1, cnt2; state vl[14348922], vr[14348922]; // meet-in-the middle
int que[15000000]; // searching deque
int main() {
	scanf("%d%lld", &N, &D);
	for (int i = 0; i < N; i++) scanf("%lld%lld", &A[i], &B[i]);

	// Meet-in-the-middle Algorithm
	int sep1 = (N >> 1), sep2 = N - sep1;
	for (int i = 0; i < sep1; i++) {
		int b1 = (1 << i), b2 = (1 << (i + 1));
		for (int j = b1; j < b2; j++) {
			sa1[j] = sa1[j - b1] + A[i];
			sb1[j] = sb1[j - b1] + B[i];
		}
	}
	for (int i = 0; i < sep2; i++) {
		int b1 = (1 << i), b2 = (1 << (i + 1));
		for (int j = b1; j < b2; j++) {
			sa2[j] = sa2[j - b1] + A[i + sep1];
			sb2[j] = sb2[j - b1] + B[i + sep1];
		}
	}
	cnt1 = 0;
	for (int i = 0; i < 1 << sep1; i++) {
		int r = (1 << sep1) - i - 1, j = r;
		do {
			// i -> remain, j -> anna, k -> bruno
			int k = r - j;
			vl[cnt1++] = state{ sa1[k] - sa1[j], sb1[k] - sb1[j] };
			j = (j - 1) & r;
		} while (j != r);
	}
	cnt2 = 0;
	for (int i = 0; i < 1 << sep2; i++) {
		int r = (1 << sep2) - i - 1, j = r;
		do {
			// i -> remain, j -> anna, k -> bruno
			int k = r - j;
			vr[cnt2++] = state{ sa2[k] - sa2[j], sb2[k] - sb2[j] };
			j = (j - 1) & r;
		} while (j != r);
	}
	sort(vl, vl + cnt1);
	sort(vr, vr + cnt2);
	int cl = 0, cr = 0, dl = 0, dr = 0;
	long long ret = 0;
	for (int i = cnt2 - 1; i >= 0; i--) {
		while (cr < cnt1 && vl[cr].a + vr[i].a <= D) {
			while ((dr - dl) && vl[que[dr - 1]].b <= vl[cr].b) dr--;
			que[dr++] = cr++;
		}
		while (cl < cnt1 && vl[cl].a + vr[i].a < -D) {
			if ((dr - dl) && que[dl] == cl) dl++;
			cl++;
		}
		if (dr - dl) ret = max(ret, vr[i].b + vl[que[dl]].b);
	}
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 457832
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int i,j,k;
	char word[100],output[1000],loopWord[2],tmpWord;
	int loop;
	
	while(scanf("%s",word)!=EOF)
	{
		i=0;
		j=0;
		while(word[i]!='0')
		{
			//@があったら
			if(word[i]=='@')
			{
				//次の文字を見て繰り返す回数を見る
				i++;
				loopWord[0]=word[i];
				loop=atoi(loopWord);
				//printf("%d回\n",loop);
				//更に次の文字を見て繰り返される文字を見る
				i++;
				tmpWord=word[i];
				for(k=1;k<loop;k++)
				{
					output[j]=tmpWord;
					j++;
				}
			}
			//それ以外の時
			else
			{
				output[j]=word[i];
				i++;
				j++;
			}
		}
		output[j]='\0';
		printf("%s\n",output);
	}
	
	return 0;
}

Measured memory_bytes: 536
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w;cin>>h>>w;
    vector<vector<char>> a(h,vector<char> (w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a.at(i).at(j);
        }
    }
    for(int i=0;i<w+2;i++){
        cout<<"#";
    }
    cout<<endl;
    for(int i=0;i<h;i++){
        cout<<"#";
        for(int j=0;j<w;j++){
            cout<<a.at(i).at(j);
        }
        cout<<"#"<<endl;;
    }
    for(int i=0;i<w+2;i++){
        cout<<"#";
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
const int inf=10000000;

int n,num[10];

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		vector<int> l,r;
		l.push_back(-1*inf);
		r.push_back(-1*inf);
		bool ans=true;
		for(int j=0;j<10;j++){
			cin>>num[j];
		}
		l.push_back(num[0]);
		for(int j=1;j<10;j++){
			if(num[j]>l.back()&&num[j]>r.back()){
				if(l.back()>=r.back()) l.push_back(num[j]);
				else r.push_back(num[j]);
			}
			else{
				if(num[j]<=l.back()&&num[j]<=r.back()) ans=false;
				else{
					if(num[j]>l.back()) l.push_back(num[j]);
					else r.push_back(num[j]);
				}
			}
		}
		if(ans) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> P(N), C(N);
    rep(i,N){
        cin >> P[i];
        P[i]--;
    }
    rep(i,N){
        cin >> C[i];
    }
    ll M = min(N,K);
    ll ans = -1e18;
    rep(i,N){
        ll pos = P[i];
        ll cur = 0;
        rep(j,M){
            cur += C[pos];
            pos = P[pos];
            cmax(ans,cur);
        }
    }
    if(K <= N){
        cout << ans << endl;
        return 0;
    }
    vector<Pll> v(N); 
    rep(i,N){
        ll pos = P[i];
        ll cur = 0;
        vector<ll> memo(N,0);
        rep(j,N+10){
            if(memo[pos] == 1){
                v[i] = Pll(cur,j);
                break;
            }else{
                memo[pos] = 1;    
                cur += C[pos];
                pos = P[pos];
            }
        }
    }
    //rep(i,v.size()){
    //    cout << v[i].fi << " " << v[i].se << endl;
    //}
    rep(i,N){
        ll sc = v[i].fi;
        ll cnt = v[i].se;
        ll cur = 0;
        //cout << "bbb:"<< v[0].se << endl;
        cur += (K/cnt)*sc;
        ll r = K%cnt;
        ll pos = P[i];
        //cout << "aaa"<<endl;
        cmax(ans,cur);
        rep(i,r){
            cur += C[pos];
            cmax(ans,cur);
            pos = P[pos];
        }
    }
    rep(i,N){
        ll sc = v[i].fi;
        ll cnt = v[i].se;
        ll cur = 0;
        cur += ((K/cnt)-1)*sc;
        ll pos = P[i];
        cmax(ans,cur);
        rep(i,cnt){
            cur += C[pos];
            cmax(ans,cur);
            pos = P[pos];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3832
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int ans,key,tm;
    key=999999999;
    ans=0;
    for(int i=0; i<n; i++){
        cin>>tm;
        if(tm<key&&tm%10!=0)key=tm;
        ans+=tm;
    }
    if(key==999999999)cout<<"0"<<endl;
    else if(ans%10!=0)cout<<ans<<endl;
    else cout<<ans-key<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char const *argv[]) {
    int N;
    cin >> N;
    vector<int> Hs(N);
    for (int i = 0; i < N; i++) {
        cin >> Hs[i];
    }
    vector<long long int> costs(N, 0);
    for (int i = 0; i < N; i++) {
        if (i == 0) {
            continue;
        } else if (i == 1) {
            int diff_1 = max(Hs[i] - Hs[i - 1], Hs[i - 1] - Hs[i]);
            costs[1] = (long long int) diff_1;
        } else {
            int diff_1 = max(Hs[i] - Hs[i - 1], Hs[i - 1] - Hs[i]);
            int diff_2 = max(Hs[i] - Hs[i - 2], Hs[i - 2] - Hs[i]);
            costs[i] = min(diff_1 + costs[i - 1], diff_2 + costs[i - 2]);
        }
    }
    cout << costs[N - 1] << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h> 
using namespace std;
#define fl(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define ld long double
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define pii          pair<int,int>
#define pll          pair<ll,ll>
#define vi           vector<int>
#define vll          vector<long long>
#define all(x)       x.begin(),x.end()
#define mod 1000000007 
#define mx 1000005
#define mii          map<int,int>
#define mumii        multimap<int,int> 
#define mx2 65
#define inf 4e18
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define gt           greater<int>()
//The ASCII value of the lowercase alphabet is from 97 to 122.
//The ASCII value of the uppercase alphabet is from 65 to 90.

int solve()
{
     int n,m,sum=0;
     double y;
     cin>>n>>m;
     vi a;
     fl(i,0,n)
     {
          int x;
          cin>>x;
          a.pb(x);
          sum+=x;
     }
     y=(double)sum/(double)(4*m);
     int cnt =0;
     fl(i,0,n)
     {
          if(y>a[i])
          cnt++;
     }
     
     if((cnt+m)>n)
     cout<<"No";
     else
     cout<<"Yes";
}
int main()
{
	fast;
	int t=1;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

# In[1]:


N = int(input())
A = [int(x) for x in input().split()]
MOD = 10 ** 9 + 7


# In[2]:


count = [0] * 60
for i in range(N):
#     s = format(A[i], '060b')
#     for d in range(60):
#         count[d] += int(s[d])
    for j in range(60):
        count[j] += A[i] % 2
        A[i] //= 2


# In[ ]:





# In[3]:


ans = 0
for d in range(60):
    ans = (ans + count[d] * (N - count[d]) * 2 ** (d)) % MOD


# In[4]:


print(ans)


# In[ ]:






Measured memory_bytes: 122808
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mt make_tuple
typedef long long int ll;

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;

typedef long long int ll;
int n;
string a, b, c;

int main(void){
	cin >> n >> a >> b >> c;

	int ans = 0;
	for(int i=0;i<n;i++){
		vi cnt(26);
		cnt[a[i] - 'a']++;
		cnt[b[i] - 'a']++;
		cnt[c[i] - 'a']++;
		int maxi = 0;
		for(int j=0;j<26;j++){
			maxi = max(maxi, cnt[j]);
		}
		ans += 3 - maxi;
	}
	cout << ans << endl;



    return 0;
}


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

long long MOD = 1e9+7;
int MAX_INT = 1e9;

// 最大公約数
long long gcd(long long a, long long b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
// 最小公倍数
long long lcm(long long a, long long b) {
  return a / gcd(a, b) * b;
}

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

  int N, K;
  cin >> N >> K;
  vector<int> A(200000 + 1, 0);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A[a]++;
  }
  sort(A.rbegin(), A.rend());
  int ans = 0;
  for (int i = 0; i < K; i++) {
    ans += A[i];
  }

  cout << N - ans << endl;

  return 0;
}


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

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i, n){
        cin >> a[i];
    }
    int ans = 4000000;
    for (int i = -100; i <= 100; i++)
    {
        int sum = 0;
        for (int j = 0; j < n; j++)
        {
            sum += pow(a[j]-i, 2);
        }
        ans = min(ans, sum);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
 
public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int mum = sc.nextInt();
        String[] input = new String[num];
        String[][] str = new String[num][mum];
        String[][] transpose = new String[mum][num];
        boolean[] row = new boolean[num];
        boolean[] line = new boolean[mum];
        for (int i = 0 ; i < num ; i++){
            input[i] = sc.next();
            for (int j = 0 ; j < mum ; j++){
                str[i][j] = String.valueOf(input[i].charAt(j));    
                if(String.valueOf(str[i][j]).equals("#")){
                row[i]=true;    
                }
            }
        }
        for(int i = 0; i < num; i++) {
            for (int j = 0; j < mum; j++) {
                transpose[j][i] = str[i][j];
            }
        }
        for (int i = 0 ; i < mum ; i++){
            for (int j = 0 ; j < num ; j++){
                if(String.valueOf(transpose[i][j]).equals("#")){
                line[i]=true;    
                }
            }
        }
         for (int i = 0 ; i < num ; i++){
             if(row[i]){
                 for (int j = 0 ; j < mum ; j++){
                     if(line[j]){
                         System.out.print(String.valueOf(str[i][j]));    
                     }
                 }
                 System.out.println();
             }
         }
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

int UF[100010];
bool UL[100010];

int root(int x) {
	if (UF[x] == x)return x;
	return UF[x] = root(UF[x]);
}

void unite(int x, int y) {
	x = root(x);
	y = root(y);
	if (x == y)return;
	UF[x] = y;
}

int main() {
	for (int i = 0;i < 100010;i++)UF[i] = i, UL[i] = 0;
	int N, M, K, fl, L;
	cin >> N >> M;
	for (int i = 0;i < N;i++) {
		cin >> K;
		cin >> fl;
		UL[fl] = 1;
		for (int j = 1;j < K;j++) {
			cin >> L;
			UL[L] = 1;
			unite(fl, L);
		}
	}
	
	for (int i = 1;i <= M;i++) {
		//cout << root(i) << " ";
		if (UL[i] && (root(fl) != root(i))) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}

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

int main(){
  int N;
  cin>>N;
  int M[12]={1,6,36,216,1296,7776,46656,9,81,729,6561,59049};
  int DP[100010];
  for(int i=1;i<=100009;i++){
    DP[i]=50;
  }
  DP[0]=0;
  
  for(int i=0;i<100000;i++){
    for(int j=0;j<12;j++){
      if(i+M[j] <100005 && DP[i+M[j]] > DP[i]+1){
        DP[i+M[j]]=DP[i]+1;
      }
    }
  }
  cout<<DP[N]<<endl;
  return 0;
}

        

Measured memory_bytes: 4040
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long

struct edge{ int from, to, cost; };


int n, m;
bool used[20005];

bool comp(const edge& e1, const edge& e2)
{
	return e1.cost < e2.cost;
}

int main()
{
	while (cin >> n >> m, n)
	{
		edge es[20005];
		REP(i, m)
		{
			int a, b, c;
			cin >> a >> b >> c;
			c--; b--;
			es[i] = edge{ b, c, a };
		}
		sort(es, es + m, comp);
		memset(used, false, sizeof(used));
		used[0] = true;
		REP(i, m)
		{
			if (used[es[i].from]) used[es[i].to] = true;
		}
		int cnt = 0;
		REP(i, n)
		{
			if (used[i]) cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1432
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()

int main() {
  ll n, k, q;
  cin >> n >> k >> q;
  vector<ll> point(n, 0);
  for (ll i = 0; i < q; i++) {
    ll tmp;
    cin >> tmp;
    ll x = point.at(tmp - 1);
    point.at(tmp - 1) = x + 1;
  }
  for (ll i = 0; i < n; i++) {
    ll x = point.at(i);
    point.at(i) = x + k - q;
    if (point.at(i) > 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

Measured memory_bytes: 1408
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let a: usize = read!();
    let b: usize = read!();
    let c: usize = read!();
    let k: usize = read!();

    let max = a.max(b.max(c));
    let mut sum = a + b + c - max;
    
    sum += max * 2usize.pow(k as u32);
    println!("{}", sum);
}


Measured memory_bytes: 2152
open Batteries
let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let k = Scanf.scanf "%d " (fun a -> a) in

  let rec aux n res =
    if n = 0 then res else
      aux (n-1) (if res*2 > res+k then res+k else res*2)
  in
  Printf.printf "%d\n" @@
  aux n 1


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<int, int>  pii;
typedef pair<ld, ld>  pld;
ll n;
const ll mod = 1e9+7;
ll a[200009];
ll fact[200009];
ll invfact[200009];
ll pw(ll x, ll y){
    ll ret = 1;
    while(y > 0){
        if(y%2)
            ret = ret*x%mod;
        x = x*x%mod;
        y /= 2;
    }
    return ret;
}
ll comb(ll x, ll y){
    return fact[x]*invfact[x-y]%mod*invfact[y]%mod;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n;
    for(ll i = 0; i < n; ++i)
        cin >> a[i];
    fact[0] = 1;
    invfact[0] = 1;
    for(ll i = 1; i <= 100; ++i){
        fact[i] = i*fact[i-1]%mod;
        invfact[i] = pw(fact[i], mod-2);
    }

    sort(a, a+n, greater<ll>());
    ll ans = 0;
    for(ll i = 0; i < n; ++i){
        if(i%2){
            ans += pw(2, n-i-1)*pw(2, n)%mod*a[i]%mod*(i+2)%mod*pw(2, i-1)%mod;
            ans %= mod;
        }
        else{
            ll add = (i+2)*((pw(2, i)-comb(i, i/2)+mod)%mod)/2%mod;
            add += comb(i, i/2)*(i/2+1)%mod;
            add %= mod;
            ans += pw(2, n-i-1)*a[i]%mod*pw(2, n)%mod*add%mod;
            ans %= mod;
        }
    }
    cout << ans << "\n";
}

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


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a;
    long long cum0 = 0;
    long long cum1 = 0;
    int sign = -1;
    long long cost0 = 0;
    long long cost1 = 0;
    while (n--){
        cin >> a;
        sign *= -1;
        cum0 += a;
        cum1 += a;
        if (sign * cum0 <= 0){
            cost0 += abs(cum0 - sign);
            cum0 = sign;
        }
        if (sign * cum1 >= 0){
            cost1 += abs(cum1 + sign);
            cum1 = -sign;
        }
    }
    cout << min(cost0, cost1) << endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        n:usize,
        w:[i64;n],
    }

    let mut sm = w.iter().fold(0, |sum, x| sum + x);
    let mut ans = 99999;
    let mut left = 0;
    for &x in w.iter() {
        left += x;
        ans = min(ans, (sm - left - left).abs());
    }
    println!("{}", ans);
}


Measured memory_bytes: 2192
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

int main(){
  int a,b,x;
  cin >> a >> b >> x;
  int all = a*a*b;
  if(x*2 > all){
    double less = all - x;
    double c = less*2 / double(a*a);
    cout << fixed << setprecision(8) << 180.0*atan(double(c)/double(a))/acos(-1) << endl;
  }else{
    double d = double(x*2) / double(a*b);
    cout << fixed << setprecision(8) << 180.0*atan(double(b)/double(d))/acos(-1) << endl;
  }


  return 0;
}


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

using namespace std;

#define ll long long
#define pi pair<int, int>
#define mkp make_pair
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 1e6 + 5;
const ll MOD = 1e9 + 7;
int arr[mxn];
int n, m, k;
int a, b, c, d;
string s;

ll POW(ll A,ll B,ll R=1)
{while(B){if(B&1)R=R*A%MOD;A=A*A%MOD;B>>=1;}return R;}


void read(){
    cin >> a >> b >> c >> d;
//    for(int i = 0, u, v; i < n; i++){
//        cin >> arr[i];
//    }
}

void solve(){
    while(a > 0 && c > 0){
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            return;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            return;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    //cin >> T;
    while(T--) read(), solve();
    return 0;
}


Measured memory_bytes: 3636
A11,A12,A13 = list(map(int, input().split()))
A21,A22,A23 = list(map(int, input().split()))
A31,A32,A33 = list(map(int, input().split()))
l=[[A11,A12,A13],[A21,A22,A23],[A31,A32,A33],[A11,A22,A33],[A13,A22,A31],[A11,A21,A31],[A12,A22,A32],[A13,A23,A33]]
N = int(input())
for i in range(N):
    b = int(input())
    for j in range(8):
        if b in l[j]:
            l[j].remove(b)
f=1
for i in range(8):
    if l[i]==[]:
        print('Yes')
        f-=1
        break
if f==1:
    print('No')

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

bool isLeap(int y){
	if(y % 4 == 0){
		if(y % 100 == 0){
			if(y % 400 == 0) return true;
			return false;
		}
		return true;
	}
	return false;
}

int main(void){
	int a,b;
	bool first = true;

	while(cin>>a>>b && (a||b)){
		if(first) first = false;
		else cout<<endl;

		int count = 0;

		for(int i=a;i<=b;i++){
			if(isLeap(i)){
				cout<<i<<endl;
				count++;
			}
		}

		if(count == 0){
			cout<<"NA\n";
		}
	}

	return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long [] L = new long[n];
        long sum = 1;
        for(int i=0;i<n;i++){
            L[i]= sc.nextLong();
            if(L[i]==0) sum = 0;
        }
        if(sum!=0) {
            long lim = (long)Math.pow(10,18);
            for(int i=0;i<n;i++){
                long lim2 = (long)Math.ceil(lim/sum);
                if(L[i]>lim2){
                    sum=-1;
                    break;
                }
                else sum*=L[i];
            }
        }
        if(sum!=-1)System.out.println(sum);
        else System.out.println("-1");
    }
}

Measured memory_bytes: 61332
#include<stdio.h>
int main(){

  int i,j,H,W;

  while(1){
    
    scanf("%d %d", &H, &W);
    if ( H == 0 && W == 0 ) break;
    
    for ( i = 0 ; i < H ; i++){
      
      for ( j = 0 ; j < W; j++){
	printf("#");
      }
      printf("\n");
      
    }

    printf("\n");
  }

  return 0;
  
}

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

int main() {
  string n;
  cin >> n;
  if (n[0] == '7' || n[1] == '7' || n[2] == '7') cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3628
from collections import deque

s=list(input())
q=int(input())
d = deque(s)
reverse=False

for i in range(q):
  qs=list(input().split())
  if qs[0]=='1':
    reverse=not reverse
  else:
    if qs[1]=='1':
      d.appendleft(qs[2]) if not reverse else d.append(qs[2])
    else:
      d.append(qs[2]) if not reverse else d.appendleft(qs[2])
#  print(d)
if reverse:
  d.reverse()
print("".join(d))


Measured memory_bytes: 9332
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	h := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}
	var cnt int
	var ans int
	for i := 0; i < n-1; i++ {
		if h[i] >= h[i+1] {
			cnt++
			ans = max(cnt, ans)
		} else {
			cnt = 0
		}
	}
	fmt.Println(ans)
}

// func max(a ...int) int {
// 	r := a[0]
// 	for i := 0; i < len(a); i++ {
// 		if r < a[i] {
// 			r = a[i]
// 		}
// 	}
// 	return r
// }
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define P pair<int,int>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define asort(x) sort(x.begin(),x.end())
 
int main() {
    int N,K;
  	cin >> N >> K;
    vector<int> nedan(N);
    for(int i = 0; i < N; i++){
      cin >> nedan.at(i);
    }
    sort(nedan.begin(),nedan.end());
    int ans=0;
    for(int i = 0; i < K; i++){
      ans+=nedan.at(i);
    }
    cout << ans << endl;
    }

Measured memory_bytes: 3624
while True:
    M, T, P, R = map(int, input().split())
    if M == 0: break
    teams = [[0, 0, i+1] for i in range(T)]
    miss = [[0 for _ in range(P)] for _ in range(T)]
    solved, time = 0, 1
    logs = [map(int, input().split()) for _ in range(R)]
    for m, t, p, r in logs:
        t -= 1
        p -= 1
        if r == 0:
            teams[t][solved] += 1
            teams[t][time] -= (m + miss[t][p] * 20)
        else:
            miss[t][p] += 1
    teams = sorted(teams, reverse=True)
    before_s, before_t = 0, 0
    for i in range(T):
        s, t, n = teams[i]
        if i != 0:
            print('=' if (s == before_s and t == before_t) else ',', end='')
        before_s, before_t = s, t
        print(n, end='')
    print('')

Measured memory_bytes: 7788
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

int main() {
	int N, K;
	string S;
	cin >> N >> K >> S;
	S[K - 1] = tolower(S[K - 1]);
	cout << S;


	/*string S;
	if(S[0])*/

	/*double N, K;
	cin >> N >> K;
	double ret;

	if (N > K) {

	}
	cout << ret;*/


	return 0;
}

Measured memory_bytes: 256
n = int(input())
ai = list(map(int, input().split(' ')))
while len(ai) > 1:
    ai = list(sorted(list(ai)))
    ai_head = ai[0]
    ai = list(filter(lambda x: x != 0, map(lambda x: x%ai_head, list(ai[1:]))))
    ai.append(ai_head)
print(ai[0])

Measured memory_bytes: 14252
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
  if (!(s))     \
    cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  vector<int> x(5);
  rep(i, 5) {
    cin >> x[i];
    if (x[i] == 0) {
      cout << (i + 1) << endl;
      return 0;
    }
  }
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long


int main(){
    int n;
    cin >> n;
    map<string, int> a;
    REP(i, n) {
        string s;
        cin >> s;
        a[s]++;
    }

    int tmp = 0;
    for(auto &s: a) {
        tmp = max(tmp, s.second);
    }

    for(auto &s: a) {
        if (s.second == tmp) {
            cout << s.first << endl;
        }
    }

    return 0;
}


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

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        while(true) {
            int m = Integer.parseInt(sc.next());
            int f = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if (m == -1 && f == -1 && r == -1) {
                break;
            }
            if (m == -1 || f == -1) {
                out.printf("F\n");
            } else if (m + f >= 80) {
                out.printf("A\n");
            } else if (m + f >= 65) {
                out.printf("B\n");
            } else if (m + f >= 50) {
                out.printf("C\n");
            } else if (m + f >= 30) {
                if (r >= 50) {
                    out.printf("C\n");
                } else {
                    out.printf("D\n");
                }
            } else {
                out.printf("F\n");
            }
        }
        out.flush();
    }
}


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

int f(int x)
{
    int sum = 0;
    while (x != 0) {
        sum += x % 10;
        x /= 10;
    }
    return sum;
}

int main()
{
    int n;
    cin >> n;
    bool flg = 0 == n % f(n);
    cout << (flg ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0567?year=2012

#include <bits/stdc++.h>

using namespace std;


bool cmp(pair<int, int> lhs, pair<int, int> rhs) {
    return lhs.first * rhs.second > rhs.first * lhs.second;
}


int main() {
    int n;//トッピングの種類
    cin >> n;

    int a;//生地の値段
    int b;//トッピングの値段
    int c;//生地のカロリー数
    cin >> a >> b >> c;

    vector<int> topping(105);//トッピングのカロリー
    for (int i = 0; i < n; ++i) {
        cin >> topping[i];
    }
    sort(topping.begin(), topping.end(), greater<>());

    vector<pair<int, int>> vt;//(カロリー，値段)
    for (int k = 0; k <= n; ++k) {
        int sum = accumulate(topping.begin(), topping.begin() + k, c);
        vt.emplace_back(make_pair(sum, a + b * k));
    }

    sort(vt.begin(), vt.end(), cmp);
    cout << vt[0].first / vt[0].second << endl;

    return 0;
}

/*
 * カロリーと値段の比を最大にしたい。
 * トッピングはカロリーの高いものから順に使う。
 * カロリーL/値段L > カロリーR/値段R
 * と比較すると除算による丸めが生じそうなので
 * (カロリーL)*(値段R) > (カロリーR)*(値段L)
 * で比較した。
 *
 */


Measured memory_bytes: 3116
#include <stdio.h>
#include <stdlib.h>

int main() {
    system("python3 -c \'\
s, t = input().split()\n\
a, b = map(int, input().split())\n\
u = input()\n\
if s == u:\n\
    print(a-1, b)\n\
elif t == u:\n\
    print(a, b-1)\n\
\'");

    return 0;
}

Measured memory_bytes: 7876
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

def SI():
    return int(readline())
def MI():
    return map(int, readline().split())
def MLI():
    return map(int, open(0).read().split())

inf = float("inf")


def main():
    N, *AB = MLI()
    
    happiness = defaultdict(list) 
    for A, B in zip(*[iter(AB)]*2):
        happiness[A+B].append((A, B))
        
    turn = -1
    score_A = 0
    score_B = 0
    for key in sorted(happiness.keys())[::-1]:
        values = deque(sorted(happiness[key]))
        while len(values) > 0:
            if turn == -1:
                A, B = values.pop()
                score_A += A
            else:
                A, B = values.popleft()
                score_B += B
            turn *= -1
            
    print(score_A - score_B)
    

if __name__ == "__main__":
    main()

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

using namespace std;

enum FACE { TOP = 0, SOUTH = 1, EAST = 2, WEST = 3, NORTH = 4, BOTTOM = 5 };
class Dice {
 public:
  Dice(int top, int south, int east, int west, int north, int bot) {
    id[TOP] = top;
    id[SOUTH] = south;
    id[EAST] = east;
    id[WEST] = west;
    id[NORTH] = north;
    id[BOTTOM] = bot;
  }
  Dice(vector<int> fs) {
    assert((int)fs.size() == 6);
    for (int i = 0; i < 6; i++) {
      id[i] = fs[i];
    }
  }
  int& operator[](FACE f) { return id[f]; }
  const int& operator[](FACE f) const { return id[f]; }
  bool operator==(const Dice& b) const {
    const Dice& a = *this;
    return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] && a[SOUTH] == b[SOUTH] &&
           a[NORTH] == b[NORTH] && a[WEST] == b[WEST] && a[EAST] == b[EAST];
  }
  // TOP -> SOUTH
  void roll_x() { roll(TOP, NORTH, BOTTOM, SOUTH); }
  // TOP -> EAST
  void roll_y() { roll(TOP, WEST, BOTTOM, EAST); }
  // SOUTH -> WEST
  void roll_z() { roll(SOUTH, EAST, NORTH, WEST); }
  vector<Dice> all_rolls() {
    vector<Dice> ret;
    for (int k = 0; k < 6; (k & 1 ? roll_y() : roll_x()), ++k)
      for (int i = 0; i < 4; roll_z(), ++i) ret.push_back(*this);
    return ret;
  }
  bool equivalent_to(const Dice& di) {
    for (int k = 0; k < 6; (k & 1 ? roll_y() : roll_x()), ++k)
      for (int i = 0; i < 4; roll_z(), ++i)
        if (*this == di) return true;
    return false;
  }

 private:
  void roll(FACE a, FACE b, FACE c, FACE d) {
    auto tmp = id[a];
    id[a] = id[b];
    id[b] = id[c];
    id[c] = id[d];
    id[d] = tmp;
  }
  int id[6];
};

int main() {
  vector<int> v(6);
  for (int i = 0; i < 6; i++) cin >> v[i];
  Dice dc(v);
  auto dcs = dc.all_rolls();
  int q;
  cin >> q;
  while (q--) {
    int top, south;
    cin >> top >> south;
    for (auto x : dcs) {
      if (x[TOP] != top || x[SOUTH] != south) continue;
      cout << x[EAST] << endl;
    }
  }
}


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

int main()
{
    cin >> a >> P;
    cout << (a * 3 + P) / 2 << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

#define X first
#define Y second
#define N 4
#define M 350

typedef long long ll;
const ll INF = 1ll<<60;
const int Mod = 1000000007;

struct Matrix
{
	int mat[N][N];
	void init(int v){memset(mat, 0, sizeof(mat)); for (int i = 0; i < N; ++i) mat[i][i] = v;}
	
	Matrix operator * (const Matrix &v)
	{
		Matrix res; res.init(0);
		for (int i = 0; i < N; ++i)
			for (int j = 0; j < N; ++j)
				for (int k = 0; k < N; ++k)
				{
					res.mat[i][j] += 1ll * mat[i][k] * v.mat[k][j] % Mod;
					if (res.mat[i][j] >= Mod) res.mat[i][j] -= Mod;
				}
		return res;
	}
};

Matrix Power(Matrix A, int P)
{
	Matrix res; res.init(1);
	for (;P;P >>= 1)
	{
		if (P & 1) res = res * A;
		A = A * A;
	}
	return res;
}

int main()
{
	//freopen("A.in","r",stdin);
	//freopen("A.out","w",stdout);
	
	Matrix p, q, ans;  ans.init(0);
	ans.mat[0][0] = ans.mat[0][1] = ans.mat[0][2] = ans.mat[0][3] = 1; 
	p.mat[0][0] = 1, p.mat[0][1] = 1, p.mat[0][2] = 1, p.mat[0][3] = 1;
	p.mat[1][0] = 0, p.mat[1][1] = 1, p.mat[1][2] = 0, p.mat[1][3] = 1;
	p.mat[2][0] = 0, p.mat[2][1] = 0, p.mat[2][2] = 1, p.mat[2][3] = 1;
	p.mat[3][0] = 1, p.mat[3][1] = 1, p.mat[3][2] = 1, p.mat[3][3] = 2;
	q.mat[0][0] = 1, q.mat[0][1] = 1, q.mat[0][2] = 1, q.mat[0][3] = 1;
	q.mat[1][0] = 0, q.mat[1][1] = 1, q.mat[1][2] = 0, q.mat[1][3] = 1;
	q.mat[2][0] = 0, q.mat[2][1] = 0, q.mat[2][2] = 1, q.mat[2][3] = 1;
	q.mat[3][0] = 0, q.mat[3][1] = 0, q.mat[3][2] = 0, q.mat[3][3] = 1;
	
	int n, m, pre = 1;
	scanf("%d%d", &n, &m);
	for (int i = 1, x; i <= m; ++i)
	{
		scanf("%d", &x);
		ans = ans * Power(p, x - pre);
		if (x != n) ans = ans * q;
		pre = x + 1;
	}
	if (pre < n) ans = ans * Power(p, n - pre);
	printf("%d\n", ans.mat[0][3]);
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  ll m[5] = {};
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if(s[0] == 'M'){
      m[0]++;
    }else if(s[0] == 'A'){
      m[1]++;
    } else if(s[0] == 'R') {
      m[2]++;
    } else if(s[0] == 'C') {
      m[3]++;
    } else if(s[0] == 'H') {
      m[4]++;
    }
  }
  int cnt = 0;
  for(int i = 0; i < 5; i++){
    if(m[i] > 0){
      cnt++;
    }
  }
  if(cnt < 3){
    cout << 0 << '\n';
    return 0;
  }
  
  ll ans = m[0] * m[1] * m[2] + m[0] * m[1] * m[3] + m[0] * m[2] * m[3] +
        m[1] * m[2] * m[3] + m[0] * m[1] * m[4] + m[0] * m[2] * m[4] +
        m[0] * m[3] * m[4] + m[1] * m[2] * m[4] + m[1] * m[3] * m[4] +
        m[2] * m[3] * m[4];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#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 rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
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; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    map<ll, ll> ans;
    ll n;
    cin >> n;
    rept(i,1,100){
        rept(j,1,100){
            rept(k,1,100){
                ll tmp=i*i+j*j+k*k+i*j+i*k+j*k;
                ans[tmp]++;
            }
        }
    }
    for(int i=1; i<=n; i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 6004
N, M = map(int, input().split())
A, B = (
    zip(*(map(int, input().split()) for _ in range(N))) if N else
    ((), ())
)


class SegmentTree:
    def __init__(self, n, f, e):
        self.n = 2**((n - 1).bit_length())
        self.f = f
        self.e = e
        self.d = [e for _ in range(2 * self.n)]

    def __setitem__(self, key, value):
        key += self.n - 1
        self.d[key] = value
        while key > 1:
            key //= 2
            self.d[key] = self.f(self.d[2 * key], self.d[2 * key + 1])

    def __getitem__(self, key):
        return self.q(key, 1, 1, self.n + 1)

    def q(self, key, i, left, right):
        return (
            self.e if left >= key.stop or right <= key.start else
            self.d[i] if key.start <= left <= right <= key.stop else
            self.f(
                self.q(key, 2 * i, left, (left + right) // 2),
                self.q(key, 2 * i + 1, (left + right) // 2, right)
            )
        )


T = SegmentTree(M, max, -1)
for i in range(M + 1):
    T[i] = i

ans = 0
for a, b in sorted(zip(A, B), key=lambda t: (-t[1], t[0])):
    x = T[1:(M-a+2)]
    if x != -1:
        ans += b
        T[x] = -1

print(ans)


Measured memory_bytes: 123280