akhauriyash/Code-Regression huggingface dataset:
# AGC039B - Graph Partition
from collections import deque


def is_bipartite() -> bool:
    stack = deque([(1, 1)])
    color = [-1] * (N + 1)
    color[1] = 1
    while stack:
        v, cur_color = stack.pop()
        next_color = cur_color ^ 1
        for u in E[v]:
            if color[u] == cur_color:
                return False
            if color[u] == -1:
                color[u] = next_color
                stack.append((u, next_color))
    return True


def bfs(start) -> int:
    que = deque([start])
    dist = [-1] * (N + 1)  # dist[i] := distance from V_start to V_i
    dist[start] = 0
    while que:
        v = que.popleft()
        cur = dist[v]
        for u in E[v]:
            if dist[u] == -1:
                dist[u] = cur + 1
                que.append(u)
    return max(dist)


def main():
    # if bipartite graph -> diameter of the graph + 1
    global N, E
    N, *S = open(0).read().split()
    N = int(N)
    E = [0] + [[i for i, flg in enumerate(s, 1) if flg == "1"] for s in S]
    if is_bipartite():
        ans = max(bfs(i) for i in range(1, N + 1)) + 1
        print(ans)
    else:
        print(-1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3700
package main

import "fmt"

func main() {
	var a, b, k int
	fmt.Scan(&a, &b, &k)
	for i := 1; i <= k; i++ {
		if i%2 == 1 { // T's turn
			if a%2 == 1 {
				a = a - 1
			}
			b = b + a/2
			a /= 2
		} else { // A's turn
			if b%2 == 1 {
				b = b - 1
			}
			a = a + b/2
			b /= 2
		}
	}
	fmt.Println(a, b)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
    using namespace std;
    int main(){
		int n,k,a,ans=0,b[200005]={};
		cin>>n>>k;
		for(int i=0;i<n;i++){
			cin>>a;
			b[a]++;
		}
		sort(b,b+200001);
		for(int i=0;i<200001-k;i++){
			ans+=b[i];
		}
		cout<<ans<<endl;
      return(0);
	}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**7)

n = int(input())

def search(x, use, cnt):
    if x > n:
        return
    if use == 0b111:
        cnt.append(1)
        
    search(x * 10 + 3, use | 0b100, cnt)
    search(x * 10 + 5, use | 0b010, cnt)
    search(x * 10 + 7, use | 0b001, cnt)

res = []
search(0, 0, res)
print(sum(res))

Measured memory_bytes: 9292
#include<iostream>
using namespace std;
#include<vector>
#include<functional>
#include<limits>
template<typename T>
struct segtree{
	function<T(T,T)>calcfn,updatefn;
	int n;
	T defvalue;
	vector<T>dat;
	segtree(int n_=0,T defvalue_=numeric_limits<T>::max(),
		function<T(T,T)>calcfn_=[](T a,T b){return a<b?a:b;},
		function<T(T,T)>updatefn_=[](T a,T b){return b;}
	):defvalue(defvalue_),calcfn(calcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[i*2+1],dat[i*2+2]);
	}
	void update(int i,T a)
	{
		i+=n-1;
		dat[i]=updatefn(dat[i],a);
		while(i>0)
		{
			i=(i-1)/2;
			dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
		}
	}
	T query(int a,int b)//[a,b)
	{
		int L=(a<0?0:a>n?n:a)+n-1;
		int R=(b<0?0:b>n?n:b)+n-1;
		T ret=defvalue;
		for(;L<R;L>>=1,R>>=1)
		{
			if(!(L&1))ret=calcfn(ret,dat[L]);
			if(!(R&1))ret=calcfn(ret,dat[--R]);
		}
		return ret;
	}
};
int N,K;
int P[2<<17];
bool flag[2<<17];
main()
{
	cin>>N>>K;
	segtree<int>X(N,0,[](int a,int b){return a<b?b:a;});
	segtree<int>Y(N,1e9,[](int a,int b){return a>b?b:a;});
	for(int i=0;i<N;i++)
	{
		cin>>P[i];
		X.update(i,P[i]);
		Y.update(i,P[i]);
	}
	int ans=0;
	int p=0;
	int ret=0;
	for(int i=0;i<N;i++)
	{
		if(i>0&&P[i-1]>P[i])p=i;
		if(i-p+1>=K)
		{
			flag[i]=true;
			ret=1;
		}
		if(i>=K-1&&!flag[i])
		{
			if(i==K-1||flag[i-1]||!flag[i-1]&&(P[i-K]!=Y.query(i-K,i)||P[i]!=X.query(i-K+1,i+1)))
			{
				ans++;
			}
		}
	}
	//cout<<ans<<endl;
	//cout<<cnt<<endl;
	cout<<ans+ret<<endl;
}


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

namespace ABC124_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split(' ');
            int a = int.Parse(strs[0]);
            int b = int.Parse(strs[1]);

            int button0 = Math.Max(a, b);

            if (a > b)
            {
                --a;
            }
            else
            {
                --b;
            }

            int button1 = Math.Max(a, b);

            Console.WriteLine($"{button0 + button1}");
        }
    }
}


Measured memory_bytes: 13140
a,b,c = map(int,input().split())
li = [a,b,c]
li.sort()
x = li[0]
y = li[1]
z = li[2]
count_list = []

def search(target,origin):
    tmp = 0
    if target > origin and (target-origin)%2 == 0:
        tmp += (target-origin)//2
    elif target > origin and (target-origin)%2 == 1:
        tmp += (target-origin)//2 + 2
    elif origin > target:
        tmp += origin - target
    return tmp

for t in range(x,z+1):
    tmp = 0
    tmp += search(t,x)
    tmp += search(t,y)
    tmp += search(t,z)
    count_list.append(tmp)
    #print(t)

#print(count_list)
print(min(count_list))

Measured memory_bytes: 38256
N = int(input())
Alist = list(map(int,input().split()))

dailist = [0]*N
Alist.append(0)
dailist.append(0)
max = 0
for i in range(N):
  if Alist[i]>max:
    max=Alist[i]
    #dailist[i+1]=max-Alist[i+1]
    #print("max="+str(max))
  
  if max>Alist[i+1]:
    dailist[i+1]=max-Alist[i+1]
    #print ("dailist="+str(dailist[i+1]))

#print (Alist)
#print (dailist)
del dailist[-1]
print (sum(dailist))

Measured memory_bytes: 32216
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>

#define range(i, n) for (i = 0; i < n; i++) 
#define rrange(i, n) for(i = n-1; i>=0; i--)

using namespace std;

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


int main() {

	int N, K;

	cin >> N >> K;

	vector<pair<long long , long long > >s(N);
	vector<pair<long long , long long > >select;

	vector<bool>neta(N+1, false);
	long long netacount = 0;
	long long sum = 0;
	long long result = 0;

	int i, k, n;
	range(i, N) {
		cin >> s[i].second >> s[i].first;
	}

	sort(s.begin(), s.end());
	reverse(s.begin(), s.end());

	k = 0;
	range(i, K) {
		sum += s[i].first;
		if (neta[s[i].second] == false) {
			neta[s[i].second] = true;
			netacount++;
			continue;
		}
		select.push_back(s[i]);
	}

	result = sum + (netacount * netacount);


	for(i=select.size()-1; i<N; i++) {
		if (netacount >= K)break;
		if (select.size() <= 0)break;
		if (neta[s[i].second] == true) continue;

		sum = (sum - select.back().first) + s[i].first;
		neta[s[i].second] = true;
		netacount++;
		chmax(result, sum + (netacount * netacount));
		select.pop_back();

	}

	cout << dec << result;







	return 0;
}


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

int main()
{
    long long x;
    long long k, d;
    cin >> x >> k >> d;
    x = fabs(x);
    long long go = x / d;
    long long ans = x;
    if (k < go)
    {
        go = k;
        k = 0;
    }
    else
    {
        k -= go;
    }
    ans -= d * go;
    if (k % 2 == 0)
    {
        cout << abs(ans) << endl;
    }
    else
    {
        cout << abs(ans - d) << endl;
    }
}

Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;

int main(){
  double a,b;
  cin>>a>>b;
  int c=a;
  int d=b;
  int x=a/b;
  cout<<x<<" "<<c%d<<" "<<fixed<<setprecision(10)<<a/b<<endl;
}



Measured memory_bytes: 3284
#include <cstdio>
#include <map>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[3*n]; for (int i = 0; i < 3*n; i++) cin >> a[i];
    long long b[n+1], c[n+1];
    long long sum = 0;
    map<int, int> temp;
    int i = 0;
    while (i < n) sum += a[i], temp[a[i]]++, i++;
    b[0] = sum;
    while (i < 2*n) {
        int m = temp.begin()->first;
        if (m < a[i]) {
            if (temp[m] == 1) temp.erase(m);
            else temp[m]--;
            temp[a[i]]++;
            sum += a[i] - m;
        }
        b[i-n+1] = sum;
        i++;
    }
    i = 3*n-1;
    temp.clear();
    sum = 0;
    while (i >= 2*n) sum += a[i], temp[-a[i]]++, i--;
    c[n] = sum;
    while (i >= n) {
        int m = temp.begin()->first;
        if (-m > a[i]) {
            if (temp[m] == 1) temp.erase(m);
            else temp[m]--;
            temp[-a[i]]++;
            sum += a[i] + m;
        }
        c[i-n] = sum;
        i--;
    }

    long long ans = -(1LL<<60);
    for (i = 0; i <= n; i++) ans = max(ans, b[i] - c[i]);
    cout << ans << endl;
}


Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int n;
  cin >> n;
  
  int ans = 0;
  
  for(int i = 0 ; i < n ; i++){
    int a;
    cin >> a;
    ans += a;
  }
  
  cout << ans -n << endl;
}

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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

llint a[55],b[55],c[55],d[55];
llint n,m,q;
vector<llint>v;

int dfs(int p,int x){
	if(p==n+1){
		int sum=0;
		for(int i=1;i<=q;i++){
			if(v[a[i]]+c[i]==v[b[i]])sum+=d[i];
		}
		return sum;
	}
	int ret=0;
	v.push_back(x);
	ret=max(ret,dfs(p+1,x));
	v.pop_back();
	if(x+1<=m)ret=max(ret,dfs(p,x+1));
	return ret;
}

void solve(){
	vector<llint> A(12);
	cin >> n >> m >> q;
	for(int i=1;i<=q;i++){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;b[i]--;
	}
	cout << dfs(1,1) << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long

const unsigned int BIT_FLAG_0 = (1 << 0);  // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1);  // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2);  // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3);  // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4);  // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5);  // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6);  // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7);  // 0000 0000 1000 0000

const double PI = 3.14159265358979323846;

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

#define H_MAX 500
#define W_MAX 500
#define INF 1e9 + 7
const ll mod = 1000000007;

int main() {
    int cnt = 0;
    string S;
    cin >> S;
    if (S == "RRR") {
        cout << 3 << endl;
    } else if (S == "RRS" || S == "SRR") {
        cout << 2 << endl;
    } else if (S == "RSS" || S == "SRS" || S == "SSR" || S == "RSR") {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;
int main()
{
	int i, j, m, n, cnt = 0, cnt1 = 0;
	char str[602];
	for (i = 0; i < 300; i = i + 2) {
		str[i] = '#';
		str[i + 1] = '.';
	}
	while (1) {
		scanf("%d %d", &m, &n);
		if (m == 0 && n == 0) {
			break;
		}
		for (i = 0; i < m; i++) {
			for (j = 0; j < n; j++) {
				if (i % 2 == 0) {
					printf("%c", str[j]);
				}
				else {
					printf("%c", str[j + 1]);

				}
				if (j == j - 1) {
					printf(" ");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = (1LL << 60);
 const int INFI = (1 << 30);

 int main() {
   int A, B; cin >> A >> B;
   cout << A * B << endl;
 }


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

bool is(string s) {
    string t = s;
    reverse(t.begin(),t.end());
    return t == s;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    string s; cin >> s;
    int n = s.size();
    s = '#' + s;
    string a;
    for (int i = 1; i <= (n-1)/2; i++) {
        a += s[i];
    }
    string b;
    for (int i = (n+3)/2; i <= n; i++) {
        b += s[i];
    }
    cout << (is(s.substr(1))&&(is(a)&&is(b))?"Yes": "No") << '\n';
}



Measured memory_bytes: 256
import java.util.*;

public class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    String a = sc.next();
    String b = sc.next();
    
    if(a.equals("H") && b.equals("H")){
      System.out.println("H");
    }else if(a.equals("D") && b.equals("D")){
      System.out.println("H");
    }else if(a.equals("D") && b.equals("H")){
      System.out.println("D");
    }else if(a.equals("H") && b.equals("D")){
      System.out.println("D");
    }
    
  }
  
}

Measured memory_bytes: 35648
#include<bits/stdc++.h>
using namespace std;
string s,s1="AKIHABARA";
int e;
int main(){
	cin>>s;
	if(s.size()-1>8){
		printf("NO");
		return 0;
	}
	for(int i=0;i<s.size();i++){
		if(s[i]==s1[e])e++;
		else{
			if(s1[e]=='A'){
				e++;
				i--;
			}
			else{
				printf("NO");
				return 0;
			}
		}
	}
	if(e<=7){
		printf("NO\n");
	}
	else printf("YES\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
int n,x,sum1=0;
cin>>n;
for(int i=0;i<n;i++)
{
	cin>>x;
	int sum=0;
	for(double j=2;j<=(int) (sqrt(x+0.5));j++)
	{
		if(x%(int)j!=0)
		sum++;
	}
	if(sum==(int)(sqrt(x+0.5))-1)
	sum1++;
}
   cout<<sum1<<endl;
}


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


int map[50][50] = {};
int w,h;
int ans;
int dx[4] = {0,-1,0,1};
int dy[4] = {-1,0,1,0};

void search(int y, int x){

  map[y][x] = 0;
  for(int t = 0; t < 4 ; t++){ 
    int ny = y + dy[t], nx = x + dx[t]; 
    if(nx >= 0 && ny >= 0 && nx < w && ny < h && map[ny][nx] == 1){
      //cout << "IN ";
      ans++;
      search(ny,nx);
    }
  }
}


int main(){
  
  while(1){
    for(int j = 0; j < 50 ; j++){
      for(int i = 0; i < 50 ; i++){
	map[j][i] = 0;
      }
    }
    
    ans = 1;

    cin >> w >> h;
    if(w == 0 && h == 0) break;

    int stx,sty;
    for(int k = 0; k < h ; k++){
      string s;
      cin >> s;
      for(int i = 0; i < w ; i++){
	if(s[i] == '.') map[k][i] = 1;
	if(s[i] == '#') map[k][i] = 0;
	if(s[i] == '@') {
	  map[k][i] = 2;
	  stx = i;
	  sty = k;
	}
      }
    }


 
    //竪臓即巽造尊
    /*
    for(int j = 0; j < h ; j++){
      for(int i = 0; i < w ; i++){
	cout << map[j][i];
      }
      cout << endl;
    }
    cout << endl;
    */
    search(sty,stx);
    cout << ans << endl;
	  
  }
  return 0;
}

Measured memory_bytes: 1220
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int A,B,C,D,E;
int main() {
	cin>>A>>B>>C>>D>>E;
	int S=0,T=0;
	if(A<B && A<C)S=A;
	if(B<C && B<A)S=B;
	if(C<A && C<B)S=C;
	if(A<C && B<C && A==B)S=A;
	if(B<A && C<A && B==C)S=B;
	if(C<B && A<B && C==A)S=C;

	if(D<E)T=D;
	if(E<D || D==E)T=E;
	cout<<S+T-50<<endl;

	return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll Min = *min_element(a.begin(),a.end());
    ll Max = *max_element(a.begin(), a.end());
    ll Sum = accumulate(a.begin(), a.end(), 0ll);
    printf("%lld %lld %lld\n",Min,Max,Sum);
    return 0;
}


Measured memory_bytes: 3312
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second



using namespace __gnu_pbds;
using namespace std;
 const int mod=1e9+7;
// const int mod=998244353;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i; 


int pow(int a, int b)
{
    int prod=1;
    int mult=a%mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod*=mult;
            prod%=mod;
        }
        mult*=mult;
        mult%=mod;
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int mod)
{
    return pow(q, mod-2);
}
const int MAXN=2e5;
std::vector <int> prime;
bool is_composite[MAXN];
int phi[MAXN];

void sieve (int n) {
    std::fill (is_composite, is_composite + n, false);
    phi[1] = 1;
    for (int i = 2; i < n; ++i) {
        if (!is_composite[i]) {
            prime.push_back (i);
            phi[i] = - 1;                 //i is prime
        }
        for (int j = 0; j < prime.size () && i * prime[j] < n; ++j) {
            is_composite[i * prime[j]] = true;
            if (i % prime[j] == 0) {
                phi[i * prime[j]] = 0;  //prime[j] divides i
                break;
            } else {
                phi[i * prime[j]] = phi[i] * phi[prime[j]]; //prime[j] does not divide i
            }
        }
    }
}

signed main()

{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
       cout.tie(NULL);
     #ifndef ONLINE_JUDGE
        if(fopen("INPUT.txt","r"))
        {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
        }
     #endif
    auto clk=clock(); 
    // -------------------------------------Code starts here---------------------------------------------------------------------     
 
    int n;
    cin>>n;
    int k;
    cin>>k;
    vector<int> function(k+1);
    sieve(k+100);
    for(int i=1;i<=k;i++)
        function[i]=i;
    for(int i=1;i<=k;i++)
    {
        for(int j=2;j*i<=k;j++)
        {
            function[j*i]+=i*phi[j]; 
            function[j*i]=(mod+function[j*i])%mod;
        }
    }

    //create linear mappping
    int sum=0;
    for(int i=1;i<=k;i++)
    {
        sum+=((function[i]%mod) * (pow((int)k/(int)i, n)))%mod;
        sum%=mod;
    }
    cout<<sum<<endl;

    // -------------------------------------Code ends here------------------------------------------------------------------


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
 }


Measured memory_bytes: 5040
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	ll a, b, c; cin >> a >> b >> c;
    //cerr << poww(1) << " " << poww(36) << endl;
    if(c - a - b <= 2) {
        cout << "No" << endl;
        return;
    }
    if(4LL * a * b < (c - a - b) * (c - a - b)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <cstdio>
#include <iomanip>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;(i)>=0;(i)--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

typedef long long ll;

int main(){

    int A[4];
    int B[4];
    REP(i,4)cin>>A[i];
    REP(i,4)cin>>B[i];
    
    int a=0,b=0;
    REP(i,4){
        a+=A[i];
        b+=B[i];
    }
    
    cout<<max(a,b)<<endl;
    
    return 0;
    
}

Measured memory_bytes: 3096
#define _USE_MATH_DEFINES
#include <math.h>
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int k,x;
    cin >> k >> x;
    if(500 * k >= x)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

x,y = inpl()
if x >= 0 and y >= 0:
    if x <= y:
        print(y-x)
    else:
        if x == 0 or y == 0:
            print(x+y+1)
        else:
            print(x-y+2)
elif x < 0 and y < 0:
    if x <= y:
        print(y-x)
    else:
        print(x-y+2)
else:
    if x <= y:
        if -x > y:
            if y == 0:
                print(-x)
            else:
                print(1-y-x)
        else:
            print(x+y+1)
    else:
        print(abs(x+y)+1)


Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <random>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	int A = rei();
	int B = rei();
	int C = rei();
	int ans = max(C+B-A,0);
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

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

bool used[30];

int main(){
    string s;
    cin >> s;
    for(int i = 0;i < s.length();++i){
        used[s[i] - 'a'] = 1;
    }

    bool ed = 0;

    for(int i = 0;i < 26;++i){
        if(!used[i]){
            cout << char(i + 'a') << "\n";
            ed = 1;
            break;
        }
    }

    if(!ed) cout << "None\n";

    return 0;
}


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

using namespace std;
int main()
{
	int n, m, l[100000], r[100000];
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> l[i] >> r[i];
	}
	sort(l, l + m);
	sort(r, r + m);
	if (r[0] - l[m - 1] + 1 <= 0) {
		cout << "0" << endl;
	}
	else {
		cout << r[0] - l[m - 1] + 1 << endl;
	}
    return 0;
}

Measured memory_bytes: 1024
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let S = rl();

    let t = S.chars().map(|_| 'x').collect::<String>();

    println!("{}", t)
}


Measured memory_bytes: 4352
#include<stdio.h>
int n,m,k,srx;
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<n;++i)
	{srx=i*m;
	if(srx==k)
	{printf("Yes\n");
	return 0;}
	for(int j=0;j<m;++j)
	{srx+=(n-i)-i;
	if(srx==k)
	{printf("Yes\n");
	return 0;}}}
	printf("No\n");
	return 0;
}


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

int main(void) {
    int a, b;
    cin >> a >> b;
    int c = 1;
    int ans = 0;
    while (c < b) {
        c--;
        c += a;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
N = int(input())
A = list(map(int, input().split()))
for i in range(len(A)):
  if A[i]%2 == 0:
    if A[i]%3 != 0 and A[i]%5 != 0:
      A[i] = 0
if 0 in A:
  print('DENIED')
else:
  print('APPROVED')

Measured memory_bytes: 3060
/*
貪欲
後ろから見る
DP
順位表をチェック
二分探索


*/
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include<tuple>
using namespace std;
#define INF 3e18+7
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,ll>,ll> p;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);

//http://kmjp.hatenablog.jp/entry/2019/11/24/0900

ll A[210000],S[210000];

int main(){
    int N,K;
    cin>>N>>K;
    map<ll,int> M;
    ll ret=0;
    M[0]=1;
    for(int i=0;i<N;i++){
        cin>>A[i];
        S[i+1]=S[i]+A[i]+K-1;
        if(i+1-K>=0) M[ S[i+1-K]%K ]--;
        ret+=M[S[i+1]%K];
        M[S[i+1]%K]++;
    }
    cout<<ret<<endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
ll n,a,b,ans;
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(a); read(b);
	if (a%2==b%2) printf("%lld\n",(b-a)/2);
	else {
		ans=min(a-1,n-b);
		if (b-a>1) {
			ans+=(b-a-1)/2+1;
		} else ans=min(b-1,n-a);
		printf("%lld\n",ans);
	}
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
string s; cin>>s;
string t=s;
reverse(t.begin(), t.end());

int ret=0;
for(int i=0; i<s.size(); i++) {
 if(s[i]!=t[i])ret++;
}
cout<<ret/2<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        
        int count = 0;
        
        for(int i=0; i<=a; i++){
            for(int j=0; j<=b; j++){
                for(int k=0; k<=c; k++){
                    //System.out.println("i;" + i +", j;" + j + ", k;" + k);
                    int result = 500*i + 100*j + 50*k;
                    //System.out.println(result);
                    if(result == x){
                        count++;
                    }
                }
            }
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 21588
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    print(n**3)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};
ll h, w, n;
ll sr, sc;
string s, t;

int main() {
	IOS;
	ll h, w, n;
	ll sr, sc;
	string s, t;
	cin >> h >> w >> n;
	cin >> sr >> sc >> s >> t;
	bool ok = false;
	ll now  = sc;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') now++;
		if (now > w) ok = true;
		if (t[i] == 'L' && now > 1) now--;
	}
	now = sr;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'D') now++;
		if (now > h) ok = true;
		if (t[i] == 'U' && now > 1) now--;
	}
	now = sc;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'L') now--;
		if (now < 1) ok = true;
		if (t[i] == 'R' && now < w) now++;
	}
	now = sr;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'U') now--;
		if (now < 1) ok = true;
		if (t[i] == 'D' && now < h) now++;
	}
	dump(!ok ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 776
#include <iostream>

using namespace std;

bool inRect(
    const int &right,
    const int &top,  
    const int &x, 
    const int &y, 
    const int &r
){
    if(x-r < 0)     return false;
    if(x+r > right) return false;
    if(y-r < 0)     return false;
    if(y+r > top)   return false;
    return true;
}

int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    
    cout << (inRect(W, H, x, y, r)? "Yes": "No") << endl;

    return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
 string s,t;
  ll n,m,k,x=0,y=0,c=0,q,ans=0;
  cin>>n>>m>>k;
  x = min(n,k);
  n-=x;
  k-=x;
  x = min(m,k);
  m-=x;

  
  
  cout<<n<<" "<<m<<"\n";
}

signed main(){
     
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


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

typedef long long ll;
typedef pair<int, int> pii;

const int MOD = 1'000'000'007;

int mult(int a, int b) {
	return 1LL * a * b % MOD;
}

int add(int a, int b) {
	return (a + b) % MOD;
}

int sub(int a, int b) {
	return (a - b + MOD) % MOD;
}

int binPow(int a, int pow) {
	int res = 1;

	while (pow > 0) {
		if (pow & 1) {
			res = mult(res, a);
		}

		a = mult(a, a);
		pow /= 2;
	}

	return res;
}

int mu[100'000 + 100];

void precalc() {
	vector<int> primes;
	vector<int> lp(100'000 + 100);
	mu[1] = 1;

	for (int i = 2; i <= 100'000; i++) {
		if (lp[i] == 0) {
			lp[i] = i;
			primes.emplace_back(i);
			mu[i] = -1;
		} else if ((i / lp[i]) % lp[i] == 0) {
			mu[i] = 0;
		} else {
			mu[i] = mu[lp[i]] * mu[i / lp[i]];
		}

		for (int j = 0; j < primes.size() && primes[j] <= lp[i]; j++) {
			if (primes[j] * i > 100'000) {
				break;
			}
			lp[primes[j] * i] = primes[j];
		}
	}
}

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

	precalc();

	int n, k;
	cin >> n >> k;

	int res = 0;

	for (int i = 1; i <= k; i++) {
		int cnt = 0;

		for (int j = i; j <= k; j += i) {
			cnt = add(cnt, mu[j / i] * binPow(k / j, n));
		}

		res = add(res, mult(cnt, i));
	}

	cout << res;

	return 0;
}

Measured memory_bytes: 4140
#include<cstdio>

const int N = 50;

char s[N + 2];
int n, m, a[N + 2][N + 2], tr[4][2] = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} }, cnt;

bool in(int x, int y)
{
	return x >= 0 && x < n && y >= 0 && y < m;
}

bool sol(int x, int y, int d)
{
	if (!x && !y  && cnt == 4)
		return 1;
	if (!in(x, y) || !a[x][y])
		return 0;
	a[x][y] = 0;
	if ((!x || x == n - 1) && (!y || y == m - 1))
		cnt++;
	for (int i = 1; i >= -1; i--)
	{
		int t = (d + i + 4) % 4;
		if (sol(x + tr[t][0], y + tr[t][1], t))
			return 1;
	}
	if ((!x || x == n - 1) && (!y || y == m - 1))
		cnt--;
	return 0;
}

int main()
{
	for (; scanf("%d%d", &n, &m) && (n || m); )
	{
		for (int i = 0; i < n; i++)
		{
			scanf("%s", s);
			for (int j = 0; j < m; j++)
				a[i][j] = s[j] == '.';
		}
		cnt = 0;
		printf("%s\n", sol(0, 0, 1) ? "YES" : "NO");
	}
}

Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int k,n;
    in>>n>>k;
    vector<int> p(n);
    for(auto&i:p) in>>i;
    int s{},ans;
    fr(i,k) s+=p[i]+1;
    ans=s;
    fr(i,n-k) s-=p[i],s+=p[i+k],ans=max(ans,s);
    cout<<setprecision(20)<<ans/2.0<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin >> n;
	long long s[n+1];
	for (int i=1; i<=n; i++){
		cin >> s[i];
		if (s[i]==0){
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i=2; i<=n; i++){
		if(1000000000000000000ll/s[i-1]<s[i]){
			cout << -1 << endl;
			return 0; 
		}
		s[i]*=s[i-1];
	}
	cout << s[n] << endl;
	return 0;
}


Measured memory_bytes: 4408
# E - Roadwork
from bisect import bisect_left
from operator import itemgetter


def main():
    N, Q, *STXD = map(int, open(0).read().split())
    STX, D = sorted(zip(*[iter(STXD[: 3 * N])] * 3), key=itemgetter(2)), STXD[3 * N :]
    ans = [-1] * Q
    road = [-1] * Q  # (road[i] = x) := if -1: open / else: closed until x
    for s, t, x in STX:
        l, r = bisect_left(D, s - x), bisect_left(D, t - x)
        while l < r:
            if road[l] == -1:
                ans[l] = x
                road[l] = r
                l += 1
            else:
                l = road[l]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 96932
#include<bits/stdc++.h>
using namespace std; typedef long long int ll;
#define all(a) a.begin() , a.end()
#define print(x)   cout<<x<<"\n";
const ll M = ll(1e9 + 7);
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << ", "; } os << "]\n"; return os;}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{os << "["; for (auto it : v) {os << it; if (it != *v.rbegin())os << ", ";} os << "]\n"; return os;}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v)
{for (auto it : v)os << it.first << " : " << it.second << "\n"; return os;}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v)
{os << "("; os << v.first << ", " << v.second << ")"; return os;}
/***********************************************************************/
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    ll n;
    cin >> n;
    vector<ll> a(n);
    for (auto& x : a)   cin >> x;
    vector<ll> dp(n);
    dp[1] = abs(a[1] - a[0]);
    for (ll i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
    }
    cout << dp[n-1];
}

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

int main(){
  int N;
  cin >> N;
  vector<long long> T(N);
  vector<long long> A(N);
  for(int i=0; i<N; i++) cin >> T.at(i) >> A.at(i);
  vector<long long> taka(N);
  vector<long long> aoki(N);
  taka.at(0)=T.at(0);
  aoki.at(0)=A.at(0);
  for(int i=1; i<N; i++){
    long long j=1;
    j=max((taka.at(i-1)+T.at(i)-1)/T.at(i) , (aoki.at(i-1)+A.at(i)-1)/A.at(i));
    taka.at(i)=T.at(i)*j;
    aoki.at(i)=A.at(i)*j;
  }
  cout << taka.at(N-1)+aoki.at(N-1) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  int i,j,total[26],sstr;
  char str[1200],temp='a';
  for(i=0;i<26;i++)total[i]=0;
  while(gets(str)!=0){
    sstr=strlen(str);
    for(i=0;i<sstr;i++){
      if(64<str[i] && str[i]<91)str[i]+=32;
      for(j=0;j<26;j++){
	temp='a'+j;
	if(str[i]==temp){
	  total[j]++;
	}
      }
    }
  }
  for(i=0;i<26;i++){
    printf("%c : %d\n",'a'+i,total[i]);
  }
  return(0);
}

Measured memory_bytes: 524
#include<cstdio>
main(){int a,b,c,d;while(scanf("%d%d%d",&a,&b,&c)!=EOF){d=a*10000+b*100+c;if(d<18680908){printf("pre-meiji\n");continue;}if(d<19120730){printf("meiji %d %d %d\n",a-1867,b,c);continue;}if(d<19261225){printf("taisho %d %d %d\n",a-1911,b,c);continue;}if(d<19890108){printf("showa %d %d %d\n",a-1925,b,c);continue;}printf("heisei %d %d %d\n",a-1988,b,c);}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  ll ans=0;
  REP(x,1,10) {
    REP(y,1,10) {
      REP(z,1,10) {
        vector<int> v;
        rep(i,x) v.pb(3);
        rep(i,y) v.pb(5);
        rep(i,z) v.pb(7);
        ll s=0;
        rep(i,v.size()) {
          s*=10;
          s+=v[i];
        }
        if(s>n) break;
        do {
          s=0;
          rep(i,v.size()) {
            s*=10;
            s+=v[i];
          }
          if(s<=n) ans++;
        } while(next_permutation(all(v)));
      }
    }
  }
  pr(ans);
}

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


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ERedAndGreenApples {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int X, Y, A, B, C;
        cin >> X >> Y >> A >> B >> C;
        vector<int> p(A), q(B), r(C);
        REP(i, A) cin >> p[i];
        REP(i, B) cin >> q[i];
        REP(i, C) cin >> r[i];
        priority_queue<int, vector<int>, greater<>> pq, qq;
        REP(i, A) {
            pq.push(p[i]);
            if (pq.size() > X) {
                pq.pop();
            }
        }
        REP(i, B) {
            qq.push(q[i]);
            if (qq.size() > Y) {
                qq.pop();
            }
        }

        priority_queue<int> rq;
        REP(i, C) {
            rq.push(r[i]);
        }
        while (!rq.empty()) {
            if (rq.top() <= pq.top() && rq.top() <= qq.top()) break;

            if (pq.top() < qq.top()) {
                pq.pop();
                pq.push(rq.top());
            } else {
                qq.pop();
                qq.push(rq.top());
            }
            rq.pop();
        }

        int res = 0;
        while (!pq.empty()) {
            res += pq.top();
            pq.pop();
        }
        while (!qq.empty()) {
            res += qq.top();
            qq.pop();
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ERedAndGreenApples solver;
    solver.solve(in, out);
    return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
double eps = 0.0000000000001;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<long long, long long>> ps;
  vector<pair<long long, long long>> qs;
  for (int i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) {
    } else {
      ps.emplace_back(x, y);
      qs.emplace_back(x, y);
      qs.emplace_back(-x, -y);
      qs.emplace_back(-y, x);
      qs.emplace_back(y, -x);
    }
  }
  n = ps.size();
  long long ans = 0.;
  for (int i = 0; i < qs.size(); i++) {
    long long x = 0, y = 0, dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0;
    for (int j = 0; j < n; j++) {
      if (qs[i].first * ps[j].first + qs[i].second * ps[j].second > 0) {
        x += ps[j].first;
        y += ps[j].second;
      }
      if (qs[i].first * ps[j].first + qs[i].second * ps[j].second == 0) {
        if (qs[i].first * ps[j].second - qs[i].second * ps[j].first > 0) {
          dx1 += ps[j].first;
          dy1 += ps[j].second;
        } else {
          dx2 += ps[j].first;
          dy2 += ps[j].second;
        }
      }
    }
    ans = max(ans, x * x + y * y);
    ans = max(ans, (x + dx1) * (x + dx1) + (y + dy1) * (y + dy1));
    ans = max(ans, (x + dx2) * (x + dx2) + (y + dy2) * (y + dy2));
  }
  printf("%.20lf\n", (double) sqrt((long double) ans));
  return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (r, g, b, n) = scan!(usize, usize, usize, usize);
    let mut ans = 0;
    for i in 0..3001 {
        for j in 0..3001 {
            if n >= i * r + j * g && (n - i * r - j * g) % b == 0 {
                ans += 1;
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352