akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)

static const int mod = 1e9+7;

ll dp[100001][13];


int main() {
  string S;
  cin >> S;
  reverse(All(S));
  dp[0][0] = 1;


  ll b = 1;
  int size = S.size();
  rep(i, 0, size) {
    // 桁
    int idx = i+1;
    char ch = S[i];
    int s = S[i];
    s -= 48;
    if (ch != '?') {
      // 桁の数によるmod
      int digitmod = s * b % 13;
      rep(j, 0, 13) {
        // 一つ前の個数 j mod 13 での個数
        int prev = dp[i][j];
        // 一つ前と合計した時のmod
        int tmpmod = (digitmod + j) % 13;
        dp[idx][tmpmod] += prev;
        dp[idx][tmpmod] %= mod;
      }
    } else {
      rep(j, 0, 13) {
        // 一つ前の j mod 13 での個数
        int prev = dp[i][j];
        rep(k, 0, 10) {
          // 桁の数によるmod
          int digitmod = k * b % 13;
          // 一つ前と合計した時のmod
          int tmpmod = (digitmod + j) % 13;
          dp[idx][tmpmod] += prev;
          dp[idx][tmpmod] %= mod;
        }
      }
    }
    b *= 10;
    b %= 13;
  }

  cout << dp[size][5] << endl;
};


Measured memory_bytes: 10624
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		LinkedList<Integer> que=new LinkedList<Integer>();
		int[] wait=new int[100]; // Ò¿Ô
		int[] a=new int[17]; // ÀÁÄ¢éq
		int[] rest=new int[17]; // qªAéÜÅÌÔ
		int[] b=new int[17];

		for(int t=0;; t++){
			// HI¹
			for(int i=0; i<17; i++){
				if(--rest[i]<=0){
					a[i]=-1;
				}
			}

			// Vµ¢q
			if(t%5==0&&t<500){
				que.addLast(t/5);
			}

			// Âßçêé¾¯Âßé
			for(; !que.isEmpty();){
				int c=que.getFirst();
				int n=c%5==1?5:2;
				int j=-1;
				for(int i=16; i>=0; i--){
					b[i]=a[i]==-1?((i==16?0:b[i+1])+1):0;
					if(b[i]>=n){
						j=i;
					}
				}
				if(j==-1){
					break;
				}
				for(int i=j; i<j+n; i++){
					a[i]=c;
					rest[i]=17*(c%2)+3*(c%3)+19;
				}
				wait[c]=t-5*c;
				que.removeFirst();
			}

			if(t>500&&que.isEmpty()){
				break;
			}
		}

		for(; sc.hasNext();){
			println(""+wait[sc.nextInt()]);
		}

	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 11000
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB"){
        cout << "No";
    }else{
        cout << "Yes";
    }
}

Measured memory_bytes: 3584
import itertools
N, M, X = map(int, input().split())
C = []
A = []
ans = -1
for i in range(N):
  tmp = list(map(int, input().split()))
  C.append(tmp[0])
  A.append(tmp[1:])
for bit in itertools.product([0,1], repeat=N):
  tmpX = [0 for _ in range(M)]
  tmpC = 0
  for i in range(N):
    if bit[i] == 1:
      for j in range(M):
        tmpX[j] += A[i][j]
      tmpC += C[i]
  flag = True
  for i in range(M):
    if tmpX[i] < X:
      flag = False
      break
  if not flag:
    continue
  if ans == -1:
    ans = tmpC
  else:
    ans = min(ans, tmpC)
print(ans)

Measured memory_bytes: 9248
from collections import deque
# import os
# import io
# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
# import sys
# input = sys.stdin.readline


def main():
    n, q = map(int, input().split())
    node = [[]for _ in range(n)]
    looked = [1] * n
    for i in range(n - 1):
        a, b = map(int, input().split())
        node[b - 1].append(a - 1)
        node[a - 1].append(b - 1)
    counter = [0] * n
    for i in range(q):
        p, x = map(int, input().split())
        counter[p - 1] += x
    queue = deque([0])
    looked[0] = 0
    while queue:
        now = queue.pop()
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)

main()


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    vector<int> twopow(11);
    twopow[0] = 1;
    for(int i = 1; i <= 10; i++) twopow[i] = pow(2, i);
    int ans = *(upper_bound(twopow.begin(), twopow.end(), N) - 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4056
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N = II()
    from collections import defaultdict
    num_c = defaultdict(int)
    E = defaultdict(lambda:defaultdict(int))
    inputE = []
    for i in range(N-1):
        ai,bi = LMIIS()
        if bi < ai:
            ai,bi = bi,ai
        num_c[ai] += 1
        num_c[bi] += 1
        E[ai][bi]= -1
        inputE.append((ai,bi))
    max_c = max(num_c.values())
    


    def colour(e1,c):
        tmpc = 0
        for e2 in E[e1].keys():
            tmpc += 1
            if tmpc == c:
                tmpc += 1
            E[e1][e2] = tmpc
            colour(e2,tmpc)

            
        pass
    
    colour(1,0)
    # print(E)
    print(max_c)


    for ai,bi in inputE:
        if E[ai][bi] != -1:
            print(E[ai][bi])



if __name__ == '__main__':
    main()

Measured memory_bytes: 153176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

template <class T>
T gcd(T a,T b) {
	if (b==0) return a;
	else return gcd(b,a%b);
}

template <class T>
T lcm(T a,T b){
	return a*(b/gcd(a,b));
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	vector<ll> a(n);
	rep(i,n){
		cin>>a[i];
		a[i]/=2;
	}
	ll num=1;
	rep(i,n){
		num=lcm(num,a[i]);
	}
	rep(i,n){
		if((num/a[i])%2==0){
			cout<<0<<endl;
			return 0;
		}
	}
	ll ans=(m/num);
	ans=(ans+1)/2;
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        int N = RInt();
        var L = RInts();
        var sum = L.Sum();
        bool frag = true;
        for (int i = 0; i < N; i++)
        {
            if (sum - L[i] <= L[i]) frag = false;
        }
        WriteLine(frag?"Yes":"No");

    }
}



class Scanner
{
    public static string RString() => Console.ReadLine();
    public static int RInt() => ReadTuple<int>();
    public static long RLong() => ReadTuple<long>();
    public static double RDouble() => ReadTuple<double>();

    public static string[] RStrings() => Console.ReadLine().Split();
    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();

    public static T1 ReadTuple<T1>()
    {
        var r = RString();
        var r1 = (T1)Convert.ChangeType(r, typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadTuple<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadTuple<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}


Measured memory_bytes: 27968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    string N; cin >> N;
    ll ans = 0;
    for(auto n : N) {
        ans += n-'0';
    }
    if (ans%9 == 0) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
	int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(1){
    c-=b;
    if(c<=0){
      cout<<"Yes"<<endl;
      return 0;
    }
    a-=d;
    if(a<=0){
cout<<"No"<<endl;
      return 0;
    }
  }
  return 0;
}


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

map<long, long> prime_factorize(long long N) {
    map<long, long> res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res[a]=ex;
    }

    // 最後に残った数について
    if (N != 1){
        res[N] = 1;
    }
    return res;
}

void Main()
{
    long n;
    cin >> n;
    auto sosu = prime_factorize(n);

    int sousa = 0;
    for(auto a: sosu){
        // cerr << a.first << ": " << a.second << endl;
        long e = 1;
        for (long i = 1; i <= a.second; i=i+e)
        {
            e++;
            sousa++;
        }
    }

    cout << sousa << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>
 
using namespace std;
typedef int status;
typedef long long ll;
typedef unsigned long long ull;
const ull base = 343;
const int INF = int(1e9);
const int MAX = 200002;

int N,M;
char a[MAX];

int main()
{
    
    N = 0;
    cin>>a;
    for(int i =0;i<3;i++)
        if(a[i]=='1')
        N++;
    cout<<N<<endl;
    
    
    return 0;
}


Measured memory_bytes: 768
n, m = map(int, input().split())

sc = []
for _ in range(m):
    s, c = map(int, input().split())
    sc.append((s, c))

def check(i):
    global n, sc
    str_i = list(str(i))
    for sci in sc:
        # print(sci, str_i)
        if sci[0] <= len(str_i):
            if int(str_i[sci[0] - 1]) != sci[1]:
                return None
    return i

if n == 1:
    for i in range(0, 10):
        result = check(i)
        if result is not None:
            print(result)
            exit(0)
elif n == 2:
    for i in range(10, 100):
        result = check(i)
        if result is not None:
            print(result)
            exit(0)
else:
    for i in range(100, 1000):
        result = check(i)
        if result is not None:
            print(result)
            exit(0)
print(-1)


Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int digit(ll n){
   if(n < 10)  return n;
   return digit(n/10) + n%10;
}
int main(){
  vector<ll> X(10010);
  X.at(0)=0;
  for(ll i=1;i<10010;i++) X.at(i)=digit(i);
  ll N,A,B;
  cin>>N>>A>>B;
  ll count=0;
  for(ll i=1;i<=N;i++){
    if(A<=X.at(i)&&X.at(i)<=B) count+=i;
  }
  cout<<count;
return 0;}


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

using namespace std;
using ll = long long;

struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<int> sz;

	UnionFind(size_t Size) {
		par.resize(Size);
		rank.resize(Size, 0);
		sz.resize(Size, 1);
		for (int i = 0; i < Size; ++i) { par[i] = i; }
	}

	int find(int x) {
		if (par[x] == x) { return x; }
		else { return par[x] = find(par[x]); }
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) { return; }

		if (rank[x] < rank[y]) { swap(x, y); }
		if (rank[x] == rank[y]) { ++rank[x]; }
		par[y] = x;
		sz[x] += sz[y];
	}

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

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

	UnionFind uf(N + 1);
	vector<ll> res(M, 0);
	res[M - 1] = (N - 1) * N / 2;
	for (int i = M - 1; i > 0; --i) {
		if (uf.same(a[i], b[i])) {
			res[i - 1] = res[i];
			continue;
		}
		ll s = uf.sz[uf.find(a[i])];
		ll t = uf.sz[uf.find(b[i])];
		res[i - 1] = res[i] - (s * t);
		uf.unite(a[i], b[i]);
	}

	for (int i = 0; i < M; ++i) {
		cout << res[i] << endl;
	}

	return 0;
}


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

int main(){
	long long n,a,b;	cin>>n>>a>>b;

	long long cnt=n/(a+b);
	n-=cnt*(a+b);
	
	long long ans=cnt*a;
	ans+=min(n,a);

	cout<<ans<<endl;

	return 0;
}


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

using namespace std;

int main()
{
    int x = 0;
    int N; cin >> N;
    string S; cin >> S;
    int max = 0;
    for(int i = 0; i < N; i++)
    {
        if(x > max) max = x;
        if(S[i] == 'I') x++;
        if(S[i] == 'D') x--;
    }
    if(x > max) max = x;

    cout << max << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
void dice1();
void dice2();
class DICE{
	int face[6],a;
public:
	void set(int&f,int&f1,int&f2,int&f3,int&f4,int&f5){
		face[0]=f;face[1]=f1;face[2]=f2;face[3]=f3;face[4]=f4;face[5]=f5;
	}
	void N(){
		a=face[0];
		face[0]=face[1];
		face[1]=face[5];
		face[5]=face[4];
		face[4]=a;
	}
	void E(){
		a=face[0];
		face[0]=face[3];
		face[3]=face[5];
		face[5]=face[2];
		face[2]=a;
	}
	void S(){
		a=face[0];
		face[0]=face[4];
		face[4]=face[5];
		face[5]=face[1];
		face[1]=a;
	}
	void W(){
		a=face[0];
		face[0]=face[2];
		face[2]=face[5];
		face[5]=face[3];
		face[3]=a;
	}
	void output(){
		cout<<face[0]<<endl;
	}
	int up(){
		return face[0];
	}
	void turn(){
		a=face[1];
		face[1]=face[3];
		face[3]=face[4];
		face[4]=face[2];
		face[2]=a;
	}
	int front(){
		return face[1];
	}
	int right(){
		return face[2];
	}
};
int main(){
	DICE a;
	dice2();
	return 0;
}
void dice1(){
DICE a;
	int d[6];string str;
	for(int i=0;i<6;++i){
		cin>>d[i];
	}
	a.set(d[0],d[1],d[2],d[3],d[4],d[5]);
	getline(cin,str);
	getline(cin,str);
	for(int i=0;i<str.size();++i){
		if(str[i]=='E'){
			a.E();
		}
		else if(str[i]=='S'){
			a.S();
		}
		else if(str[i]=='W'){
			a.W();
		}
		else if(str[i]=='N'){
			a.N();
		}
	}
	a.output();
	return;
}
void dice2(){
	DICE a;
	int d[6],p,u;
	for(int i=0;i<6;++i){
	cin>>d[i];
	}a.set(d[0],d[1],d[2],d[3],d[4],d[5]);
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>p>>u;
		int k=0;
		while(1){
			k++;
			if(k<=5){
			a.E();
			}
			else{
				a.N();
			}
			if(p==a.up()){
				break;
			}
		}
		k=0;
		while(1){
			k++;
			a.turn();
			if(u==a.front()){
				break;
			}
		}
		cout<<a.right()<<endl;
	}
	return;
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int64_t N, B=1;
  cin >> N;
  for (int64_t A=1; A<=sqrt(N); A++) {
    if (N%A==0) {
      B=N/A;
    }
  }
  if (B<10) {
    cout << 1 << endl;
  }
  else if (B<100) {
    cout << 2 << endl;
  }
  else if (B<1000) {
    cout << 3 << endl;
  }
  else if (B<10000) {
    cout << 4 << endl;
  }
  else if (B<100000) {
    cout << 5 << endl;
  }
  else if (B<1000000) {
    cout << 6 << endl;
  }
  else if (B<10000000) {
    cout << 7 << endl;
  }
  else if (B<100000000) {
    cout << 8 << endl;
  }
  else if (B<1000000000) {
    cout << 9 << endl;
  }
  else if (B<10000000000) {
    cout << 10 << endl;
  }
}

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


def main():
    import sys
    input = sys.stdin.readline

    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    # See:
    # https://www.youtube.com/watch?v=ENSOy8u9K9I&feature=youtu.be
    path = list()
    order = [-1 for _ in range(n + 1)]
    place = 1

    while order[place] == -1:
        order[place] = len(path)
        path.append(place)
        place = a[place - 1]

    cycle = len(path) - order[place]
    before_cycle_count = order[place]

    if (k < before_cycle_count):
        print(path[k])
    else:
        k -= before_cycle_count
        k %= cycle
        print(path[before_cycle_count + k])


if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
  int n, m;
  cin >> n >> m;
  for (int i = m / n; i > 0; i--)
    if (m % i == 0 && m / i >= n)
    {
      cout << i << endl;
      return 0;
    }

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main()
{
	int n;
	cin >> n;
	int *h = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int ans = 0;
	int count = 0;
	for (int i = 0; i < n - 1; i++) {
		if (h[i] >= h[i + 1]) {
			count++;
			ans = max(ans, count);
		}
		else {
			count = 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
N=parse(Int,readline())
A=map(x->parse(Int,x),split(readline()))
L=Array{Int}(0)
push!(L,0)
tmp=0
for i=A
	tmp=gcd(tmp,i)
	push!(L,tmp)
end
R=Array{Int}(0)
push!(R,0)
tmp=0
for i=reverse(A)
	tmp=gcd(tmp,i)
	push!(R,tmp)
end
R=reverse(R)
ans=0
for i=1:N
	ans=max(ans,gcd(L[i],R[i+1]))
end
println(ans)


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

#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define END(x) do{cout<<(x)<<endl;exit(0);}while(0)
#define debug(x)  do{cerr<<#x<<": "<<(x)<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define exp2(x)  (1LL<<(x))

using ll=long long;
using namespace std;


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

    int N; cin >> N; vector<ll> A(N);
    ll s = 0;
    rep(i, 0, N-1) {
        cin >> A[i];
        if (i % 2==0) s += A[i];
        else s-= A[i];
    }
    ll ans = s/2;
    rep(i, 0, N-1) {
        cout << 2*ans << ((i==N-1)?"\n":" ");
        ans = A[i] - ans;
    }

}


Measured memory_bytes: 2176
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
     
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=(int)(1e5)+5;
int a[maxn],rk[maxn],pt[maxn];

inline int chk(int i,int j) {return a[i]<a[j];}

int main() {
    int n,res=0;
    read(n);
    REP(i,1,n) read(a[i]),rk[i]=i;
    sort(rk+1,rk+n+1,chk);
    REP(i,1,n) pt[rk[i]]=i;
    REP(i,1,n) res+=(pt[i]^i)&1;
    printf("%d\n",res/2);
    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    string s;
    cin >> s;
    int ans = 700;

    rep(i, s.size())
    {
        if (s[i] == 'o')
        {
            ans += 100;
        }
    }

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


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

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

ll T1,T2;
ll A1,A2,B1,B2;

int main(){
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    if(A1>B1 && A2>B2){
        cout << 0 << endl;
        return 0;
    }
    if(A1<B1 && A2<B2){
        cout << 0 << endl;
        return 0;
    }
    if(A1 < B1){
        swap(A1,B1);
        swap(A2,B2);
    }
    ll D1 = (A1-B1) * T1;
    ll D2 = (B2-A2) * T2;
    if(D1 > D2){
        cout << 0 << endl;
        return 0;
    } 
    if(D1 == D2){
        cout << "infinity" << endl;
        return 0;
    }
    ll dd = D2 - D1;
    ll r = D1 / dd;
    if(D1 % dd == 0) r = r*2;
    else r = r*2 + 1;
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

for i in range(N, 0, -1):
    s = sqrt(i)
    if int(s) ** 2 == int(i):
        print(i)
        break


Measured memory_bytes: 5192
use num_integer::gcd;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n]
    }
    let mut ans = 0;
    for i in a.iter() {
        ans = gcd(*i, ans);
    }
    println!("{:?}", ans);
}


Measured memory_bytes: 3684
using System;
using System.Collections.Generic;

namespace Atc_0020
{
    class Program
    {
        static void Main(string[] args)
        {
            ulong X = ulong.Parse(Console.ReadLine());

            ulong index = 0;
            ulong N = 100;

            while (true)
            {
                index++;

                N += (ulong)(N / 100);

                if (X <= N)
                {
                    break;
                }
            }

            Console.WriteLine(index);

        }
    }
}


Measured memory_bytes: 27592
#include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n;
  pair<int,int> num[105];
  int i;

  cin>>n;

  rep(i,n){
    cin>>num[i].second>>num[i].first;
    num[i].first*=-1;
  }
  sort(num,num+n);
  cout<<num[0].second<<" "<<-num[0].first<<endl;

}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;

    vector<int> s(n, 0);
    auto add = [&](int i, int j) {
        s[i]++;
        s[j + 1]--;
    };

    auto f = [&](int x, int y) {
        int z = (x + y) / 2;
        for (int i = 0; i < x; i++) {
            int d = x - i;
            add(1, i);
            add(1, d - 1);
            add(d, d + (z - x));
            add(d + 1, d + 1 + (y - (z + 1)));
            add(d + 2, d + 1 + (n - 1 - y));
        }
    };
    f(x, y);
    f(n - 1 - y, n - 1 - x);

    auto g = [&](int x, int y, int t) {
        int z = (x + y) / 2;
        if ((x + y) % 2 == 0) z -= t;
        for (int i = x; i <= z; i++) {
            int d = i - x;
            add(1, i);
            int e = (y - i) - (d + 1);
            if (e <= 0) {
                add(1, n - 1 - i);
            } else {
                int w = y - e / 2;
                add(1, (w - 1) - i);
                add(d + 1, d + 1 + (y - w));
                add(d + 2, d + 1 + (n - 1 - y));
            }
        }
    };
    g(x, y, 0);
    g(n - 1 - y, n - 1 - x, 1);

    for (int i = 1; i < n; i++) {
        s[i] += s[i - 1];
        cout << s[i] / 2 << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <numeric>
#include <vector>
#include <math.h>
#include <string>

using namespace std;

int main()
{
	int N;

	cin >> N;

	vector<int> num;
	for(int i = 0 ; i < 4 ; i++)
	{
		num.insert(num.begin(), N % 10);
		N /= 10;
	}
	
	int p;
	for (p = 0; p < pow(2, num.size()-1); p++)
	{
		int kekka = num[0];

		for (int i = 1; i < num.size(); i++)
		{
			if ((p & (1 << i-1)) == 0)
			{
				kekka += num[i];
			}
			else
			{
				kekka -= num[i];
			}
		}

		if (kekka == 7)
		{
			break;
		}
	}

	cout << num[0];
	if ((p & 1) == 0)
	{
		cout << "+";
	}
	else
	{
		cout << "-";
	}

	cout << num[1];
	if ((p & 2) == 0)
	{
		cout << "+";
	}
	else
	{
		cout << "-";
	}

	cout << num[2];
	if ((p & 4) == 0)
	{
		cout << "+";
	}
	else
	{
		cout << "-";
	}

	cout << num[3] << "=7" << endl;

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    rep(i, 0, N) {
        if (!A[i]) {
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = 1;
    rep(i, 0, N) {
        if (ans > 1000000000000000000LL / A[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans *= A[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3992
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean ans = true;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if(a%2 == 0){
                if(a%3 != 0 && a%5 != 0){
                    ans = false;
                    break;
                }
            }
        }
        System.out.println(ans ? "APPROVED" : "DENIED");
        sc.close();

    }

}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int n,m,q;
int a[100],b[100],c[100],d[100];

vector<int>v;
int Max=0;

void dfs(){
	if(v.size()==n){
		int sum=0;
		rep(i,q){
			if(v[b[i]]-v[a[i]]==c[i])sum+=d[i];
		}
		Max=max(Max,sum);
		return;
	}
	for(int i=(v.empty()?1:v.back());i<=m;i++){
		v.push_back(i);
		dfs();
		v.pop_back();
	}
}
int main(){
	cin>>n>>m>>q;
	rep(i,q){
		scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);a[i]--;b[i]--;
	}
	dfs();
	cout<<Max<<endl;
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

class SectionUnion {
public:
	struct Section {
		int64_t begin;
		int64_t end;
		bool operator < (const Section& comp) const {
			return this->begin < comp.begin;
		}
	};

	void Input(Section section) {
		auto it = this->sections_.lower_bound(section);
		auto prev = it;
		if (prev != this->sections_.begin()) {
			prev--;
			if (section.begin <= prev->end) {
				section.begin = prev->begin;
				section.end = max(section.end, prev->end);
				this->sections_.erase(prev);
			}
		}
		if (it != this->sections_.end()) {
			if (it->begin <= section.end) {
				while (true) {
					auto next = it;
					next++;
					if (next == this->sections_.end()) {
						break;
					}
					if (section.end < next->begin) {
						break;
					}

					this->sections_.erase(it);
					it = next;
				}
				section.end = max(section.end, it->end);
				this->sections_.erase(it);
			}
		}

		this->sections_.insert(section);
	}

	set<Section>& Sections() { return this->sections_; }

private:
	set<Section> sections_;
};


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int64_t n, x, d; cin >> n >> x >> d;
	if (d == 0) {
		if (x == 0) {
			cout << 1 << endl;
		}
		else {
			cout << n + 1 << endl;
		}
		return 0;
	}
	if (x == 0) {
		cout << n * (n - 1) / 2 + 1 << endl;
		return 0;
	}

	int64_t m = abs(d) / gcd(abs(x), abs(d));
	m = min(n + 1, m);
	vector<SectionUnion> sus(m);
	FOR_LE(i, 0, n) {
		int64_t orig = x * i;
		int64_t a = (int64_t)i * (i - 1) / 2;
		int64_t b = (n * (n - 1) / 2) - ((n - i) * (n - i - 1) / 2);
		a *= d;
		b *= d;
		if (b < a) swap(b, a);

		sus[i % m].Input({ orig + a, orig + b + abs(d) });
	}

	int64_t ans = 0;
	FOR_LT(i, 0, m) {
		set<SectionUnion::Section>& sections = sus[i].Sections();
		for (auto& elem : sections) {
			assert((elem.end - elem.begin) % d == 0);
			ans += (elem.end - elem.begin) / abs(d);
		}
	}
	cout << ans << endl;

	return 0;
}

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

int main(){
  int n,m,x;
  cin >>n >>m >>x;
  int a[12][12];
  vector<int> c(n);
  rep(i,n){
    cin >>c[i];
    rep(j,m) cin >>a[i][j];
  }
  int ans = 1001001001;
  rep(s,1<<n){
    int cost = 0;
    vector<int> d(m);
    rep(i,n){
      if (s>>i&1){
        cost += c[i];
        rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,m) if(d[j]<x) ok = false;
    if(ok) ans = min(ans,cost);
  }
  if(ans==1001001001) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

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

int main(){
    int mini, n, array[100], sw=0;

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> array[i];
    }

    for(int i=0;i<n;i++){
        mini = i;
        for(int j=i+1;j<n;j++){
            if(array[mini]>array[j]){
                mini = j;
            }
        }
        if(i!=mini){
            swap(array[i], array[mini]);
            sw++;
        }
    }
    for(int i=0;i<n;i++){
        if(i) cout << " ";
        cout << array[i];
    }
    cout << endl << sw << endl;

    return 0;
}


Measured memory_bytes: 3072
using System;

namespace AOJ.Volume0
{
    public class CupGame
    {
        public static int Main()
        {
            string answer = "A";
            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }
                string left = input.Substring(0, 1);
                string right = input.Substring(2);

                if (left == answer) { answer = right; }
                else if (right == answer) { answer = left; }
            }

            Console.WriteLine(answer);
            return 0;
        }
    }
}

Measured memory_bytes: 8780
K = int(input())
A = [
    1,
    1,
    1,
    2,
    1,
    2,
    1,
    5,
    2,
    2,
    1,
    5,
    1,
    2,
    1,
    14,
    1,
    5,
    1,
    5,
    2,
    2,
    1,
    15,
    2,
    2,
    5,
    4,
    1,
    4,
    1,
    51,
]
print(A[K - 1])



Measured memory_bytes: 2940
import itertools

n = int(input())
saids = {}  # saids[i][j] は，人iの，人jについての証言(True:正直 False:不親切)
for i in range(1, n + 1):
    said = {}
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        said[x] = y
    saids[i] = said
ans = 0
for p in range(2**n):
    honest = [i + 1 for i in range(n) if p & 2 ** i != 0]
    for x, y in itertools.product(honest, range(1, n+1)):
        if y not in saids[x]:
            continue
        if saids[x][y] == 0 and y in honest:
            break
        if saids[x][y] == 1 and y not in honest:
            break
    else:
        ans = max(ans, len(honest))
print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;
import java.util.Arrays;

public class Main {
        public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);
                int input1 = scan.nextInt();
                int input2 = scan.nextInt();
                int input3 = scan.nextInt();
                int div[] = new int[100];
                Arrays.fill( div, 0 );
                int result1;
                int result2;
                int total = 0;
                int i=0;

                for (i=1; i<=input1; i++) {
                        result1 = input1 % i;
                        result2 = input2 % i;
                        if ( result1 == 0 && result2 == 0 ) {
                                total++;
                                div[total] = i;
                        }
                }

                System.out.println( div[total+1-input3] );
                scan.close();
        }
}


Measured memory_bytes: 22612
#include <iostream>
#include <map>
#include <string>

int main(){
    int n;
    std::cin >> n;
    while(n != 0){
        std::map<char,char>map;
        for(int i=0;i<n;i++){
            char a,b;
            std::cin >> a >> b;
            map[a] = b;
        }
        int temp;
        std::cin >> temp;
        std::string s;
        for(int i=0;i<temp;i++){
            char a;
            std::cin >> a;
            if(map.find(a) == map.end()){
                s += a;
            }else{
                s += map[a];
            }
        }
        std::cout << s << std::endl;
        std::cin >> n;
    }
}

Measured memory_bytes: 3260
mod=1000000007
n=int(input())
#dp[文字数][前3][前2][前1]=個数
dp=[[[[0for i in range(4)]for i in range(4)]for i in range(4)]for i in range(n)]
s=[0 for i in range(n)]
for i in range(4):
  for j in range(4):
    for k in range(4):
      dp[0][i][j][k]=1
s[0]=4
for i in range(4):
  for j in range(4):
    for k in range(4):
      dp[1][i][j][k]=1
s[1]=16
for i in range(4):
  for j in range(4):
    for k in range(4):
      dp[2][i][j][k]=1
dp[2][0][2][1]=0
dp[2][0][1][2]=0
dp[2][2][0][1]=0
s[2]=61
for a in range(3,n):
  for i in range(4):
    for j in range(4):
      for k in range(4):
        dp[a][i][j][k]=sum(dp[a-1][j][k])
  #agc-,ag-c,a-gc,-agc,gac-,-gac,acg-,-acg
  #-agc,-gac,-acg
  #0120,0121,0122,0123
  dp[a][0][1][2]-=dp[a-1][1][2][0]+dp[a-1][1][2][1]+dp[a-1][1][2][2]+dp[a-1][1][2][3]
  #0210,0211,0212,0213
  dp[a][0][2][1]-=dp[a-1][2][1][0]+dp[a-1][2][1][1]+dp[a-1][2][1][2]+dp[a-1][2][1][3]
  #0221
  dp[a][0][2][2]-=dp[a-1][2][2][1]
  #0231
  dp[a][0][2][3]-=dp[a-1][2][3][1]
  #0321
  dp[a][0][3][2]-=dp[a-1][3][2][1]
  #2010,2011,2013
  dp[a][2][0][1]-=dp[a-1][0][1][0]+dp[a-1][0][1][1]+dp[a-1][0][1][3]
  for i in range(4):
    for j in range(4):
      for k in range(4):
        dp[a][i][j][k]%=mod
        s[a]+=dp[a][i][j][k]
        s[a]%=mod
print(s[n-1])

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

int main(void) {
	int X, ans;

	cin >> X;
	int sq = (int)sqrt(2 * X);
	ans = sq - 1;
	while (true) {
		if (ans * (ans + 1) >= 2 * X)
			break;
		++ans;
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
INF = 10**20
N,M = map(int,input().split())
node = [[] for _ in range(N)]
for _ in range(M):
  l,r,d = map(int,input().split())
  node[l-1].append([r-1,d])
  node[r-1].append([l-1,-1*d])
 
ans = "Yes"
pos = [INF]*N
for i in range(N):
  if pos[i]==INF:
    que = [[i,0]]
    while(que):
      c,cp = que.pop()
      if pos[c]==INF:
        pos[c] = cp
        for n,d in node[c]:
          if pos[n]==INF:
            que.append([n,cp+d])
          elif pos[n] != cp+d:
            ans="No"
            break
        else:
          continue
        break
      elif pos[c] != cp:
        ans="No"
        break
    else:
      continue
    break
print(ans)

Measured memory_bytes: 116512
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, M = map(int, readline().split())
    S = [0] * M
    for i in range(M):
        k, *S[i] = [int(s) - 1 for s in readline().split()]
    P = list(map(int, readline().split()))

    ans = 0
    for bit in range(1 << N):
        ok = True
        for j in range(M):
            lit = sum(1 for s in S[j] if bit & (1 << s))
            if lit % 2 != P[j]:
                ok = False
                break
        if ok:
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main() {
    int s,w;
    cin >> s >> w;
    if(s > w) {
        cout << "safe" << endl;
    } else {
        cout << "unsafe" << endl;
    }
    return 0;
}



Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;

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

        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        System.out.println(a[n - 1] - a[0]);
    }
}


Measured memory_bytes: 22996
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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

	int ans = n / 3;
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	long a,b,c;
	cin >> a >> b >> c;
	cout << (a+b >= c-1  ? b + c : a + 2*b + 1) << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();
		double e=(double)((double)a*b)/2;
		if(a==2*c&&b==2*d){
			System.out.printf("%.6f",e);
		 System.out.println(" 1");
		}
		else{
			System.out.printf("%.6f",e);
	      System.out.println(" 0");
	}
	}
}

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

using ll = long long;
// #define int long long
using P = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
int counts[100005];
/***** MAIN *****/
signed main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<P> v(q);
  REP(i,q) {
    int first, second;
    cin >> first >> second;
    --first;
    --second;
    v[i] = P(first, second);
  }
  REPS(i,1,n) {
    if(s[i-1] == 'A' && s[i] == 'C') {
      counts[i] = counts[i-1]+1;
    } else {
      counts[i] = counts[i-1];
    }
  }
  REP(i,q) {
    int ans;
    if(v[i].first == 0) {
      ans = counts[v[i].second];
    } else {
      ans = counts[v[i].second] - counts[v[i].first];
    }
    cout << ans << endl;
  }
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 2176
import string 
letters = string.ascii_letters

while True:
    n = int(input())
    if n == 0:
        exit(0)
    k = list(map(int, input().split()))
    s = input()
    
    res = ""
    i = 0
    for x in s:
        res += letters[letters.find(x) - k[i]]
        i = (i + 1) % n

    print(res)
        
    



Measured memory_bytes: 6720
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int a, b; cin >> a >> b;
  int q = b / a, r = b - q * a;
  if (!r or a - r <= q) cout << -1 << '\n';
  else cout << (b + a - 1) / a * a << '\n';
}


Measured memory_bytes: 3200