akhauriyash/Code-Regression huggingface dataset:
#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 mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

#define MAX_N 1000

int n;
int a[44],b[44];
int c[44];
int ma,mb;
P p1[1111111],p2[1111111];

int main(){
	cin.sync_with_stdio(false);
	cin>>n>>ma>>mb;
	rep(i,n){
		cin>>a[i]>>b[i]>>c[i];
	}
	int n1=n/2,n2=n-n1;
	int res=INF;
	rep(S,1<<n1){
		rep(i,n1){
			if((S>>i)&1){
				p1[S].fi+=a[i]*mb-b[i]*ma;
				p1[S].se+=c[i];	
			}
		}
		if(S!=0&&p1[S].fi==0)minch(res,p1[S].se);
	}
	rep(S,1<<n2){
		rep(i,n2){
			if((S>>i)&1){
				p2[S].fi+=a[i+n1]*mb-b[i+n1]*ma;
				p2[S].se+=c[i+n1];
			}
		}
		if(S!=0&&p2[S].fi==0)minch(res,p2[S].se);
	}
	sort(p2,p2+(1<<n2));
	repl(S,1,1<<n1){
		P pp=p2[lower_bound(p2,p2+(1<<n2),P(-p1[S].fi,-INF))-p2];
		if(pp.fi+p1[S].fi==0)minch(res,p1[S].se+pp.se);
	}
	if(res==INF)cout<<-1<<endl;
	else cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 17152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
const int h_max = 1e4+10;
const int n_max = 1e3+10;
vector<ll> dp(h_max,LLONG_MAX);


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h,n;
  cin >> h  >> n;
  int a[n];
  ll b[n];
  rep(i,n){
    cin >> a[i] >> b[i];
  }
  dp[h] = 0;
  for(int he = h; he>=0; he--){
    if(dp[he]==LLONG_MAX) continue;
    rep(i,n){
      int nx = max(he - a[i],0);
      dp[nx] = min(dp[nx],dp[he]+b[i]);
    }    
  }
  cout << dp[0] << endl;
  
  return 0;
    

}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>

constexpr long long int MOD = 1000000007;
long long int power(long long int base, long long int exp) {
	switch (exp) {
	case 0: return 1;
	case 1: return base % MOD;
	default: return power(base, exp & 1) * power(base * base % MOD, exp >> 1) % MOD;
	}
}
int main() {
	int n; std::cin >> n;
	std::vector<long long int> costs(n); for (auto& c : costs) std::cin >> c;
	if (n == 1) {
		std::cout << costs.front() * 2 % MOD << std::endl;
		return 0;
	}
	std::sort(costs.begin(), costs.end());
	long long int result = 0;
	for (auto i = 0; i < n; ++i) {
		result += costs[i] * power(2, n - 2) % MOD * (n - i + 1) % MOD;
		result %= MOD;
	}
	std::cout << result * power(2, n) % MOD << std::endl;
}

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

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> num(n + 1, -1);
	bool flag = true;
	for(int i = 1; i <= m; ++i)
	{
		int ind, val;
		cin >> ind >> val;
		if(num[ind] == -1 || num[ind] == val)
			num[ind] = val;
		else
			flag = false;
	}
	if(flag == false)
	{
		cout << -1 << endl;
		return 0;
	}
	if(num[1] == 0 && n > 1)
	{
		cout << -1 << endl;
		return 0;
	}
	if(num[1] == -1 && n == 1)
	{
		cout << 0 << endl;
		return 0;
	}
	for(int i = 1; i <= n; ++i)
	{
		if(i == 1 && num[i] == -1)
			cout << 1;
		else if(num[i] == -1)
			cout << 0;
		else 
			cout << num[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

void Check(int x, int i){
    if (x % 10 == 3) cout << " " << i;
    else if ((x / 10)!= 0) Check(x / 10, i);
}

int main() {
    cout << setprecision(20) << fixed;
    int n;
    cin >> n;

    for (auto i = std::size_t(1); i < n + 1; ++i) {
        int x = i;
        if (x % 3 == 0) cout << " " << i;
        else Check(x, i);
    }
    cout << "\n";
    return 0;
}



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  cout << setprecision(10) << fixed << (N / 2 + (N % 2)) / (double)N << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define N 16
#define INT(X) \
  ( (const int *)(X) )

int comparator (
  const void  * a,
  const void  * b
  )
{
  int res;

  res = *INT( b ) - *INT( a );
  if ( res )  return ( res );
  res = INT( a )[ 1 ] - INT( b )[ 1 ];

  return ( res );
}

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i, j;

  for ( ; ; )
  {
    int d[ N ][ 4 ] = { { 0 } };
    int n;

    scanf ( " %d", &n );
    if ( !( n ) ) break ;

    for ( j = 0; j < n; ++j )
    {
      scanf ( " %c", &d[ j ][ 3 ] );
      for ( i = 0; i < n - 1; ++i )
      {
        int t;

        scanf ( " %d", &t );
        ++d[ j ][ t ];
      }
    }

    qsort ( d, n, sizeof ( int ) * 4, comparator );

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

  return ( 0 );
}

Measured memory_bytes: 0
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;


int main(int argc, const char * argv[]) {

    int r;
    cin >> r;
    
    cout << (int)pow(r, 2) << endl;

    return 0;
}


Measured memory_bytes: 256
import math

#n = int(input())
#a = int(input())
n,a,b = list(map(int,input().split(" ")))
#ls = list(input().split(" "))
#ls = list(map(int,input().split(" ")))
#a,b = list(input().split())
#string = input()
#ls = [int(input()) for i in range(n)]

ls = []
for i in range(1,n+1):
  tmp = str(i)
  num = 0
  for j in range(len(tmp)):
    num += int(tmp[j])
  if a <= num <= b:
    ls.append(i)
print(sum(ls))

Measured memory_bytes: 3292
#include <cstdio>
#include <algorithm>
#include <iostream>

using namespace std;
int main() {
    string S;
    int w;
    int i;
    cin >> S;
    cin >> w;

    for(i=0; w*i < S.length(); i++){
        printf("%c", S[i*w]);
    }
    if(i*w<S.length()) {
        printf("%c", i * w);
    }


}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

int gcd(int c,int d){
    return d ? gcd(d, c % d) : c;
}



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

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



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

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

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a), end(a)

int main(void) {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i += 2) {
        int n = i;
        int cnt = 0;
        REP(j, i) {
            int m = j + 1;
            if (n % m == 0) {
                cnt++;
            }
        }
        if (cnt == 8) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define endl "\n"
#define int long long
#define F first
#define S second
#define B begin
#define E end
#define RB rbegin
#define RE rend
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const ll P = 1e9 + 7;
const int Q = 47;
 
using namespace std;
 
void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
 
void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}


signed main()
{
    hello();
    
    int n;
    cin >> n;
    vector <int> seq(n), seq1;
    for (int i = 0; i < n; ++i)
        cin >> seq[i];
    sort(seq.B(), seq.E());
    seq.resize(unique(seq.B(), seq.E()) - seq.B());
    if (seq.size() == n)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

}

Measured memory_bytes: 1792
s=input()
l_s=list(s)
count=0
for i in range(len(s)-1):
    if l_s[i] == l_s[i+1]:
        if l_s[i+1] == '1':
            l_s[i+1] = '0'
        else:
            l_s[i+1] = '1'
        count+=1
print(count)

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    vector<int> A(a);
    for(int i = 0;i<a;i++){
        
    }
    if(b > 0)
        cout << ((b+1)+(b+a-1))*(a-1)/2 << endl;
    else if(abs(b) >= a)
        cout << ((b)+(b+a-2))*(a-1)/2 << endl;
    else
    {
        cout << (b + (b+a-1))*a/2 << endl;
    }
}

Measured memory_bytes: 256
a, b = map(int, input().split())
s = input()
for i in range(len(s)):
    if i == a:
        if s[i] != '-':
            print('No')
            exit()
        else:
            continue

    if not '0' <= s[i] <= '9':
        print('No')
        exit()
print('Yes')


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

using namespace std;

#define print(s) cout << (s) << endl;
#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n) 
#define all(a) (a).begin(), (a).end()
#define inf 10000000
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long ans, x, y; cin>>x>>y;
    if (x>0 && y<0){
        ans = abs(abs(x) - abs(y)) + 1;
    } else if (x<0 && y>0) {
        ans = abs(abs(x) - abs(y)) + 1;
    } else if (x<0 && y<0 && x>y) {
        ans = abs(abs(x) - abs(y)) + 2;    
    } else if (x>0 && y>0 && x>y) {
        ans = abs(abs(x) - abs(y)) + 2;
    } else if (x==0 && y<0){
        ans = abs(abs(x) - abs(y)) + 1;
    } else if (x>0 && y==0){
        ans = abs(abs(x) - abs(y)) + 1;
    } else {
        ans = abs(abs(x) - abs(y));        
    }
    cout<<ans<<endl;
return 0;
}

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
#define VL vector<lol>
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    lol result{0};
    lol n, r; cin >> n >> r;
    if(n < 10)
    {
        result = r + 100*(10-n);
    }
    else
    {
        result = r;
    }
    
    

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

int road[17][17];
int ans;
int a, b;
void rec(int i, int j);

int main(void)
{
	int m;
	int i, j;
	int x, y;
	
	scanf("%d %d", &a, &b); 
	
	while (a != 0 && b != 0){
		
		for (i = 0; i < 17; i++){
			for (j = 0; j < 17; j++){
				road[i][j] = 0;
			}
		}
		
		road[a][b] = -1;
		scanf("%d", &m);
		
		for (i = 0; i < m; i++){
			scanf("%d %d", &x, &y);
			road[x][y] = 1;
		}
		
		ans = 0;
		rec(1, 1);
		
		printf("%d\n", ans);
		scanf("%d %d", &a, &b); 
		
	}
	
	return (0);
}

void rec(int i, int j)
{
	//("i=%d j=%d a=%d b=%d\n");
	
	if (road[i][j] == 1 || i > a || j > b){
		return;
	}
	
	else if (road[i][j] == -1){
		ans++;
		return;
	}
	
	else {
		rec(i + 1, j);
		rec(i, j + 1);
	}
	
}

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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

pair<ll, ll> f(ll n)
{
    for(int i = sqrt(n); i >= 2; i--)
    {
        if(n % i == 0)
            return mp(i, n / i);
    }

    return mp(1, n);
}

int main()
{
    ll n;
    cin >> n;

    cout << f(n).fst + f(n).snd - 2;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct node{
	int x,y;
};
node a[101],b[101];
int dist(int x1,int y1,int x2,int y2){
	return abs(x1-x2)+abs(y1-y2);
}
int main(){
	int n,m,i,j,id=1;
	cin>>n>>m;
	for(i=1;i<=n;i++){
		cin>>a[i].x>>a[i].y;
	} 
	for(j=1;j<=m;j++){
		cin>>b[j].x>>b[j].y;
	} 
	int now_dist,min_dist;
	for(i=1;i<=n;i++){
		min_dist=dist(a[i].x,a[i].y,b[1].x,b[1].y);
//		cout<<i<<" "<<min_dist<<" ";
		id=1;
		for(j=2;j<=m;j++){
			now_dist=dist(a[i].x,a[i].y,b[j].x,b[j].y);
			//cout<<now_dist<<endl; 
			if(now_dist<min_dist){
				min_dist=now_dist;
				id=j;
			}
		}
		
		cout<<id<<endl;
	}
	return 0;
} 

/*
2 2
2 0
0 0
-1 0
1 0
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const double pi=acos(-1);

int main(){
  int n;
  cin >> n;
  vector<int>vec(n);
  rep(i,n) cin >> vec[i];
  rep(i,n-1) cout << vec[n-1-i] << " ";
  cout << vec[0];
  cout << endl;
  return 0;

      
}



Measured memory_bytes: 3096
L = []
for i in range(1, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            L.append(i * 10000 + j * 1000 + k * 100 + j * 10 + i)
a, b = map(int, input().split())
# print(sum(i in L for i in range(a, b + 1)))
print(sum(a <= e <= b for e in L))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long

void test_case()
{
    long n;
    cin>>n;
    long a[n],b[n],c[n],i,j,k;
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    vector<vector<long>> dp(n,vector<long>(3,INT_MIN));
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    long m;
    for(i=1;i<n;i++)
    {
        for(j=0;j<3;j++)
        {
            if(j==0)
            {
                dp[i][j]=a[i]+max(dp[i-1][1],dp[i-1][2]);
            }
            else if(j==1)
            {
                dp[i][j]=b[i]+max(dp[i-1][0],dp[i-1][2]);
            }
            else if(j==2)
            {
                dp[i][j]=c[i]+max(dp[i-1][0],dp[i-1][1]);
            }
        }

    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}


Measured memory_bytes: 8064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
int N,N1;
cin>>N;
int X;
X=N/1.08;
if(floor(X*1.08)==N){
  cout<<X/1<<"\n";
}
else if(floor((X-1)*1.08)==N){
  cout<<(X-1)<<"\n";
}
else if(floor((X+1)*1.08)==N){
  cout<<(X+1)<<"\n";
}
else{
  cout<<":("<<"\n";
}
return 0;
}

Measured memory_bytes: 256
// http://algorithms.blog55.fc2.com/blog-entry-66.html
#define M 100
int R[M+1],C[M][M],B[M][M];
D(i,j){
	if(i==j)printf("M%d",i);
	else printf("("),D(i,B[i][j]-1),D(B[i][j],j),printf(")");
}
main(N,i,j,k,c){
	scanf("%d",&N);
	for(i=0;i<N;i++)scanf("%d%d",R+i,&c);
	R[i]=c;
	memset(C,99,sizeof(C));
	for(i=0;i<N;i++)C[i][i]=0;
	for(j=1;j<N;j++)for(i=0;i<N-j;i++)for(k=i;k<i+j;k++)
		if((c=C[i][k]+C[k+1][i+j]+R[i]*R[k+1]*R[i+j+1])<C[i][i+j])C[i][i+j]=c,B[i][i+j]=k;
	printf("%d\n",C[0][N-1]);
	//order(0,N);
	//puts("");
	exit(0);
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

int n; vector<int> g[150010];
double dp[150010],ans[150010];
void dfs1(int v,int pre){
    dp[v]=0; int cnt=0;
    for(int to:g[v])if(to!=pre){
        dfs1(to,v); 
        dp[v]+=dp[to]+1; cnt++;
    } if(cnt)dp[v]/=cnt;
}
void dfs2(int v,int pre,double add){
    double sum=0;
    for(int to:g[v]){
        if(to==pre)sum+=add+1;
        else sum+=dp[to]+1;
    } ans[v]=sum/g[v].size();
    for(int to:g[v])if(to!=pre){
        dfs2(to,v,(double)((sum-dp[to]-1)/max(1,(int)g[v].size()-1)));
    }
}

int main(){
    scanf("%d",&n);
    rep(i,0,n-1){
        int a,b; scanf("%d%d",&a,&b); a--; b--;
        g[a].push_back(b); g[b].push_back(a);
    }
    dfs1(0,-1); dfs2(0,-1,1);
    rep(i,0,n)printf("%.12f\n",ans[i]);
    return 0;
}

Measured memory_bytes: 18816
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

map<char,int> mp;
map<char,char> rmp;
int n,k;
string s;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  cin >> n >> k;
  cin >> mp['r'] >> mp['s'] >> mp['p'];
  rmp['r']='p';
  rmp['s']='r';
  rmp['p']='s';
  cin>>s;
  int ans = 0;
  for(int i=0;i<n;i++){
    if(i<k){
      ans+=mp[rmp[s[i]]];
    }
    else if(s[i]!=s[i-k]){
      ans+=mp[rmp[s[i]]];
    }
    else s[i]='.';
  }    
  cout<<ans<<endl;

return 0;
}
///....


Measured memory_bytes: 512
// https://atcoder.jp/contests/abc179/tasks/abc179_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
template <typename T>
using VV = V<V<T>>;
using VVL = VV<ll>;
template <typename T>
using VVV = VV<V<T>>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
using asc_pq = priority_queue<T, V<T>, greater<T>>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  string S;
  cin >> S;

  if (S.back() == 's') {
    S += "es";
  } else {
    S += "s";
  }

  cout << S << "\n";
}


Measured memory_bytes: 3604
int L,R,d;
int f(int n)
{
  int cnt=0;
  for(int i=1;i<=n;i++)if(i%d==0)cnt++;
  return cnt;
}
main()
{
  scanf("%d%d%d",&L,&R,&d);
  printf("%d\n",f(R)-f(L-1));
}

Measured memory_bytes: 1708
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++){
    cout<<"node "<<i+1<<": key = "<<a[i]<<", ";
    if(i) cout<<"parent key = "<<a[(i-1)/2]<<", ";
    if(i*2+1<n) cout<<"left key = "<<a[i*2+1]<<", ";
    if(i*2+2<n) cout<<"right key = "<<a[i*2+2]<<", ";
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3088
MOD = 10 **9 + 7
INF = 10 ** 10

def main():
    n,m,l = map(int,input().split())
    dist = [[INF] * n for _ in range(n)]  
    for _ in range(m):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        dist[a][b] = c
        dist[b][a] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j])

    cnt = [[INF] * n for _ in range(n)]   
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                cnt[i][j] = 1

    for k in range(n):
        for i in range(n):
            for j in range(n):
                cnt[i][j] = min(cnt[i][j],cnt[i][k] + cnt[k][j])
    
    q = int(input())
    for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        print(cnt[s][t] - 1 if cnt[s][t] != INF  else -1)       
if __name__ == '__main__':
    main()

Measured memory_bytes: 59864
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
  string S;
  cin >> S;
  bool judge = true;

  if(S[0]!='A') judge = false;

  int l = S.size();
  int cnt = 0;
  for(int i=2;i<l-1;i++){
    if(S[i]=='C') cnt++;
  }

  if(cnt!=1) judge = false;

  for(int i=1;i<l;i++){
    if(S[i]!='C' && isupper(S[i])) judge = false;
  }

  if(judge) cout << "AC" <<endl;
  else cout << "WA" <<endl;


  return 0;
}

Measured memory_bytes: 256
N = int(input())
ans = [0]*((10**4)+1)

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            num = x * x + y * y + z * z + x * y + y * z + z * x
            if num <= N:
                ans[num] = ans[num] + 1

for i in range(N):
    print(ans[i+1])


Measured memory_bytes: 9272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool memo[51][2];
ll ma;
pair<bool, ll> f(int p, ll s) {
	if (p < 0) return {true, s};
	if (memo[p][1]) {
		auto ss = s | (1LL<<p);
		if (ss <= ma) {
			auto r = f(p-1, ss);
			if (r.first) return r;
		}
	}
	if (memo[p][0]) {
		return f(p-1, s);
	}
	return {false, 0};
}
int main() {
	int N;
	cin >> N;
	vector<ll> A(N);
	for (auto& x : A) cin >> x;
	ll s = 0;
	for (int i = 2; i < N; ++ i) s ^= A[i];
	ll t = A[0] + A[1];
	if (t-s < 0 || (t - s) % 2) {
		cout << -1 << endl;
		return 0;
	}
	ll u = (t-s) / 2;
	for (int i = 50; i >= 0; -- i) {
		int si = (s>>i)&1;
		int ui = (u>>i)&1;
		if ((si^1) == ui) {
			memo[i][1] = true;
		}
		if (0 == ui) {
			memo[i][0] = true;
		}
	}
	ma = A[0];
	auto r = f(50, 0);
	if (!r.first || r.second == 0) {
		cout << -1 << endl;
		return 0;
	}
	auto rr = A[0] - r.second;
	cout << rr << endl;
}


Measured memory_bytes: 3612
def main():
    n = int(input())
    mod = 0
    pow10 = 1
    for i in range(20*n):
        mod = (mod+7*pow10) % n
        if mod == 0:
            print(i+1)
            return
        pow10 = pow10*10 % n
    print(-1)


main()


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


int main(){
  
  map<char, int> S;
  for(int i = 0; i < 3; i++){
    char s;
    cin >> s;
    S[s]++;
  }
  
  if(S['a'] == 1 && S['b'] == 1 && S['c'] == 1){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3576
#include <algorithm>
#include <cassert>
#include <iostream>
#include <memory>
#include <numeric>

#include <array>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <ostream>
#include <type_traits>
#include <utility>
#include <chrono>
#include <random>

#ifdef ONLINE_JUDGE
#pragma GCC optimize ("O2")
#pragma GCC target ("avx,avx2")
#endif

using namespace std;

using u64 = uint64_t;
using i64 = int64_t;
using u32 = uint32_t;
using vi = vector<int>;
using vi64 = vector<i64>;

#define seq(i,a,b) for (int i = (a); i < (b); ++i)
#define rev(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define dbg(x) {cerr << #x << ": " << x << endl;}

struct timeit {
    decltype(chrono::high_resolution_clock::now()) begin;
    string label;
    timeit(string label = "") : label(label) {
        begin = chrono::high_resolution_clock::now();
    }
    ~timeit() {
        auto end = chrono::high_resolution_clock::now();
        auto duration = chrono::duration_cast<chrono::milliseconds>(end-begin).count();
        cerr << duration << "ms elapsed [" << label << "]" << endl;
    }
};

int main(int argc, char *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    auto start = chrono::high_resolution_clock::now();

    i64 n; cin >> n;
    i64 ga,sa,ba; cin >> ga >> sa >> ba;
    i64 gb,sb,bb; cin >> gb >> sb >> bb;



    auto f = [&](i64 cur) {
        i64 newval = cur;
        if ((double)(gb-ga)/ga < (double)(sb-sa)/sa) {
            swap(ga,sa);
            swap(gb,sb);
        }
        if ((double)(gb-ga)/ga < (double)(bb-ba)/ba) {
            swap(ga,ba);
            swap(gb,bb);
        }
        if ((double)(sb-sa)/sa < (double)(bb-ba)/ba) {
            swap(ba,sa);
            swap(bb,sb);
        }
        //cerr << ga <<" "<< sa <<" "<< ba << endl; 
        //cerr << gb <<" "<< sb <<" "<< bb << endl; 
        if (sb-sa <= 0 and gb-ga <= 0 and bb-ba <= 0) return newval;
        int lim = n/ga + 1;
        rev(i,0,lim) {
            auto end = chrono::high_resolution_clock::now();
            auto dur = chrono::duration_cast<chrono::milliseconds>(end-start).count();

            if (dur > 1500) break;

            seq(j,0,(n-i*ga)/sa + 1) {
                for (int k : {0L, (n - i*ga - j*sa)/ba}) {
                    i64 tmp = cur + i*(gb - ga) + j*(sb - sa) + k*(bb - ba);
                    newval = max(tmp, newval);
                    //cerr << tmp << " " << newval*0.95 << endl;
                }
            }
        }
        return newval;
    };

    n = f(n);
    swap(ga,gb);
    swap(sa,sb);
    swap(ba,bb);
    n = f(n);

    cout << n << endl;
}


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

int main()
{
	int n, m, c; cin >> n >> m >> c;

	vector<int> b(m); for (int i = 0; i < m; i++) cin >> b[i];

	vector<vector<int>> a(n, vector<int>(m));
	
	int ans = 0;
	for (int i = 0; i < n; i++) {

		int tmp = c;

		for (int j = 0; j < m; j++) {
		
			cin >> a[i][j];
			tmp += a[i][j] * b[j];

		}

		if (0 < tmp) ans++;

	}

	cout << ans << endl;

	return 0;
}

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

int main() {
  int A, B, ans;
  cin >> A >> B;
  if (A > 9){
    ans = -1;
  }
  else if (B > 9){
    ans = -1;
  }
  else {
    ans = A * B;
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 256
//
//  Created by TaoSama on 2016-09-24
//  Copyright (c) 2016 TaoSama. All rights reserved.
//
#pragma comment(linker, "/STACK:102400000,102400000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;



int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);


    string s;
    cin >> s;
    s.insert(4, 1, ' ');
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 10000005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll st[N];
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;
	ll an=0;
	for(i=1;i<=n;i++){
		for(j=i;j<=n;j+=i){
			st[j]+=1;
		}
	}

	for(i=1;i<=n;i++){
		// cout<<i<<" "<<st[i]<<endl;
		an+=(i*st[i]);
	}
	cout<<an<<endl;

	return 0;	
}

Measured memory_bytes: 81776
// I look at my watch
// it say nine twenty-five
// And I think oh God
// I'm still alive
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) int((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(int i = int(a); i < int(b); ++i)
#define roF(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;
typedef long double ld;




int main(){	
	int n,k,c;cin>>n>>k>>c;
	string s;cin>>s;
	set<int>set1,set2;
	int prev=-10000000;
	for(int i=0;i<n;){
		while(i<n&&(s[i]=='x'||i-prev<=c))i++;
		if(i>=n)break;
		prev=i;
		set1.insert(i);
		i++;
	}
	prev=-10000000;
	reverse(all(s));
	for(int i=0;i<n;){
		while(i<n&&(s[i]=='x'||i-prev<=c))i++;
		if(i>=n)break;
		prev=i;
		set2.insert(n-1-i);
		i++;
	}
	if(sz(set1)>k)return 0;
	For(i,0,n)if(set1.count(i)&&set2.count(i)){
		cout<<i+1<<endl;
	}


	return 0;
}


Measured memory_bytes: 20484
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int a, b;
    cin >> a >> b;
    
    int index, h2;
    index = b - a;
    for(int i=1;i<=index;i++)
        h2 += i;
    
    cout << h2 - b << endl;    

}

Measured memory_bytes: 256
#include<stdio.h>
#define N 25
typedef struct{
  int p;
  int l;
  int r;
}Node;
   
void preorder(int);
void inorder(int);
void postorder(int);
   
Node T[N];
int main(){
  int num, i, j, id, le, ri;
  scanf("%d\n",&num);
  for(i = 0 ; i < num ; i++){
    T[i].p =T[i].l =T[i].r =-1;
  }
  for(i = 0 ; i < num ; i++){
    scanf("%d%d%d", &id, &le, &ri);
    T[id].l = le;
    T[le].p = id;
    T[id].r = ri;
    T[ri].p = id;
  }
  printf("Preorder\n");
  for(i = 0 ; i < num ; i++){
    if(T[i].p == -1){
      preorder(i);
    }
  }
  printf("\n");
  printf("Inorder\n");
  for(i = 0 ; i < num ; i++){
    if(T[i].p == -1){
      inorder(i);
    }
  }
  printf("\n");
  printf("Postorder\n");
  for(i = 0 ; i < num ; i++){
    if(T[i].p == -1){
      postorder(i);
    }
  }
  printf("\n");
  return 0;
}
   
void preorder(int u)
{
  if(u == -1) return;
  printf(" %d", u);
  preorder(T[u].l);
  preorder(T[u].r);
}
void inorder(int u)
{
  if(u == -1) return;
  inorder(T[u].l);
  printf(" %d", u);
  inorder(T[u].r);
}
   
void postorder(int u)
{
  if(u == -1) return;
  postorder(T[u].l);
  postorder(T[u].r);
  printf(" %d", u);
}


Measured memory_bytes: 2060
#include <cstdio>
#include <cstdlib>
#include <cstring>
//手动搭建 列表 ！
//定义结构体（在C++中，不需要typedef直接就行？？）
struct Node {
	int key;
	Node *next,*prev;
};
//创建头结点，方便在表头插入，头结点是起始标记，不存储输入的有效数据，但很有用
Node *nil;
//init()是头结点的初始化，直接写在main里也行，包装起来更简洁
void init()
{
	nil=(Node *)malloc( sizeof(Node) );
	nil->next=nil;
	nil->prev=nil;
}
//
Node* listSearch(int key)
{
	Node *cur=nil->next;
	while( cur!=nil && cur->key!=key)
	{
		cur=cur->next;
	}
	return cur;
}

void printList()
{
	Node *cur=nil->next;
	int isf=0;
	while(1)
	{
		if(cur==nil) { free(nil); break;}
		if(isf++>0) printf(" ");
		printf("%d",cur->key);
		cur=cur->next;
		free(cur->prev);
	}
	printf("\n");
}

void deleteNode(Node* t)
{
	if(t==nil) return;
	t->next->prev=t->prev;
	t->prev->next=t->next;
	free(t);
}

void deleteFirst()
{
	deleteNode(nil->next);
}

void deleteLast()
{
	deleteNode(nil->prev);
}

void deleteKey(int key)
{
	deleteNode( listSearch(key) );
}

void insertNode(int key)
{
	Node* x=(Node *)malloc(sizeof(Node));
	x->key=key;
	x->next=nil->next;
	x->prev=nil;
	nil->next->prev=x;
	nil->next=x;
}
//手动搭建 列表 ！

int main()
{
	int key,n,i;
	int size=0;
	char com[20];
	int np=0,nd=0;
	scanf("%d",&n);
	init();
	for(i=0;i<n;i++)
	{
		scanf("%s%d",com,&key);
		if(com[0]=='i') { insertNode(key);np++;size++; }
		else if( com[0]=='d' )
		{
			if(strlen(com)>6)
			{
				if(com[6]=='F') deleteFirst();
				else if( com[6]=='L' ) deleteLast();
			}
			else
			{
				deleteKey(key);
				nd++;
			}
			size--;
		}
	}
	printList();
	return 0;
}


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

typedef long long ll;
ll n, ans;
vector<ll> a, b;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	a.resize(n);
	b.resize(n);
	for(int i=0; i<n; ++i) cin >> a[i];
	for(int i=0; i<n; ++i) cin >> b[i];
	for(int i=0; i<29; ++i){
		ll t = 1 << i;
		vector<ll> c(b);
		for(int j=0; j<n; ++j) c[j] %= 2*t;
		sort(c.begin(), c.end());
//		cout << "t " << t << "\n";
//		for(int j=0; j<n; ++j) cout << c[j] << (j==n-1?"\n":" ");
		bool f = false;
		for(int j=0; j<n; ++j)
			f ^= (lower_bound(c.begin(), c.end(), 2*t-a[j]%(2*t)) - lower_bound(c.begin(), c.end(), t-a[j]%(2*t)) + lower_bound(c.begin(), c.end(), 4*t-a[j]%(2*t)) - lower_bound(c.begin(), c.end(), 3*t-a[j]%(2*t))) % 2;
		if(f) ans += t;
//		cout << "ans " << ans << "\n";
	}
	cout << ans << "\n";
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll X[15], Y[15], P[15], ans[16];
vector <int> non;
vector <ll> x, y;

int Solve(int turn){
  int cnt = 0;
  non.clear();
  x.clear(); y.clear();

  for (int i = 0; i < N; i++){
    int now = turn % 3; turn /= 3;
    if (now == 0) non.push_back(i);
    else{
      cnt++;
      if (now == 1) x.push_back(X[i]);
      else y.push_back(Y[i]);
    }
  }
  ll res = 0;
  for (int i = 0; i < non.size(); i++){
    int Index = non[i];
    ll Dist = min(abs(X[Index]), abs(Y[Index]));

    for (int j = 0; j < x.size(); j++){
      Dist = min(Dist, abs(X[Index] - x[j]));
    }
    for (int j = 0; j < y.size(); j++){
      Dist = min(Dist, abs(Y[Index] - y[j]));
    }
    res += P[Index] * Dist; 
  }
  ans[cnt] = min(ans[cnt], res);
  return 0;
}

int main(){
  cin >> N;
  fill(ans, ans + N + 1, 1e16);
  ll pow3 = 1;
  for (int i = 0; i < N; i++) {
    pow3 *= 3;
    cin >> X[i] >> Y[i] >> P[i];
  }
  for (int i = 0; i < pow3; i++) Solve(i);
  for (int i = 0; i <= N; i++) cout << ans[i] << endl;
  
  return 0;
}


Measured memory_bytes: 3620
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using Enu = System.Linq.Enumerable;
using System.Numerics;

public class Program
{
    static readonly long Atmost = (long)1e18;

    public void Solve()
    {
        int N = Reader.Int();
        var Ratio = Reader.IntTable(N);
        BigInteger a = Ratio[0][0];
        BigInteger b = Ratio[0][1];

        for (int i = 1; i < N; i++)
        {
            long ra = Ratio[i][0], rb = Ratio[i][1];
            BigInteger na = (a + ra - 1) / ra * ra;
            BigInteger nb = (b + rb - 1) / rb * rb;
            if (na / ra * rb < nb) na = nb / rb * ra;
            if (nb / rb * ra < na) nb = na / ra * rb;
            a = na; b = nb;
        }

        Console.WriteLine(a + b);
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    static string[] Split(string s) { return s.Split(separator, op); }
    static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

Measured memory_bytes: 3672
#include <iostream>

using namespace std;

int main()
{
  string S;
  cin>>S;
  if(S.length()==4){
    if(S[0]==S[1]&&S[1]==S[2]&&S[2]==S[3]){
       cout<<"No";
    }
    
    else if((S[0]==S[1]||S[0]==S[2]||S[0]==S[3]) && (S[1]==S[0]||S[1]==S[2]||S[1]==S[3]) && (S[2]==S[0]||S[2]==S[1]||S[2]==S[3]) && (S[3]==S[0]||S[3]==S[1]||S[3]==S[2])){
     cout<<"Yes";
    }
    else{
        cout<<"No";
    }
  }
    
    return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int>v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    int count = 0;
    for(int i = 0 ; i < n; i++){
        int a = v[i];
        for(int j = i+1; j < n; j++){
            int b = v[j];
            int k = j+1;
            while(a+b>v[k] && k < n){
                count++;
                k++;
            }
        }
    }
    cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
using ll=long long;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  ll N; cin >> N;
  vector<ll> A(N);
  rep(i,N){
    cin >> A[i];
  }
  ll ans=1ll;
  int C[3]={0,0,0};
  rep(i,N){
    int cnt=0,id=-1;
    if(A[i]==C[0]) {cnt++; id=0;}
    if(A[i]==C[1]) {cnt++; id=1;}
    if(A[i]==C[2]) {cnt++; id=2;}
    if(id==-1) {cout << 0 << endl; break;}
    C[id]++;
    ans=ans*cnt%MOD;
    if(i==N-1) {cout << ans << endl;}
  }
  
}

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

using namespace std;

const int MAX = 222;
int N, M, R;
int r[MAX];
int G[MAX][MAX];

int main() {
    cin >> N >> M >> R;
    for (int i = 0; i < R; i++) {
        cin >> r[i];
        r[i]--;
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            G[i][j] = 1e9;
        }
    }
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;b--;
        G[a][b] = G[b][a] = c;
    }
    assert(R <= 8);

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }
    int ans = 1e9;
    vector<int> vec(R);
    iota(vec.begin(), vec.end(), 0);
    do {
        int now = -1;
        int buf = 0;
        for (int e : vec) {
            if (now != -1)  {
                buf += G[r[now]][r[e]];
            }
            now = e;
        }
        ans = min(ans, buf);
    } while (next_permutation(vec.begin(), vec.end()));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
import numpy as np
n = int(input())
ab = np.zeros((n, 2))
for i in range(n):
    l = list(map(int, input().split()))
    ab[i, :] = l
ab = ab[np.argsort(ab[:, 1])]
a_cum = np.cumsum(ab[:, 0])
for i in range(n):
    if a_cum[i] > ab[i, 1]:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 20300
#include<cstdio>
int main() {
	char s[4];
	scanf("%s",s+1);
	if(s[1]==s[2]||s[2]==s[3]||s[1]==s[3]) {
		puts("No");
		return 0;
	}
	else
		puts("Yes");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
ll nc2(ll x){
  return x*(x-1)/2;
}
int main()	{
  int n;
  cin>>n;
  vector<int>a(n),d(n);
  rep(i,n){
    cin>>a[i];
    a[i]--;
  }
  rep(i,n)
    d[a[i]]++;
  ll sum=0;
  rep(i,n)
    sum+=nc2(d[i]);
  rep(i,n){
    ll ans=sum;
    ans-=nc2(d[a[i]]);
    ans+=nc2(d[a[i]]-1);
    cout<<ans<<endl;
  }
}

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

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

typedef vector<string> S;

//3*3ツづ個配ツ療アツづーツ篠楪計ツ嘉アツづィ90ツ度ツ嘉アツ転
S rot90(S s){
	S res = s;
	rep(i,3) rep(j,3) res[j][2-i] = s[i][j];
	return res;
}
S rot180(S s){return rot90(rot90(s));}
S rot270(S s){return rot90(rot180(s));}

class Dice{
public:
	vector<string> t,b,w,e,n,s;

	Dice(S _t,S _b,S _w,S _e,S _n,S _s){
		t = _t;
		b = _b;
		w = _w;
		e = _e;
		n = _n;
		s = _s;
	}

	Dice move(int d){
		if(d == 0)
			return Dice(s,rot180(n),rot90(w),rot270(e),rot180(t),b);
		else
			return Dice(rot270(w),rot270(e),rot270(b),rot270(t),rot90(n),rot270(s));
	}

	bool isAns(void){
		return
			(s[2][0]=='*' || s[2][1]=='*' || s[2][2]=='*') &&
			(n[2][0]=='*' || n[2][1]=='*' || n[2][2]=='*');
	}
};

int solve(Dice d){
	typedef pair<Dice,int> P;
	queue<P> open;
	open.push(P(d,0));

	while(!open.empty()){
		P p = open.front(); open.pop();

		if(p.first.isAns()){
			return p.second;
		}

		open.push(P(p.first.move(0),p.second+1));
		open.push(P(p.first.move(1),p.second+1));
		open.push(P(p.first.move(0).move(0).move(0),p.second+1));
		open.push(P(p.first.move(1).move(1).move(1),p.second+1));
	}

	return -1;
}

int main(void){
	while(1){
		S s[6];
		rep(i,6) rep(j,3){
			string str;
			cin>>str;
			s[i].push_back(str);
			if(s[i][j] == "#") return 0;
		}

		Dice d(s[4],s[5],s[3],s[1],s[2],s[0]);
		cout<<solve(d)<<endl;
	}

	return 0;
}

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

int f[45];

void FibonacciInit(){

    f[0] = 1;
    f[1] = 1;
    for(int i=2; i<=44; i++){
        f[i] = f[i-1] + f[i-2];
    }
}

int main() {

    int n;
    cin >> n;

    FibonacciInit();

    cout << f[n] << endl;

    return 0;
}


Measured memory_bytes: 3096
loop do
  points = []

  8.times do |_y|
    gets.split(//).map(&:to_i).each_with_index do |n, _x|
      points.push({ x: _x, y: _y }) if n == 1
    end
  end

  p1, p2, p3, p4 = points

  if ((p1[:x] == p3[:x]) && (p2[:x] == p4[:x]) &&
      (p1[:y] == p2[:y]) && (p3[:y] == p4[:y]))
    puts 'A'
  elsif points.all? { |point| point[:x] == p1[:x] }
    puts 'B'
  elsif points.all? { |point| point[:y] == p1[:y] }
    puts 'C'
  elsif p2[:y] == p3[:y]
    if p1[:x] > p4[:x]
      puts 'D'
    else
      puts 'F'
    end
  else
    if p1[:x] < p4[:x]
      puts 'E'
    else
      puts 'G'
    end
  end

  break if gets.nil?
end

Measured memory_bytes: 8772