akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(){
    int n;
    int *a;
    cin >> n;
    a = new int[n];
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    long long int money = 1000;
    long long int kabu = 0;
    for(int i = 0;i < n-1;i++){
        if(a[i] < a[i+1]){
            kabu += money / a[i];
            money = money % a[i];
        }else if(a[i] > a[i+1]){
            money += kabu * a[i];
            kabu = 0;
        }
    }
    money += kabu * a[n-1];
    cout << money << endl;
    return 0;
}


Measured memory_bytes: 3628
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

void Sequence() {
	char c;
	cin >> c;
	char b[5] = { 'a','i','u','e','o' };
	for (size_t i = 0; i < 5; i++)
	{
		if (c == b[i]) {
			cout << "vowel" << endl;
			return;
		}
	}
	cout << "consonant" << endl;
}
int main() {
	Sequence();
	return 0;
}



Measured memory_bytes: 256
/*GOD     IS    GREAT,
  SO    AM    I*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define op(z) cout<<z<<endl
#define ops(z) cout<<z<<" "
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(x) cout<<#x<<" "<<x<<endl
int main()
{
  ll n,k;
  cin>>n>>k;
  if(n>9||k>9)op("-1");
                 else op(n*k);
                 }

Measured memory_bytes: 256
while True:
  n,m=map(int,input().split())
  matrix=[]
  if n==m==0:
    break
  else:
    for i in range(n):
      D,P=map(int,input().split())
      matrix.append([D,P])
      matrix.sort(key = lambda x:x[1],reverse=True)
    i=0
    while m>0 and i<=n-1:
      pp=matrix[i][1]
      dd=matrix[i][0]
      if dd > m:
        matrix[i][0]=dd-m
        m=0
      else:
        matrix[i][1]=0
        m=m-dd
        i+=1
    sum_matrix=[mm[0]*mm[1] for mm in matrix]
    print(sum(sum_matrix))


Measured memory_bytes: 7056
//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007 
#define MAXN 1000005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll S; cin>>S;
    ll dp[S + 1];
    memset(dp,0,sizeof(dp));
    
    dp[0] = 1;
    for(ll i=0;i<=S;++i)
    {
        for(ll j=3;j<=S;++j)
        {
            if(i >= j)
                dp[i] = (dp[i] + dp[i - j]) % MOD;
        }
    }
    
    cout<<dp[S]<<endl;
}

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

int main() {
	
	int n; cin >> n;
	vector<pair<int, int>> pa;
	for (int i = 0; i < n; i++) {
		ll x, L; cin >> x >> L;
		pa.push_back({ x + L ,x - L });	
	}
	sort(pa.begin(), pa.end());
	int cur = -1000000000;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (cur <= pa[i].second) {
			ans++;
			cur = pa[i].first;
		}
	}	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4312
N, M = map(int, input().split())
S = []
for i in range(M):
    a, b = map(int, input().split())
    S.append([a, b])
    
from operator import itemgetter
S = sorted(S, key=itemgetter(1))
ans = 0
last = -1*float('Inf')
for si in S:
    if si[0] >= last:
        ans += 1
        last = si[1]
print(ans)

Measured memory_bytes: 22112
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=1000+10;
const int mod=1e9+7;
int qpow(int a,int b) { int c=1;
	for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) c=1ll*c*a%mod;
	return c;
}

int n,a,b,c,d,dp[N][N];

int fac[N],ifac[N];
void init(int n) {
	fac[0]=1;
	for (int i=1;i<=n;++i) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=qpow(fac[n],mod-2);
	for (int i=n;i;--i) ifac[i-1]=1ll*ifac[i]*i%mod;
}
int C(int n,int m) { return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod; }

int main() {
	init(1000);
	n=read(),a=read(),b=read(),c=read(),d=read();
	for (int i=0;i<=b;++i) dp[0][i]=1;
	for (int i=1;i<=n;++i)
		for (int j=a;j<=b;++j) {
			dp[i][j]=dp[i][j-1];
			for (int k=c;k<=d;++k) {
				if (i-j*k<0) break;
				dp[i][j]=(dp[i][j]+1ll*dp[i-j*k][j-1]*C(n-i+j*k,j*k)%mod
						 *fac[j*k]%mod*ifac[k]%mod*qpow(ifac[j],k))%mod;
			}
		}
	printf("%d\n",dp[n][b]);
	return 0;
}

Measured memory_bytes: 7636
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> ret;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i] ++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

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



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll N, L;
	cin >> N >> L;

	// N<=200なので...
	ll ans = 0;
	ll min_val=L;
	rep(i, 0, N) {
		ans += L + i;
		if (abs(L + i) < abs(min_val)) {
			min_val = L + i;
		}
	}
	ans -= min_val;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3672
#include <iostream>
#define MOD 1000000007

using namespace std;

long long dp[1 << 21];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    bool comp[n][n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> comp[i][j];
    // dp[i] = # of ways to assign men in i to first __bipc(i) women
    dp[0] = 1;
    for (int i = 1; i < (1 << n); i++) {
        for (int j = 0; j < n; j++) {
            if ((i & (1 << j)) && (comp[j][__builtin_popcount(i) - 1])) {
                dp[i] += dp[i ^ (1 << j)];
                dp[i] %= MOD;
            }
        }
    }
    cout << dp[(1 << n) - 1];
    return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);

int main() {
    ll n,m,ans=0;
    cin >> n >> m;
    vector<ll> a(m, 0);
    rep(i, n) {
        ll k;
        cin >> k;
        rep(j, k) {
            ll tmp;
            cin >> tmp;
            tmp--;
            a[tmp]++;
        }
    }
    rep(i, m) {
        if(a[i] == n) ans++;
    }
    cout << ans << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,dp[1010][1010];
pi p[1010];

int f(int c,int a){
	int& r=dp[c][a];
	if(r<INF)return r;
	if(!c)return r=a?INF:0;
	if(!a)return r=0;
	r=f(c-1,a);
	if(f(c-1,a-1)+p[c-1].sec<=p[c-1].fir)r=min(r,f(c-1,a-1)+p[c-1].sec);
	return r;
}

int main(){
	cin>>n;
	rep(i,n)cin>>p[i].sec>>p[i].fir;
	sort(p,p+n);
	rep(i,n+1)rep(j,n+1)dp[i][j]=INF;
	for(int i=n;;i--)if(f(n,i)<INF){
		cout<<i<<endl;
		break;
	}
}

Measured memory_bytes: 0
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n <= 111) {
            System.out.println(111);
        }else if (n <= 222) {
            System.out.println(222);
        }else if (n <= 333) {
            System.out.println(333);
        }else if (n <= 444) {
            System.out.println(444);
        }else if (n <= 555) {
            System.out.println(555);
        }else if (n <= 666) {
            System.out.println(666);
        }else if (n <= 777) {
            System.out.println(777);
        }else if (n <= 888) {
            System.out.println(888);
        }else{
            System.out.println(999);
        }
    }
}

Measured memory_bytes: 23764
/* ALDS1_7_D:Reconstruction of a Tree */
/* 20181125 AOJ */

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#define N 100
#define NIL -1

typedef struct {
	int parent;
	int left;
	int right;
} Tree;

int preOrder[N];
int inOrder[N];
int postOrder[N];
void TreeReconstruction(Tree *node, int left, int right);

int pos1, order[N], pos2; 

int main(void) {
	Tree *node = (Tree *)malloc(sizeof(Tree) * N);
	int i, n;

	scanf("%d", &n);
	for(i = 0; i < n; i++) scanf("%d", preOrder + i);
	for(i = 0; i < n; i++) scanf("%d", inOrder + i);
	
	for(i = 0; i < n; i++) order[inOrder[i]] = i;
	pos1 = 0;
	pos2 = 0;
	TreeReconstruction(node, 0, n);

	for(i = 0; i < n; i++) {
		if(i) printf(" ");
		printf("%d", postOrder[i]);
	}
	printf("\n");

	return 0;
}

void TreeReconstruction(Tree *node, int left, int right) {
	int root, temp;

	if(left >= right) return;
	root = preOrder[pos1++];
	temp = order[root];
	TreeReconstruction(node, left, temp);
	TreeReconstruction(node, temp + 1, right);
	postOrder[pos2++] = root;

}


Measured memory_bytes: 2108
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	n,k=MI()
	A=LI()


	l=1
	r=max(A)+10

	while l+1<r:
		m=(l+r)//2
		cnt=0

		for i in A:
			cnt+=(i-1)//(m-1)
		#print(l,m,r,cnt)
		if cnt<=k:
			r=m
		else:
			l=m



	print(l)
















if __name__ == "__main__":
	main()


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

#define ll long long

using namespace std;

int main() {
  ll H, N;
  cin >> H >> N;
  ll sum = 0;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  if (sum >= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
using namespace std;




int main(){
string s,t;
cin>>s>>t;
int eend = s.size();
eend--;

for(ll i=0;i<s.size();i++){
if(s==t){
  cout<<"Yes"<<endl;
  return 0;
}

string h(1,s[eend]);
s.pop_back();
s = h+s;

}
cout<<"No"<<endl;

}


Measured memory_bytes: 256
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))

p = [0]
for i in range(N):
    p.append(p[-1] + (P[i] + 1) / 2)

print(max([p[j + K] - p[j] for j in range(N - K + 1)]))


Measured memory_bytes: 24808
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
robots = []
for i in range(n):
    x, l = [int(item) for item in input().split()]
    robots.append((x+l, x-l))

robots.sort()

cnt = 0
node = -10**12
for end, start in robots:
    if start >= node:
        node = end
        cnt += 1
print(cnt)

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

int main(){
  int a, b;
  while(true){
    cin >> a >> b;
    if(a == 0 && b == 0){
      break;
    }
    if(a <= b){
      cout << a << " " << b << endl;
    } else {
      cout << b << " " << a << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;



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

  string s;
  cin >> s;
  int f = stoi(s.substr(0, 2));
  int g = stoi(s.substr(2, 2));

  if(f && f < 13){ // mes
	if(g && g < 13)cout << "AMBIGUOUS" << endl;
	else cout << "MMYY" << endl;
  }else{//anio
	if(g && g < 13)cout << "YYMM" << endl;
	else cout << "NA"<< endl;
  }






}




Measured memory_bytes: 3652
import java.util.*;

public class Main{
	public static String decode(String str){
		String[] s = str.split(" ");
		List<String> check = new ArrayList<String>();
		for(String word : s){
			if( word.length() == 4 ){
				check.add(word);
			}
		}
		int[] thiz = {7,8,18};
		int[] that = {7,0,19};
		int mul = 0;
		int sur = 0;
	outer:	for(int i = 1; i < 26; i++){
			if( i%26 == i ){
			inner:	for(String word : check){
					int[] ch = new int[3];
					mul = i;
					sur = ((int)(word.charAt(0)-'a')-i*19)%26;
					for(int j = 0; j < ch.length; j++){
						ch[j] = (mul*(thiz[j])+sur)%26;
						if( ch[j] < 0 ){
							ch[j] += 26;
						}
						if( ch[j] == (int)(word.charAt(j+1)-'a') ){
							continue;
						} else {
							ch[j] = (mul*that[j]+sur)%26;
							if( ch[j] < 0 ){
								ch[j] += 26;
							}
							
							if( ch[j] != (int)(word.charAt(j+1)-'a') ){
								continue inner;
							}
						} 
					}
					break outer;
				}
			}
		}
	//	char[] alpha = new char[26];
		char[] refer = new char[26];
		for(int i = 0; i < 26; i++){
			int a = (i*mul+sur)%26;
			if( a < 0 ){
				a += 26;
			}
			refer[i] = (char)( 'a' + a );
		}
		Map<String, String> code = new HashMap<String, String>();
		for(int i = 0; i < 26; i++){
			code.put(Character.toString(refer[i]), Character.toString((char)('a'+i)));
		}
			
		StringBuilder ans = new StringBuilder();
		for(int i = 0; i < s.length; i++){
			char[] temp = s[i].toCharArray();
			for(int j = 0; j < temp.length; j++){
				if( Character.isLetter(temp[j]) ){
					ans.append(code.get(Character.toString(temp[j])));
				} else {
					ans.append(temp[j]);
				}
			}
			ans.append(" ");
		}
		ans.deleteCharAt(ans.length()-1);
		return ans.toString();
	}
			
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		List<String> result = new ArrayList<String>();
		
		int T = stdIn.nextInt();
		stdIn.nextLine();
		for(int i = 0; i < T; i++){
			String str = stdIn.nextLine();
			result.add(decode(str));
		}
		
		for(String sentence : result){
			System.out.println(sentence);
		}
	}
}

Measured memory_bytes: 12000
class Dice:
    def __init__(self, top, front, right, left, back, bottom):
        self.TOP = top
        self.BOTTOM = bottom
        self.FRONT = front
        self.BACK = back
        self.LEFT = left
        self.RIGHT = right
    
    def move(self, direction):
        if direction == "N":
            self.move_N()
        elif direction == "E":
            self.move_E()
        elif direction == "S":
            self.move_S()
        elif direction == "W":
            self.move_W()
        elif direction == "SIDE":
            self.move_SIDE()
        else:
            raise Exception
    
    def move_N(self):
        tmp = self.TOP
        self.TOP = self.FRONT
        self.FRONT = self.BOTTOM
        self.BOTTOM = self.BACK
        self.BACK = tmp

    def move_S(self):
        tmp = self.TOP
        self.TOP = self.BACK
        self.BACK = self.BOTTOM
        self.BOTTOM = self.FRONT
        self.FRONT = tmp
        
    def move_W(self):
        tmp = self.TOP
        self.TOP = self.RIGHT
        self.RIGHT = self.BOTTOM
        self.BOTTOM = self.LEFT
        self.LEFT = tmp

    def move_E(self):
        tmp = self.TOP
        self.TOP = self.LEFT
        self.LEFT = self.BOTTOM
        self.BOTTOM = self.RIGHT
        self.RIGHT = tmp
    
    def move_SIDE(self):
        tmp = self.FRONT
        self.FRONT = self.RIGHT
        self.RIGHT = self.BACK
        self.BACK = self.LEFT
        self.LEFT = tmp

def is_same():
    for _ in range(4):
        dice.move("SIDE")
        for _ in range(4):
            dice.move("N")
            if dice.TOP == dice2.TOP and dice.FRONT == dice2.FRONT \
                and dice.RIGHT == dice2.RIGHT and dice.LEFT == dice2.LEFT \
                and dice.BACK == dice2.BACK and dice.BOTTOM == dice2.BOTTOM:
                return True
        for _ in range(4):
            dice.move("E")
            if dice.TOP == dice2.TOP and dice.FRONT == dice2.FRONT \
                and dice.RIGHT == dice2.RIGHT and dice.LEFT == dice2.LEFT \
                and dice.BACK == dice2.BACK and dice.BOTTOM == dice2.BOTTOM:
                return True
    return False
    
top, front, right, left, back, bottom = map(int,input().split())
dice = Dice(top, front, right, left, back, bottom)
top2, front2, right2, left2, back2, bottom2 = map(int,input().split())
dice2 = Dice(top2, front2, right2, left2, back2, bottom2)

if is_same():
    #print(dice.TOP, dice.FRONT, dice.RIGHT, dice.LEFT, dice.BACK, dice.BOTTOM)
    #print(dice2.TOP, dice2.FRONT, dice2.RIGHT, dice2.LEFT, dice2.BACK, dice2.BOTTOM)
    print("Yes")
else:
    #print(dice.TOP, dice.FRONT, dice.RIGHT, dice.LEFT, dice.BACK, dice.BOTTOM)
    #print(dice2.TOP, dice2.FRONT, dice2.RIGHT, dice2.LEFT, dice2.BACK, dice2.BOTTOM)
    print("No")


Measured memory_bytes: 5616
// strongly connected component

#include <cstdio>
#include <cstdlib>
#include <cstring>

const int N = 10010;
const int M = 60010;
const int inf = 0x3fffffff;

struct Edge {
	int to, next;
} es[M];

int SIZE = 0; // number of edges
int h1[N], h2[N]; // pointer to edge list
int vis[N], list[N], t = 0;
int color[N];

inline void add(int u, int v) {
	int i = ++SIZE;
	es[i].to = v;
	es[i].next = h1[u];
	h1[u] = i; 
	int j = ++SIZE;
	es[j].to = u;
	es[j].next = h2[v];
	h2[v] = j; 
}

void dfs_1(int x) {
	vis[x] = 1;
	for (int i = h1[x]; i; i = es[i].next) {
		int y = es[i].to;
		if (!vis[y])
			dfs_1(y);
	}
	list[t++] = x;
}

void dfs_2(int x, int c) {
	vis[x] = 1;
	color[x] = c;
	for (int i = h2[x]; i; i = es[i].next) {
		int y = es[i].to;
		if (!vis[y])
			dfs_2(y, c);
	}
}

void run() {
	int n, m, x, y, q;
	scanf("%d%d", &n, &m);
	memset(h1, 0, sizeof(h1));
	memset(h2, 0, sizeof(h2));
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &x, &y);
		add(x, y);
	}
	memset(vis, 0, sizeof(vis));
	for (int i = 0; i < n; i++)
		if (!vis[i])
			dfs_1(i);
	memset(vis, 0, sizeof(vis));
	for (int i = n - 1; i >= 0; i--) {
		int x = list[i];
		if (!vis[x])
			dfs_2(x, x);
	}
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d%d", &x, &y);
		printf("%d\n", color[x] == color[y]);
	}
}

int main() {
	run();
}

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

public class Main {
	
	public void solve() throws IOException{
		int n = nextInt();
		for(int i = 0; i < n; i++){
			int s = nextInt();
			writer.println("Case " + (i+1) + ":");
			int repeat = 10;
			while( repeat-- > 0 ){
				s = s*s;
				StringBuilder sb = new StringBuilder(Integer.toString(s));
				sb.reverse();
				int l = 8-sb.length();
				while( l-- > 0 ){
					sb.append(0);
				}
				sb.reverse();
				s = Integer.parseInt(sb.substring(2, 6));
				writer.println(s);
			}
		}
		writer.flush();
	}			
	public static void main (String args[]) throws IOException{
		new Main().run();
	}
	
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	
	public void run() throws IOException{
		try{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}
	public int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}	
	public String nextToken() throws IOException{
		while( tokenizer == null || !tokenizer.hasMoreTokens() ){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

Measured memory_bytes: 9368
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,k;

int main(){
	cin>>n>>k;
	cout<<(n+k-3)/(k-1)<<endl;
}

Measured memory_bytes: 256
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.IArray           as IA
import qualified Data.Array.IO               as AI
import qualified Data.Array.MArray           as MA
import qualified Data.Array.ST               as STA
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import qualified Data.Graph                  as G
import           Data.Int
import qualified Data.IntMap                 as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence               as SQ
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Tree                   as T
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putLn :: Show a => a -> IO ()
putLn = print

putList :: Show a => [a] -> IO ()
putList [n] = put n
putList (n:ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n] = putStr n
putStrList (n:ns) = do
  putStr n
  putStr " "
  putStrList ns

main = do
  [a, b, x] <- readInt
  if a + b < x || a > x
    then putStrLn "NO"
    else putStrLn "YES"


Measured memory_bytes: 380
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> dig(3);
    rep(i, 3) {
      cin >> dig[i];
    }

    sort(dig.begin(), dig.end(), greater<int>());

    cout << dig[0] * 10 + dig[1] + dig[2] << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define mod 1000000007
using namespace std;
long long kai(int x){
	long long res=1;
	for(int i=1;i<=x;i++){
		res=res*i;
		res=res%mod;
	}
	return res;
}
int main(){
	long long m,n,ans;
	cin>>n>>m;
	if(n==m){
		ans=kai(n)*kai(m)*2;
		ans=ans%mod;
	}
	else if(n==m+1){
		ans=kai(n)*kai(m);
		ans=ans%mod;
	}
	else if(n+1==m){
		ans=kai(n)*kai(m);
		ans=ans%mod;
	}
	else ans=0;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int x = a + b;
  int y = c + d;
  cout << (x > y ? "Left" : (x < y ? "Right" : "Balanced")) << endl;
}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main()
{
int a1,a2;
int length;
cin>>length;
int height[length];
for(int i=0;i<length;++i)
{
	cin>>height[i];
}
a2=0;
if(height[1]>height[0])
  a1=height[1]-height[0];
else
  a1=height[0]-height[1];
 int temp1,temp2;
for(int i=2;i<length;++i)
 {
	if(height[i-1]>=height[i])
     temp1=(height[i-1]-height[i])+a1;
   else if(height[i]>height[i-1])
     temp1=(height[i]-height[i-1])+a1;
  	if(height[i-2]>=height[i])
     temp2=(height[i-2]-height[i])+a2;
   else if(height[i]>height[i-2])
     temp2=(height[i]-height[i-2])+a2;
  if(temp2>=temp1)
  {a2=a1;
   a1=temp1;
  } 
  else
  {
    a2= a1;
    a1=temp2;
  }
 } 
 cout<<a1;
 return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#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 mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// How to use 「map」
/*
  - 宣言
    map<{key_type}, {value_type}> salary;
  - 要素の挿入
    salary["Alice"] = 1000;
  - 要素の取得 O(logn)
    salary.at("Alice");
  - 要素の削除
    salary.erase("Alice");
  - キー検索
    salary.find("Alice"); -> true
    salary.find("Bob");   -> false
  - イテレーション
    for(auto& [key, value] : salary) {...}
 */
// -------------------------------------


// How to use 「lower_bound」, 「upper_bound」
/*
  vector<int> a = {1, 2, 3, 4, 5};
  auto iter1 = lower_bound(all(a), 3);  <- 第二引数「以上」の最小イテレータが返る
  auto iter2 = upper_bound(all(a), 3);  <- 第二引数「より大きい」最小のイテレータが返る
 */
// -------------------------------------


// How to use 「struct sort」
/*
  struct Person {
    string name;
    int age;

    Person(string _name, int _age) {
      name = _name;
      age = _age;
    }

    bool operator<(const Person &another) const {
      return age < another.age;
    }
  };

  vector<Person> people;
  people.pb(Person("Alice", 20));
  people.pb(Person("Bob", 19));
  people.pb(Person("John", 40));
  people.pb(Person("Chris", 30));
  sort(all(people));
 */
 // -------------------------------------

// -------------------------------------------------------------------------------------



int main() {
  int d, g;
  cin >> d >> g;
  vector<int> p(d), c(d);
  rep(i, d) cin >> p[i] >> c[i];

  int ans = INF<int>;
  rep(i, (1 << d)) {
    int _sum = 0;
    int _cnt = 0;
    // ビットを見て、どの問題を完全に解くか決める
    rep(j, d) {
      if(((i >> j) & 1) == 1) {
        _sum += (100 * (j+1) * p[j]) + c[j];
        _cnt += p[j];
      }
    }

    // 他には問題を解かない
    if(_sum >= g) {
      ans = min(ans, _cnt);
    }

    // 完全に解かない問題から、0個以上選ぶ
    rep(j, d) {
      if(((i >> j) & 1) == 0) {
        rep1(k, p[j]) {
          if(_sum + (100 * (j+1) * k) >= g) {
            ans = min(ans, _cnt + k);
          }
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; } /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; } /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b)
{
	return *(char *)a - *(char *)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b)
{
	return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)

int main(void)
{
	int n, b[101];
	scanf("%d", &n);

	int i, j, k;
	for (i = 0; i < n - 1; i++)
		scanf("%d", &b[i]);
	int sum = b[0];

	for (i = 0; i < n - 2; i++) {
		sum += min(b[i], b[i + 1]);
	}
	sum += b[n - 2];

	printf("%d\n", sum);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,a[400001],b[400001],ta[400001],tb[400001],l=1,r=1;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),ta[a[i]]++;
	for(int i=1;i<=n;i++)scanf("%d",&b[i]),tb[b[i]]++;
	for(int i=1;i<=n;i++)if(ta[i]+tb[i]>n)puts("No"),exit(0);
	memset(b,0,sizeof(b));
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=tb[i];j++)
		{
			while(b[l])++l;
			while(a[r]<=a[l]&&r<=n)++r;
			while(b[r])++r;
			if(a[l]!=i)b[l++]=i;
			else b[r++]=i;
		}
	}
	l=1;
	for(int i=n+1;b[i];i++)
	{
		while(b[l])++l;
		if(a[l]!=b[i])a[l]=b[i];
		else 
		{
			while(a[r=(rand()%n+1)]==b[i]||b[r]==a[l]);
			b[l]=b[r],b[r]=b[i];
		}
	}
	puts("Yes");
	for(int i=1;i<=n;i++)printf("%d ",b[i]);
	return 0;
}


Measured memory_bytes: 7696
// 標準入力から一行を読み取り、指定の型に変換する
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

// ユークリッドの互除法
fn gcd(x: u64, y: u64) -> u64 {
    let low: u64;
    let high: u64;

    if x > y { 
        high = x;
        low = y;
    } else {
        low = x;
        high = y;
    }

    if low == 0 { high }
    else { gcd(high%low, low) }
}

fn main() {
    let _n: u64 = read();
    let a: Vec<u64> = read_vec();

    // 配列aの全ての値に対してGCDを取れば、その値が答え.
    // gcd(a,b,c) = gcd(a, gcd(b, c))
    // gcd(a, b) = gcd(a, b - a)
    // という性質から導ける
    let mut res: u64 = 0;
    for ai in a
    {
        res = gcd(res, ai);
    }
    println!("{}", res);
}


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

#define rep(i,n) for(int i = 0; i < (int)n; ++i)

#define INF 100000000

int main() {
  int H, N;
  cin >> H >> N;
  int64_t atack = 0;
  rep(i, N){
    int tmp;
    cin >> tmp;
    atack += tmp;
  }
  if (H <= atack){
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define DIR_UP 		0
#define DIR_DOWN	1
#define DIR_LEFT	2
#define DIR_RIGHT	3

int w,h;
int map[30][30][4];
int tansaku_map[30][30];

int queue_start,queue_end;
int queue[900][2];

int main(void) {
	int i,j;
	int now;
	int x,y;
	while(1) {
		scanf("%d%d",&w,&h);
		if(w==0 && h==0) break;
		for(i=0;i<2*h-1;i++) {
			if(i%2==0) {
				for(j=1;j<w;j++) {
					scanf("%d",&now);
					map[i/2][j][DIR_LEFT]=!now;
					map[i/2][j-1][DIR_RIGHT]=!now;
				}
			} else {
				for(j=0;j<w;j++) {
					scanf("%d",&now);
					map[i/2][j][DIR_DOWN]=!now;
					map[i/2+1][j][DIR_UP]=!now;
				}
			}
		}
		for(i=0;i<h;i++) {
			map[i][0][DIR_LEFT]=0;
			map[i][w-1][DIR_RIGHT]=0;
			for(j=0;j<w;j++) {
				tansaku_map[i][j]=0;
				map[0][j][DIR_UP]=0;
				map[h-1][j][DIR_DOWN]=0;
			}
		}
		queue_start=0;queue_end=1;
		queue[0][0]=0;
		queue[0][1]=0;
		tansaku_map[0][0]=1;
		while(queue_start<queue_end) {
			x=queue[queue_start][0];
			y=queue[queue_start][1];
			queue_start++;
			if(map[y][x][DIR_LEFT] && tansaku_map[y][x-1]==0) {
				queue[queue_end][0]=x-1;
				queue[queue_end][1]=y;
				tansaku_map[y][x-1]=tansaku_map[y][x]+1;
				queue_end++;
			}
			if(map[y][x][DIR_RIGHT] && tansaku_map[y][x+1]==0) {
				queue[queue_end][0]=x+1;
				queue[queue_end][1]=y;
				tansaku_map[y][x+1]=tansaku_map[y][x]+1;
				queue_end++;
			}
			if(map[y][x][DIR_UP] && tansaku_map[y-1][x]==0) {
				queue[queue_end][0]=x;
				queue[queue_end][1]=y-1;
				tansaku_map[y-1][x]=tansaku_map[y][x]+1;
				queue_end++;
			}
			if(map[y][x][DIR_DOWN] && tansaku_map[y+1][x]==0) {
				queue[queue_end][0]=x;
				queue[queue_end][1]=y+1;
				tansaku_map[y+1][x]=tansaku_map[y][x]+1;
				queue_end++;
			}
		}
		printf("%d\n",tansaku_map[h-1][w-1]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
ll mod = 1e9 + 7;

using namespace std;



int main()

{
	int N;

	cin >> N;
	vector<int> t(N);
	vector<int> a(N);

	for (int i = 0; i < N; i++)
	{
		cin >> t[i] >> a[i];
	}

	ll ta = t[0];
	ll aa = a[0];

	for (int i = 1; i < N; i++)
	{
		ll ti = t[i];
		ll ai = a[i];
		ll n = max((ta + ti - 1) / ti, (aa + ai - 1) / ai);
		ta = n * ti;
		aa = n * ai;

	}

	cout << ta + aa << endl;
	
	return 0;
	
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Usize1;
use std::collections::HashSet;

fn main() {
    input! {
        h: usize,
        w: usize,
        m: usize,
        bombs: [(Usize1, Usize1); m],
    }

    let mut pos = HashSet::new();
    let mut rows = vec![0; h];
    let mut cols = vec![0; w];

    //O(n)
    for bomb in &bombs {
        rows[bomb.0] += 1;
        cols[bomb.1] += 1;
        pos.insert(bomb);
    }

    let mut rows_with_index = vec![];
    let mut cols_with_index = vec![];

    //O(n)
    for (i, row) in rows.iter().enumerate() {
        rows_with_index.push((row, i));
    }
    for (i, col) in cols.iter().enumerate() {
        cols_with_index.push((col, i));
    }

    //O(nlogn)
    rows_with_index.sort_by(|a, b| b.0.cmp(a.0));
    cols_with_index.sort_by(|a, b| b.0.cmp(a.0));

    let row_max = rows_with_index[0].0;
    let col_max = cols_with_index[0].0;

    let mut row_max_count = 1;
    let mut col_max_count = 1;

    //O(n)
    for row in rows_with_index.iter().skip(1) {
        if row_max != row.0 {
            break;
        }
        row_max_count += 1;
    }
    //O(n)
    for col in cols_with_index.iter().skip(1) {
        if col_max != col.0 {
            break;
        }
        col_max_count += 1;
    }

    //worst O(n^2)?
    let mut sub = true;
    'outer: for i in 0..row_max_count {
        for j in 0..col_max_count {
            if !pos.contains(&(rows_with_index[i].1, cols_with_index[j].1)) {
                sub = false;
                break 'outer;
            }
        }
    }

    if sub {
        println!("{}", row_max + col_max - 1);
    } else {
        println!("{}", row_max + col_max);
    }
}


Measured memory_bytes: 30308
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(i;0..n){t[i]=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t)v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}

void main()
{
  int n; readV(n);
  int d, x; readV(d, x);
  int[] a; readM(n, a);
  writeln(a.map!(ai => (d+ai-1)/ai).sum + x);
}


Measured memory_bytes: 256
program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,k,m,n
    integer(8)::a,b,c,d
    integer(8),allocatable::x(:),y(:)
  
    read(*,*) s
    if(s(1:1) .ne. 'A')then
        write(*,*)'WA'
        stop
    end if
    n=len_trim(s)


    do i=3,n-1
        if(s(i:i) .eq. 'C')then
            t=s(1:i-1)//s(i+1:n)
           exit
        end if
        if(i==n-1)then
            write(*,*)'WA'
            stop
        end if
    end do
    do i=2,n-1
        if(ichar(t(i:i))<97)then
            write(*,*)'WA'
            stop
        end if
    end do
    write(*,*)'AC'


    stop
end program sample
  



Measured memory_bytes: 2824
#[allow(dead_code)]
fn main() {
    let (a, b, c, k) = (i::i(), i::i(), i::i(), i::i());
    if a >= k {
        println!("{}", k);
        return;
    }
    if a + b >= k {
        println!("{}", a);
        return;
    }
    println!("{}", a + a + b - k);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
long long int f[100005][3];
long long int a[100006],a1[100005],a2[100005];
int main()
{

    long long int mod,t,k=0,i,m,n,x,j=0,l,c=0,r=0,w,s,d=0,sum=0,mul,mx1,mx,s1=10000000,s2=0;

    cin>>n;


    for(i=1; i<=n; i++)
    {

        cin>>a[i]>>a1[i]>>a2[i];
    }
f[n+1][0]=f[n+1][1]=f[n+1][2]=0;


    for(i=n; i>=1; i--)
    {


    f[i][0]=max((a1[i]+f[i+1][1]),(a2[i]+f[i+1][2]));
    f[i][1]=max((a[i]+f[i+1][0]),(a2[i]+f[i+1][2]));
    f[i][2]=max((a1[i]+f[i+1][1]),(a[i]+f[i+1][0]));

    }

    d=max(max(f[1][0],f[1][1]),f[1][2]);

    cout<<d<<endl;
    return 0;

}


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

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str.
   builtin functions :
   __builtin_popcount(n) : no. of set bits in n.
   __builtin_parity(n) : parity of no. of set bits
   __builtin_clz(n) : no. of leading zeros before 1
   __builtin_ctz(n) : no of zeros from last to first occurrence of 1
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll binlen(ll a)
{
	ll v = 0;
	for(ll i=0;i<61;++i)
	{
		v += (1ll<<i);
		if(a<=v) return i;
	}
}

ll cnt[M],ar[M],br[M];
map<pi,ll> mp;

ll k;

void ch(ll a,ll b)
{
	if(mp[pi(a,b)] == 0)
		mp[pi(a,b)] = ++k;

	cnt[mp[pi(a,b)]]++;
}

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

	ll a,b,c,d,z = 0,f = 0,s = 0,ans = 1,n,i,g,v;

	cin >> n;
	for(i=1;i<=n;++i)
	{
		cin >> a >> b;
		if(a == 0 && b == 0)
			z++;
		else if(a == 0)
			f++;
		else if(b == 0)
			s++;
		else
		{
			g = __gcd(abs(a),abs(b));
			a = a/g;
			b = b/g;
			if(a<0 && b<0)
			{
				a *= -1;
				b *= -1;
			}
			else if(b<0)
			{
				a *= -1;
				b *= -1;
			}
			ch(a,b);
		}
		ar[i] = a;
		br[i] = b;
	}

	for(i=1;i<=n;++i)
	{
		a = ar[i];
		b = br[i];
		if(a == 0)
		{
			if(b<0)
			{
				a *= -1;
				b *= -1;
			}
		}
		else if(a != 0 && b != 0)
		{
			g = __gcd(abs(a),abs(b));
			a = a/g;
			b = b/g;
			if(a<0 && b<0)
			{
				a *= -1;
				b *= -1;
			}
			else if(b<0)
			{
				a *= -1;
				b *= -1;
			}
		}
		if(mp[pi(a,b)] == 0)
			continue;
		c = -b;
		d = a;
		if(c == 0)
		{
			if(b<0)
			{
				c *= -1;
				d *= -1;
			}
		}
		else if(c != 0 && d != 0)
		{
			g = __gcd(abs(c),abs(d));
			c = c/g;
			d = d/g;
			if(c<0 && d<0)
			{
				c *= -1;
				d *= -1;
			}
			else if(d<0)
			{
				c *= -1;
				d *= -1;
			}
		}
		v = pwr(2,cnt[mp[pi(a,b)]],md);
		v = (v+pwr(2,cnt[mp[pi(c,d)]],md))%md;
		ans = 1ll*ans*((v+md-1)%md)%md;
		// cout << ar[i] << " " << br[i] << " " << a << " " << b << " " << c << " " << d << " " << ans << "\n";
		mp[pi(a,b)] = 0;
		mp[pi(c,d)] = 0;
	}

	ans = (ans+md-1)%md;
	v = ans;
	ans = (ans+z)%md;
	ans = (ans+1ll*v*((md+pwr(2,f,md)-1)%md))%md;
	ans = (ans+1ll*v*((md+pwr(2,s,md)-1)%md))%md;
	ans = (ans+(md+pwr(2,f,md)-1)%md)%md;
	ans = (ans+(md+pwr(2,s,md)-1)%md)%md;

	cout << ans << "\n";
}

	

Measured memory_bytes: 33296
#include <stdio.h>

int main (){
    int n,i;
    int A[200];
    scanf("%d",&n);
    for(i=0 ; i<n ; ++i){
        scanf("%d" ,&A[i]);
    }

    int count=0;
    int flag=0;
    while(flag == 0){
        for(i=0; i<n ;i++){
            if(A[i]%2 == 0) A[i]/=2;
            else flag=1;
        }
        count++;
    }
    count--;
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
typedef long long ll;

ll K,A,B;
int main(){
	cin >> K >> A >> B;
	ll k = K;
	if(A>=B){
		cout << K+1 << endl;
		return 0;
	}
	if(K<=A){
		cout << K+1 << endl;
		return 0;
	}
	ll ans = 0;
	K -= A+1;
	ans = B;
	if(B-A>1){
		ans += (B-A)*(K/2);
		if(K%2==1) ans++;
		cout << max(ans,k+1) << endl;
	}else cout << max(B+K,k+1) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.InputMismatchException;

class Main {
   public static void main(String args[]) {
      int x[] = new int[6];
      try {
         Scanner scanner = new Scanner(System.in);
         for (int i=0; i<6; i++) {
            x[i] = scanner.nextInt();
         }
         scanner.close();
      } catch (InputMismatchException e) {
         System.out.println("error");
      }
      if (x[4]-x[0]>x[5]) {
         System.out.println(":(");
      } else {
         System.out.println("Yay!");
      }
   }
}


Measured memory_bytes: 21972
k,a,b=map(int,input().split())
if a-1>=k:
    print(1)
elif a-1<=k:
    if a+1<b:
        if (k+1-a)%2==0:
            print(a+((k+1-a)//2)*(b-a))
        else:
            print(a+1+((k+1-a)//2)*(b-a))
    
    
    elif a+1>=b:
        print(k+1)

Measured memory_bytes: 38384
n, m = map(int, input().split())
k = [[int(i) for i in input().split(" ")] for i in range(m)]
p = [int(i) for i in input().split(" ")]
c = 0
for i in range(2**n):
    t = bin(i+2**n)[2:]
    a = sum([0 if sum([1 if t[l]=="1" else 0 for l in k[j][1:]])%2 == p[j] else 1 for j in range(len(k))])
    if a == 0:
        c+=1
print(c)

Measured memory_bytes: 3064