akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N := sc.nextInt()
	A := sc.nextIntSlice(N)
	set := make(map[int]int)
	for i := 0; i < N; i++ {
		set[A[i]]++
	}
	sum := 0
	for _, num := range set {
		sum += num * (num - 1) / 2
	}
	//fmt.Fprintln(wtr, sum)
	for i := 0; i < N; i++ {
		if set[A[i]] <= 1 {
			fmt.Fprintln(wtr, sum)
		} else {
			num := set[A[i]]
			before := num * (num - 1) / 2
			after := (num - 1) * (num - 2) / 2
			fmt.Fprintln(wtr, sum-(before-after))
		}
	}
}


Measured memory_bytes: 14464
from collections import Counter

def resolve():
  N = int(input())
  countA = Counter([int(x) for x in input().split(" ")])
  Q = int(input())

  sum_A = 0
  for a in countA.keys():
    sum_A += a*countA[a]

  for _ in range(Q):
    B, C = map(int, input().split(" "))
    if B in countA.keys():
      target_value = countA.pop(B)
      sum_A += (C - B) * target_value
      countA[C] += target_value
      print(sum_A)
    else:
      print(sum_A)


if __name__ == "__main__":
  resolve()

Measured memory_bytes: 87676
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <queue>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef vector<vector<char>> field_t;
typedef unsigned long long ull;
typedef pair<int, int> point_t;


int main()
{
    long double A,B;
    cin >> A >> B;
    A*=10000;
    B*=10000;
    long double ans=A*B/100000000;
    cout << (ll)ans <<endl;
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int inf = 1e9;

int main() {
	int N,M,Tsum=0;
	cin>>N;
	vector<int> T(N),P(M),X(M);
	rep(i,N){
		cin>>T[i];
		Tsum+=T[i];
	}
	cin>>M;
	rep(i,M){
		cin>>P[i]>>X[i];
		cout<<Tsum-T[P[i]-1]+X[i]<<endl;
	}
}

Measured memory_bytes: 512
import java.util.*;
import java.math.*;

public class Main {
    static final int MOD = 1_000_000_007; // 10^9+7
    // static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] ary = new int[m];
        long sum = 0;
        for(int i = 0;i < m;i++){
            sum+=sc.nextInt();
        }
        if(sum<=n){
            System.out.println(n-sum);
        }else{
            System.out.println(-1);
        }

        

    }

}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    string S; cin >> S;
    sort(ALL(S));
    if(S=="abc") cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<math.h>
using namespace std;

int main() {
	int N, D, X;
	cin >> N >> D >> X;
	int a[109];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		int j = 0;
		while (j * a[i] + 1 <= D) {
			j++;
			X++;
		}
	}
	cout << X;

}

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

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

    int i=1, n = s;
    int F[10000000] = {};
    F[1] = s;

    bool flag = false;
    while(!flag){
        if(n % 2 == 0){
            n /= 2;
            i++;
        }
        else{
            n = 3 * n + 1;
            i++;
        }
        F[i] = n;
        for(int j=1;j<=i;j++){
            if(F[j] == F[i] && j != i){
                flag = true;
                break;
            }
        }
    }
    cout << i << endl;
}

Measured memory_bytes: 39296
N, A, B = map(int, input().split())
S = input()

qualified = 0
qualified_foreign = 0.
for s in S:
    if s == 'c':
        print('No')
    elif s == 'a':
        if qualified < A + B:
            print('Yes')
            qualified += 1
        else:
            print('No')
    else:
        if (qualified < A + B) & (qualified_foreign < B):
            print('Yes')
            qualified += 1
            qualified_foreign += 1
        else:
            print('No')
  


Measured memory_bytes: 4016
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<map>
#include<queue>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int mod=1000000007;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};



#define int ll
signed main(){
    int n;
    cin>>n;
    int a[100010];
    int x=0,ans=0;
    rep(i,0,n){
        cin>>a[i];
        x=max(a[i],x);
    }
    sort(a,a+n,greater<int>());
    a[0]=0;
    int y=1<<30;
    rep(i,0,n){
        if(y>abs((x/2)-a[i])){
            y=abs((x/2)-a[i]);
            ans=a[i];
        }
    }
    cout<<x<<" "<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=200005;
//i_am_noob

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	int n;
	set<string> st;
	string str;
	cin >> n;
	rep(n){
		cin >> str;
		st.insert(str);
	}
	print1(sz(st));
	return 0;
}

Measured memory_bytes: 19284
n = [int(x) for x in input()]
op_cnt = len(n) - 1
for i in range(1 << op_cnt):
    op = ['-'] * op_cnt
    for j in range(op_cnt):
        if (i >> j) & 1:
            op[op_cnt - 1 - j] = '+'
    formula = "{}{}{}{}{}{}{}".format(n[0], op[0], n[1], op[1], n[2], op[2], n[3])
    if eval(formula) == 7:
        print(formula + '=7')
        break


Measured memory_bytes: 9160
n = str(input())
k = int(input())

DP = [[[0 for _ in range(k+1)] for _ in range(2)] for _ in range(len(n)+1)]
DP[0][0][0] = 1

for i in range(len(n)):
    now = int(n[i])
    for j in range(2):
        for non_zero in range(k+1):
            for m in range(10):
                if j == 1 or (j == 0 and m < now):
                    next_j = 1
                elif m == now:
                    next_j = 0
                else:
                    continue

                if non_zero == k and m != 0:
                    continue
                elif m == 0:
                    next_non_zero = non_zero
                else:
                    next_non_zero = non_zero + 1
                
                DP[i+1][next_j][next_non_zero] += DP[i][j][non_zero]

ans = DP[len(n)][1][k] + DP[len(n)][0][k]
print(ans)
# print(DP)



Measured memory_bytes: 41456
/**
*    created: 04.07.2020 20:51:00
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

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

    int n;
    cin >> n;
    map<int,int> mp;
    rep(i,n) {
        int a;
        cin >> a;
        if (mp[a] == 0) mp[a]++;
        else mp.erase(a);
    }
    cout << mp.size() << endl;
    return 0;
}


Measured memory_bytes: 9756
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;


vector<int>A;
int N, M;
vector<P>v;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> M;
	A.resize(N); v.resize(M);
	REP(i, N) {
		cin >> A[i];
	}
	REP(i, M) {
		int B, C; cin >> C >> B;
		v.push_back(P(B, C));
	}
	VSORT(A);
	A.pb(INF);
	VSORT(v); VREVERSE(v);
	/*REP(i, M) {
		print(v[i].first);
	}*/
	/*REP(i, M) {
		VSORT(A);
		int B = v[i].first, C = v[i].second;
		auto itr = lb(A, B);
		int it = itr - A.begin();
		int cnt = min(C, it);
		REP(j, cnt) {
			A[j] = B;
		}
	}*/
	int cnt = 0;
	REP(i, M) {
		REP(j, v[i].second) {
			if (A[cnt] < v[i].first) {
				A[cnt] = v[i].first;
				cnt++;
				if (cnt >= N)break;
			}
			else {
				break;
			}
		}
	}
	ll ans = 0;
	REP(i, N) {
		ans += A[i];
	}
	print(ans);
}

Measured memory_bytes: 5632
#include <stdio.h>
int main(void) {
    int n;
    scanf("%d", &n);
    for (int i = 3; i <= n; i++) {
        if (i % 3 == 0) {
            printf(" %d", i); continue;
        }
        for (int j = 1; j <= n*10; j *= 10) {
            if ((i / j) % 10 == 3) {
                printf(" %d", i); break;
            }
        }
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n,g;cin>>n>>g;
    vint p(n),c(n);
    rep(i,n)cin>>p[i]>>c[i];
    int res=INF;

    rep(bit,1<<n){
        int s=0,t=0;
        pri_que<int> pq;
        rep(i,n){
            if(bit&(1<<i)){
                s+=(i+1)*100*p[i]+c[i];
                t+=p[i];
            }else{
                rep(j,p[i]) pq.push((i+1)*100);
            }
        }
        while(s<g){
            s+=pq.top(); pq.pop(); t++;
        }
        if(s>=g) chmin(res,t);
    }   
    cout<<res<<endl;
}

Measured memory_bytes: 3636
N = int(input())
K = int(input())
ans = []

def DFS(num=1, cnt = 1):
    
    if cnt==N+1:
        ans.append(num)
        return False
        
    if DFS(num*2, cnt+1):
        return True
    
    if DFS(num+K, cnt+1):
        return True

DFS()
print(min(ans))

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

N = int(input())
INF = float("inf")
adj = []
for _ in range(N):
    inp = tuple(map(int, input().split()))
    adj.append(tuple(zip(inp[2::2], inp[3::2])))

checked = [False for _ in range(N)]
d = [float("inf") for _ in range(N)]
d[0] = 0

heap = [[0, 0]] # cost, vec

while heap:
    c, u = heappop(heap)
    if d[u] < c or checked[u]:
        continue
    for nu, nc in adj[u]:
        new_d = d[u] + nc
        if new_d < d[nu]:
            d[nu] = new_d
            heappush(heap, [d[nu], nu])
    checked[u] = True

for n in range(N):
    print("{} {}".format(n, d[n]))

Measured memory_bytes: 69716
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){ 
  cout << fixed << setprecision(10);
  long double n ; cin >> n;
  cout << (n*n*n)/27 << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

n = int(input())
as_ = map(int, input().strip().split())

d = defaultdict(int)

for a in as_:
    d[a] += 1

rects = sorted([k for k, v in d.items() if v >= 2], reverse=True)
squares = sorted([k for k, v in d.items() if v >= 4], reverse=True)

max_rect = rects[0] * rects[1] if len(rects) >= 2 else 0
max_square = squares[0] ** 2 if len(squares) > 0 else 0

print(max(max_rect, max_square))


Measured memory_bytes: 24104
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,string> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	vi dp(1000010,inf);
	vi dp2(1000010,inf);
	dp[0]=dp2[0]=0;
	loop(i,1,2000){
		int a=i*(i+1)*(i+2)/6;
		if(a>=1000010)break;
		rep(j,1000010)if(j+a<1000010)dp[j+a]=min(dp[j+a],dp[j]+1);else break;
		if(a%2)rep(j,1000010)if(j+a<1000010)dp2[j+a]=min(dp2[j+a],dp2[j]+1);else break;
	}
	int n;
	while(cin>>n,n)cout<<dp[n]<<" "<<dp2[n]<<endl;
}

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

#define all(x) (x).begin(),(x).end()
#define init() \
  ios::sync_with_stdio(false); \
  cin.tie(0)

#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

#ifdef LOCAL

template<typename T>
void show(vector<T>& v) {
    cout << '[';
    for (const T& e : v) {
        cout << e << ',';
    }
    cout << ']' << endl;
}

#endif

template<typename M, typename N>
constexpr common_type_t<M, N> gcd(M a, N b) {
  return a == 0 ? b
    : b == 0 ? a
    : gcd(b, a % b);
}

template <typename M, typename N>
constexpr common_type_t<M, N> lcm(M a, N b) {
  return a * b / gcd(a, b);
}

template <long long MAX>
class CombinationCalculator {
  long long mod_;
  long long fac[MAX];
  long long finv[MAX];
  long long inv[MAX];

public:
  CombinationCalculator(long long mi = MOD): fac(), finv(), inv() {
    mod_ = mi;
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i - 1] * i % mod_;
      inv[i] = mod_ - inv[mod_ % i] * (mod_ / i) % mod_;
      finv[i] = finv[i - 1] * inv[i] % mod_;
    }
  }

  long long c(long long n, long long k) const {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod_) % mod_;
  }
};

template <long long MAX = 210000>
using CC = CombinationCalculator<MAX>;

template<typename T>
T modpow(T a, T n, T mod = MOD) {
    T res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template<typename T>
T modinv(T a, T m = MOD) {
    T b = m, u = 1, v = 0;
    while (b) {
        T t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

template<typename T>
vector<T> read_n(const size_t n) {
    T dummy;
    vector<T> v(n);
    for (size_t i = 0; i < n; i++) {
        cin >> dummy;
        v[i] = dummy;
    }
    return v;
}

template<typename T>
vector<T> read_n() {
    size_t n;
    cin >> n;
    return read_n<T>(n);
}

int main() {
  init();

  ull h, w;
  cin >> h >> w;

  ull c = h * w;
  if (h == 1 || w == 1) {
      cout << 1 << endl;
  } else {
      cout << c / 2 + (c % 2 == 1) << endl;
  }

  return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a=700;
	char s[3]={0,1,2};
	cin>>s;
	if(s[0]=='o'&&s[1]=='o'&&s[2]=='o')
		a=1000;
	else if(s[0]=='x'&&s[1]=='o'&&s[2]=='o'||s[0]=='o'&&s[1]=='x'&&s[2]=='o'||s[0]=='o'&&s[1]=='o'&&s[2]=='x')
		a=900;
	else if(s[0]=='x'&&s[1]=='o'&&s[2]=='x'||s[0]=='x'&&s[1]=='x'&&s[2]=='o'||s[0]=='x'&&s[1]=='x'&&s[2]=='o'||s[0]=='o'&&s[1]=='x'&&s[2]=='x')
		a=800;
	if(s[0]=='x'&&s[1]=='x'&&s[2]=='x')
		a=700;
	cout<<a;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    rep(i, n) cout << s[i] << t[i];
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    cout << 3 * n * n << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var boad = new int[3, 3];
            for (int i = 0; i < 3; i++)
            {
                var s = Console.ReadLine().Trim();
                if (s == "0") goto end;
                for (int j = 0; j < 3; j++)
                    if (s[j] == 'b') boad[i, j] = 1;
                    else if (s[j] == 'w') boad[i, j] = 4;
            }
            var ret = checkWin(boad);
            if (ret == 4) Console.WriteLine("w");
            else if (ret == 1) Console.WriteLine("b");
            else Console.WriteLine("NA");
        }
        end:;
    }
    public static int checkWin(int[,] b)
    {
        for (int i = 0; i < 3; i++)
        {
            var t = 0; var u = 0;
            for (int j = 0; j < 3; j++) { t += b[i, j]; u += b[j, i]; }
            if (t == 12 | u == 12) return 4;
            else if (t == 3 | u == 3) return 1;
        }
        if (b[0, 0] + b[1, 1] + b[2, 2] == 12) return 4;
        if (b[0, 0] + b[1, 1] + b[2, 2] == 3) return 1;
        if (b[0, 2] + b[1, 1] + b[2, 0] == 12) return 4;
        if (b[0, 2] + b[1, 1] + b[2, 0] == 3) return 1;
        return 0;
    }
}

Measured memory_bytes: 8768
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String str=sc.next();
		boolean s=true;
		String[] a=new String[4];

		for(int i=0;i<4;i++){
			a[i]=str.substring(i,i+1);
		}
		for(int i=0;i<3;i++){
			if(a[i].equals(a[i+1]))
				s=false;
		}
		if(s==true)
			System.out.println("Good");
		else
			System.out.println("Bad");
		
	}
}

Measured memory_bytes: 23636
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int a,b,k;
    while(cin>>k>>a>>b)
    {
        double result = ceil(a/(double)k);
       // cout<<result<<endl;
        result=result*k;
        //cout<<result<<endl;
        if(result>=a && b>=result)
            cout<<"OK\n";
        else
            cout<<"NG\n";
    }
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(),(x).end()
#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 rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repd2(i, s, n) for (ll i = n-1; i >= (s); i--)

int main() {
    string s,t;
    cin >> s >> t;
    ll cost = t.size();
    ll a = 0;
    rep(i, s.size()-t.size()+1) {
        ll b = 0;
        rep(j, t.size()) {
            // cout << s[i+j] << t[j] << endl;
            if (s[i+j]!=t[j]) b++;
        }
        cost = min(cost, b);
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 3508
S = list(input())
for i in range(4):
    S[i] = int(S[i])


flag1 = 0
if S[0] == 1:
    if S[1] <= 2:
        flag1 = 1
if S[0] == 0:
    if S[1] != 0:
        flag1 = 1

flag2 = 0
if S[2] == 1:
    if S[3] <= 2:
        flag2 = 1
if S[2] == 0:
    if S[3] != 0:
        flag2 = 1

if flag1 == 0 and flag2 == 0:
    print("NA")
if flag1 == 1 and flag2 == 0:
    print("MMYY")
if flag1 == 0 and flag2 == 1:
    print("YYMM")
if flag1 == 1 and flag2 == 1:
    print("AMBIGUOUS")

Measured memory_bytes: 3064
#include <cstdio>

long long a, b, k;

int main(void)
{
    scanf("%lld%lld%lld", &k, &a, &b);
    if (k <= a)
        puts("1");
    else if (a <= b)
        puts("-1");
    else
        printf("%lld\n", ((k - a) / (a - b) + bool((k - a) % (a - b))) << 1 | 1);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
using namespace std;


int main(void) {

  int n;
  cin >> n;

  vector< vector< vector<int> > > a(4, vector< vector<int> >(3, vector<int>(10, 0)));

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

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


  return 0;
}

Measured memory_bytes: 3152
import java.util.*;
public class Main{
	public static void main(String[]i){
		long s=Long.parseLong(new Scanner(System.in).next());
		int a=1000000000;
		System.out.println("0 0 "+a+" 1 "+(a-s%a)%a+" "+((s-1)/a+1));
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#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(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int ok(int x,ll k, vector<int> &a){
	int res = 0;
	rep(i, a.size()) {
		res += (a[i] - 1) / x;
	}
	return res <= k;
}

int main()
{
	ll n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	ll l = 0, r = 1e10;
	while(r-l > 1)
	{
		int x = (r + l) / 2;
		if (ok(x,k,a))
			r = x;
		else
			l = x;

	}
	cout << r << endl;

	return 0;
}

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

// 入力
int n, W;
int w[100], v[100];

int dp[101][10001];


int rec_dp(int i, int j) {
  if (dp[i][j] != -1) {

    return dp[i][j];
  }

  int res;
  if (i == n) {
 
    res = 0;
  } else if (j < w[i]) {

    res = rec_dp(i + 1, j);
  } else {
   
    int r[2]={rec_dp(i + 1, j),
              rec_dp(i + 1, j - w[i]) + v[i],
	      /*   rec_dp(i,j-w[i])+v[i]*/};
    sort(r,r+2);
    res=r[1];
    
  }

  return dp[i][j] = res;
}

int main() {
  memset(dp, -1, sizeof(dp)); // メモ化テーブルを-1で初期化　以下のforループと等価


  cin>>n>>W;
  for(int i=0;i<n;i++){
    cin>>v[i]>>w[i];
  }
  cout << rec_dp(0, W) << endl;
}

Measured memory_bytes: 5128
import sys
import numpy as np
from heapq import heappop, heappush

# Dijikstra
def main():
    H, W = map(int, sys.stdin.readline().split())

    grid = np.array([list(sys.stdin.readline().rstrip()) for _ in range(H)])
    grid = np.pad(grid, 1, 'constant')
    # atcoderではnp.pad() のargにconstant_valuesを指定できない
    q = []
    heappush(q, (0, 1, 1))
    visited = set()
    cost = np.full((H + 1, W + 1), np.inf)
    cost[1][1] = 0
    while q:
        c, i, j = heappop(q)
        if (i, j) in visited:
            continue
        visited.add((i, j))
        cost[i][j] = c
        if i == H and j == W:
            break
        for dy, dx in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            y = i + dy
            x = j + dx
            if grid[y][x] == '.' and not (y, x) in visited:
                heappush(q, (c + 1, y, x))
    

    if cost[H][W] != np.inf:
        ans = int(np.sum(grid == '.') - (cost[H][W] + 1))
    else:
        ans = -1

    print(ans)  

if __name__ == "__main__":
    main()

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

int main(void){
	string s,s2;
	cin>>s;
	s2="";
	for(int i=0; i<4;i++){
		s2.push_back(s[i]);
	}
	s2.push_back(' ');
	for(int i=4; i<12;i++){
		s2.push_back(s[i]);
	}
	cout<<s2<<endl;
	return 0;
}

Measured memory_bytes: 256
import copy
n = int(input())
vote_ls = [[0,0] for _ in range(n)]
for i in range(n):
    a,b = map(int,input().split())
    vote_ls[i] = [a,b]

def check(previous,now):
    ok = True
    for j in [0,1]:
        if previous[j] > now[j]:
            ok = False
    return ok

previous = vote_ls[0]
for i in range(1,n):
    now = copy.copy(vote_ls[i])
    if check(previous,now):
        previous = now
        continue

    time_a = -(-previous[0]//now[0])
    time = float('inf')
    if now[1] * time_a >= previous[1]:
        time = min(time,time_a)
    time_b = -(-previous[1]//now[1])
    if now[0] * time_b >= previous[0]:
        time = min(time,time_b)
    now[0]*=time
    now[1]*=time
    previous = now

print(sum(previous))

Measured memory_bytes: 74284
import sys

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


def divisors(n):
    lower = []
    upper = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            lower.append(i)
            if i != n // i:
                upper.append(n // i)

    lower.extend(reversed(upper))
    return lower


def main():
    N = int(readline())

    D = divisors(N)
    D1 = divisors(N - 1)
    ans = len(D1) - 1

    for d in D[1:]:
        n = N
        while n % d == 0:
            n //= d
            if (n - 1) % d == 0:
                ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 66228
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
int n,a[101010];
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	fo(i,0,n)cin>>a[i];
	sort(a,a+n);
	if(n%3==0){
		if(a[0]==a[n/3-1]&&a[n/3]==a[n/3*2-1]&&a[n/3*2]==a[n-1]&&
		(a[0]^a[n/3])==a[n/3*2]&&(a[0]^a[n/3*2])==a[n/3]&&(a[n/3]^a[n/3*2])==a[0])cout<<"Yes\n";
		else cout<<"No\n";
	}else{
		if(a[0]==a[n-1]&&a[0]==0)cout<<"Yes\n";
		else cout<<"No\n";
	}
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    string s, t;
    cin >> s >> t;
    int ssize = s.size();
    int tsize = t.size();
    vector<int> ss(ssize+1);
    vector<int> ts(tsize+1);
    for(int i = 0; i < ssize; i++)
    {
        if(s[i] == 'A')
        {
            ss[i+1] = ss[i] + 1;
        }
        else
        {
            ss[i+1] = ss[i] + 2;
        }
    }
    for(int i = 0; i < tsize; i++)
    {
        if(t[i] == 'A')
        {
            ts[i+1] = ts[i] + 1;
        }
        else
        {
            ts[i+1] = ts[i] + 2;
        }
    }
    int q;
    cin >> q;
    while(q)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int s3 = (ss[b] - ss[a-1]) % 3;
        int t3 = (ts[d] - ts[c-1]) % 3;
        if(s3 == t3) cout << "YES" << endl;
        else cout << "NO" << endl;
        q--;
    }
}


Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <queue>
#include <map>
#define N 55
using namespace std;

typedef long long ll;
ll n, M = 1e9, Z = 2e9 + 1, tc, s, mn = -1, dx, dy, x[N], y[N], v[N];
map<ll, ll> e;
queue<ll> qu;
void ch(ll p, ll q) {
	ll t = p * Z + q, t2;
	t2 = e[t];
	if (t2 != 0 && v[t2] != tc) {
		v[t2] = tc;
		qu.push(t2);
	}
}

void f(ll p) {
    ll i;
    v[p] = tc;
    qu.push(p);
    while (!qu.empty()) {
		p = qu.front(); qu.pop();
		ch(x[p] + dx, y[p] + dy);
		ch(x[p] - dx, y[p] - dy);
    }
}

int main()
{
	ll i, j, k;
	cin >> n;
	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	for (i = 1; i <= n; i++) {
		scanf ("%lld %lld", &x[i], &y[i]);
		x[i] += M;
		y[i] += M;
		e[(x[i] * Z) + y[i]] = i;
	}
	for (i =1; i <= n; i++) {
		for (j = i + 1; j <= n; j++) {
            tc++;
            dx = x[j] - x[i];
            dy = y[j] - y[i];
            f(i);
            s = 1;
            for (k = 1; k <= n; k++) {
				if (v[k] != tc) {f(k); s++;}
            }
            if (mn == -1 || s < mn) mn = s;
		}
	}
	cout << mn << endl;
    return 0;
}


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

bool bin_serach(vector<int> a, int sum, int m);

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  int q;
  cin >> q;
  vector<int> m(q);
  for (i = 0; i < q; i++) {
    cin >> m[i];
  }
  for (i = 0; i < q; i++) {
    cout << (bin_serach(a, 0, m[i]) ? "yes" : "no") << endl;
  }
  return 0;
}

bool bin_serach(vector<int> a, int sum, int m) {
  if (sum == m) {
    return true;
  }
  if (a.size() == 0) {
    return false;
  }
  int a_last = a.back();
  a.pop_back();
  if (bin_serach(a, sum + a_last, m) || bin_serach(a, sum, m)) {
    return true;
  }
  return false;
}



Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    long long ans=a*c;
    ans=max(ans,a*d);
    ans=max(ans,b*c);
    ans=max(ans,b*d);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int s[10000];
int n;

int linear_search(int t) {
  for (int i = 0; i < n; i++)
    if (s[i] == t)
      return 1;
  return 0;
}

int main(void) {
  int q;
  int t[500];
  int i;
  int count = 0;
  
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", &s[i]);
  scanf("%d", &q);
  for (i = 0; i < q; i++)
    scanf("%d", &t[i]);

  for (i = 0; i < q; i++) {
    count += linear_search(t[i]);
  }

  printf("%d\n", count);
  
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>

using namespace std;

int main(void)
{
    int N, X, T;

    cin >> N >> X >> T;

    int m = N / X;
    int n = N % X;
    int ans = m * T;

    if (n != 0) {
        ans += T;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
	int n,d,x;
	cin >> n >> d >> x;
	vector<int> a(n,0);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	int sum=0;
			for(int i=0;i<n;i++){
				for(int j=0;j<=d;j++){
					if(1<= (j*a[i]+1) && (j*a[i]+1)<=d)sum++;
				}
			}
	sum+=x;
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
class Dice

  def initialize(dice)
    @top  = dice[0]
    @side   = [ dice[2], dice[1], dice[3], dice[4] ]
    @bottom = dice[5]
  end

  def roll(action)
    b = @bottom
    u = @top
    case action
    when "N"
      @top   = @side[2]
      @bottom  = @side[0]
      @side[2] = b
      @side[0] = u
    when "E"
      @top   = @side[3]
      @bottom  = @side[1]
      @side[3] = b
      @side[1] = u
    when "S"
      @top   = @side[0]
      @bottom  = @side[2]
      @side[0] = b
      @side[2] = u
    when "W"
      @top   = @side[1]
      @bottom  = @side[3]
      @side[1] = b
      @side[3] = u
    end
  end

  def top
    @top
  end

  def bottom
    @bottom
  end

  def north
    @side[0]
  end

  def east
    @side[1]
  end

  def south
    @side[2]
  end

  def west
    @side[3]
  end
end

d = Dice.new(gets.split.map(&:to_i))
gets

ARGF.each_line do |line|
  top_south = line.split.map(&:to_i)
  action = ["N", "E", "S", "W"]
  loop do
    d.roll(action.sample)
    if d.top == top_south[0] && d.south == top_south[1]
      puts d.east
      break
    end
  end
end

Measured memory_bytes: 6120
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-9;


int main() {
    
    // ld a,b,c,d;
    // cin>>a>>b>>c>>d;
    // ld tyo = d/60*360;
    // ld tan = (c/12 + 1.0/12*d/60)*360;
    // ld doo=abs(tan-tyo);
    // // fin(doo);
    // ld co = cos(doo/180*MATHPI);
    // // fin(co);
    // ld ans=a*a+b*b-2*a*b*co;
    // printf("%.9Lf\n",sqrt(ans));
    // int k;
    // string s;
    // cin>>k>>s;
    // if(s.size()<=k)fin(s);
    // else {
    //     fin(s.substr(0,k)+"...");
    // }
    int n;
    cin>>n;
    if(n%10==3)fin("bon");
    else if(n%10==0||n%10==1||n%10==6||n%10==8){
        fin("pon");
    } else {
        fin("hon");
    }
}



Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int M1 = sc.nextInt();
		int D1 = sc.nextInt();
		int M2 = sc.nextInt();
		int D2 = sc.nextInt();
		if(M1 != M2){
			System.out.println(1);
		}else{
			System.out.println(0);			
		}
	}
}


Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
/*    #ifndef ONLINE_JUDGE
      // for getting input from input.txt
      freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      freopen("output.txt", "w", stdout);
  #endif*/
fast();
ll n,s;
cin>>n>>s;
if(n*500>=s)
{
  Yes
}
else
{
  No
}

  
  


return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void roll(char x,int a[6]){
    int b[6];
    for(int i=0;i<6;i++){
        b[i]=a[i];
    }
    if(x=='N'){
        a[0]=b[1];
        a[1]=b[5];
        a[5]=b[4];
        a[4]=b[0];
    }
    else if(x=='W'){
        a[0]=b[2];
        a[2]=b[5];
        a[5]=b[3];
        a[3]=b[0];
    }
    else if(x=='S'){
        a[0]=b[4];
        a[4]=b[5];
        a[5]=b[1];
        a[1]=b[0];
    }
    else if(x=='E'){
        a[0]=b[3];
        a[3]=b[5];
        a[5]=b[2];
        a[2]=b[0];
    }
}
int main(){
    int a[6];
    for(int i=0;i<6;i++){
        cin >>a[i];
    }
    string dist;
    cin>>dist;
    for(int j=0;j<dist.size();j++){
        roll(dist[j],a);
    }
    cout<<a[0]<<endl;
}


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

using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> cs(m);
	for(int i=0; i<m; ++i){
		cin >> cs[i];
	}
	vector<int> cache(n+1);
	for(int i=0; i<=n; ++i) cache[i]=i;
	for(int ni=1; ni<=n; ++ni){
		for(int mi=0; mi<m; ++mi){
			int t;
			if(cs[mi]>ni) t=cache[ni];
			else t=min(cache[ni], cache[ni-cs[mi]]+1);
			cache[ni]=t;
		}
	}
	cout << cache[n] << endl;
	return 0;
}



Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <bitset>
using namespace std;

bool f(int n) {
	n &= n - 1;
	return n == 0;
}

vector<int> gray(int n) {
	vector<int> res(1 << n);
	for (int i = 0; i < 1 << n; i++) {
		res[i] = i ^ (i >> 1);
	}
	auto it = find(res.begin(), res.end(), 0);
	rotate(res.begin(), it, res.end());
	return res;
}

int popcnt(int x) {
	int res = 0;
	while (x > 0) {
		res++;
		x &= x - 1;
	}
	return res;
}

int rev(int x, int n) {
	int res = 0;
	for (int i = 0; i < n; i++) {
		res ^= (x >> i & 1) << (n - 1 - i);
	}
	return res;
}

vector<int> tomato(int n) {
	if (n == 1) return {0, 1};
	vector<int> g = gray(n - 2);
	vector<int> res;
	int x = 1 << n - 2;
	int y = 1 << n - 1;
	for (int i = 0; i < g.size(); i++) res.push_back(g[i]);
	for (int i = g.size() - 1; i >= 0; i--) res.push_back(g[i] ^ x);
	res.push_back(x ^ y);
	for (int i = 0; i < g.size(); i++) res.push_back(g[i] ^ y);
	auto f = tomato(n - 2);
	for (int i = 1; i < f.size(); i++) {
		res.push_back(rev(f[i], n - 2) ^ x ^ y);
	}
	return res;
}

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int M = 1 << N;
	vector<int> p0;
	vector<int> p1;
	for (int i = 0; i < N; i++) {
		if ((A ^ B) >> i & 1) p1.push_back(i);
		else p0.push_back(i);
	}
	if (p1.size() % 2 == 1) {
		auto to = tomato(p1.size());
		cout << "YES" << endl;
		auto g = gray(p0.size());
		auto F0 = [&](int l) {
			for (int i = 0; i < g.size(); i++) {
				int a = A;
				for (int j = 0; j < p0.size(); j++) {
					int x = g[i] >> j & 1;
					a ^= x << p0[j];
				}
				for (int j = 0; j < p1.size(); j++) {
					int x = to[l] >> j & 1;
					a ^= x << p1[j];
				}
				cout << a << ' ';
			}
		};
		auto F1 = [&](int l) {
			for (int i = g.size() - 1; i >= 0; i--) {
				int a = A;
				for (int j = 0; j < p0.size(); j++) {
					int x = g[i] >> j & 1;
					a ^= x << p0[j];
				}
				for (int j = 0; j < p1.size(); j++) {
					int x = to[l] >> j & 1;
					a ^= x << p1[j];
				}
				cout << a << ' ';
			}
		};
		for (int i = 0; i < to.size(); i++) {
			if (i % 2 == 0) F0(i);
			else F1(i);
		}
		cout << endl;
	} else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 1152