akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int a, p;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> p;
  cout << (a*3+p)/2 << endl;
}

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

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

  if(k <= a) a -= k;
  else if(k > a){
    if( k - a <= b){
      b = b - (k - a);
      a = 0;
    }
    else if(k - a > b){
      a = 0;
      b = 0;
    }
  }

  cout << a << " " << b;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const int N = 2e4 + 10;

struct IOsetup{
  IOsetup(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cout.tie(nullptr);
   cout << fixed << setprecision(20);
  }
}IO;

int32_t main(){
  int n; cin >> n;
  if (n & 1) cout << (n / 2) + 1 << endl;
  else cout << n / 2 << endl;
}

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

using namespace std;

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        String str1 = scanner.next();
        String str2 = scanner.next();
        int dp[][] = new int[str1.length()+1][str2.length()+1];
        for (int i = str1.length()-1; i >= 0; i--) {
            for (int j = str2.length()-1; j >=0; j--) {
                if (str1.charAt(i) == str2.charAt(j)) {
                    dp[i][j] = 1 + dp[i+1][j+1];
                    continue;
                }
                dp[i][j] = Math.max(dp[i+1][j], dp[i][j+1]);
            }
        }
        int i =0, j=0;
        String result = "";
        while (i < str1.length() && j < str2.length()) {
            if (str1.charAt(i) == str2.charAt(j)) {
                result = result + str1.charAt(i);
                i = i+1;
                j = j+1;
                continue;
            }
            if (dp[i+1][j] > dp[i][j+1]) {
                i = i+1;
            } else {
                j = j+1;
            }
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 100572
# coding: utf-8
# Your code here!
a, b = map(int,input().split())
g1 = [1,3,5,7,8,10,12]
g2 =  [4,6,9,11]
g3 = [2]

if a in g1 and b in g1:
    print('Yes')
elif a in g2 and b in g2:
    print('Yes')
elif a in g3 and b in g3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
n,d=map(int,input().split())
ps=[list(map(int,input().split())) for _ in range(n)]
cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        s=0
        for x1,x2 in zip(ps[i],ps[j]):
            s+=(x1-x2)**2
        s=s**0.5
        if s==int(s):
            cnt+=1
print(cnt)


Measured memory_bytes: 3060
H,W,N = map(int,input().split())
sr,sc = map(int,input().split())
S = input()
T = input()

L = 0
R = W+1
U = 0
D = H+1

for i in range(N-1,-1,-1):
    if S[i] == "L":
        L += 1
    elif S[i] == "R":
        R -= 1
    elif S[i] == "U":
        U += 1
    elif S[i] == "D":
        D -= 1
    if L+1==R or U+1==D:
        print("NO")
        break

    if i>0:
        if T[i-1] == "L":
            R = min(W+1,R+1)
        elif T[i-1] == "R":
            L = max(0,L-1)
        elif T[i-1] == "U":
            D = min(H+1,D+1)
        elif T[i-1] == "D":
            U = max(0,U-1)
else:
    if sr<=U or D<=sr or sc<=L or R<=sc:
        print("NO")
    else:
        print("YES")


Measured memory_bytes: 48080
import java.util.Scanner;

public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      
      while(sc.hasNext()) {
         double wgt = Double.parseDouble(sc.nextLine());
         
         String opt;
         
         if(wgt <= 48.00) {
            opt = "light fly";
         } else if (wgt <= 51.00) {
            opt = "fly";
         } else if (wgt <= 54.00) {
            opt = "bantam";
         } else if (wgt <= 57.00) {
            opt = "feather";
         } else if (wgt <= 60.00) {
            opt = "light";
         } else if (wgt <= 64.00) {
            opt = "light welter";
         } else if (wgt <= 69.00) {
            opt = "welter";
         } else if (wgt <= 75.00) {
            opt = "light middle";
         } else if (wgt <= 81.00) {
            opt = "middle";
         } else if (wgt <= 91.00) {
            opt = "light heavy";
         } else {
            opt = "heavy";
         }
         
         System.out.println(opt);
      }
   }
}



Measured memory_bytes: 26008
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
vector<pii> v[200005];
int ok;
vector<pll> dfs(int x,LL sum){
    if(v[x].empty())return vector<pll>{mp(0,0)};
    vector<pll> v1,v2;
    v1=dfs(v[x][0].x,sum);
    v2=dfs(v[x][1].x,sum);
    for(auto &it:v1){
        it.x+=v[x][0].y;
        it.y+=v[x][0].y;
    }
    for(auto &it:v2){
        it.x+=v[x][1].y;
        it.y+=v[x][1].y;
    }
    if(v1.size()>v2.size())swap(v1,v2);
    vector<pll> t1,t2;
    int now=v2.size();
    now--;
    for(auto& it:v1){
        while(now!=-1&&it.x+v2[now].x>sum)now--;
        if(now==-1)break;
        t1.pb(mp(it.y,v2[now].y));
        t2.pb(mp(v2[now].y,it.y));
    }
    reverse(t1.begin(),t1.end());
    vector<pll> ret;
    int i=0,j=0;
    while(i!=t1.size()||j!=t2.size()){
        if(i==t1.size()){
            if(ret.empty()||ret.back().y>t2[j].y){
                ret.pb(t2[j]);
            }
            j++;
        }
        else if(j==t2.size()){
            if(ret.empty()||ret.back().y>t1[i].y){
                ret.pb(t1[i]);
            }
            i++;
        }
        else if(t1[i]<t2[j]){
            if(ret.empty()||ret.back().y>t1[i].y){
                ret.pb(t1[i]);
            }
            i++;
        }
        else{
            if(ret.empty()||ret.back().y>t2[j].y){
                ret.pb(t2[j]);
            }
            j++;
        }
    }
    if(ret.empty())ok=0;
   /* if(sum==16){
        printf("%d\n",x);
        for(auto it:ret){
            printf("%d %d ",it.x,it.y);
        }
        printf("\n");
        for(auto it:t1)
        printf("%d %d ",it.x,it.y);
        printf("\n");
        for(auto it:t2)
        printf("%d %d ",it.x,it.y);
        printf("\n");
    }*/
    return ret;
}
int main(){
    int n;
    scanf("%d",&n);
    int allzero=1;
    for(int i = 2;i<=n;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        v[x].pb(mp(i,y));
        if(y!=0)allzero=0;
    }
    if(allzero){
        printf("0\n");
        return 0;
    }
    LL Max=1e18,Min=0;
    while(Max>Min+1){
        LL mid=(Max+Min)/2;
        ok=1;
        dfs(1,mid);
        if(ok){
            Max=mid;
        }
        else{
            Min=mid;
        }
    }
    printf("%lld\n",Max);
}
/*
1441152
*/

Measured memory_bytes: 24320
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
#define ALL(x) x.begin(), x.end()
#define fir first
#define sec second
using namespace std;

int main()
{
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    int t[n], g[n] = {};
    rep(i, n) cin >> t[i];
    ll ans = 1ll << 20;
    rep(i, (int)pow(4, n))
    {
        int p[3] = {0, 0, 0};
        ll now = 0;
        rep(j, n)
        {
            if (g[j] == 3)
                continue;
            int ind = g[j];
            if (p[ind] != 0)
                now += 10;
            p[ind] += t[j];
        }
        if (p[0] == 0)
            now = 1ll << 20;
        else
            now += abs(a - p[0]);
        if (p[1] == 0)
            now = 1ll << 20;
        else
            now += abs(b - p[1]);
        if (p[2] == 0)
            now = 1ll << 20;
        else
            now += abs(c - p[2]);
        ans = min(ans, now);
        //  cout << now << endl;
        g[n - 1]++;
        int ii = n - 1;
        while (g[ii] == 4)
        {
            g[ii] = 0;
            g[ii - 1]++;
            ii--;
        }
    }
    cout << ans << endl;

    return 0;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    int diff = b - a;
    int tall = 0;
    For(i, 1, diff - 1) tall += i;
    cout << tall - a << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())

using namespace std;

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;
const ll inf =1000000007;

void dsolve(){
    ll x;
    cin >> x;
    ll a,b;
    for(ll i=1;i<=2000;i++){
        for(ll j=-2000;j<2000;j++){
            ll score=pow(i,5)-pow(j,5);
            if(score==x){
                a=i;
                b=j;
                break;
            }
        }
    }
    cout << a <<" "<< b<< endl;
}

void bsolve(){
    ll n,k;
    cin >> n >>k;
    ll w[n];
    rep(i,n) w[i]=0;
    rep(i,k){
        ll d;
        cin>>d;
        rep(j,d){
            ll a;
            cin >>a;
            a--;
            w[a]++;
        }
    }
    ll ans=0;
    rep(i,n){
        if(w[i]==0){
            ans++;
            //kaku(i);
        }
    }
    kaku(ans);
}

void asolve(){
    string s;
    cin >>s;
    if(s=="ABC"){
        cout <<"ARC" << endl;
    }
    else{
        cout <<"ABC" << endl;
    }
}

void csolve(){
    ll n,m;
    cin >> n >>m;
    ll h[n];
    rep(i,n) cin >> h[i];
    vector<ll> g[n];
    Pair ma[n];
    rep(i,n) ma[i]=make(h[i],1);
    rep(i,m){
        ll a,b;
        cin >>a >>b;
        a--;b--;
        g[a].pb(b);
        g[b].pb(a);
        if(ma[a].first<h[b]) ma[a]=make(h[b],1);
        else if(ma[a].first==h[b]) ma[a]=make(h[b],0);
        if(ma[b].first<h[a]) ma[b]=make(h[a],1);
        else if(ma[b].first==h[a]) ma[b]=make(h[a],0);
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        if(ma[i].first==h[i]&& ma[i].second==1) ans++;
    }
    kaku(ans);
}
int main() {
   asolve();
}






Measured memory_bytes: 3724
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
int N, K;

void solve() {
    if (N%K == 0) {
        printf("%d\n", 0);
    } else{
        printf("%d\n", 1);
    }
}

int main() {
    cin >> N >> K;
    solve();
    return 0;
}


Measured memory_bytes: 256
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    N,T = i_map()
    t = i_list()

    ans = 0
    for i,k in enumerate(t[1:], start=1):
        if k - t[i-1] <= T:
            ans += k - t[i-1]
        else:
            ans += T
    ans += T
    print(ans)



if __name__=="__main__":
    main()


Measured memory_bytes: 31252
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for(int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

using namespace std;

int main() {
  int N, M, R;
  cin >> N >> M >> R;
  vector<int> r = vector<int>(R);
  REP(i, R) {
    cin >> r.at(i);
    r.at(i)--;
  }

  int d[N][N];  //隣接行列

  REP(i, N) REP(j, N) {
    if(i == j) {
      d[i][j] = 0;
    } else {
      d[i][j] = INF;
    }
  }

  REP(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    d[a][b] = c;
    d[b][a] = c;
  }

  REP(k, N) REP(i, N) REP(j, N) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

  sort(ALL(r));

  int ans = INF;
  do {
    int dist = 0;
    REP(i, R - 1) dist += d[r[i]][r[i + 1]];
    ans = min(ans, dist);
  } while(next_permutation(ALL(r)));

  cout << ans << endl;
}


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

int main() {
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  
  string t;
  cin >> t;
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  
  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;
using ll = long long;

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

  int n;
  ll x;
  cin >> n >> x;
  vector<int> a(n);
  for (auto &aa : a)
    cin >> aa;

  ll ans = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] + a[i - 1] <= x)
      continue;
    ll r = a[i] + a[i - 1] - x;
    ans += r;
    if (a[i] >= r) {
      a[i] -= r;
      continue;
    }
    a[i] = 0;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3696
#include <iostream>
#include <vector>
#include <utility>

using namespace std;
int main() {
    long long N, P, ans;
    cin >> N >> P;
    vector<pair<long long, int>> factors;
    long long factor = 2;
    while (P >= factor*factor) {
        int exp = 0;
        while (P % factor == 0) {
            P /= factor;
            exp++;
        }
        if (exp > 0) {
            factors.push_back(make_pair(factor, exp));
        }
        if (factor == 2) factor = 3;
        else factor += 2;
    }
    if (P > 1) factors.push_back(make_pair(P, 1));
    //for (auto fe : factors) cerr << fe.first << "**" << fe.second << endl;

    ans = 1;
    for (auto fe: factors) {
        long long f = fe.first;
        int e = fe.second;
        for (int i = 0; i < e/N; i++) {
            ans *= f;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
//import java.io.*;
//import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		//InputStreamReader is = new InputStreamReader(System.in);
		//BufferedReader br = new BufferedReader(is);
		//String text = scan.next();
		int sum = 0;
		for(int i = 0 ; i < 4 ; i++){
			sum += scan.nextInt();
		}
		System.out.println(sum/60);
		System.out.println(sum%60);
	}
}

Measured memory_bytes: 26216
import sys
input = sys.stdin.readline
N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0]
b = [0]
for i in range(N):
    a.append(a[i] + A[i])

for i in range(M):
    b.append(b[i] + B[i])

j = M
ans = 0

for i in range(N + 1):
    if a[i] > K:
        break

    while b[j] + a[i] > K:
        j -= 1
    
    ans = max(ans, i + j)

print(ans)

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

int main() {
        long long X, K, D;
        cin >> X >> K >> D;
        X = abs(X);
        long long a = floor(X/D);
        if(a<K) {
                X -= a*D;
                K -= a;
                if (K%2==1) {
                        X = min(abs(X-D), abs(X+D));
                }
        } else if (a==K) {
                X -=a*D;
        } else {
                X -= D*K;
        }
        cout << X << endl;
}

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

using namespace std;
int main() {
int n;
cin>>n;
int x=0,y=0,tp=0;
while(n--)
{
int t,nx,ny;
cin>>t>>nx>>ny;
int t1=t;
t=t-tp;
tp=t1;
int d=abs(nx-x)+abs(ny-y);
x=nx,y=ny;
if(d>t)
{
    cout<<"No";
    return 0;
}
if(d<t&&(t-d)%2==1)
{
    cout<<"No";
    return 0;
}
}
cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//
const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

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

    mint ans=0;
    rep(b,0,60){
        int zero=0;
        int one=0;
        ll mask=1LL << b;
        rep(i,0,n){
            if(mask & a[i]) one++;
            else zero++;
        }
        ans+=(mint)one*(mint)zero*((mint)mask);
    }
    cout<<ans<<endl;
}

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

int main(){
	int n;
	cin >> n;
	int* w = new int[n];
	int sum = 0;
	for(int i=0;i<n;i++){
		cin >> w[i];
		sum += w[i];
	}
	int left = w[0];
	int right = sum - left;
	int min_gap = INT_MAX;
	for(int t = 1; t<n;t++){
		int tmp = abs(left-right);
		if(tmp < min_gap) min_gap = tmp;
		left += w[t];
		right -= w[t];
	}
	cout << min_gap << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
void func(string &s1, string &s2){
    int n1 = s1.length();
    int n2 = s2.length();
    vector<vector<int>>dp(n1+1, vector<int>(n2+1, 0));
    vector<vector<pii>>par(n1+1, vector<pii>(n2+1, {0, 0}));
    vector<vector<int>>flag(n1+1, vector<int>(n2+1, 0));
    par[0][0]={-1, -1};
    for(int i = 1; i <= n1 ; i++){
        for(int j = 1 ; j<= n2; j++){
            if(s1[i-1]==s2[j-1]){
                dp[i][j] = max(dp[i-1][j-1]+1, max(dp[i-1][j], dp[i][j-1]));
                if(dp[i][j]==dp[i-1][j-1]+1){
                    par[i][j] = {i-1, j-1};
                    flag[i][j] = 1;
                }
                else if(dp[i][j]==dp[i-1][j]){
                    par[i][j] = {i-1, j};
                }
                else if(dp[i][j]==dp[i][j-1]){
                    par[i][j] = {i, j-1};
                }
            }
            else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
                if(dp[i][j]==dp[i-1][j]){
                    par[i][j] = {i-1, j};
                }
                else if(dp[i][j]==dp[i][j-1]){
                    par[i][j] = {i, j-1};
                }
            }
        }
    }
    string ans;
    int i = n1, j = n2;
    while(par[i][j].first!=-1 && par[i][j].second!=-1){
        if(flag[i][j]){
            ans.push_back(s1[i-1]);
        }
        int t = par[i][j].first;
        int r =par[i][j].second;
        i = t;
        j = r;
    }
    reverse(ans.begin(), ans.end());
    cout<<ans;
}

int main(){
    string s1;
    string s2;
    cin>>s1>>s2;
    func(s1, s2);
}

Measured memory_bytes: 141312
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	if(n<1200){printf("ABC\n");return 0;}
	if(n<2800){printf("ARC\n");return 0;}
	printf("AGC\n");
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp12
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var str = Console.ReadLine();
            int cnt = 0;
            int s = 0;


            while (true)
            {
                s = str.IndexOf("ABC",s);
                if (s == -1) break;
                s++;
                cnt++;
            }
            Console.WriteLine(cnt);
        }

        static void MainA(string[] args)
        {
            var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            Console.WriteLine(arr[0] * 500 >= arr[1] ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 11356
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define INF 1e9
#define MOD 1e9+7
typedef long long llong;
using namespace std;

int main(){
	int a[5];
	REP(i,5) cin>>a[i];
	int k;
	cin>>k;
	
	for(int i=0;i<4;++i){
		for(int j=i+1;j<5;++j){
			if(a[j]-a[i]>k){
				cout<<":("<<endl;
				return 0;
			}
		}
	}
	
	cout<<"Yay!"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int N, A, B, C;

int min_cost(int length, vector<int> l_set) {
    int sum = 0, cost = 0;
    for(int l: l_set) sum += l;
    cost += 10*(l_set.size() - 1);
    cost += abs(sum - length);
    return cost;
}

int cost_under_this_allocation(vector< vector<int> >& allocation) {
    int cost = 0;
    if(allocation[1].size() == 0 || allocation[2].size() == 0 || allocation[3].size() == 0) return 1e9;
    cost += min_cost(A, allocation[1]);
    cost += min_cost(B, allocation[2]);
    cost += min_cost(C, allocation[3]);
    return cost;
}

int dfs(int cur_index, vector<int>& l, vector< vector<int> >& allocation) {
    vector< vector<int> > best_allocation;
    if(cur_index == N) return cost_under_this_allocation(allocation);
    int cost = 1e9;
    for(int i=0; i<=3; i++) {
        allocation[i].push_back(l[cur_index]);
        int cost_tmp = dfs(cur_index+1, l, allocation);
        if(cost > cost_tmp) {
            cost = cost_tmp;
            best_allocation = allocation;
        }
        allocation[i].pop_back();
    }
    // if(cost == 21 && cur_index==N-1)
    //     REP(i, 4) {
    //         for(int l: best_allocation[i])
    //             cerr << l << " ";
    //         cerr << endl;
    //     }
    return cost;
}

int main() {

    cin >> N >> A >> B >> C;
    vector<int> l(N);
    REP(i, N) cin >> l[i];
    vector< vector<int> > allocation(4, vector<int>());

    int min_cost = dfs(0, l, allocation);
    cout << min_cost << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf ll(10e15)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll t;
    t=1;
    while(t--)
    {
        ll n,m;
        cin>>n>>m;
        n=n%m;
        cout<<min(n,abs(n-m))<<endl;
    }
    return 0;
}


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

using namespace std;

typedef long long int64;

int main()
{
  int N, XX[2000][4];

  cin >> N;
  vector< int > nums;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < 4; j++) {
      cin >> XX[i][j];
      nums.push_back(XX[i][j]);
    }
  }

  sort(begin(nums), end(nums));
  nums.erase(unique(begin(nums), end(nums)), end(nums));

  for(int i = 0; i < N; i++) {
    for(int j = 0; j < 4; j++) {
      XX[i][j] = lower_bound(begin(nums), end(nums), XX[i][j]) - begin(nums);
    }
  }


  vector< vector< int > > sum(nums.size(), vector< int >(nums.size(), 0));
  for(int i = 0; i < N; i++) {
    ++sum[XX[i][0]][XX[i][1]];
    --sum[XX[i][2]][XX[i][1]];
    --sum[XX[i][0]][XX[i][3]];
    ++sum[XX[i][2]][XX[i][3]];
  }

  for(int i = 1; i < nums.size(); i++) {
    for(int j = 0; j < nums.size(); j++) {
      sum[i][j] += sum[i - 1][j];
    }
  }
  for(int i = 0; i < nums.size(); i++) {
    for(int j = 1; j < nums.size(); j++) {
      sum[i][j] += sum[i][j - 1];
    }
  }

  int64 ret = 0;
  for(int i = 0; i + 1 < nums.size(); i++) {
    for(int j = 0; j + 1 < nums.size(); j++) {
      if(sum[i][j] > 0) {
        ret += 1LL * (nums[i + 1] - nums[i]) * (nums[j + 1] - nums[j]);
      }
    }
  }

  cout << ret << endl;
}

Measured memory_bytes: 253384
// respect cos's solution!!

#include<cstdio>
#include<vector>
#include<cstring>

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

using namespace std;

class union_find{
	vector<int> a;
public:
	union_find(int n):a(n,-1){}
	int find(int x){
		if(a[x]<0) return x;
		return a[x]=find(a[x]);
	}
	void unite(int x,int y){
		x=find(x),y=find(y);
		if(x!=y){ a[x]+=a[y]; a[y]=x; }
	}
	int size(int x){ return -a[find(x)]; }
};

// even : 頂点数が偶数である連結成分の個数
// odd  : 頂点数が奇数である連結成分の個数
// e : 連結成分の個数を変えずに追加できる辺数 mod 2
int dp[1001][1001][2];
int dfs(int even,int odd,int e){
	int &res=dp[even][odd][e];
	if(res!=-1) return res;

	if(even+odd==1) return res=1;

	if(e==1 && !dfs(even,odd,0)) return res=1;

	if(even>=2 && !dfs(even-1, odd ,e^1)) return res=1;
	if(odd >=2 && !dfs(even+1,odd-2, e )) return res=1;
	if(even>=1 && odd>=1 && !dfs(even-1,odd,e^1)) return res=1;

	return res=0;
}

int main(){
	int n; scanf("%d",&n);
	static char adj[1000][1001];
	rep(u,n) scanf("%s",adj[u]);

	union_find U(n);
	rep(u,n) rep(v,u) if(adj[u][v]=='Y') U.unite(u,v);

	int even=0,odd=0,cnt[1000];
	bool vis[1000]={};
	rep(u,n){
		int i=U.find(u);
		if(!vis[i]){
			vis[i]=true;
			if(U.size(u)%2==0) even++;
			else               odd++;
			cnt[i]=U.size(u)*(U.size(u)-1)/2;
		}
	}
	rep(u,n) rep(v,u) if(adj[u][v]=='Y') cnt[U.find(u)]--;

	int e=0;
	rep(i,n) if(vis[i] && cnt[i]%2==1) e^=1;

	memset(dp,-1,sizeof dp);
	puts(dfs(even,odd,e)?"Taro":"Hanako");

	return 0;
}

Measured memory_bytes: 9948
N = int(input())
K = len(str(N))
if K % 2 == 0:
  NN = 10**(K-1) - 1
else:
  NN = N
KK = len(str(NN))
if KK == 1:
  print(NN)
else:
  print(NN-int('90'*int((KK-1)/2)))

Measured memory_bytes: 3060
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
        PEOPLE'S LIVES DON'T END WHEN THEY DIE.
        IT ENDS WHEN THEY LOSE FAITH
                                     -ITACHI UCHIHA
        EXPLAINATION BELOW->
        SAME AS EDITORIAL
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
vector<int>adj1[100001];
int parent;
int dsu[100001];
map<ll,ll>Comp_size;
void dfs(int v)
{
    int i;
    dsu[v]=parent;
    Comp_size[parent]++;
    fo(i,0,sz(adj1[v]))
    {
        if(dsu[adj1[v][i]]==0)
        dfs(adj1[v][i]);
    }
}
void solve()
{
    ll n,m,k,v1,v2,i,j;cin>>n>>m>>k;
    fo(i,0,m)cin>>v1>>v2,adj1[v1].pb(v2),adj1[v2].pb(v1);
    
    foe(i,0,n)
    {
        if(dsu[i]==0)
        {
            parent=i;
            dfs(i);
        }
    }
    
    fo(i,0,k)cin>>v1>>v2,adj1[v1].pb(v2),adj1[v2].pb(v1);
    
    int ans;
    foe(i,1,n)
    {
        ans=Comp_size[dsu[i]]-1;
        fo(j,0,sz(adj1[i]))
        {
            if(dsu[i]==dsu[adj1[i][j]])ans--;
        }
        cout<<ans<<" ";
    }
    cout<<"\n";
    
}
int main()
{
   fastio
   solve();
  return 0;
}


Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
ofstream fo("output.out");
#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define out(a) { fo << #a << ":" << (a) <<" ";}
#define outv(a) { fo << "["; \
	for(int i = 0; i < (a).size(); ++i){ \
		fo << i <<":" << a[i] <<" "; \
		if(i % 10 == 9) fo <<"\n"; \
		} \
	fo << "]"; \
}
#define outvv(a) { fo << "["; \
	for(int i = 0; i < a.size(); ++i){ \
		for(int j = 0; j < a[i].size(); ++j){ \
			fo << "(" << i <<"," <<j <<")" <<":" << a[i][j] <<" "; \
		} \
		fo << "\n"; \
	} \
	fo << "]"; \
}
#define outp(a) { fo <<"[" << #a << ".fi:"<<a.first; \
					fo << " "<< #a << ".se:" << a.second <<"]"; }
using ll = long long;
const int mod = 1e9 + 7;
const int nax = 10123;
void add_self(int &a, int b){
	a += b;
	if(a > mod){
		a -= mod;
	}
}
int main()
{
	string s;
	cin >> s;
	int D;
	cin >> D;
	vector<vector<int>>dp(D, vector<int>(2, 0));
	dp[0][0] = 1;
	for(int where = 0; where < s.length(); ++where){
		vector<vector<int>> new_dp(D, vector<int>(2, 0));
		for(int sum = 0; sum < D; ++sum){
			for(bool sm_already: {false, true}){
				for(int digit = 0; digit < 10; ++digit){
					if(digit > s[where] - '0' && !sm_already){
						break;
					}
					add_self(new_dp[(sum + digit) % D][sm_already||digit < s[where] - '0'],
						dp[sum][sm_already]);
				}
			}
		}
		dp = new_dp;
	}
	int ans = 0 ;
	ans += (dp[0][false] + dp[0][true])%mod;
	ans--;
	if(ans == - 1){
		ans = mod - 1;
	}
	cout << ans;
}

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

int main(){
 int b,r,f,v,n,i;
 int house[5][4][11];
 cin >> n;

 for(int s = 0; s < 5; s++)
  for(int t = 0; t < 4; t++)
   for(int r = 0; r < 11; r++)
    house[s][t][r] = 0;

 for(i = 0; i < n; i++){
  cin >> b >> r >> f >> v;
  
  house[b][r][f] += v;
 }

 for(int s = 1; s <= 4; s++){
  for(int t = 1; t <= 3; t++){
   for(int r = 1; r <= 10; r++){
    cout << " " << house[s][t][r] ;
   }
   cout << "\n";
  }
  
  if(s != 4)
   cout << "####################\n" ;
 }

 return 0;
}
 
 

Measured memory_bytes: 1168
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

    # 2と5を因数としていくつ含むか
    cnt = collections.Counter()
    for _ in range(N):
        A = SS()
        cnt2 = 0
        cnt5 = 0
        if '.' in A:
            idx = A.index('.')
            cnt2 -= len(A) - 1 - idx
            cnt5 -= len(A) - 1 - idx
            A = int(A[:idx] + A[idx+1:])
        else:
            A = int(A)
        while A % 2 == 0:
            A //= 2
            cnt2 += 1
        while A % 5 == 0:
            A //= 5
            cnt5 += 1
        cnt[(cnt2, cnt5)] += 1

    ans = 0
    for c0, c1 in itertools.combinations_with_replacement(cnt.items(), 2):
        k0, v0 = c0
        k1, v1 = c1
        if k0[0] + k1[0] >= 0 and k0[1] + k1[1] >= 0:
            if k0 == k1:
                ans += v0 * (v0 - 1) // 2
            else:
                ans += v0 * v1

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9872
def cheese(a, b)
  return Math.sqrt(a * a + b * b) / 2
end

until (arr = gets.split.map(&:to_i)) == [0, 0, 0]
  tmp = cheese(*arr.sort.first(2))
  
  gets.to_i.times do
    puts tmp < gets.to_i ? "OK" : "NA"
  end
end

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

int main(){
    string st;
    cin >> st;
    int f = 0;
    rep(i, st.size()){
        if(i%2 == 0){
            if(st.at(i) == 'L') f = 1;
        }else{
            if(st.at(i) == 'R') f = 1;
        }
    }
    if(f == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
#define REP(i,a,b) for(in i=(in)(a);i<(in)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const in inf=1e9+7;
using P=pair<in,in>;
vector<in> dx={0,1,-1,0};
vector<in> dy={1,0,0,-1};

using T=tuple<in,in,in>;

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    in n;
  	string s;
    cin>>n>>s;
    vector<T> rgb(n);
    rgb[n-1]=T(0,0,0);
    for(in i=n-2;i>=0;i --){
        rgb[i]=rgb[i+1];
        if(s[i+1]=='R') get<0>(rgb[i]) ++;
        else if(s[i+1]=='G') get<1>(rgb[i]) ++;
        else get<2>(rgb[i]) ++;
    }
    in ans=0ll;
    rep(i,n){
        REP(j,i+1,n){
            in nok=2ll*j-i;
            if(s[i]==s[j]) continue;
            if(s[i]!='R'&&s[j]!='R'){
                ans +=get<0>(rgb[j]);
                if(nok<n && s[nok]=='R') ans --;
            }
            else if(s[i]!='G'&&s[j]!='G'){
                ans +=get<1>(rgb[j]);
                if(nok<n && s[nok]=='G') ans --;
            }
            else{
                ans +=get<2>(rgb[j]);
                if(nok<n && s[nok]=='B') ans --;
            }
        }
    }
    cout<<ans<<endl;
}
//./problem.exe


Measured memory_bytes: 3648
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll N,t,a,res=0,alp,T,A;
  cin >> N;
  REP(i,N){
    cin >> t >> a;
    if(res == 0){
      T = t;
      A = a;
      res = T + A;
    }else{
      if(res %(t+a) == 0){
        alp = max(max(T%t == 0 ? T/t : T/t + 1,A%a == 0 ? A/a : A/a+1),res/(t+a));
      }else
        alp = max(max(T%t == 0 ? T/t : T/t + 1,A%a == 0 ? A/a : A/a+1),res/(t+a));
      T = alp*t;
      A = alp*a;
      res = alp*(t+a);
    }
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


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

#define rep(i, n)     for(int i = 0;      i < int(n); ++i)
#define rep3(i, a, b) for(int i = int(a); i < int(b); ++i)
#define all(x)        (x).begin(),(x).end()
#define sz(x)         int(x.size())

typedef long long ll;

using namespace std;

int main(){
  const int TLE = 1001;
  int n, time;
  cin >> n >> time;
  
  int cost = TLE;
  rep(i, n){
    int c, t;
    cin >> c >> t;
    if(t <= time){
      if(c < cost){
        cost = c;
      }
    }
  }
  if(cost == TLE){
    cout << "TLE" << endl;
  }else{
    cout << cost << endl;
  }

  return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long[] ret = new long[2];
		for(int i=0;i<2;i++){
			ret[i] = check(1-2*i);
		}
		Console.WriteLine(ret.Min());
		
	}
	
	long check(int bw){
		long ret = 0;
		int[] sig = new int[N];
		sig[0] = bw;
		for(int i=1;i<N;i++) sig[i] = sig[i-1] * (-1);
		
		long[] tot = new long[N];
		for(int i=0;i<N;i++){
			tot[i] = A[i] + (i > 0 ? tot[i-1] : 0);
			if(sig[i] == 1){
				if(tot[i] > 0) continue;
				long diff = 1 - tot[i];
				ret += diff;
				tot[i] = 1;
			} else {
				if(tot[i] < 0) continue;
				long diff = tot[i] + 1;
				ret += diff;
				tot[i] = -1;
			}
		}
		return ret;
		
	}
	
	
	int N;
	long[] A;
	public Sol(){
		N = ri();
		A = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

int f(int x,int y,int a,int b){
	if( x >= 5 && y >= 2 ) return ( a * x + b * y ) * 8 / 10;
	return ( a * x + b * y );
}

int main(){
	int N;
	cin >> N;
	while(N--){
		int x,y,a,b;
		cin >> x >> y >> a >> b;
		int calc = 1e9;
		for(int i = a ; i < 10 ; i++){
			for(int j = b ; j < 10 ; j++){
				calc = min(calc,f(i,j,x,y));
			}
		}
		cout << calc << endl;
	}
}

Measured memory_bytes: 1160
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int K = sc.nextInt();
		int X = sc.nextInt();
		System.out.println(500 * K >= X ? "Yes" : "No");
	}
}

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

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 21716
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}
/********************************************************/
//	d.erase(unique(all(d)), d.end());



int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n;
		// n=s.length();
		ll a[n];
		unordered_map<ll,ll> mp;
		repe(i,2,n+1)
		{
			cin>>a[i];
			mp[a[i]]++;
		}
		rep(i,n)
		{
			cout<<mp[i+1];
			cout<<"\n";

		}

		
	}
	return 0;
}

Measured memory_bytes: 13064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  if (s == "ABC")
    cout << "ARC" << endl;
  else
    cout << "ABC" << endl;
  return 0;
}


Measured memory_bytes: 3596
using System;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine((solver()));
        }

        static int solver()
        {
            var NK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NK[0]; var K = NK[1];
            var S = Console.ReadLine();

            if (N == 1) return 0;

            var happiness = 0;
            if (S[0] == 'R' && S[1] == 'R') happiness++;
            if (S[N - 1] == 'L' && S[N - 2] == 'L') happiness++;
            for (int i = 1; i < N - 1; i++)
            {
                if (S[i] == 'L' && S[i - 1] == 'L') happiness++;
                if (S[i] == 'R' && S[i + 1] == 'R') happiness++;
            }
           return Math.Min(N - 1, happiness + 2 * K);
        }
    }
}


Measured memory_bytes: 11232
#include <cstdio>
#include<bitset>
#include<algorithm>
#include<iostream>
#include<string>
#define ll long long 
using namespace std;
long long n;
bitset<2000010> bs;
long long sum,temp;
int main()
{
	cin>>n;
	bs[0]=1;
	for(int i=1;i<=n;i++)
	{
		cin>>temp;
		sum+=temp;
		bs|=(bs<<temp);
	}
	sum=(sum+1)/2;
	for(long long i=sum;;i++)
	{
		if(bs[i]==1)
		{
			cout<<i;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 1024