akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int MAX_H = 110;
const int MAX_W = 110;

int v[MAX_H][MAX_W], E[MAX_H][MAX_W], N, H, W, _W, _H;

void init(){
  memset(E, 0, sizeof(E));
  E[0][0] = v[0][0];
  FOR(i, 1, H) E[i][0] = E[i - 1][0] + v[i][0];
  FOR(i, 1, W) E[0][i] = E[0][i - 1] + v[0][i];
  FOR(y, 1, H)
    FOR(x, 1, W)
    E[y][x] = v[y][x] + E[y - 1][x] + E[y][x - 1] - E[y - 1][x - 1];
}

int calc(int Y1, int X1, int Y2, int X2){
  int ret = E[Y2][X2];
  if(X1 - 1 >= 0) ret -= E[Y2][X1 - 1];
  if(Y1 - 1 >= 0) ret -= E[Y1 - 1][X2];
  if(X1 - 1 >= 0 && Y1 - 1 >= 0) ret += E[Y1 - 1][X1 - 1];
  return ret;
}

int main() {
  while(cin >>N && N){
    cin >>W >>H;
    memset(v, 0, sizeof(v));
    REP(i, N){
      int x, y; cin >>x >>y;
      v[y - 1][x - 1] = 1;
    }
    cin >>_W >>_H;
    init();
    int ans = 0;
    REP(y, H - _H + 1) REP(x, W - _W + 1) ans = max(ans, calc(y, x, y + _H - 1, x + _W - 1));
    cout <<ans <<endl;
  }
}

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

const int N=1e5+5;
int n,m,ans;
int p[N];

int fp(int x){
	if(x==p[x]) return x;
	return p[x]=fp(p[x]);
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) p[i]=i;
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		x=fp(x);y=fp(y);
		p[x]=y;
	}
	for(int i=1;i<=n;i++) if(fp(i)==i) ans++;
	ans--;
	printf("%d\n",ans);
	return 0;
}

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


int main()
{
	int X,beki=0, answer=1;
	cin >> X;

	//1000までで最高のべき乗数は高々31×31=961
	for (int i = 2; i <= 31; ++i) {
		beki = i;
		//2乗できなければ終わり
		if (beki*beki > X) break;
		//X以上になるまで掛け続ける
		for (int j = 1; beki*i <= X; ++j) {
			beki = beki*i;
		}
		//大きかったら答えを入れ替える
		answer = max(beki, answer);
	}

	cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 998244353;
ll N;
ll Sum[1000005];
ll Quad[1000005];
ll beki(ll a, ll b) {
    if(b == 0) return 1;
    ll ret = beki(a, b / 2);
    ret = ret * ret % mod;
    if(b & 1) ret = ret * a % mod;
    return ret;
}
ll ans = 0;
ll Val[1000500];

vector<ll> Div[1000500];
ll Factorial[1000500];
ll FactorialInv[1000050];
ll Inv[1000050];
ll num[1000050];

int main() {
    Factorial[0] = 1;
    for(ll i = 1; i <= 1e6; i++) {
        Factorial[i] = Factorial[i-1] * i % mod;
    }
    FactorialInv[(int)1e6] = beki(Factorial[(int)1e6], mod - 2);
    for(ll i = 1e6 - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
    Inv[0] = 1;
    for(ll i = 1; i <= 1e6; i++) {
        Inv[i] = FactorialInv[i] * Factorial[i-1] % mod;
    }
    cin >> N;
    for(int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        num[a]++;
    }
    for(ll i = 1; i <= 1e6; i++) {
        for(ll j = i; j <= 1e6; j += i) {
            Div[j].push_back(i);
        }
    }
    for(ll i = 1; i <= 1e6; i++) {
        for(ll val : Div[i]) {
            Sum[val] += i * num[i];
            Sum[val] %= mod;
            Quad[val] += i * i * num[i];
            Quad[val] %= mod;
        }
    }
    for(ll i = 1e6; i >= 1; i--) {
        Val[i] = Sum[i] * Sum[i] - Quad[i] + mod;
        Val[i] %= mod;
        for(ll val = i + i; val <= 1e6; val += i) {
            Val[i] += mod - Val[val];
            //Val[i] %= mod;
        }
        Val[i] %= mod;
        ans += Val[i] * Inv[i];
        ans %= mod;
    }
    ans *= beki(2, mod - 2);
    ans %= mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 235520
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1 << 30;

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


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

int main() {
  char N[5];
  scanf("%s" ,&N) ;

  if ( N[0] == N[1] && N[1] == N[2]|| N[1] == N[2] && N[2] == N[3] ) {
    puts("Yes" );
  }
  
  else puts("No") ;
}


Measured memory_bytes: 256
# div2019-2B - Picking Up
n = int(input())
arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
cnt = {}
for i in range(n):
    for j in range(i + 1, n):
        dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])
        cnt.setdefault(dif, 0)
        cnt[dif] += 1
print(n - max(cnt.values(), default=0))

Measured memory_bytes: 3188
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int N, P[201010];

int mm[202020];

int main() {
    cin >> N ;
    for (int j = 0; j < N; ++j) { cin >> P[j]; }

    fill(mm, mm+N+1, 0);
    for (int j = 0; j < N; ++j) {
        mm[P[j]] = mm[P[j]-1]+1;
    }

    int ans = 10101010;
    for (int j = 1; j <= N; ++j) {
        ans = min(ans, N - mm[j]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int Cin()
{
    int n;
    cin >> n;
    return n;
}

const bool IsPrimeNumber(const int N)
{
    for (int i = 2; i * i <= N; ++i)
    {
        if (N % i == 0) return false;
    }
    return true;
}

int main()
{
    vector<int> primes;
    for (int i = 6; i <= 55555; i += 5)
    {
        if (IsPrimeNumber(i)) primes.push_back(i);
    }
    int N = Cin();
    for (int i = 0; i < N; ++i)
        cout << primes[i] << ' ';
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N; cin >> N;
    ll yen = 1000;
    vector<ll> A(N);
    rep(i,N) cin >> A.at(i);
    ll i = 0, j = 1;
    while (i < N && j < N) {
        if (A[i] < A[j]) {
            ll n = yen / A[i];
            yen += (A[j] - A[i]) * n;
        }
        i = j;
        j = i+1;
    }
    cout << yen << endl;
}


Measured memory_bytes: 3556
#include<iostream>
using namespace std;
#define GOO 1
#define CHO 2
#define PA 3
#define WIN 1
#define LOSE 2
#define EVEN 3
int main()
{
    while(true)
    {
        int field[5] ={};
        int te[5] = {};
        bool fin= false;
        cin >> te[0];
        if(te[0] == 0)break;
        field[te[0] ] = 1;
        for(int i=1;i<5;i++)
        {
            cin >> te[i];
            field[te[i]] = 1;
            //if(cin.eof()){fin = true; break;}
        }
        if(fin)break;


        //  aiko
        int tekazu = 0;
        for(int i=1;i<=3;i++)
        {
            tekazu += field[i];
        }
        //cout << tekazu << endl;
        if((tekazu == 3) || (tekazu == 1) )
        {
            for(int i=0;i<5;i++){ cout << EVEN << endl;}
            continue;
        }
        if(field[GOO] == 0)
        {
            for(int i=0;i<5;i++)
            {
                if(te[i] == CHO) cout << WIN<<endl;
                else cout << LOSE << endl;
            }
        }
        if(field[CHO] == 0)
        {
            for(int i=0;i<5;i++)
            {
                if(te[i] == PA) cout << WIN<<endl;
                else cout << LOSE << endl;
            }
        }
        if(field[PA] == 0)
        {
            for(int i=0;i<5;i++)
            {
                if(te[i] == GOO) cout << WIN<<endl;
                else cout << LOSE << endl;
            }
        }
    }
    return 0;
}

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

int main() {
  int a;
  cin >> a;
  
  if(a%2==0){
    cout << (a/2)*(a/2) << endl;
  }
  
  else{
    cout << ((a/2)+1)*(a/2) << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long lld;
typedef pair<int,int> pii;
lld n,a,b;
int main(){
    scanf("%lld%lld%lld",&n,&b,&a);
    if(n>a*b||n<a+b-1){
        printf("-1");
        return 0;
    }
    else{
        lld now=0;
        for(lld i=b-1;i>=0;i--){
            for(lld j=min(n-now-i,a);j>=1;j--) printf("%lld ",now+j);
            now+=min(n-now-i,a);
        }
    }
    return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
struct UnionFind{
    vector<int> d;
    UnionFind(int n) : d(n,-1) {}
    //根なら、-サイズを格納それ以外は、親を格納
    int find(int x){
        if(d[x] < 0) return x;
        return d[x] = find(d[x]); //経路縮約
    }
    bool unite(int x,int y){
        //二つ頂点を持ってくる
        x = find(x);
        y = find(y);
        if(x == y) return false;//根が一致するなら何もしない
        if(d[x] > d[y]) swap(x,y);
        //ex:d[x]=-5,d[y]=-2
        //小さい方が、大きい方に引っ付く
        d[x] += d[y];//この場合、yがxにくっつく
        d[y] = x;
        return true;
    }
    bool same(int x,int y) {return find(x) == find(y);}
    int size(int x) {return -d[find(x)];}
};
int main(){
    cout << fixed << setprecision(10);
    UnionFind uf(12);
    uf.unite(0,2);
    uf.unite(0,4);
    uf.unite(0,6);
    uf.unite(0,7);
    uf.unite(0,9);
    uf.unite(0,11);

    uf.unite(3,5);
    uf.unite(3,8);
    uf.unite(3,10);

    int x,y;

    cin >> x >> y;
    x--; y--;
    if(uf.same(x,y) == 1) cout << "Yes" << endl;
    else cout << "No" << endl;  
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << x << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x) for(int i = 0; i < (sizeof(x)/sizeof(x[0])); i++){ cout << (x[i]) << " ";} cout << endl;

typedef long long ll;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B;
    cin >> A >> B;
    if (A > 8 || B > 8){
        print(":(");

    }else{
        print("Yay!");
    }
}

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

int main() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  set<int> color;
  int a,b,c;
  cin>>a>>b>>c;
  color.insert(a),color.insert(b),color.insert(c);
  cout<<color.size()<<endl;
  return 0;
}


Measured memory_bytes: 256
A = [1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
N = int(input())

dp = [N] * (N+1)
dp[0] = 0
for i in range(1, N+1):
    for j in A:
        if i >= j:
            dp[i] = min(dp[i], dp[i - j] + 1)

print(dp[N])

Measured memory_bytes: 73856
// A.

#include <stdio.h>

typedef long long LL;

char buffer[3072000];
LL cnt[20][20];
LL sum[20][20];
LL n;
LL ans;

int main(int argc, char* argv[]) {
	char c, *bufptr = buffer;
	fread(buffer, 1, 3072000, stdin);
	while ((c = *bufptr++) >= '0') {
		n = (n * 10) + (c - '0');
	}
	for (LL i = 0; i < n; ++i) {
		LL x = 0, two = 0, five = 0, df = 0;
		while ((c = *bufptr++) >= ' ') {
			if (c == '.') {
				df = -1;
			} else {
				x = (x * 10) + c - '0';
				five += df;
			}
		}
		two = __builtin_ctzll(x);
		x >>= two;
		two += five;
		while (x % 5 == 0) {
			++five;
			x /= 5;
		}
		if (two > 9) two = 9;
		if (five > 9) five = 9;
		cnt[10 + two][10 + five] += 1;
		sum[10 - two][10 - five] += 1;
	}
	for (int i = 0; i < 20; ++i) {
		for (int j = 1; j < 20; ++j) {
			sum[i][j] += sum[i][j - 1];
		}
	}
	for (int i = 1; i < 20; ++i) {
		for (int j = 0; j < 20; ++j) {
			sum[i][j] += sum[i - 1][j];
		}
	}
	for (int i = -9; i <= 9; ++i) {
		for (int j = -9; j <= 9; ++j) {
			ans += sum[10 + i][10 + j] * cnt[10 + i][10 + j];
			if (i >= 0 && j >= 0) {
				ans -= cnt[10 + i][10 + j];
			}
		}
	}
	printf("%lld\n", ans >> 1);
	return 0;
}


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

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

    cout << (a / b) << " " << (a % b) << " " << flush;
    cout << fixed << setprecision(5) << (double)a / (double)b << endl;

    return 0;
}


Measured memory_bytes: 3256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b;
signed main()
{
	cin>>a>>b;
	cout<<(1+b-a)*(b-a)/2-b;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int cup[3] = {1, 0, 0};
  int i = 0;
  int tmp = 0;
  char x, comma, y;

  while(1){

    if(i > 50)
      break;

    cin >> x >> comma >> y;
   
    if(x == '0')
      break;

    tmp = cup[x- 'A'];
    cup[x - 'A'] = cup[y - 'A'];
    cup[y - 'A'] = tmp;

    i++;
  }

  for(i=0; i<3; i++){
    if(cup[i] == 1)
      cout << char('A'+i) << endl;
  }
}



Measured memory_bytes: 3080
n = int(input())
table = [[i for i in input().split()] for j in range(n)]

for k in range(n) :
	table[k][1] = int(table[k][1]) 
	table[k].append(k + 1)

sortedtable = sorted(table, key=lambda x:(x[0], -x[1]))

for l in range(n) :
	print(sortedtable[l][2])

Measured memory_bytes: 3060
import sys
from collections import deque, Counter

n = int(input())
es = [[] for _ in range(n + 1)]

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

depth = [-1 for _ in range(n + 1)]
dq = deque([1])
depth[1] = 0

while dq:
	v = dq.pop()
	for e in es[v]:
		if depth[e] != -1:
			continue
		depth[e] = depth[v] + 1
		dq.append(e)

ans = [-1 for _ in range(n + 1)]	
cnt_dict = Counter([x % 2 for x in depth[1:]])

nums = [[i for i in range(1, n + 1) if i % 3 == 1], [i for i in range(1, n + 1) if i % 3 == 2], [i for i in range(1, n + 1) if i % 3 == 0]]
if cnt_dict[0] <= n // 3:
	for i in range(1, n + 1):
		if depth[i] % 2 == 0:
			ans[i] = nums[2].pop()
		else:
			if nums[0]:
				ans[i] = nums[0].pop()
			elif nums[1]:
				ans[i] = nums[1].pop()
			else:
				ans[i] = nums[2].pop()
elif cnt_dict[1] <= n // 3:
	for i in range(1, n + 1):
		if depth[i] % 2 == 1:
			ans[i] = nums[2].pop()
		else:
			if nums[0]:
				ans[i] = nums[0].pop()
			elif nums[1]:
				ans[i] = nums[1].pop()
			else:
				ans[i] = nums[2].pop()
else:
	for i in range(1, n + 1):
		if depth[i] % 2 == 0:
			if nums[0]:
				ans[i] = nums[0].pop()
			else:
				ans[i] = nums[2].pop()
		else:
			if nums[1]:
				ans[i] = nums[1].pop()
			else:
				ans[i] = nums[2].pop()

print(*ans[1:])


Measured memory_bytes: 69756
#include<bits/stdc++.h>
using namespace std;
const int N = 106;
int a[N];
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int s = accumulate(a,a+n,0);
    pair<int,int> ans(1e9,1e9);
    for (int i = 0; i < n; ++i) {
        ans = min(ans, {abs(n*a[i]-s),i});
    }
    cout << ans.second << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323
#define nu          pair<ll,pll>

const int N = 1e5+5;
vl g[N];
bool vis[N];
ll fact[N];
ll n,k;

ll binpow(ll val, ll deg)
{
        if (!deg) return 1 % mod;
        if (deg & 1) return binpow(val, deg - 1) * val % mod;
        ll res = binpow(val ,deg >> 1);
        return (res*res) % mod;
}

void initfact()
{
        fact[0] = 1;
        for(ll i = 1; i < N; i++)
       {
                fact[i] = (fact[i-1] * i);
                fact[i] %= mod;
        }
}

ll nCr(ll n, ll i)
{
        ll res = fact[n];
        ll div = fact[n-i] * fact[i];
        div %= mod;
        div = binpow(div, mod - 2);
        return (res * div) % mod;
}

ll ways=1;

void dfs(ll s, ll p)
{
       if(s==1)
       {
              ll c = g[s].size();
              if(c+1 > k) {  cout<<0<<endl; exit(0); }
              ways = (((ways*nCr(k,c+1))%mod)*fact[c+1])%mod;
              vis[s]=1;
              for(ll d : g[s])
              {
                     if(d!=p) dfs(d,s);
              }
              return;
       }
       if(vis[s]) return;
       vis[s]=1;

       ll c = g[s].size();       if(c==1) return;
       c--;
       if(c > k-2) { cout<<0<<endl; exit(0); }
       ways = (((ways*nCr(k-2,c))%mod)*fact[c])%mod;
       for(ll d : g[s])
       {
              if(d!=p) dfs(d,s);
       }
}


void solve()
{
       initfact();
       cin>>n>>k;
       rep(i,0,n-1)
       {
              ll a,b; cin>>a>>b;
              g[a].push_back(b);
              g[b].push_back(a);
       }
       dfs(1, -1);
       cout<<ways<<endl;
}



int main() {
	ll T = 1;
	//speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


Measured memory_bytes: 10112
package main

import "fmt"

var (
	H int
	W int
)

func main() {
	fmt.Scanln(&H, &W)
	multi := H * W
	result := 0
	if H == 1 || W == 1 {
		result = 1
	} else if multi%2 == 0 {
		result = multi / 2
	} else {
		result = (multi / 2) + 1
	}
	fmt.Println(result)
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n;
string s;

string cal(ll l,ll r){
    string ans = s;
    if(r!=0){
        string tmp;
        rep(i,r){
            tmp.pb('(');
        }
        ans = tmp+ans;
    }
    if(l!=0){
        string tmp; 
        rep(i,l){
            tmp.pb(')');
        }
        ans += tmp;
    }
    return ans;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>s;
    ll lef = 0;
    ll rig = 0;
    rep(i,s.size()){
        if(s[i]==')'){
            if(lef!=0){
                lef--;
            }else{
                rig++;
            }
        }else{
            lef++;
        }
    }
    string ans = cal(lef,rig);
    print(ans);
    return 0;  
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public Main(){}
  
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    String[] tokens = scanner.nextLine().split(" +");
    
 	int[] nums = new int[3];
    nums[0] = Integer.parseInt(tokens[0]);
    nums[1] = Integer.parseInt(tokens[1]);
    nums[2] = Integer.parseInt(tokens[2]);
    
    for(int i=0; i<3; i++){
      int sum = 0;
      for(int j=0; j<3; j++){
        if(i == j){
          continue;
        }
        sum += nums[j];
      }
      
      if(sum == nums[i]){
        System.out.println("Yes");
        return;
      }
    }
    
    System.out.println("No");
    
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
char a[1001][1001];
int wi[8]={1,1,0,-1,-1,-1,0,1};
int wj[8]={0,-1,-1,-1,0,1,1,1},n=0,m=0;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
        }
	}
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j]=='#')
            {
                cout<<'#';
            }
            else
            {
                int num=0;
                for(int m=0;m<8;m++)
                {
                    if(a[i][j]!='.')
                    {
                        continue;
                    }
                    if(a[i+wi[m]][j+wj[m]]=='#')
                    {
                        num++;
                    }
                }
                cout<<num;
            }
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B
  * Structured Program II - How many ways?
  */
object Main {
  def main(args: Array[String]): Unit = {
    val dataSets = Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).map(_.split(" ").map(_.toInt))
      .map { case Array(n, x) => (n, x) }
      .takeWhile(_ != (0, 0))
      .toList
    val results = dataSets.map { case (n, x) =>
      // Memory Limit Exceeded
      // (1 to n).combinations(3).count(_.sum == x)
      (for (a <- 1 to n; b <- 1 to n if a < b; c <- 1 to n if a < c && b < c && (a + b + c) == x)
        yield 1).length
    }
    results.foreach(println)
  }

}

Measured memory_bytes: 88456
#include <bits/stdc++.h>
#include <unistd.h>
#include <random>

using namespace std;
typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
    //    random_device rnd;
    //    mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    for(int i = 1;i <= 9;i++){
        if(N % i == 0 && N / i < 10){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repf(i, f, l) for(int i = f; i < (int)l; ++i)
#define repit(it, t) for(__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++)
#define endl "\n"
#define pb emplace_back
#define lb lower_bound
#define int long long
#define ul unsigned long
#define ull unsigned long long
#define ll long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second
#define DBG0(x) { cout << #x << ": " << x << "\t"; }
#define DBG(x) {DBG0(x); cout << endl;}
#define DBG2(x, y) {DBG0(x); DBG(y);}
#define DBG3(x, y, z) {DBG0(x); DBG2(y, z);}
#define DBG4(w, x, y, z) {DBG0(w); DBG3(x, y, z);}

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef vector<bool> vbl;
typedef pair<int, int> pii;

int gcd(int m, int n) {
    int tmp;
    while (m % n) {
        tmp = n;
        n = m % n;
        m = tmp;
    }
    return n;
}

bool solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a < b) return false;
    if (d < b) return false;
    if (b <= c) return true;
    int m = gcd(b, d);
    int i = 1 + (a - b) / m;
    return (a - m * i) <= c;
}

signed main(void){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i, n) {
        cout << (solve() ? "Yes" : "No") << endl;
    }
    return 0;

}




Measured memory_bytes: 256
s= input()
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        print(i+1,i+2)
        break
    if i+2<=len(s)-1 and (s[i]==s[i+2] or s[i+1]==s[i+2]):
        print(i+1,i+3)
        break
else:print('-1 -1')

Measured memory_bytes: 3188
#include <bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vp = vector<P>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;
const int INF = 1e9;
const int MOD = 1e9+7;

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

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

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    
    ll N, L; cin >> N >> L;
    vl a(N); REP(i, N) cin >> a[i];
    bool isPossible = false;
    ll last;
    REP(i, N-1) if(a[i]+a[i+1] >= L)
    {
        isPossible = true;
        last = i;
    }
    if(!isPossible)
    {
        cout << "Impossible" << endl;
        return 0;
    }
    cout << "Possible" << endl;
    for(int i = 0; i < last; i++) cout << i+1 << endl;
    for(int i = N-2; i > last; i--) cout << i+1 << endl;
    cout << last+1 << endl;
}

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

int main(){
	int n;
	string s,st;
	scanf("%d",&n);
	printf("0\n");
	cin>>s;
	if(s=="Vacant")return 0;
	int l=0,r=n-1;
	int hit=0;
	while(true){
		hit++;
		int mid=(l+r+1)/2;
		printf("%d\n",mid);
		cin>>st;
		if(st=="Vacant")return 0;
		if(st==s && mid%2==0) {
			l=mid;
		}
		else if(st!=s && mid%2==1){
			l=mid;
		}
		else{
			r=mid;
		}
		if(hit==19)break;
	}
}

Measured memory_bytes: 852
#include <iostream>
#include <cmath>

using namespace std;

int main(){
	long long N, A, B;
	cin>>N>>A>>B;
	if(A==B){
		cout << 1 << endl;
	} else if(A>B){
		cout << 0 << endl;
	} else {
		if(N==1)
			cout << 0 << endl;
		else
			cout <<  ((B*(N-1)+A)-(A*(N-1)+B)+1) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
/* ex5_3.c Grid Compression
    dada__              */
#include<stdio.h>

int main(void){
    int row, col, i, j;
    scanf("%d %d", &row, &col); //行と列の数の入力
    int judge_row[row], judge_col[col];
    char grid[row][col];

    //各マス目の記号の入力
    for(i=0;i<row;i++){
        for(j=0;j<col;j++){
            scanf(" %c", &grid[i][j]);
        }
    }

    //各行について，取り除くかの判定
    for(i=0;i<row;i++){
        judge_row[i] = 0;
        for(j=0;j<col;j++){
            if(grid[i][j]=='#'){
                judge_row[i]=1;
                break;
            }
        }
    }
    //各列について，取り除くかの判定
     for(j=0;j<col;j++){
        judge_col[j] = 0;
        for(i=0;i<row;i++){
            if(grid[i][j]=='#'){
                judge_col[j]=1;
                break;
            }
        }
    }

    //各判定に基づいた出力
    for(i=0;i<row;i++){
        if(judge_row[i]==1){ //行の判定が1の場合に出力
            for(j=0;j<col;j++){
                if(judge_col[j]==1){//列の判定が1の場合に出力
                printf("%c", grid[i][j]);
                }
            }
        printf("\n"); //1行出力した段階で改行
        }
    }
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin>>n;
  vll a(n);
  map<ll,ll> m;
  REP(i,n){
    cin>>a[i];
    m[a[i]]+=1;
  }

  sort(ALL(a),greater<ll>());
  ll ans=0;
  REP(i,n){
      if(m[a[i]]==0)
        continue;
      m[a[i]]-=1;

      ll t=1;
      while(t<=a[i])
        t*=2;

      if(m[t-a[i]]!=0){
        m[t-a[i]]-=1;
        ans++;
      }
    }

  cout<<ans<<endl;
}



Measured memory_bytes: 29864
#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;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, std::vector<long long> a){
  ll cur=0;
  REP(N){
    if(a[i]==cur+1){
      cur=a[i];
    }
  }
  if(cur==0){
    cur=N+1;
  }
  cout<<N-cur<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 1792
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (n, m) = listOfInt()
    val ppl = mutableListOf<Pair<Int, Int>>()
    val ppt = mutableListOf<Pair<Int, Int>>()

    repeat(n) {
        val (a, b) = listOfInt()
        ppl.add(Pair(a, b))
    }

    repeat(m) {
        val (c, d) = listOfInt()
        ppt.add(Pair(c, d))
    }

    for (i in 0 until n) {
        var min = Int.MAX_VALUE
        var ans = 0

        for (j in 0 until m) {
            val dis = Math.abs(ppl[i].first - ppt[j].first) + Math.abs(ppl[i].second - ppt[j].second)
            if (dis < min) {
                min = dis
                ans = j + 1
            }
        }

        println(ans)
    }
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

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

using namespace std;
int main(void){
    
    string c;
    cin >> c;
    
    if(c == "a" || c == "e" || c == "i" || c == "o" || c == "u") {
        cout << "vowel" << endl;
    }
    else {
        cout << "consonant" << endl;
    }

    return 0;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    
    if(c <= a+b+1) {
        cout << b + c;
    }
    else {
        cout << a + 2*b + 1; 
    }
    
    cout << endl;
    return 0;
}

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

namespace ConsoleApp15
{
    class Class274
    {
        static void Main()
        {
            var Nx = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int N = Nx[0];
            int x = Nx[1];
            var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            long count = 0;
            if (a[0] > x) { count += a[0] - x;a[0] = x; }
            for(int i = 0; i < N - 1; i++)
            {
                if (a[i] + a[i + 1] > x)
                {
                    count += a[i + 1] + a[i] - x;
                    a[i + 1] -= a[i + 1] + a[i] - x;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 29148
N = int(input())
A = list(map(int,input().split()))

def solve(n):
    n = int(n)
    l= [0]*N
    l[0] = int(n)
    for i in range(1,N):
        l[i] = int(2*A[i-1] - l[i-1])
    if 2*A[-1] - l[-1] == n:
        print(" ".join(map(str,l)))
        exit()
    elif 2*A[-1] - l[-1] > n:
        return True
    else:
        return False


l = 0
r = sum(A)
for i in range(100):
    m = (l+r)/2
    if solve(m):
        l = m
    else:
        r = m



Measured memory_bytes: 88548
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000000007
#define ll long long 
ll power(ll x, ll y) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % MAX;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y%2==1) 
        {res = (res*x) % MAX; y--;}
  
        // y must be even now 
        y /=2; // y = y/2 
        x = (x*x) % MAX;   
    } 
    return res; 
} 
ll finv(ll n){
  return(power(n,MAX-2));
}
long long int ncr(long long int A,long long int B){
 	if(B==0) return(1);
  	long long int fac[A+1];
  	fac[0]=fac[1]=1;
  	for(long long int i=2;i<=A;i++){
      fac[i]=(i*fac[i-1])%MAX;
       
    }
  	return (fac[A]* finv(fac[B]) % MAX *finv(fac[A-B]) % MAX) % MAX; 
}
int main(){
  long long int x,y;
  cin>>x>>y;
  long long int A=(2*y-x)/3,B=(2*x-y)/3;
  if((2*y-x)%3!=0 || (2*x-y)%3!=0) cout<<0;
  else if(A<0 || B<0) cout<<0;
  else cout<<ncr(A+B,A);
}
    

Measured memory_bytes: 5504
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
const int MAXN = 15;
char input[MAXN];
int main(void)
{
    scanf("%s", input);
    int length = strlen(input);

    int answer;
    for(int i = 0; i < length - 2; i++)
    {
        int temp = 0;
        for(int j = 0; j < 3; j++)
        {
            temp = temp * 10 + (input[i + j] - '0');
        }
        if(i == 0)
            answer = fabs(temp - 753);
        else
            answer = min(answer, (int)fabs(temp - 753));
    }

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

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    string s = to_string(i);
    if (s.size() % 2 == 1) {
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}
      

Measured memory_bytes: 256
import math
N, D = map(int, input().split(' '))
X = []
for j in range(N):
    Xj = list(map(int, input().split(' ')))
    X.append(Xj)

cnt = 0
for j in range(N):
    for k in range(j+1, N):
        dist = 0
        for i in range(D):
            dist += (X[j][i]-X[k][i]) * (X[j][i]-X[k][i])
        dist = math.sqrt(dist)
        if dist.is_integer() is True:
            cnt += 1
print(cnt)


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

using namespace std;

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

	if (N > 81) {
		cout << "No" << endl;
		return 0;
	}
	for (int i=1; i<=9; i++) {
		if (N%i == 0 && N/i <=9) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
//#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
ll ceil(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 1000000000;
const ll INF64 = 9223372036854775807ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！
itn main(){
    int n;
    std::cin >> n;
    ll t,tt;
    ll a=1,aa=1;
    rep(i,n){
        std::cin >> t>>tt;
        ll b=max(ceil(a,t),ceil(aa,tt));
        a=t*b;aa=tt*b;
    }
    std::cout << aa+a << std::endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int count=0;
  for(int i=1;i<=n;i++){
    string str=to_string(i);
    if(str.size()%2==1) count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main(){
  lint n, k; cin >> n >> k;
  v1li v(n), u = {};
  rep(i, n){
    cin >> v[i];
    v[i]--;
  }
  lint a, b, c = 0, tmp = 0;
  unordered_set<lint> w;
  while(!w.count(tmp)){
    u.push_back(tmp+1);
    w.insert(tmp);
    ++c;
    tmp = v[tmp];
  }
  rep(i, c){
    if(u[i] == tmp+1){
      b = i;
      a = c-b;
      break;
    }
  }
  if(k < b) cout << u[k] << endl;
  else cout << u[(k-b)%a+b] << "\n";
  return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);

    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<long long> a(X), b(Y), c(Z), res;
    for (auto &e : a) cin >> e;
    for (auto &e : b) cin >> e;
    for (auto &e : c) cin >> e;

    sort(a.begin(), a.end(), greater<long long>());
    sort(b.begin(), b.end(), greater<long long>());
    sort(c.begin(), c.end(), greater<long long>());

    for (int i = 0; i < X; i++) {
        for (int j = 0; j < Y; j++) {
            for (int k = 0; k < Z; k++) {
                if ((i + 1) * (j + 1) * (k + 1) > K) break;
                res.push_back(a[i] + b[j] + c[k]);
            }
        }
    }

    sort(res.begin(), res.end(), greater<long long>());
    for (int i = 0; i < K; i++) {
        cout << res[i] << '\n';
    }
}

Measured memory_bytes: 1404
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a / gcd(a, b) * b; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


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

    ll k,now = 1,ans;
    cin>>k;

    queue<ll>que;
    rep(i,1,10)que.push(i);

    while(!que.empty()){
        ll tp = que.front(),md;
        que.pop();
        md = tp%10;
        if(k == now){
            cout<<tp<<endl;
            break;
        }
        else{
            if(md > 0)que.push(tp * 10 + md - 1);
            que.push(tp * 10 + md);
            if(md < 9)que.push(tp * 10 + md + 1);
        }
        now++;
    }




    return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int H, W;
char C[55][55];

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

bool in(int y, int x) {
  return 0<=y&&y<H&&0<=x&&x<W&&C[y][x]!='#';
}

bool used[55][55];
bool bfs() {
  memset(used, false, sizeof(used));
  queue<Pi> que;
  used[0][0] = true;
  que.emplace(0, 0);
  while(!que.empty()) {
    int y, x; tie(y, x) = que.front(); que.pop();
    if(y == H-1 && x == W-1) break;
    rep(i, 2) {
      int ny = y + dy[i], nx = x + dx[i];
      if(!in(ny, nx)) continue;
      if(used[ny][nx]) continue;
      used[ny][nx] = true;
      que.emplace(ny, nx);
    }
  }
  return used[H-1][W-1];
}

vector<Pi> hole[26];

int dp[55][55][55][55];
int dfs(int sy, int sx, int ty, int tx) {
  if(!in(sy, sx) || !in(ty, tx)) return -inf;
  if(sy > ty || sx > tx) return -inf;
  if(sy == ty && sx == tx) return 0;
  int &res = dp[sy][sx][ty][tx];
  if(~res) return res;
  res = -inf;
  rep(i, 2) {
    int ny = sy + dy[i], nx = sx + dx[i];
    if(!in(ny, nx)) continue;
    chmax(res, dfs(ny, nx, ty, tx));
  }
  if(!islower(C[sy][sx])) return res;
  int c = C[sy][sx] - 'a';
  rep(i, hole[c].size()) {
    int hy = hole[c][i].first, hx = hole[c][i].second;
    if(sy > hy || sx > hx) continue;
    if(ty < hy || tx < hx) continue;
    bool flag = false;
    rep(j, 2) {
      int ny = sy + dy[j], nx = sx + dx[j];
      if(ny == hy && nx == hx) flag = true;
    }
    if(flag) {
      chmax(res, dfs(hy, hx, ty, tx)+1);
      continue;
    }
    rep(j, 2) {
      int ny = sy + dy[j], nx = sx + dx[j];
      if(!in(ny, nx)) continue;
      rep(k, 2) {
	int my = hy - dy[k], mx = hx - dx[k];
	if(!in(my, mx)) continue;
	int tmp1 = dfs(ny, nx, my, mx);
	int tmp2 = dfs(hy, hx, ty, tx);
	chmax(res, tmp1+tmp2+1);
      }
    }
  }

  return res;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> H >> W, H || W) {
    rep(i, 26) hole[i].clear();
    rep(i, H) rep(j, W) {
      cin >> C[i][j];
      if(isupper(C[i][j])) hole[C[i][j]-'A'].emplace_back(i, j);
    }
    if(!bfs()) {
      cout << -1 << endl;
      continue;
    }
    memset(dp, -1, sizeof(dp));
    int ans = dfs(0, 0, H-1, W-1);
    //cout << (ans < 0 ? -1 : ans) << endl;
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 74580
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>  //for bool
#include <stdlib.h> // abs,labs,llabs
#include <limits.h>
#include <ctype.h>

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld; //%Lf

int main(void) {
  int n, flag = 0, ans = 0, i;
  scanf("%d", &n);
  int a[n + 1], b[n + 1], c[n];
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
  }
  for (i = 1; i < n; i++) {
    scanf("%d", &c[i]);
  }
  for (i = 1; i <= n; i++) {
    if (flag == 1) {
      ans += (b[a[i]] + c[a[i - 1]]);
      // printf("%d %d\n", b[a[i]] , c[a[i - 1]]);
      if((a[i + 1] == (a[i] + 1)) && i != n) {
        flag = 1;
      } else {
        flag = 0;
      }
    } else {
      ans += b[a[i]];
      // printf("%d\n", b[a[i]]);
      if((a[i + 1] == (a[i] + 1)) && i != n) {
        flag = 1;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128