akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<ll, ll>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> ab(N);
    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        ab[i] = {a, b};
    }
    sort(ab.begin(), ab.end());
    ll ans = 0, num = 0;
    rep(i, N) {
        ll tmp = M - num;
        if (tmp - ab[i].second >= 0) {
            tmp -= ab[i].second;
            ans += ab[i].second * ab[i].first;
            num += ab[i].second;
            if (tmp == 0) break;
        }
        else {
            ans += tmp * ab[i].first;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    vector<int> v(3);

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

    sort(v.begin(),v.end());

    int s = abs(v[0] - v[1]);
    s += abs(v[1] - v[2]);

    int s2 = abs(v[2] - v[1]);
    s2 += abs(v[0] - v[2]);


    cout<<min(s,s2)<<endl;

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 21;
int g[N][N];
int dp[1 << N][N];
bool visit[1 << N][N];
int n;

int solve(int mask, int u) {
  if (u == n) return 1;
  int& ret = dp[mask][u];
  if (visit[mask][u]) return ret;
  visit[mask][u] = true;
  ret = 0;
  for (int i = 0; i < n; ++i) {
    if (!(mask & (1 << i)) || !g[u][i]) continue;
    ret = (ret + solve(mask ^ (1 << i), u + 1)) % MOD;
  }
  return ret;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      scanf("%d", &g[i][j]);
    }
  }
  int ret = solve((1 << n) - 1, 0);
  printf("%d\n", ret);
  return 0;
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void debug_out() {cerr << endl;}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H), debug_out(T...);}

int main() {
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
#define debug(...) 3
    fastIO;
#endif
    ll n, x, t;
    cin >> n >> x >> t;
    cout << ((n+x-1)/x)*t << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
long L,A,B,M;
long power(long a,long b){return b?power(a*a%M,b/2)*(b%2?a:1)%M:1;}
long ten[99],sten[99],iten[99];
long n;
long sum(long k)
{
	long ret=0,p=1;
	for(int i=61;i--;)
	{
		if(k>>i&1)
		{
			(ret+=sten[i]*p)%=M;
			p=p*ten[i]%M;
		}
	}
	return ret;
}
long isum(long k)
{
	long ret=0,p=1,g=0;
	for(int i=61;i--;)
	{
		if(k>>i&1)
		{
			(ret+=(iten[i]+sten[i]*g)%M*p)%=M;
			p=p*ten[i]%M;
			g=(g+(1LL<<i))%M;
		}
	}
	return ret;
}
long cnt[18],SUM[18];
main()
{
	cin>>L>>A>>B>>M;
	long pre=-1,tmpten=1;
	long ans=0;
	for(n=1;n<=18;n++)
	{
		cnt[n-1]=1;
		long l=pre,r=L;
		tmpten*=10;
		while(r-l>1)
		{
			long m=(l+r)/2;
			if(A+B*m<tmpten)l=m;
			else r=m;
		}
		long k=l-pre;
		if(k<0)
		{
			continue;
		}
		pre=l;
		ten[0]=tmpten%M;
		sten[0]=1;
		iten[0]=0;
		if(k&1)cnt[n-1]=tmpten%M;
		for(int i=1;i<61;i++)
		{
			ten[i]=ten[i-1]*ten[i-1]%M;
			sten[i]=(ten[i-1]+1)%M*sten[i-1]%M;
			iten[i]=((ten[i-1]+1)%M*iten[i-1]+(1LL<<i-1)%M*sten[i-1]%M*ten[i-1])%M;
			if(k>>i&1)cnt[n-1]=cnt[n-1]*ten[i]%M;
		}
		long ret=0,p=1;
		for(int i=61;i--;)
		{
			if(k>>i&1)
			{
				(ret+=sten[i]*p)%=M;
				p=p*ten[i]%M;
			}
		}
		SUM[n-1]=(A+B*l)%M*ret%M;
		ret=0;
		p=1;
		long g=0;
		for(int i=61;i--;)
		{
			if(k>>i&1)
			{
				(ret+=(iten[i]+sten[i]*g)%M*p)%=M;
				p=p*ten[i]%M;
				g=(g+(1LL<<i))%M;
			}
		}
		SUM[n-1]=((SUM[n-1]-B%M*ret)%M+M)%M;
	}
	long p=1;
	for(int i=18;i--;)
	{
		ans=(ans+SUM[i]*p)%M;
		p=p*cnt[i]%M;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int n = sc.nextInt();
		int a = sc.nextInt();

		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (a <= sc.nextInt()) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 47452
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;

LL a,b,g[20],anss;
bool fl;
int main()
{
	LL i,j,x;
	scanf("%lld%lld",&a,&b);
	for(i=a;i<=b;i++)
	{
		x=i;
		for(g[0]=0;x;x/=10)	g[++g[0]]=x%10;
		fl=0;
		for(j=1;j<=g[0];j++)	if(g[j]!=g[g[0]-j+1])	fl=1;
		if(!fl)	anss++;
	}
	printf("%lld",anss);
	return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong H, A, B;
	cin >> H >> A >> B;
	int ans = 0;
	for(int i = A; i <= B; i++)
		if(H%i == 0)
			ans++;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3092
import collections

N = int(input())
V = list(map(int,input().split()))

L1 = []
L2 = []

for i in range(N):
  if i % 2 == 0:
    L1.append(V[i])
  else:
    L2.append(V[i])
    
con1 = collections.Counter(L1).most_common()
con2 = collections.Counter(L2).most_common()

nums = 0

#全てが同じなら全体の半数を変える
if len(set(V)) == 1:
  print(N // 2)

#分割数列のそれぞれが全て等しい数からできているなら変える必要はない
elif len(set(L1)) == 1 and len(set(L2)) == 1:
  print(0)
#
else:
  ans = 0
  total = 0
  if con1[0][0] == con2[0][0]:
  
    for i in range(1,len(con1)):
      total += con1[i][1]
    for i in range(2,len(con2)):
      total += con2[i][1]
    total += con2[0][1]
    
    for i in range(1,len(con2)):
      ans += con2[i][1]
    for i in range(2,len(con1)):
      ans += con1[i][1]
    ans += con1[0][1]
    
    ans = min(ans,total)
    
  else:
    for i in range(1,len(con1)):
      ans += con1[i][1]
    for i in range(1,len(con2)):
      ans += con2[i][1]
    
  print(ans)

Measured memory_bytes: 25172
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int H,W,K; cin >> H >> W >> K;
    vector<vector<char>> masu(H,vector<char>(W));
    for(auto& vec:masu)for(auto& in:vec) cin >> in;
    
    for(int bh = 0; bh < (1<<H); bh++){
        for(int bw = 0; bw < (1<<W); bw++){
            auto t = masu;
            
            int k = 0;
            for(int i = 0; i < H; i++){
                for(int j = 0; j < W;j++){
                    if(((bh>>i)&1) || ((bw>>j)&1)){
                        t[i][j] = '@';
                    }
                    if(t[i][j] == '#') k++;
                }
            }
            if(k == K) res++;
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

int main() {
    int N; cin >> N;
    int M; cin >> M;
    map<int,int> kind;
    rep(i,N) {
        int K; cin >> K;
        rep(j,K) {
            int A; cin >> A;
            if(kind.count(A))
                kind[A]++;
            else kind[A] = 1;
        }
    }
    int ans = 0;
    for(auto x:kind) {
        if(x.second == N) ans++;
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
import math
import itertools

n = int(input())
na = [i for i in range(n)]
a = []
for i in range(n):
    a.append(list(map(int, input().split())))

cntnum = 0
tmp = []
for i, j in itertools.product(na, na):
    if i != j:
        cntnum += 1
        cntwa = 0
        # print(i, j)
        cntwa += ((a[i][0] - a[j][0]) ** 2 + (a[i][1] - a[j][1]) ** 2) ** 0.5
        # print(cntwa)
        tmp.append(cntwa)
print(sum(tmp)/n)



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

int main()
{
    int k, s;
    std::cin >> k >> s;

    int ans = 0;
    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= k; j++) {
            if (s - i - j <= k && s - i - j >= 0) {
                ans++;
            }
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,k,i;
    cin>>n;
    k=0;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        if(a%2==0)
        {
            if(a%3!=0 && a%5!=0)
            {
                k=10;
            }

        }
    }
    if(k==10)
    {
        cout<<"DENIED"<<endl;
    }
    else
    {
        cout<<"APPROVED"<<endl;
    }
}



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

int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; ++i) ans += i;
  cout << ans << endl;
}

Measured memory_bytes: 256
# ABC054 C One-stroke Path
N,M = map(int, input().split())

G = [[] for _ in range(N)]
reached = [False]*N

for _ in range(M):
    a,b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

cnt = 0

def DFS(x):

    global cnt
    global reached

    reached[x] = True
 
    if all(reached):
        cnt += 1
        reached[x] = False
 
        return

    for i in G[x]:
        if reached[i]:
            continue

        else:
            DFS(i)

    reached[x] = False

DFS(0)
print(cnt)

Measured memory_bytes: 3064
from collections import Counter
s=input()
cs=Counter(s).most_common()
if len(cs)==1:print(0)
else:
    a=float("inf")
    for i,_ in cs:
        si=s[:]
        x=0
        while len(set(si))>1:
            sic=""
            for j in range(len(si)-1):
                if si[j]==i or si[j+1]==i:sic+=i
                else:sic+=si[j]
            si=sic.replace(i*2,i)
            x+=1
        a=min(a,x)
    print(a)

Measured memory_bytes: 3316
#include<iostream>

using namespace std;

#define NMAX 200
#define NOT 10000

int main(){

	int N;
	int x[NMAX];
	int y[NMAX];
	int n,d;

	while(1){

		cin>>N;
		if(N==0) break;

		for(int i=0;i<N;i++) x[i]=NOT,y[i]=NOT;
		x[0]=0,y[0]=0;
		for(int i=1;i<=N-1;i++){
			cin>>n>>d;
			if(d==0) x[i]=x[n]-1,y[i]=y[n]; 
			if(d==1) x[i]=x[n],y[i]=y[n]-1; 
			if(d==2) x[i]=x[n]+1,y[i]=y[n]; 
			if(d==3) x[i]=x[n],y[i]=y[n]+1;
		}
		int xmin=0,xmax=0,ymax=0,ymin=0;
		for(int i=0;i<=N-1;i++){
			if(xmin>x[i]) xmin=x[i];
			if(ymin>y[i]) ymin=y[i];
			if(xmax<x[i]) xmax=x[i];
			if(ymax<y[i]) ymax=y[i];
		}
		cout<<(xmax-xmin+1)<<" "<<(ymax-ymin+1)<<endl;
	}

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  int n, b;
  ll sum = 0, out1 = 0, out2 = 0;
  cin >> n;
  vector<int> a(n), d(n);
  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
    d.at(i) += a.at(i) - i;
  }
  sort(d.begin(), d.end());
  if(n % 2) {
    for(int i = 0; i < n; i++)
      out1 += abs(a.at(i) - i - d.at((n - 1) / 2));
    cout << out1 << endl;
    return 0;
  } else {
    b = (d.at(n / 2) + d.at(n / 2 - 1)) / 2;
    for(int i = 0; i < n; i++)
      out1 += abs(a.at(i) - i - b);
    b++;
    for(int i = 0; i < n; i++)
      out2 += abs(a.at(i) - i - b);
    cout << min(out1, out2) << endl;
  }
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;


int main(void) {
	int a,b,c,d;
	a=(getchar()-'0');
	b=(getchar()-'0');
	c=(getchar()-'0');
	d=(getchar()-'0');
	if(a+b+c+d==7)cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
	else if(a+b+c-d==7)cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
	else if(a+b-c+d==7)cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
	else if(a+b-c-d==7)cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
	else if(a-b+c+d==7)cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
	else if(a-b+c-d==7)cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
	else if(a-b-c+d==7)cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
	else if(a-b-c-d==7)cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
	return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

//#define int long long

/*************** using variables ***************/
int n, d, x;
vector<int> a;
/**********************************************/

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n >> d >> x;
    a.resize(n);
    REP(i, n) cin >> a[i];

    int ans = x;
    REP(i, n){
        int cnt = 1;
        REP(j, d){
            if(j == 0) ans += 1;
            else if(a[i] * cnt + 1 == j + 1){
                ans += 1;
                cnt++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import Data.Char

main = do
  [a, b, c, d] <- map digitToInt <$> getLine
  putStr $ solve a b c d

solve a b c d
  | a + b + c + d == 7
    = s ++ "+" ++ t ++ "+" ++ u ++ "+" ++ v ++ "=7"
  | a + b + c - d == 7
    = s ++ "+" ++ t ++ "+" ++ u ++ "-" ++ v ++ "=7"
  | a + b - c + d == 7
    = s ++ "+" ++ t ++ "-" ++ u ++ "+" ++ v ++ "=7"
  | a + b - c - d == 7
    = s ++ "+" ++ t ++ "-" ++ u ++ "-" ++ v ++ "=7"
  | a - b + c + d == 7
    = s ++ "-" ++ t ++ "+" ++ u ++ "+" ++ v ++ "=7"
  | a - b + c - d == 7
    = s ++ "-" ++ t ++ "+" ++ u ++ "-" ++ v ++ "=7"
  | a - b - c + d == 7
    = s ++ "-" ++ t ++ "-" ++ u ++ "+" ++ v ++ "=7"
  | a - b - c - d == 7
    = s ++ "-" ++ t ++ "-" ++ u ++ "-" ++ v ++ "=7"
  where
    s = show a
    t = show b
    u = show c
    v = show d

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

#define FOR(i,a,b) for(int i = (a);i < (b);++i)
typedef long long ll;

int main(){
   int r; cin >> r;
   if(r < 1200) cout << "ABC" << endl;
   else if(r < 2800) cout << "ARC" << endl;
   else cout << "AGC" << endl;
   return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

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

    int N, M; cin >> N >> M;
    map<int, int> count;
    int64_t answer = 0;
    count[0] = 1;
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        int x; cin >> x;
        sum = (sum + x) % M;

        answer += count[sum];
        count[sum]++;
    }

    cout << answer << "\n";
}


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

using namespace std;

const int MAX_N = 3000;

int a[MAX_N];
long long Solve[MAX_N][MAX_N];

long long solve(int i, int j) {
  if (Solve[i][j] == -1) {
    if (i == j) {
      Solve[i][j] = a[i];
    } else {
      Solve[i][j] = std::max(a[i] - solve(i + 1, j), a[j] - solve(i, j - 1));
    }
  }
  return Solve[i][j];
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      Solve[i][j] = -1;
    }
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  long long answer = solve(0, n - 1);
  printf("%lld\n", answer);
  return 0;
}


Measured memory_bytes: 70144
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  if(n<r)return 0;
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // int codeforces;cin>>codeforces;while(codeforces--){
  ll i,j,K,A,B,ans;
  string s;
  cin>>K>>A>>B;
  if(B/K==(A-1)/K)print("NG");
  else print("OK");
  // }return 0;
}

Measured memory_bytes: 3632
// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
    "2 4 6" => "YES",
    "2 5 6" => "NO",
    "3 2 1" => "YES",
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: i8,
        b: i8,
        c: i8,
    }

    if b - a == c - b {
        return String::from("YES");
    } else {
        return String::from("NO");
    }
}

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

int main(){
	long long N, K;
	cin >> N >> K;
	vector<long long> H;
	for(int i=0;i<N;i++){
		long long x;
		cin >> x;
		H.push_back(x);
	}
	sort(H.begin(), H.end());
	long long ans = 0;
	for(int i=0;i<N-K;i++){
		ans += H[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 5340
#include <algorithm>
#include <iostream>

using namespace std;

int n, k, sum_a, ans;
int a[550];
int r[550];

int main()
{
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum_a += a[i];
  }
  
  for (int mod = 1; mod * mod <= sum_a; mod++) {
    if (sum_a % mod) continue;
    
    int sum_r = 0;
    for (int i = 0; i < n; i++) {
      r[i] = a[i] % mod;
      sum_r += r[i];
    }
    sort(r, r+n);
    int cnt_x = sum_r, cnt_y = 0;
    for (int i = n-1; i >= 0; i--) {
      cnt_x -= r[i];
      cnt_y += mod - r[i];
      if (cnt_x == cnt_y) break;
    }
    if (cnt_x <= k) ans = max(ans, mod);
    
    int mod2 = sum_a / mod;
    sum_r = 0;
    for (int i = 0; i < n; i++) {
      r[i] = a[i] % mod2;
      sum_r += r[i];
    }
    sort(r, r+n);
    cnt_x = sum_r, cnt_y = 0;
    for (int i = n-1; i >= 0; i--) {
      cnt_x -= r[i];
      cnt_y += mod2 - r[i];
      if (cnt_x == cnt_y) break;
    }
    if (cnt_x <= k) ans = max(ans, mod2);
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            int iR = int.Parse(sS[1]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = iR;
            if (iN < 10) { iOut += 100 * (10 - iN); }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
a = input()
b = input()
c = input()
t='a'
while True:
    if t=='a':
        if len(a) == 0:
            print('A')
            break
        t=a[0]
        a=a[1:]
    if t=='b':
        if len(b) == 0:
            print('B')
            break
        t=b[0]
        b=b[1:]
    if t=='c':
        if len(c) == 0:
            print('C')
            break
        t=c[0]
        c=c[1:]

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int n;
    cin >> n;
    map<string, int> m;
    vector<string> str = {"AC", "WA", "TLE", "RE"};
    for (auto s : str)
        m[s] = 0;
    rep(i, n)
    {
        string s;
        cin >> s;
        m.at(s)++;
    }
    for (auto s : str)
    {
        cout << s << " x " << m[s];
        ed;
    }
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
#define MAX_C 1000000001
#define MOD 1000000007

bool debflag = false; //debug

struct Node {
  int depth = -1; //1からの深さ
  int counter = 0;
  set<int> nxt;
};

void printtree(vector<Node>&tree) {
  for (Node node: tree) {
    cout << "depth: " << node.depth << ", counter: " << node.counter << ", nxt: ";
    for (int i: node.nxt) cout << i << " ";
    cout << endl;
  }
}

void dfs(int nd, int point, vector<Node>&tree) {
  //if (debflag) cout << "dfs" << endl;
  tree[nd-1].counter += point;
  for (int nx: tree[nd-1].nxt) {
    if (tree[nd-1].depth < tree[nx-1].depth) dfs(nx, tree[nd-1].counter, tree);
  }
  return;
}

void init_tree(int nd, int dep, vector<Node>&tree) {
  if (debflag) cout << "init_tree: " << nd << endl;
  nd--;
  tree[nd].depth = dep;
  for (int nx: tree[nd].nxt) {
    if (tree[nx-1].depth == -1) {
      init_tree(nx, tree[nd].depth + 1, tree);
      //(tree[nx-1].nxt).erase(nd+1);
    }
  }
  return;
}

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

  int n, q;
  cin >> n >> q;
  vector<Node> tree(n);
  //vector<vector<int>> branch(n-1);
  for (int i = 0; i < n-1; i++) {
    int a, b;
    cin >> a >> b;
    (tree[a-1].nxt).insert(b);
    (tree[b-1].nxt).insert(a);
  }
  init_tree(1, 0, tree);

  if (debflag) printtree(tree);

  vector<pii> ops(q);
  for (int i = 0; i < q; i++) {
    int p, x;
    cin >> p >> x;
    ops[i] = pii(p, x);
    tree[p-1].counter += x;
  }

/*
  for (pii op: ops) {
    //dfs(op.first, op.second, tree);
  }
*/
  dfs(1, 0, tree);

  for (int i = 0; i < tree.size(); i++) {
    cout << tree[i].counter << " ";
  }
  cout << endl;
}


Measured memory_bytes: 46208
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int[] A = new int[5];
        for (int i = 0; i < 5; i++) {
            A[i] = scan.nextInt();
        }
        for (int i = 0; i < 5; i++) {
            if (A[i] == 0) {
                System.out.println(i + 1);
                return;
            }
        }
    }
}


Measured memory_bytes: 35788
"use strict";

const fs = require("fs");

const main = (argv: string[]) => {
  const [N, K] = argv[0].split(" ").map(Number);
  if (N <= K) {
    console.log(0);
    return;
  }
  const hps = argv[1].split(" ").map(Number);
  const sorted = hps.sort((a, b) => b - a);
  console.log(sorted.slice(K).reduce((a, c) => a + c));
}

const parser = (argv: any) => {
  main(argv.split("\n"));
}

parser(fs.readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 37328
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>

using namespace std;


int main() {
	map<int, int> mp;

	long long int a, b, c, d, e, f, g,result;
	
	cin >>a>>b>>c>>d>>e>>f>>g;

	result = b;

	if (a % 2 == d % 2 && d % 2 == e % 2) { result += a + d + e; }
	else {
		result += a + d + e-1;
		if (a == 0 || d == 0 || e == 0) { result = b + a / 2 + d / 2 + e / 2; }
	}
	cout << result;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
/*vector<Type> v;
vector<Type> v();
vector<Type> v(n);
vector<Type> v(n, d);
vector<vector<Type>> vv;
vector<vector<Type>> vv();
vector<vector<Type>> vv(n);
vector<vector<Type>> vv(n, vector<Type>(m));
vector<vector<Type>> vv(n, vector<Type>(m, d));*/

int main() {
  int N;
  cin >> N;
  string judge;
  int AC=0, WA=0, TLE=0, RE=0;
  rep(i,N){
    cin >> judge;
    if(judge=="AC"){
      AC++;
    }else if(judge=="WA"){
      WA++;
    }else if(judge=="TLE"){
      TLE++;
    }else{
      RE++;
    }
  }
  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;

  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <typeinfo>
#include <numeric>
#include "math.h"
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <numeric>
using namespace std;

//1%
int main() {

	long long int k, m = 100, cnt = 0;


	cin >> k;
	while (m<k)
	{
		cnt++;
		m += m / 100;
	} 
	cout << cnt;
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include<string>
using namespace std;
int main(void){
    int n, y;
    cin >> n >> y;
    int i = -1, j = -1, k = -1;
    for (int _i = 0; _i <= n; _i++){
        bool end_flg = false;
        for (int _j = 0; _j <= n; _j++){
            int _k = n - (_i + _j);
            if (_k < 0)continue;
            int total = 10000*_i + 5000*_j + 1000*_k;
            if (total == y){
                i = _i;
                j = _j;
                k = _k;
                end_flg = true;
                break;
            }
        }
        if (end_flg) break;
    }
    cout << i << " " << j << " " << k << endl;
    return 0;
}


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

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;

  if (s.empty() || t.empty()) {
    cout << endl;
    return 0;
  }

  vector<vector<int>> dp(s.size()+1, vector<int>(t.size()+1, 0));

  for (int i=1; i<=s.size(); i++) {
    for (int j=1; j<=t.size(); j++) {
      if (s[i-1] == t[j-1]) {
        dp[i][j] = dp[i-1][j-1] + 1;
      } else {
        dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      }
    }
  }

  int i = s.size(), j = t.size();
  string result;
  while (i > 0 && j > 0) {
    if (s[i-1] == t[j-1]) {
      result.insert(0, 1, s[i-1]);
      i--;
      j--;
    } else {
      if (dp[i-1][j] > dp[i][j-1]) {
        i--;
      } else {
        j--;
      }
    }
  }

  cout << result << endl;

  return 0;
}

Measured memory_bytes: 35584
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

const int MOD = 1001;

int fib[1002];

class UnionFind{
public:
    UnionFind(){}
    UnionFind(int n){
        init(n);
    }
    void init(int n){
        REP(i, n){
            parent[i] = i;
            rank[i] = 0;
        }
    }
    int find(int v){
        if(v == parent[v]){return v;}
        return parent[v] = find(parent[v]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y){return;}

        if(rank[x] > rank[y]){
            parent[y] = x;
        }else{
            parent[x] = y;
            if(rank[x] == rank[y]){rank[y] += 1;}
        }
    }
    bool same(int u, int v){
        return find(u) == find(v);
    }
private:
    int parent[1002], rank[1002];
};

UnionFind uf;

int main(){
    fib[0] = 1;
    fib[1] = 2;
    FOR(i, 2, 1002){fib[i] = (fib[i-1] + fib[i-2]) % MOD;}
    
    int V, d;
    while(std::cin >> V >> d, !std::cin.eof()){
        uf.init(V+1);
        FOR(i, 1, V+1){
            FOR(j, i+1, V+1){
                if(std::abs(fib[i] - fib[j]) < d){uf.unite(i, j);}
            }
        }

        int res = 0;
        FOR(i, 1, V+1){
            if(i == uf.find(i)){res += 1;}
        }

        std::cout << res << std::endl;
    }
}

Measured memory_bytes: 1172
import sys
a, b, c = map(int, sys.stdin.readline().split())
nums = []
nums.append(a)
nums.append(b)
nums.append(c)

counted = []
cnt = 0
for item in nums:
    if item in counted:
        continue
    else:
        cnt += 1
        counted.append(item)
print(cnt)

Measured memory_bytes: 3060
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 3e5 + 10;
int n , a[N];

int main(){
  scanf("%d",&n);
  rep(i,0,n*3) scanf("%d",a+i);
  sort(a,a+n*3);
  reverse(a,a+n*3);
  ll ans=0;
  rep(i,0,n) ans+=a[i*2+1];
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    if (s[0]==s[1]&&s[2]==s[3]&&s[2]!=s[1])
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int N;string S;
    cin >> N;
    cin >> S;
    if(S.length()%2==0){
        int len = S.length()/2;
        for(int i=0;i<len;i++){
            if(S.at(i)!=S.at(i+len)){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath> 
#include <algorithm>
#include <cstring>
using namespace std;
string a={"CODEFESTIVAL2016"},b;
int ans,i;
int  main()
{
    cin>>b;
    for(i=0;i<16;i++)
    {
        if(a[i]!=b[i])
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main(){
	int d,t,s;
	cin >> d >> t >> s;
	// meeter per second
	// time available 
	// distance in meter
	float m=(float)d/s;
	//cout<<"Time calculate: "<<m;
	if(m <= t)
		cout<<"Yes\n";
	else 
		cout<<"No\n";
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		int sum = 0;

		if ((y % 2) != 0) {
			System.out.println("No");
			System.exit(0);
		} else if ((y == 2 * x) || (y == 4 * x)) {
			System.out.println("Yes");
			System.exit(0);
		} else {
			for (int i = 0; i < x; i++) {
				sum = (2 * (x - i)) + (4 * i);
				if (sum == y) {
					System.out.println("Yes");
					System.exit(0);
				}
			}
		}
		System.out.println("No");

		scan.close();

	}

}


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

int main()
{
  string map[51];
  int height,width;
  cin >> height >> width;
  
  rep(i,height) cin >> map[i];
  
  int dx[8]={-1,0,1,-1,1,-1,0,1};
  int dy[8]={-1,-1,-1,0,0,1,1,1};
  
  rep(i,height)
  {
    rep(j,width)
    {
      if(map[i][j]=='#') continue;
      
      int num=0;
      rep(k,8)
      {
        int ni = i + dy[k];
        int nj = j + dx[k];
        
        if(ni < 0 || ni > height) continue;
        if(nj < 0 || nj > width) continue;
        if(map[ni][nj]=='#') num++;
      }
      map[i][j]='0'+num;
    }
  }
  rep(i,height) cout << map[i] << endl;
}

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

using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i,t,s;

ll gcd(int a,int b){
  return (b==0) ? a : gcd(b,a%b);
}
void solve(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  ll a=1,b=1,l;
  rep(i,n){
    cin>>t>>s;
    // if(i==0) a=t;b=s;
    l = max((a%t==0)?a/t:a/t+1,(b%s==0)?b/s:b/s+1);
    a = l*t; b = l * s;
    // cout<<a<<" "<<b<<endl;
  }
  cout<<a+b<<endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pdd = pair<double, double>;

int main() {
    int N; cin >> N;
    vector<pdd> points(N);
    for (int i = 0; i < N; i++) {
        double x, y; cin >> x >> y;
        points[i] = make_pair(x, y);
    }
    vector<vector<double>> dist(N, vector<double>(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            dist[i][j] = sqrt(pow(points[i].first - points[j].first, 2) + pow(points[i].second - points[j].second, 2));
        }
    }
    vector<int> perm(N);
    for (int i = 0; i < N; i++) perm[i] = i;
    double ans = 0;
    double n_fact = 1.0;
    for (int i = 1; i <= N; i++) n_fact *= i;
    do {
        double pathlen = 0;
        for (int i = 0; i < N - 1; i++) pathlen += dist[perm[i]][perm[i+1]];
        ans += pathlen / n_fact;
    } while (next_permutation(perm.begin(), perm.end()));
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
#define pll pair<ll,ll>
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
const ll mod2= 998244353;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

ll d[200][200];
int main(){
    ll n,k,ans=0;
    cin>>n;
    bool f=false;
    ll cnt=0;
    rep(i,0,n){
        rep(j,0,2){
            cin>>d[i][j];
        }
    }
    rep(i,0,n){
        if(d[i][0]==d[i][1])cnt++;
        else{
            if(cnt>2)f=true;
            cnt=0;
        }
    }
    if(cnt>2)f=true;
    if(f)cout<<"Yes";
    else cout<<"No";
}



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

int main() {
    int N, A[200002];
    int num_sup[200002] = {0};
    cin >> N;
    for (int i = 2; i <= N; i++){
        cin >> A[i];
    }
    for (int i = 2; i <= N; i++){
        num_sup[A[i]]++;
    }
    for(int i = 1; i <= N; i++) {
        cout << num_sup[i] << endl;
    }
}

Measured memory_bytes: 5140
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 998244353;

const int maxn = 1e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    if (n == 1) {
        if (k) {
            cout << -1 << '\n';
        }
        else {
            cout << "0 0 1 1\n";
        }
        exit(0);
    }
    n = 1 << (n);
    if (k >= (n)) {
        cout << -1 << '\n';
        exit(0);
    }
    n <<= 1;
    int ans[n + 5] = {};
    ans[n/2] = ans[n] = k;
    for (int p = 0, i = 1 ; i < n/2 ; i++,p++) {
        if (p == k) {
            ++p;
        }
        ans[i] = ans[n-i] = p;
    }
    f1(n) {
        cout << ans[i] <<' ';
    }
    cout << '\n';
}

Measured memory_bytes: 2816
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

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

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

const mod = 1e9 + 7

func main() {
	sc.Split(bufio.ScanWords)

	N, M := getInt(), getInt()
	if abs(N-M) > 1 {
		out(0)
		return
	}
	ans := 1
	for i := 1; i <= N; i++ {
		ans *= i
		ans %= mod
	}
	for i := 1; i <= M; i++ {
		ans *= i
		ans %= mod
	}
	if N == M {
		ans *= 2
		ans %= mod
	}
	out(ans)
}


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

class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int r = sc.nextInt();
        if (r < 1200){
            System.out.println("ABC");
        } else if (r < 2800) {
            System.out.println("ARC");
        } else {
            System.out.println("AGC");
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;cin>>n;cout<<3*n*n<<endl;
    return 0;
}


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

char C[201][201];
char  c[201 * 201];

int main() {
    int H,W; cin >> H >> W;
    rep(y,H) rep(x,W) { cin >> C[y][x]; }
    rep(y,H*2) {
        rep(x,W) { cout << C[y/2][x]; }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#define ll long long
using namespace std;



int main(){

ll A,B;
cin>>A>>B;
for(int N=0;N<10000;N++){
  int ZA=N*8/100;
  int ZB=N*10/100;
  if(ZA==A&&ZB==B) {
    cout<<N<<endl;
    return 0;
  }
}
cout<<"-1"<<endl;

  return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        ArrayList<Integer> al = new ArrayList<>();
        al.add(a);
        al.add(b);
        al.add(c);
        Collections.sort(al);
        System.out.println(al.get(0) + al.get(1));
    }
}

Measured memory_bytes: 23764
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	p := make([]int, N+1)
	for i := 1; i <= N; i++ {
		p[i] = getInt()
	}

	ans := 0
	for i := 1; i <= N; i++ {
		if i == p[i] {
			if i == 1 {
				p[i], p[i+1] = p[i+1], p[i]
				ans++
			} else if i == N {
				p[i], p[i-1] = p[i-1], p[i]
				ans++
			} else {
				if p[i+1] == i+1 {
					p[i], p[i+1] = p[i+1], p[i]
				} else {
					p[i], p[i-1] = p[i-1], p[i]
				}
				ans++
			}

		}
	}
	out(ans)

}


Measured memory_bytes: 1920