akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
using namespace std;

int main(void) {
    string T,S; 
    cin >> T;
    cin >> S;
    int i = 0;
    if (T == S) {
        cout << "Yes" << endl;
        return 0;
    }
    while(i < T.size()) {
        char lastChar = T[T.size() - 1];
        T = T.substr(0, T.size() - 1);
        T = lastChar + T;
        if (T == S) {
            cout << "Yes" << endl;
            return 0;
        }
        i++;
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

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

	ll n, k;
	cin >> n >> k;
	vector<ll> x(n), y(n);
	vector<char> c(n);
	rep(i, n) {
		cin >> x[i] >> y[i] >> c[i];
	}

	// マス(i,j)とマス(i + k,j)の色は異なる
	// マス(i,j)とマス(i j + k)の色も異なる
	// すべて左端に寄せる

	int sum = 0;

	vector<vector<ll>> wNum(2 * k + 1, vector<ll>(2 * k + 1, 0));
	int black = 0;

	rep(i, n) {
		if (x[i] >= 2 * k) {
			x[i] %= 2 * k;
		}
		if (y[i] >= 2 * k) {
			y[i] %= 2 * k;
		}
		if (c[i] == 'B') {
			wNum[x[i] + 1][y[i] + 1]--;
			sum--;
			black++;
		}
		else {
			wNum[x[i] + 1][y[i] + 1]++;
			sum++;
		}
	}

	Rep(i, 1, 2 * k + 1) {
		Rep(j, 1, 2 * k + 1) {
			wNum[i][j] += wNum[i][j - 1];
		}
	}

	Rep(i, 1, 2 * k + 1) {
		Rep(j, 1, 2 * k + 1) {
			wNum[i][j] += wNum[i - 1][j];
		}
	}

	int ans = 0;

	rep(i, k + 1) {
		rep(j, k + 1) {
			int tmp = 0;
			int a = wNum[i][j];
			int b = wNum[i + k][j + k] - wNum[i + k][j] - wNum[i][j + k] + a;
			int c = wNum[i][2 * k] - wNum[i][j + k];
			int d = wNum[2 * k][j] - wNum[i + k][j];
			int e = wNum[2 * k][2 * k] - wNum[2 * k][j + k]
				- wNum[i + k][2 * k] + wNum[i + k][j + k];
			tmp = a + b + c + d + e;
			ans = max(ans, black + max(tmp, sum - tmp));
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 33280
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

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

int anser(string s) {
	if (s == "Male") {
		return 0;
	}
	if (s == "Female") {
		return 1;
	}
	if (s == "Vacant") {
		exit(0);
	}
	exit(-1);
}

int query(int p) {
	cout << p << endl;
	string s;
	cin >> s;
	return anser(s);

}



bool bingo(int d, int v1, int v2) {
	if (d % 2 == 0) {
		return v1 != v2;
	} else {
		return v1 == v2;
	}
}

int main() {
	int n;
	cin >> n;
	int from = 0;
	int to = n - 1;

	int from_q = query(from);
	int to_q = query(to);

	while(true) {
		int mid = from + (to - from) / 2;
		int mid_q = query(mid);

		if (bingo(mid - from,from_q, mid_q)) {
			to = mid;
			to_q = mid_q;
		} else if (bingo(to - mid, mid_q, to_q)) {
			from = mid;
			from_q = mid_q;
		} else {
			int a[0];
			a[-10000000] = 0;
		}
	}

	return 0;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

int st(int a, int b) {
    return max(to_string(a).size(), to_string(b).size());
}

void solve() {
    int n;
    cin >> n;
    int ans = LLONG_MAX;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            int a = i, b = n / i;
            ans = min(ans, st(a, b));
        }
    }
    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 2005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
#define x1 dojadkoa
#define y1 dsaijdakji
#define x2 dsajdiosa
#define y2 diaodsdsa
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,m,q;
char str[MAXN][MAXN];
int s[MAXN][MAXN];
int sum[MAXN][MAXN];
int row[MAXN][MAXN];
int col[MAXN][MAXN];
void prefix_sum(int a[][MAXN])
{
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            a[i][j]+=a[i][j-1];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            a[i][j]+=a[i-1][j];
}
int compute_area(int a[][MAXN],int x1,int y1,int x2,int y2)
{
    return a[x2][y2]+a[x1-1][y1-1]-a[x1-1][y2]-a[x2][y1-1]; 
}
int main()
{
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=n;i++) 
    {
        scanf("%s",str[i]+1);
        for(int j=1;j<=m;j++) sum[i][j]=s[i][j]=str[i][j]-'0';
    }
    for(int i=1;i<=n-1;i++)
        for(int j=1;j<=m;j++)
            if(s[i][j]&&s[i+1][j]) row[i][j]++;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m-1;j++)
            if(s[i][j]&&s[i][j+1]) col[i][j]++;
    prefix_sum(sum);prefix_sum(row);prefix_sum(col);
    for(int i=0;i<q;i++)
    {
        int x1,y1,x2,y2;
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        printf("%d\n",compute_area(sum,x1,y1,x2,y2)-compute_area(row,x1,y1,x2-1,y2)-compute_area(col,x1,y1,x2,y2-1));
    }
    return 0;
}



Measured memory_bytes: 68480
h,w = map(int, input().split())
A = [input() for _ in range(h)]

dh = []
for l in A:
    if l[0] == '.' and len(set(l)) == 1:
        continue
    dh.append(l)

wj = []
for j in range(w):
    for i in range(len(dh)):
        if dh[i][j] == '#':
            wj.append(j)
            break

ans = ['' for _ in range(len(dh))]
for i in range(len(ans)):
    for j in wj:
        ans[i] += dh[i][j]
print('\n'.join(ans))


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {

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

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());
      String line = in.readLine();
      int nHalf = n >> 1;

      int[] seqA = new int[nHalf];
      int[] seqB = new int[nHalf];
      int[][] seq = {seqA, seqB};

      Integer num;
      Map<Integer,Integer> mapA = new HashMap<>();
      Map<Integer,Integer> mapB = new HashMap<>();
      List<Map<Integer,Integer>> aMap = new ArrayList<>();
      aMap.add(mapA);
      aMap.add(mapB);
      int offset=0,next=0;
      char regx = ' ';

      for(int i=0; i<n; i++) {
        if((next = line.indexOf(regx,offset)) == -1)
          next = line.length();
        num = new Integer(line.substring(offset, next));
        offset = ++next;

        seq[(i&1)][i>>1] = num;
        aMap.get(i&1).merge(num, 1, Integer::sum);
      }

      int[] vm1 = {0,0};
      int[] vm2 = {0,0};
      int[] x   = {0,0};

      for (int i=0; i<aMap.size(); i++) {
        for (Map.Entry<Integer,Integer> m : aMap.get(i).entrySet()) {
          int val = m.getValue();
          if(vm1[i] <val) {
            vm2[i] = vm1[i];
            vm1[i] = val;
            x[i]  = m.getKey();
          } else if(vm2[i] < val) {
            vm2[i] = val;
          }
        }
      }

      int ans = 0;
      int cca1 = nHalf - vm1[0];
      int ccb1 = nHalf - vm1[1];
      int cca2 = nHalf - vm2[0];
      int ccb2 = nHalf - vm2[1];

      if(x[0] == x[1])
        ans = cca2 > ccb2 ? cca1 + ccb2 : cca2 + ccb1;
      else
        ans = cca1 + ccb1;

      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 46976
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 2000010
#define MO 1000000007
int fac[MAXN],inv[MAXN];
void Pre()
{
	fac[0]=inv[0]=inv[1]=1;
	for(int i=1;i<MAXN;i++)
		fac[i]=1LL*fac[i-1]*i%MO;
	for(int i=2;i<MAXN;i++)
		inv[i]=1LL*(MO-MO/i)*inv[MO%i]%MO;
	for(int i=2;i<MAXN;i++)
		inv[i]=1LL*inv[i]*inv[i-1]%MO;
}
int C(int x1,int y1,int x2,int y2)
{
	return 1LL*fac[x1-x2+y1-y2]*inv[x1-x2]%MO*inv[y1-y2]%MO;
}
int x3,y3,x4,y4,ans;
int Solve(int x1,int y1,int x2,int y2)
{
	int ret=0;
	for(int i=x3;i<=x4;i++) (ret+=1LL*C(i,y3-1,x1,y1)*C(x2,y2,i,y3)%MO*(-i-y3)%MO)%=MO;
	for(int i=y3;i<=y4;i++) (ret+=1LL*C(x3-1,i,x1,y1)*C(x2,y2,x3,i)%MO*(-i-x3)%MO)%=MO;
	for(int i=x3;i<=x4;i++) (ret+=1LL*C(i,y4,x1,y1)*C(x2,y2,i,y4+1)%MO*(y4+1+i)%MO)%=MO;
	for(int i=y3;i<=y4;i++) (ret+=1LL*C(x4,i,x1,y1)*C(x2,y2,x4+1,i)%MO*(x4+1+i)%MO)%=MO;
	return ret;
}
int x[8],y[8],c[8];
int main()
{
	Pre();
	scanf("%d%d%d%d%d%d",&x[0],&x[1],&x3,&x4,&x[4],&x[5]);
	scanf("%d%d%d%d%d%d",&y[0],&y[1],&y3,&y4,&y[4],&y[5]);
	c[0]=c[1]=c[4]=c[5]=1;
	c[2]=c[3]=c[6]=c[7]=-1;
	x[0]--,y[0]--,x[5]++,y[5]++;
	x[2]=x[0],x[3]=x[1],y[2]=y[1],y[3]=y[0];
	x[6]=x[4],x[7]=x[5],y[6]=y[5],y[7]=y[4];
	for(int i=0;i<4;i++)
		for(int j=4;j<8;j++)
			(ans+=1LL*Solve(x[i],y[i],x[j],y[j])*c[i]*c[j]%MO)%=MO;
	ans=(ans%MO+MO)%MO;
	printf("%d\n",ans);
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define ul unsigned long long
#define ll long long
#define ld long double

int main()
{
  ll n;
  cin>>n;
  ll ac[200001], a[200001],cc[200001], ci;
  fill(cc, cc + 200001, 0);
  fill(ac, ac + 200001, 0);
  for (ll i = 0; i < n; i++)
  {
    cin>>ci;
    a[i]=ci;
    ac[ci]++;
  }
  ul ct=0,cv,cu[200001];
  fill(cu,cu+200001,1);
  for (ll i = 0; i < n; i++)
  {
    cv=ac[a[i]];
    //cout<<cv<<" ";
    if (cu[a[i]]) ct+=cv*(cv-1)/2;
    cu[a[i]] = 0;
    cc[i] = cv - 1;
    //cout<<ct<<endl;
  }
  for (ll i = 0; i < n; i++)
  {
    //cout<<cc[i]<<" ";
    cout<<(ct-cc[i])<<endl;
  }
  
  

  return 0;
}


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

int main() {
	int sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;
	for (int i = 0; i < gy - sy; i++) cout << "U";
	for (int i = 0; i < gx - sx; i++) cout << "R";
	for (int i = 0; i < gy - sy; i++) cout << "D";
	for (int i = 0; i < gx - sx; i++) cout << "L";
	cout << "L";
	for (int i = 0; i < gy - sy + 1; i++) cout << "U";
	for (int i = 0; i < gx - sx + 1; i++) cout << "R";
	cout << "DR";
	for (int i = 0; i < gy - sy + 1; i++) cout << "D";
	for (int i = 0; i < gx - sx + 1; i++) cout << "L";
	cout << "U" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a[101],c,d,i;
  scanf("%d",&c);
  for(i=0;i<c;i++){
    scanf("%d",&a[i]);}
  d=c-1;
  for(i=d;i>=0;i--){
    if(i==d){
    printf("%d",a[i]);}
    else{
    printf(" %d",a[i]);}
  }
  printf("\n");
  return 0;
}


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

using namespace std;

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

    set<char> st(s.begin(), s.end());
    if (st.size() == s.size()) {
        cout << "yes" << endl;
    } else {
        cout << "no" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
/// Bismillah Hir Rahmanir Rahim

#include <bits/stdc++.h>

using namespace std;

#define PI                    acos(-1.0)
#define Pi                    3.141592653589793
#define ff                    first
#define ss                    second
#define pb                    push_back
#define space                 " "
#define all(x)                (x).begin(), (x).end()
#define clr(ar)               memset(ar, 0, sizeof(ar))
#define eprintf(...)          fprintf(stderr, __VA_ARGS__)

/*
template <class T> T gcd(T a,T b){ if(b == 0) return a; return gcd( b,a % b ); }
template <class T> T lcm(T a, T b ){ return ( a / gcd( a,b ) ) * b; }
template<class T> string ToString(const T &x){ stringstream s; s << x; return s.str(); }
template<class T> int ToInteger(const T &x){ stringstream s; s << x; int r; s >> r; return r; }
*/

const int dr[] = { -1, 1, 0, 0 }; /// 4 side moves.
const int dc[] = { 0, 0, -1, 1 };
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }; /// 8 side moves.
const int dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
const int kr[] = { 1, 1, -1, -1, 2, 2, -2, -2 }; /// Knight Moves.
const int kc[] = { 2, -2, 2, -2, 1, -1, 1, -1 };

typedef  long long int            ll;
typedef  map<string,int>          msi;
typedef  map<string, string>      mss;
typedef  map<int,int>	          mii;
typedef  map<ll, ll>              mll;
typedef  map<char,int>            mci;
typedef  map<int,string>	      mis;
typedef  pair<int,int> 	          ii;
typedef  pair<string, int>        psi;
typedef  pair<string, string>     pss;
typedef  vector<int> 	          vi;
typedef  vector<string> 	      vs;
typedef  vector<char>	          vc;
typedef  vector< ii >             vii;

template<class T1> void deb(T1 e1)
{
    cout << e1 << endl;
}
template<class T1,class T2> void deb(T1 e1, T2 e2)
{
    cout << e1 << space << e2 << endl;
}
template<class T1,class T2,class T3> void deb(T1 e1, T2 e2, T3 e3)
{
    cout << e1 << space << e2 << space << e3 << endl;
}

#define sf                    scanf
#define pf                    printf

#define sf1(a)                scanf("%d", &a)
#define sf2(a,b)              scanf("%d %d",&a, &b)
#define sf3(a,b,c)            scanf("%d %d %d", &a, &b, &c)
#define sf4(a,b,c,d)          scanf("%d %d %d %d", &a, &b, &c, &d)

#define sf1ll(a)              scanf("%I64d", &a)
#define sf2ll(a,b)            scanf("%I64d %I64d", &a, &b)
#define sf3ll(a,b,c)          scanf("%I64d %I64d %I64d", &a, &b, &c)
#define sf4ll(a,b,c,d)        scanf("%I64d %I64d %I64d %I64d", &a, &b, &c, &d)

#define READ                  freopen("in.txt", "r", stdin);
#define WRITE                 freopen("out.txt", "w", stdout);
/// The End.

void check_time()
{
#ifdef the_badcoder
    eprintf("%.5lf\n", (double)clock() / CLOCKS_PER_SEC);
#endif
}

const int res = 1e5 + 50;
const ll mod = 1e9 + 7;



int main()
{
    string s, ch = "";

    cin >> s;

    for( int i = 0; i < s.size(); i++ )
    {
        if( (i + 1) % 2 == 1 ){
            ch += s[i];
        }
    }

    deb( ch );

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<pair<int,int>> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i].first;
    A[i].second=i+1;
  }
  sort(A.begin(),A.end());
  for(int i=0; i<N; i++) cout << A[i].second << ' ';
  cout << endl;
}

Measured memory_bytes: 1536
N,M=map(int,input().split())

def check(i):
    if M<i*2:
        return False
    if N+(M-i*2)//2<i:
        return False
    return True

r=M//2+1
l=0
while r-l>1:
    mid=(r+l)//2
    #print(mid,check(mid))
    if check(mid):
        l=mid
    else:
        r=mid
print(l)

Measured memory_bytes: 2940
import collections

sequence_num=int(input())
count=0
even_sequence_list=[]
odd_sequence_list=[]
sequence_list=list(map(int,input().split()))
for i in range(sequence_num):
	if i%2 == 0:
		even_sequence_list.append(sequence_list[i])
	else:
		odd_sequence_list.append(sequence_list[i])
even_mode=collections.Counter(even_sequence_list).most_common()[0][0]
odd_mode=collections.Counter(odd_sequence_list).most_common()[0][0]
if even_mode != odd_mode:
	for i in even_sequence_list:
		if i != even_mode:
			count+=1
	for j in odd_sequence_list:
		if j != odd_mode:
			count+=1
	print(count)
else:
	even_counter=collections.Counter(even_sequence_list)
	odd_counter=collections.Counter(odd_sequence_list)
	if len(even_counter.keys()) == 1 and len(odd_counter.keys()) == 1:
		even_mode=0
		for i in even_sequence_list:
			if i != even_mode:
				count+=1
		for j in odd_sequence_list:
			if j != odd_mode:
				count+=1
		print(count)
	elif len(even_counter.keys()) != 1 and len(odd_counter.keys()) == 1:
		even_mode=collections.Counter(even_sequence_list).most_common()[1][0]
		for i in even_sequence_list:
			if i != even_mode:
				count+=1
		for j in odd_sequence_list:
			if j != odd_mode:
				count+=1
		print(count)
	elif len(even_counter.keys()) == 1 and len(odd_counter.keys()) != 1:
		odd_mode=collections.Counter(odd_sequence_list).most_common()[1][0]
		for i in even_sequence_list:
			if i != even_mode:
				count+=1
		for j in odd_sequence_list:
			if j != odd_mode:
				count+=1
		print(count)
	else:
		even_2_mode=collections.Counter(even_sequence_list).most_common()[1][0]
		odd_2_mode=collections.Counter(odd_sequence_list).most_common()[1][0]
		even_change_count=0
		odd_change_count=0
		for i in even_sequence_list:
			if i != even_2_mode:
				even_change_count+=1
		for j in odd_sequence_list:
			if j != odd_mode:
				even_change_count+=1
		for i in even_sequence_list:
			if i != even_mode:
				odd_change_count+=1
		for j in odd_sequence_list:
			if j != odd_2_mode:
				odd_change_count+=1
		if even_change_count < odd_change_count:
			print(even_change_count)
		else:
			print(odd_change_count)

Measured memory_bytes: 23452
#include <stdio.h>

int main()
{
	int count = 0;
	int max_a = 0;
	int max_a_b = 0;
	long scores[100000][2];
	long player = 0;

	scanf("%d", &count);

	for (int i = 0; i < count; i++) {
		scanf("%ld %ld", &scores[i][0], &scores[i][1]);
		if (max_a < scores[i][0]) {
			max_a = scores[i][0];
			max_a_b = scores[i][1];
		}
	}

	player = max_a + max_a_b;

	for (int i = 0; i < count; i++) {
		if (max_a_b > scores[i][1]) {
			player++;
		}
	}

	printf("%d", player);

	return 0;
}



Measured memory_bytes: 2424
using namespace std;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#define all(x) (x).begin(),(x).end()

void solve(){

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

    int a;
    int dmin = 100;
    for (int i = 0; i < n; i++){
        int d = 0;
        cin >> a;
        while(a % 2 == 0){
            a /= 2;
            d++;
        }
        dmin = min(dmin,d);
    }
    cout << dmin << endl;
    return 0;
}


Measured memory_bytes: 256
import math
H, W = map(int, input().split())
ans = 10**10
for h in range(1, H):
    A = h * W
    #残りを横に割る
    B = W*math.ceil((H-h)/2)
    C = H*W - A - B
    tmp = max([A,B,C]) - min([A,B,C])
    ans = min(ans, tmp)
    #残りを縦に割る
    B = (H-h)*math.ceil(W/2)
    C = H*W - A - B
    tmp = max([A,B,C]) - min([A,B,C])
    ans = min(ans, tmp)

# 縦横入れ替え
H, W = W, H
for h in range(1, H):
    A = h * W
    #残りを横に割る
    B = W*math.ceil((H-h)/2)
    C = H*W - A - B
    tmp = max([A,B,C]) - min([A,B,C])
    ans = min(ans, tmp)
    #残りを縦に割る
    B = (H-h)*math.ceil(W/2)
    C = H*W - A - B
    tmp = max([A,B,C]) - min([A,B,C])
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 5;
char a[N][N];


int main() {
	string s, t;
	int res = INT_MAX;
	cin >> s >> t;
	int l1 = s.size(), l2 = t.size();
	for(int i = 0; i <= l1 - l2; i++) {
		int cnt = 0;
		for(int j = i; j < i + l2; j++) {
			if(s[j] != t[j - i]) {
				cnt++;
			}
		}
		res = min(res, cnt);
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		StringBuffer ans = new StringBuffer();
		sc.close();
		int size = s.length();
		for(int i = 0; i < size;++i){
			ans.append('x');
		}
		System.out.println(ans.toString());
	}
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int i =0;
  int sum =0;
  while (i<n){
      int l, r;
      cin >> l >> r;
      sum+=(r-l)+1;
      i++;
  }
  cout << sum << endl;
  
}

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

using namespace std;

int main(void){
    string S, T;
    cin >> S >> T;
    int ans = 0;
    for(int i = 0; i < S.length(); i++) if(S[i] != T[i]) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  long long H=0;
  cin>>N;
  vector<int>vec(N);
  for(int X=0;X<N-1;X++){
    cin>>vec[X];
    if(X>0){
      H+=min(vec[X],vec[X-1]);
    }
  }
  cout<<H+vec[0]+vec[N-2]<<endl;
}

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

int main()
{
 int n[4];
 cin >> n[0] >> n[1] >> n[2] >> n[3];
 int trade;
 for(int i = 3; i > 0; i--){
  for(int j = 0; j < i; j++){
   if(n[j] > n[j + 1]){
   trade = n[j];
   n[j] = n[j + 1];
   n[j + 1] = trade;
  }
  }
 }
 if(n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9){
  cout << "YES";
 }
 else cout << "NO";
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(void) {
    int64_t N, W, w0 = 1000000000;
    cin >> N >> W;
    vector< vector<int64_t> > V(4);
    while(N--) {
        int64_t w, v;
        cin >> w >> v;
        w0 = min(w0, w);
        V[w-w0].push_back(v);
    }

    for(auto &e: V) {
        sort(e.begin(), e.end());
        e.push_back(0);
        reverse(e.begin(), e.end());
        partial_sum(e.begin(), e.end(), e.begin());
    }

    int64_t ans = 0;
    for(int64_t i=0; i<V[0].size(); i++) {
        for(int64_t j=0; j<V[1].size(); j++) {
            for(int64_t k=0; k<V[2].size(); k++) {
                for(int64_t l=0; l<V[3].size(); l++) {
                    if(w0*(i+j+k+l) + j + 2*k + 3*l <= W) {
                        ans = max(ans, V[0][i] + V[1][j] + V[2][k] + V[3][l]);
                    }
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int a[N],x,y,n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=n-1;i;i--)
		if(a[i]==a[i+1]){
			if(x==0)x=a[i];
			else {
				printf("%lld",1ll*x*a[i]);
				return 0;
			}
			a[i]=0;
		}
	puts("0");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define con_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define con_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
using namespace std;
using ll = long long;
template <typename T>T digitsum(T n);
template <typename T>bool isPrime(T n);
template <typename T>vector<pair<T, T>> prime_factor(T n);
long long int intpow(long long int,long long int);
template <typename T>T intlog(T);

int main(){
    int h,w,n;
    cin>>h>>w>>n;
    cout<<(int)floor((n+max(h,w)-1)/max(h,w))<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    System.out.println((int)Math.pow((int)Math.sqrt(n), 2));
  }
}

/*
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String blank = sc.nextLine();
String s = sc.nextLine();
System.out.println();
System.exit(0)
*/


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

using namespace std;
typedef long ll;

int main(){

    ll n;
    cin >> n;
    ll a = 1;
    ll b = 1;
    ll minv = 1000000000000 + 1;
    for (ll i = 1; i < sqrt(n) + 1; i++)
    {
        if(n%i!=0)
            continue;
        a = n / i;
        b = i;
        minv = min(a + b, minv);
    }
    cout << minv - 2 << endl;
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int a, b;
    cin >> a >> b;
    if ((a + b) % 2 != 0) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << (a + b) / 2 << endl;
    }
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 256
N = int(input())
A = [0] + [int(input()) for _ in range(N)] + [0]

L = [0] * (N+1)
R = [0] * (N+2)

for i in range(1, N+1):
    L[i] = max(L[i-1], A[i-1])
    R[N-i+1] = max(R[N-i+2], A[N-i+2])

for i in range(1, N+1):
    print(max(L[i], R[i]))


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

long long INF = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;

  long long left = 0, right = 0, sum = 0;
  for(long long num = 0; num < k; num++){
    left += num;
    right += n - num;
  }
  sum += (right - left + 1) % INF;

  for(long long num = k; num <= n; num++){
    left += num;
    right += n - num;
    sum += (right - left + 1) % INF;
  }

  cout << sum % INF << endl;
  
}


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

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

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

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

int n, a;
vint x;

vector<vvll> d(51, vector<vll>(2501, vector<ll>(51, -100)));

ll dp(int pos, int wa, int num){
    if(pos == n){
        return (wa==num*a?1:0);
    }
    if(d[pos][wa][num] != -100){
        return d[pos][wa][num];
    }
    ll res = dp(pos+1, wa+x[pos], num+1)+dp(pos+1, wa, num);
    return d[pos][wa][num] = res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    cin>>n>>a;
    x = vint(n);
    rep(i, n){
        cin>>x[i];
    }
    cout << dp(0, 0, 0) - 1 << endl;
    return 0;
}


Measured memory_bytes: 56064
l,a,b,m = map(int,input().split())

# c111 -> 1001001001みたいなやつを求める
# n : 塊の数
# l : 一つの塊(00..001)の長さ
# m : mod
# ex) n=3, l=2 -> 10101
def c111(n, l, m):
    if n <= 0:
        return 0
    if n == 1:
        return 1
    if n % 2 == 1:
        return (c111(n - 1, l, m) * pow(10, l, m) + 1) % m
    half = c111(n // 2, l, m)
    return (half * pow(10, (n // 2) * l, m) + half) % m

# c123 -> 1002003004みたいなやつを求める
# n : 塊の数
# l : 一つの塊(00..001)の長さ
# m : mod
# ex) n=3, l=2 -> 10203
def c123(n, l, m):
    if n <= 0:
        return 0
    if n == 1:
        return 1
    if n % 2 == 1:
        return (c123(n - 1, l, m) + c111(n, l, m)) % m
    half = c123(n // 2, l, m)
    return (half * pow(10, (n // 2) * l, m) + half + (n // 2) * c111(n // 2, l, m)) % m

fst, lst = a, a + b * (l - 1)

fst_l, lst_l = len(str(fst)), len(str(lst))

res, margin = 0, 0
for keta in reversed(range(fst_l, lst_l + 1)):
    num_l = a + b * ((10 ** (keta - 1) - a + b - 1) // b)
    num_r = a + b * ((10 ** keta - a + b - 1) // b - 1)
    if keta == fst_l:
        num_l = fst
    if keta == lst_l:
        num_r = lst
    if num_l > num_r:
        continue
    sz = (num_r - num_l) // b + 1
    _111 = num_l * c111(sz, keta, m)
    _123 = b * c123(sz - 1, keta, m)
    res += (pow(10, margin, m) * (_111 + _123)) % m
    margin += sz * keta
print(res % m)


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  ll ans = a + b;
  if (ans > 23) ans -= 24;

  cout << ans << endl;

  return 0;
}

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

int main(){
	std::string s1, s2;
	int a, b;
	int n = 0;
	std::cin >> a >> b;

	for(int i = a; i <= b; ++i){
		s1 = std::to_string(i);
		s2.clear();
		for(unsigned int j = s1.size() - 1; j >= 0 && j <= s1.size() - 1; --j){
			s2 += s1.substr(j, 1);
		}
		if(s1 == s2){
			++n;
		}
	}

	std::cout << n << std::endl;

	return 0;
}


Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
import java.lang.*;

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

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

        if (a<10 && b<10)
            System.out.println(a*b);
        else
            System.out.println("-1");

    }
}


Measured memory_bytes: 35676
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
int main()
{
    int x;
    rep(i,5){
        cin>>x;
        if(x==0){
            cout<<i+1;
        }
    }
    return 0;
}

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

int main()
{
    int n,k,i;
    cin >> n >> k;
    vector<int> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    int ans = 1;
    n -= k;
    if(n % (k-1) == 0){
        ans += n/(k-1);
    }else{
        ans += n/(k-1)+1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import "dart:io";

main(){
  int n = int.parse(stdin.readLineSync());
  List<int> d = [];
  for (int i = 0; i < n; i++){
    d.add(int.parse(stdin.readLineSync()));
  }

  int ans = 0;
  d.sort(); //昇順ソート
  for (int i = 0; i < n-1; i++){
    if (d[i] != d[i+1]) ans++;
  }
  print(ans + 1);
}


Measured memory_bytes: 13168
#include<stdio.h>
int main(void){
  int n,i;
  char s[100];
  scanf("%d",&n);
  scanf("%s",s);
  if(n%2==1)  printf("No");
  else{
    for(i=0;i<n/2;i++){
      if(s[i]!=s[i+n/2]){
        printf("No");
        break;
      }
    }
    if(i==n/2)  printf("Yes");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 200010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

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

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    pll p[n];
    rep(i, n) cin >> p[i].first >> p[i].second;
    sort(p, p + n);
    ll money = 0, cnt = 0;

    rep(i, n) {
        if (cnt + p[i].second >= m) {
            money += p[i].first * (m - cnt);
            break;
        } else {
            money += p[i].first * p[i].second;
            cnt += p[i].second;
        }
    }
    cout << money << endl;
    return 0;
}


Measured memory_bytes: 1920
#include <iostream>

using namespace std;

int main()
{
	string s, ans;
	long long len;
	
	cin >> s;
	len = s.length();
	
	ans = "Yes";
	for (long long i = 0; i < len; i++)
	{
		if (i % 2 == 0)
		{
			if (s[i] == 'L')
			{
				ans = "No";
				break;
			}
		} else {
			if (s[i] == 'R')
			{
				ans = "No";
				break;
			}			
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;
int main(){
    int n,k,i=1,j=0,a,b=1,c;
    double s=0;
    cin>>n>>k;
 
    for(a=1;a<=n;a++){
        if(a>=k){
            s+=(1.0/n);
            continue;
        }
        else{
        for(b=1;a*pow(2,b)<k;b++){
    
        
        }
        s+=(1.0/n)*pow(2,-b);
        }
    }
    

    printf("%.12lf",s);
    return 0;
    
}

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, m, k;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m >> k;
    if (k % n == 0)
        return yes, 0;
    if (k % m == 0)
        return yes, 0;
    rep(i, n)
    {
        rep(j, m)
        {
            if(k==i*m+j*n-2*i*j)return yes,0;
        }
    }
    no;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int main(){
	int a;
	string s;
	cin >> a;
	cin >> s;
	if(a>=3200)cout << s << endl;
	else cout << "red" << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import deque

K = int(input())
q = deque([i for i in range(1, 10)])

cnt = 0
while cnt < K-1:
    n = q.popleft()
    d = int(str(n)[-1])
    cnt += 1
    for i in [d-1, d, d+1]:
        if i < 0 or 10 <= i:
            continue
        q.append(10*n+i)
print(q.popleft())

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

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,r,l) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const ll INF = LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MAXN = 3e3+20;
const double EPS= 1e-10;

long double dp[MAXN];
int n;
long double p;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<< setprecision(12)<< fixed;
    cin>> n;
    dp[0]=1;
    forn(coin,n){
        cin>> p;
        for(int i=coin+1; i>=0; --i){
            dp[i] = (i!= 0 ? p* dp[i-1] : 0) + dp[i]* (1-p);
        }
    }
    p=0;
    fore(i,n/2+1, n){
        p+= dp[i];
    }
    cout<< p<<el;
}


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

const int N = 1000 + 7;

int x[N], y[N];


int chk(int p, int q, int n) {
	for(int i = n; i >= 1; i--) {
		if(x[i] > p || y[i] > q) {
			return 0;
		}
		int mn = min(p / x[i], q / y[i]);
		p = x[i] * mn;
		q = y[i] * mn;
	}
	return 1;
}

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> x[i] >> y[i];
	}

	int l = 1, r = 1e18 / max(x[n], y[n]);
	while(l < r) {
		int mid = (l + r) >> 1;
		if(chk(x[n] * mid, y[n] * mid, n)) {
			r = mid;
		} else {
			l = mid + 1;
		}
	}

	cout << r * (x[n] + y[n]) << endl;

}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
using ll = long long;


int main() {
	ll L, R; cin >> L >> R;
	ll ans = 2020;
	for (ll i = L; i < min(L + 2020, R); i++) {
		for (ll j = i + 1; j <= min(L + 2020, R); j++) {
			ans = min(ans, i*j % 2019L);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll a, b;
    cin >>a>>b;

    cout << ((b>=a) ? a : a-1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long LINF = 1e18;

int main() {
    int N;
    cin >> N;
    vector<int> V(N);
    vector<int> C(N);
    for (int i = 0; i < N; i++) {
        cin >> V[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> C[i];
    }

    int ans = 0;
    for (int bit = 0; bit < (1<<N); bit++) {
        int value = 0;
        for (int i = 0; i < N; i++) {
            if (bit & (1<<i)) {
                value += V[i];
                value -= C[i];
            }
        }

        ans = max(ans, value);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct { char suit, value; } Card;

void bubble(Card A[], int N) {
  int i,j;
  Card t;
  for(i = 0; i<N; i++) {
    for(j = N-1; j >= i; j--) {
      if(A[j].value < A[j-1].value) {
        t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(Card A[], int N) {
  int i,j,minj;
  Card t;
  for(i=0;i<N;i++) {
    minj = i;
    for(j=i; j<N; j++) {
      if(A[j].value < A[minj].value) minj = j;
    }
    t = A[i]; A[i] = A[minj]; A[minj] = t;
  }
}

void print(Card A[], int N) {
  int i;
  for(i=0; i<N; i++) {
    if(i>0) printf(" ");
      printf("%c%d",A[i].suit,A[i].value);
  }
  printf("\n");
}

int isStable(Card C1[], Card C2[], int N) {
  int i;
  for(i=0; i<N; i++) {
    if(C1[i].suit != C2[i].suit) return 0;
  }
  return 1;
}

/* オリジナル関数を追加 */
void str2Card(Card *t,char str[]) {
    t->suit  = str[0];
    t->value = str[1] - '0';
}

int main(void) {
  Card C1[100], C2[100];
  int N,i;
  char str[3];

  scanf("%d",&N);
  for(i=0;i<N; i++) {
    scanf("%s",str);
    str2Card(&C1[i],str);
  }

  for(i=0; i<N; i++) C2[i] = C1[i];

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  printf("Stable\n");
  print(C2,N);
  if(isStable(C1,C2,N)) {
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}



Measured memory_bytes: 2044
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>

using namespace std;

int
main() {
 
  int n;
  scanf("%d\n", &n);

  string s;
  cin>>s;

  for (int i=0; i<s.length(); i++) {
    s[i] += n;
    if (s[i] > 'Z') s[i] -= 26;
  }

  cout<<s<<endl;
  return 0;
}



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

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

const ll MAX_N = 1e5 + 5, inf = 1000000LL * 1000000LL * 1000000LL;
ll n;
string s1, s2, s;
string type[MAX_N];

void t1 (vector <int> v1);

void t2 (vector <int> v1) {
//	cout << "T2 " << v1[0] << " " << v1[v1.size() - 1] << "\n";
	cout << v1[v1.size() / 2] - 1 << endl;
	cin >> s;
	
	type[v1[v1.size() / 2]] = s;
	if (type[v1[v1.size() / 2]] == "Vacant")
		return ;
	
	if ((v1.size() / 2 + 1) % 2) {
		if (type[v1[v1.size() / 2]] != type[v1[0]]) {
			vector <int> g1;
			for (int i = 0; i <= v1.size() / 2; i++)
				g1.push_back(v1[i]);
				
			t2(g1);
			return ;
		}
		
		vector <int> g1;
		for (int i = v1.size() / 2; i < v1.size(); i++)
			g1.push_back(v1[i]);
				
		t2(g1);
		return ;
	}
	else {
		if (type[v1[v1.size() / 2]] == type[v1[0]]) {
			vector <int> g1;
			for (int i = 0; i <= v1.size() / 2; i++)
				g1.push_back(v1[i]);
				
			t1(g1);
			return ;
		}
		
		vector <int> g1;
		for (int i = v1.size() / 2; i < v1.size(); i++)
			g1.push_back(v1[i]);
				
		t1(g1);
		return ;
	}
}



int main() {
//	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	
	cout << 0 << endl;
	cin >> s1;
	cout << (n + 1) / 2 - 1 << endl;
	cin >> s2;
	if (s1 == "Vacant" || s2 == "Vacant")
		return 0;
	
	type[1] = s1;
	type[(n + 1) / 2] = s2;
	
	if (((n + 1) / 2) % 2) {
		if (s1 != s2) {
			vector <int> g1;
			for (int i = 1; i <= (n + 1) / 2; i++)
				g1.push_back(i);
			
			t2(g1);
		}
		else {
			vector <int> g1;
			for (int i = (n + 1) / 2; i <= n; i++)
				g1.push_back(i);
			g1.push_back(1);
			
			t1(g1);
		}
	}
	else {
		if (s1 == s2) {
			vector <int> g1;
			for (int i = 1; i <= (n + 1) / 2; i++)
				g1.push_back(i);
			
			t1(g1);
		}
		else {
			vector <int> g1;
			for (int i = (n + 1) / 2; i <= n; i++)
				g1.push_back(i);
			g1.push_back(1);
			
			t2(g1);
		}
	}
	return 0;
}

void t1 (vector <int> v1) {
//	cout << "T1 " << v1.size() << " " << v1[0] << " " << v1[v1.size() - 1] << "\n";
	cout << v1[v1.size() / 2 - 1] - 1 << endl;
	cin >> s;
	
	type[v1[v1.size() / 2 - 1]] = s;
	if (type[v1[v1.size() / 2 - 1]] == "Vacant")
		return ;
	
	if ((v1.size() / 2) % 2) {
		if (type[v1[v1.size() / 2 - 1]] != type[v1[0]]) {
			vector <int> g1;
			for (int i = 0; i <= v1.size() / 2 - 1; i++)
				g1.push_back(v1[i]);
				
			t2(g1);
			return ;
		}
		
		vector <int> g1;
		for (int i = v1.size() / 2 - 1; i < v1.size(); i++)
			g1.push_back(v1[i]);
				
		t1(g1);
		return ;
	}
	else {
		if (type[v1[v1.size() / 2 - 1]] == type[v1[0]]) {
			vector <int> g1;
			for (int i = 0; i <= v1.size() / 2 - 1; i++)
				g1.push_back(v1[i]);
				
			t1(g1);
			return ;
		}
		
		vector <int> g1;
		for (int i = v1.size() / 2 - 1; i < v1.size(); i++) {
			g1.push_back(v1[i]);
		}
		
		t2(g1);
		return ;
	}
	return ;
}


Measured memory_bytes: 2512
#include <iostream>
#include <vector>
#include <string>

struct node{
	int x;
	int y;
	struct node* parent;

	node(): x(-1), y(-1), parent(nullptr)
	{}
};

struct node* get_root(struct node* p){
	if(p->parent == nullptr){
		return p;
	}else{
		return get_root(p->parent);
	}
}

void solve(int H, int W){
	std::string farm[H];
	node nodes[H*W];

	for(int i = 0; i < H; i++){
		std::cin >> farm[i];
		for(int j = 0; j < W; j++){
			int index = i*W + j;
			nodes[index].y = i;
			nodes[index].x = j;
		}
	}

	for(int y = 0; y < H; y++){
		for(int x = 0; x < W; x++){
			// up
			int y_u = y - 1;
			node* up_root = nullptr;
			bool up_found = y_u >= 0 && farm[y_u][x] == farm[y][x];
			if(up_found){
				up_root = get_root(&nodes[y_u*W + x]);
			}
			// left
			int x_l = x - 1;
			node* left_root = nullptr;
			bool left_found = x_l >= 0 && farm[y][x_l] == farm[y][x];
			if(left_found){
				left_root = get_root(&nodes[y*W + x_l]);
			}

			if(up_found && left_found == false){
				nodes[y*W + x].parent = up_root;
			}else if(left_found && up_found == false){
				nodes[y*W + x].parent = left_root;
			}else if(up_found && left_found){
				if(up_root != left_root){
					up_root->parent = left_root;
				}
				nodes[y*W + x].parent = left_root;
			}else{
				// no-op
			}
		}
	}

	int ans = 0;
	for(int i = 0; i < H*W; i++){
		ans += nodes[i].parent == nullptr ? 1 : 0;
	}

#if 0
	/*
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			printf("%2d ", get_root(&nodes[i*W + j])->i);
		}
		std::cout << std::endl;
	}*/
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(nodes[i*W + j].parent == nullptr){
			printf("root %d %d\n", i, j);
			}
		}
	}

#endif
	std::cout << ans << std::endl;
}

int main(){
	int H, W;

	while(true){
		std::cin >> H >> W;
		if(H == 0 && W == 0){
			break;
		}else{
			solve(H, W);
		}
	}
}



Measured memory_bytes: 3220
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,K;
string s,ans;
char mn;
void get_S(string&s){
	string t=s;
	reverse(t.begin(),t.end());
	s+=t;
}
void solve(string s,int K){
	int now=0;
	while(now<n&&s[n-now-1]==mn) now++;
	for(;K>1;K--){
		get_S(s);
		s=s.substr(min(now,n),n);
		now<<=1;
	}
	get_S(s);
	s=s.substr(max(0,n-now),n);
	ans=min(ans,s);
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>K;
	cin>>s;
	mn='z';
	for(int i=0;i<n;i++)
		mn=min(mn,s[i]);
	if(K>13){
		for(int i=0;i<n;i++) putchar(mn);
		puts("");
		return 0;
	}
	get_S(s);
	ans+=127;
	int mxlen=0;vector<int> w;
	for(int i=0;i<2*n;i++){
		if(i<=n&&K==1) ans=min(ans,s.substr(i,n));
		if(i>0&&s[i-1]==mn) continue;
		int len=0;
		while(i+len<2*n&&s[i+len]==mn) len++;
		if(len>mxlen) w.clear(),mxlen=len;
		if(len==mxlen&&i+len>=n) w.push_back(i+len);
	}
	if(K>1)
	for(auto x:w){
		string t=s.substr(x-n,n);
		solve(t,K-1);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

long long f(long long v) {
  if (v % 4 == 0) return v;
  if (v % 4 == 1) return 1;
  if (v % 4 == 2) return v + 1;
  if (v % 4 == 3) return 0;
}

int main() {
  long long A, B;
  cin >> A >> B;
  cout << (f(B) ^ f(A ? A - 1 : A)) << endl;
  return 0;
}


Measured memory_bytes: 256