akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];
        var w = Enumerable.Repeat(0, n).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        long valid = int.MaxValue;
        long invalid = 0;
        while (valid - invalid > 1)
        {
            var mid = (valid + invalid) / 2;

            int ptr = 0;
            for (int i = 0; i < k; i++)
            {
                long total = mid;
                while (ptr < w.Length && 0 <= total - w[ptr]) total -= w[ptr++];
            }
            if (ptr == w.Length) valid = mid;
            else invalid = mid;
        }
        Console.WriteLine(valid);
    }
}



Measured memory_bytes: 21416
# -*- coding: utf-8 -*-


def main():
    n, a, b = map(int, input().split())
    diff = b - a

    # See:
    # https://img.atcoder.jp/agc041/editorial.pdf
    # KeyInsight: 移動パターンを分解する

    # ◯：A, Bの位置の偶奇が一致しているかどうかの場合分け
    #   ：A, Bの位置の偶奇が不一致のときに，片方が端部まで移動する
    # ×：上記のcaseでの最短roundを計算する部分
    if diff % 2 == 0:
        print(diff // 2)
    else:
        # A, Bが端部に移動するまでの回数: min(a - 1, n - b)
        # 偶奇を調整する回数           : 1
        # AとBが合流するまでに必要な回数: (b - a - 1) // 2
        print(min(a - 1, n - b) + 1 + (b - a - 1) // 2)


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 10000; // 998244353;

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

void Main(){
    int H,N; cin >> H >> N;
    int dp[H+10101]; REP(i,H+10101) dp[i] = INF;
    dp[0] = 0;
    REP(_,N){
        int a,b; cin >> a >> b;
        REP(i,H+10101){
            if(dp[i] < INF && i+a<H+10101)
                chmin(dp[i+a], dp[i]+b);
        }
    }
    int ans = INF; FOR(i,H,H+10101) chmin(ans, dp[i]);
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3704
n = int(input())
d = [int(x.strip()) for x in input().split()]
d_sorted = sorted(d)
m = int(n/2)
abc_fin = d_sorted[m-1]
arc_start = d_sorted[m]
if abc_fin == arc_start:
  ans = 0
else:
  ans = arc_start - abc_fin
print(ans)

Measured memory_bytes: 20800
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

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

  if(n <= 111) cout << 111 << endl;
  else if(n <=222) cout << 222 << endl;
  else if(n <= 333) cout << 333 << endl;
  else if(n <= 444) cout << 444 << endl;
  else if(n<=555) cout << 555 << endl;
  else if(n<= 666) cout << 666 <<endl;
  else if(n<= 777) cout << 777 <<endl;
  else if(n<= 888) cout << 888 <<endl;
  else cout << 999 <<endl;
    
}

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

mod = 10**9 + 7

cnt = 0
pair = 0
for i in range(N):
    for j in range(i+1, N):
        if A[i] > A[j]:
                cnt += 1

    for j in range(N):
        if A[j] > A[i]:
            pair += 1

v = (K * (K-1) // 2) % mod * pair % mod
print((cnt * K % mod + v) % mod)


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

int a[114514];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	int ans = 0;
	int pm = -1;
	vector<int>v;

	for (int i = 0; i < n; i++) {
		if (v.size() < 2)v.push_back(a[i]);

		else {

			if (v[v.size() - 1] < v[v.size() - 2]) {
				pm = 0;
				if (v[v.size() - 1] < a[i]) {
					ans++;

				/*
				for (int i = 0; i < v.size(); i++)cout << v[i] << endl;
					cout << endl;
					*/

					v.clear();
					v.push_back(a[i]);
					pm = -1;
				}
				else v.push_back(a[i]);
			}

			else if (v[v.size() - 1] > v[v.size() - 2]) {
				pm = 1;

				if (v[v.size() - 1] > a[i]) {
					ans++;

				/*	
				for (int i = 0; i < v.size(); i++)cout << v[i] << endl;
					cout << endl;
					*/

					v.clear();
					v.push_back(a[i]); pm = -1;
				}
				else v.push_back(a[i]);
			}

			else {
				if (pm == 0) {
					if (v[v.size() - 1]<a[i]) {
						v.clear();
						ans++;
						pm = -1;
					}
				}
				else if (pm == 1) {
					if (v[v.size() - 1] > a[i]) {
						v.clear();
						ans ++;
						pm = -1;
					}
				}
				v.push_back(a[i]);
			}
		}

	}
	if (v.size())ans++;

/*
for (int i = 0; i < v.size(); i++)cout << v[i] << endl;
	cout << endl;
	*/

	cout << ans << endl;
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 1276
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

n=int(input())
a=list(map(int,input().split()))
cnt=[0]*n
ans=[]
d={}
for i in range(n,0,-1):
  flag=False
  for j in make_divisors(i):
    if a[i-1]==1 and cnt[i-1]%2==0:
      cnt[j-1]+=1
      flag=True
    elif a[i-1]==0 and cnt[i-1]%2==1:
      cnt[j-1]+=1
      flag=True
  if flag:
    ans.append(i)
print(len(ans))
print(*ans)

Measured memory_bytes: 96940
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    int h,w;
    int k;
    cin >> h>> w >> k;
    vector <vector <char>> a(h, vector<char>(w));
    vector <vector <char>> b(h, vector<char>(w));
    for (int i = 0; i  <h; i++) {
        for (int j =0; j <w ; j++) {
            cin >>  a[i][j];
        }
    }
    int ans = 0;
        for(int bit = 0; bit < (1 << h); bit++){
            copy(a.begin(), a.end(), b.begin());
            for(int bit2 = 0; bit2 < (1 << w); bit2++){
                int count = 0;
                for (int i = 0; i < h; i++) {
                    for (int j =0; j < w ; j++) {
                        if (b[i][j] == '#' &&!(bit & 1 <<i) && !(bit2 & 1 << j)) {
                            count++;
                        }
                    }
                }
                if (count == k) ans++;
            }
        }
    cout << ans << endl;
}

Measured memory_bytes: 3168
/**
*   @Author : MeGA
*   @InitTime :01/25/20 10:52:52
*   @Idea : 
*
*
*
*
*
*
*
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
  // freopen("in","r",stdin);
  // freopen("out","w",stdout);
#endif
      int n;
      scanf("%d",&n);
      vector<pair<int,int> > v(n);
      for(int i=0;i<n;i++){
      	    int a;
            scanf("%d",&a);
            v[i]=make_pair(a,i+1);
      }
      sort(v.begin(),v.end());
      for(int i=0;i<v.size();i++){
         if(i==0){
            printf("%d",v[i].second);
         }else{
            printf(" %d",v[i].second);
         }
      }


}

Measured memory_bytes: 1536
min = -> (a, b) { a < b ? a : b }

n = gets.to_i
h = gets.split.map &:to_i

d = [0, (h[1] - h[0]).abs]

(2...n).each { |i|
  a = d[i - 1] + (h[i - 1] - h[i]).abs
  b = d[i - 2] + (h[i - 2] - h[i]).abs
  d << min[a, b]
}

puts d.last


Measured memory_bytes: 21184
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
	int a[3];
	scanf("%d%d%d", &a[0], &a[1], &a[2]);
	sort(a, a + 3);
	if (a[0] == 5 && a[1] == 5 && a[2] == 7) puts("YES");
	else puts("NO");
	return 0;
}



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

int main()
{
    double N;
    cin >> N;
    int m;
    m = N;
    double ans = 0;
    if (m % 2 == 0) {
        cout << 0.5 << endl;
    }
    else {
        cout << (N + 1) / 2 / N << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
    int h,m,s;
    scanf("%d", &s);
    h = s/3600;
    m = (s-(h*3600))/60;
    s = s-(m*60)-(h*3600);
    printf("%d:%d:%d\n", h, m, s );
}


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

using lint = long long;

int main(){
    string S;
    lint K;
    int len1 = 0;
    char next_1 = '1';
    cin >> S >> K;
    for(int i=0;i<S.length();i++){
        if(S[i] != '1'){
            next_1 = S[i];
            break;
        }
        else{
            len1++;
        }
    }
    if(K <= len1){
        cout << '1' << endl;
    }
    else{
        cout << next_1 << endl;
    }
    return 0;
}

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

int main() {
    int mat[5];
    cin >> mat[0] >> mat[1] >> mat[2] >> mat[3] >> mat[4];
    for (int i = 0; i < 5; i++) {
        if(mat[i] == 0) {
            cout << i+1 << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3564
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

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

    int ans1 = 0;
    int ans2 = 0;
    for (int i = 0; i < S.size(); i++) {
        if (i & 0x1) {
            if (S[i] != '0') {
                ans1++;
            } else {
                ans2++;
            }
        } else {
            if (S[i] != '1') {
                ans1++;
            } else {
                ans2++;
            }
        }
    }

    cout << min(ans1, ans2) << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(){
    ll n;
    cin >> n;
    ll a[n];
    for(ll i = 0; i < n; i++) cin >> a[i];

    ll ans = gcd(a[0], a[1]);
    for(ll i = 2; i < n; i++){
        ans = gcd(ans, a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
n=int(input())
s=[]
for i in range(n):
  k=input()
  s.append(k)
m=int(input())
t=[]
for i in range(m):
  k=input()
  t.append(k)
check=[]
ans=[0]
for i in s:
  if i in check:
    continue
  ans.append(s.count(i)-t.count(i))
  check.append(i)
print(max(ans))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int double
int func(int X){
  return X>=0?X:-X;
  }
signed main(){
  int N,T,A,near=10000,ans;
  cin>>N>>T>>A;
  for(int i=1;i<=N;i++){
    int X;
    cin>>X;
    if(func(T-X*0.006-A)<near){
      ans=i;
      near=func(T-X*0.006-A);
      }
    }
  cout<<ans<<endl;
  }
    
  

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

//const int mod = 1000000007;
const int mod = 998244353;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
}
mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
}

// for prime mod
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main () {
    int n, s; cin >> n >> s;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<vector<mint>> dp(n+1, vector<mint> (s+1));
    dp[0][0] = 1;
    rep(i, n) {
        rep(j, s+1) {
            dp[i+1][j] += dp[i][j]*2;
            if (j+a[i] <= s) {
                dp[i+1][j+a[i]] += dp[i][j];
            } 
        }
    }
    cout << dp[n][s] << endl;

    return 0;
}

Measured memory_bytes: 73732
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    int n, m, x, i, a, l = 0, r = 0;
    int num[101] = {0};
    scanf("%d%d%d", &n, &m, &x);

    for (i = 0; i < m; ++i) scanf("%d", num + i);

    for (i = 0; i < m; ++i) {
        if (num[i] < x) ++l;
        else ++r;
    }
    int ans = l > r ? r : l;
    printf("%d\n", ans);
    return 0;
}

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

int main() {
  int K;
  cin >> K;
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  
  int ans = a.at(N-1) - a.at(0);
  
  for (int i = 1; i < N-1; i++) {
    int dr = a.at(i) + K - a.at(i+1);
    int dl = a.at(i-1) + K - a.at(i);
    if (ans > dr) {
      ans = dr;
    }
    if (ans > dl) {
      ans = dl;
    }
  }
  
  cout << ans <<endl;
  
}


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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    int h1, m1, h2, m2, K;
    cin >> h1 >> m1 >> h2 >> m2 >> K;

    cout << (h2 * 60 + m2) - (h1 * 60 + m1) - K << newl;

    return 0;
}

Measured memory_bytes: 3672
A = [0 for i in range(9)]
for i in range(3):
  A[3*i], A[3*i+1], A[3*i+2] = map(int, input().split())
N = int(input())
b = [0 for i in range(N)]
for i in range(N):
  b[i] = int(input())

#Check matching numbers
for i in range(9):
  for j in range(N):
    if A[i] == b[j]:
      A[i] = 1

# Check bingo or not
flag = 0
# Check rows
for i in [0, 3, 6]:
  if A[i]==A[i+1] and A[i+1]==A[i+2]:
    flag += 1
# Check colums
for j in range(3):
  if A[j]==A[j+3] and A[j+3]==A[j+6]:
    flag += 1
# Check naname?
if (A[0]==A[4] and A[4]==A[8]) or (A[2]==A[4] and A[4]==A[6]):
  flag += 1

if flag >= 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9276
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<ll> l(n + 1, 0);
    l[0] = 2;
    l[1] = 1;
    rep(i, 2, n + 1)
    {
        l[i] = l[i - 1] + l[i - 2];
    }
    cout << l[n] << endl;
    return 0;
}


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

namespace AtCorder
{
    public static class Program
    {
        static public void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            //var ans = 0;

            if (input[0] >= input[3])
            {
                Console.WriteLine(input[3].ToString());
            }
            else if ((input[0] + input[1]) >= input[3])
            {
                Console.WriteLine(input[0].ToString());
            }
            else if (((input[0] + input[1] + input[2]) >= input[3]))
            {
                var num = input[0] + input[1];
                input[3] = input[3] - num;
                num = input[0] - input[3];
                Console.WriteLine(num.ToString());
            }
            else 
            {
                Console.WriteLine(0.ToString());
            }




            //for (var i = input[3]; i > 0; i--)
            //{
            //    if (input[0] > 0)
            //    {
            //        ans = ans + 1;
            //        input[0] = input[0] - 1;
            //    }
            //    else if (input[1] > 0)
            //    {
            //        ans = ans + 0;
            //        input[1] = input[1] - 1;
            //    }
            //    else
            //    {
            //        ans = ans - 1;
            //        input[2] = input[2] - 1;

            //    }
            //}

        }
    }
}




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

cnt = 0
for n in range(N):
    killed = min(B[n], A[n])
    res = B[n] - killed
    killed2 = min(res, A[n + 1])
    A[n + 1] -= killed2
    cnt += killed + killed2

print (cnt)


Measured memory_bytes: 18624
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int cmp(const void *a,const void *b)
{
     return *(int *)a - *(int *)b;
}
int main (void)
{
    int max = 0;
    int a[100500];
    int p[100500];
    int t[100500];
    memset(t,0,sizeof(t));
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    qsort(a+1,n,sizeof(a[1]),cmp);
    int num = 0;
    p[++num] = a[1];
    t[num] = 1;
    for(int i=2;i<=n;i++)
    {
        if(a[i]!=a[i-1])
        {
            p[++num] = a[i];
            t[num] = 1;
        }
        else
            t[num]++;
    }
    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(t[i]!=p[i])
        {
            if(t[i]>p[i])
                ans+=t[i]-p[i];
            else
                ans+=t[i];
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1280
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

x, y = map(int, readline().split())
for i in range(51):
    for j in range(26):
        if i * 2 + j * 4 == y:
            if i + j == x:
                print('Yes')
                exit()
print('No')

Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll mod = 1000000007;

void solve()
{
	int n; cin >> n;
	vector<ll> a(n),b(n);
	rep(i, n)cin >> a[i] >> b[i];
	ll ans = 0;
	rrep(i, n)
	{
		ll tmp = a[i] + ans;
		if(tmp % b[i] != 0)
		{
			ll x = (tmp + b[i] - 1)/b[i];
			ans += x * b[i] - tmp;
		}
	}
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 1792
# 500 100 50 x

a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i
count = 0

(a+1).times do |a_i|
  x_temp = x
  x_temp -= 500 * a_i
  break if x_temp < 0
  if x_temp == 0
    count += 1
    break
  end
  (b+1).times do |b_i|
    x_temp = x
    x_temp -= 500 * a_i
    x_temp -= 100 * b_i
    break if x_temp < 0
    if x_temp == 0
      count += 1
      break
    end
    (c+1).times do |c_i|
      x_temp = x
      x_temp -= 500 * a_i
      x_temp -= 100 * b_i
      x_temp -= 50 * c_i
      break if x_temp < 0
      if x_temp == 0
        count += 1
        break
      end
    end
  end
end

puts count


Measured memory_bytes: 14332
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	int i;
	for(i=0;i<n;i++){
	cin>>a[i];}
	cout<<a[n-1];
	int j;
	for(j=n-2;j>=0;j--){
	cout<<" "<<a[j];}
	cout<<endl;
	return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
typedef pair<P,long double> Pi;
typedef pair <long double,int> Pd;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
const long double dinf=10000000000000.0;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
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; }
map <int,ll> mp;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
vector<ll> a(n);
for(int i=0;i<n;i++)cin>>a[i];
ll ans=0;
sort(all(a));
for(int i=0;i<n;i++){
  for(int j=i+1;j<n;j++){
     ans+= lower_bound(all(a),a[i]+a[j])-a.begin()-j-1;
     //cout<<ans<<endl;
  }
}
cout<<ans<<endl;
}


Measured memory_bytes: 256
{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes,TupleSections #-}
import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Arrow
import Debug.Trace
import Text.Printf

import Data.List
import Data.Int
import Data.Bits
import Data.Maybe
import Data.Monoid
import Data.Array.Unboxed
import Data.Array.ST
import Data.Array.Base
import Data.Function(on)
import Data.Tuple(swap)
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
    s <- getLine
    if length s == 2 then
        if S.size (S.fromList s) == 1 then
            putStrLn "1 2"
        else
            putStrLn "-1 -1"
    else 
        let ts = zip3 s (tail s) (tail (tail s)) in
        case findIndex (\(a,b,c) -> (<3) $ S.size $ S.fromList $ [a,b,c]) ts of
            Just i -> printf "%d %d\n" (i+1) (i+3)
            Nothing -> putStrLn "-1 -1"


-- IO
readInt :: B.ByteString -> Int
readInt = fromJust . fmap fst . B.readInt
readInts :: IO [Int]
readInts = map readInt . B.words <$> B.getLine
readIntPair :: IO (Int,Int)
readIntPair = l2p . map readInt . take 2 . B.words <$> B.getLine
readAllInts :: IO [[Int]]
readAllInts = map (map readInt . B.words) . B.lines <$> B.getContents
readLns :: Read a => IO [a]
readLns = map read . words <$> getLine

-- Utilities
l2p :: [a] -> (a,a)
l2p (a:b:_) = (a,b)
l2p _ = error "l2p: the input list is too short"
p2l :: (a,a) -> [a]
p2l (a,b) = [a,b]
itof :: Int -> Double
itof = fromIntegral
inf :: Int
inf = maxBound `div` 2

-- Monad
stepM_ :: Monad m => a -> (a -> Bool) -> (a -> a) -> (a -> m ()) -> m ()
stepM_ i0 judge incr step = sub i0 where 
    sub i | judge i = step i >> sub (incr i) 
          | otherwise = return ()
rep_ :: Monad m => Int -> (Int -> m ()) -> m ()
rep_ n = stepM_ 0 (<n) (+1)
thru :: Monad m => (v -> m ()) -> v -> m v
thru m v = m v >> return v
memoize :: (Monad m) => (k -> m (Maybe v)) -> (k -> v -> m ()) -> k -> m v -> m v
memoize getter setter key action = do
    mv <- getter key
    case mv of
        Just v -> return v
        Nothing -> action >>= thru (setter key)

-- Array
newUArray :: (MArray (STUArray s) e (ST s),Ix i) => 
             (i,i) -> e -> ST s (STUArray s i e)
newUArray = newArray
newBArray :: (Ix i) => (i,i) -> e -> ST s (STArray s i e)
newBArray = newArray
defaultArray :: (IArray a e,Ix i) => e -> (i,i) -> [(i,e)] -> a i e
defaultArray = accumArray $ curry snd
fromEdges :: Ix i => (i,i) -> [(i,e)] -> Array i [e]
fromEdges = accumArray (flip (:)) []


Measured memory_bytes: 7292
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;



int main()
{
   int a,b,i;
  cin>>a>>b;
     char ca= a+'0';
     char cb=b+'0';
     //cout<<ca<<" "<<cb;

   string s1,s2;
    for(i=0;i<b;i++)
    {

        s1+=ca;
    }

    for(i=0;i<a;i++)
    {

        s2+=cb;
    }
    //cout<<s1;
    //cout<<s2;
      if(s1<s2) cout<<s1;
      else cout<<s2;

}


Measured memory_bytes: 256
while 1:
    n = int(raw_input())
    if n == 0: break
    exist = set([])
    enter = [0]*1000
    bless = [0]*1000
    for loop in xrange(n):
        md,hm,io,p = raw_input().split()
        h,m = map(int,hm.split(":"))
        t = 60*h+m
        p = int(p)
        if io == "I":
            enter[p] = t
            exist.add(p)
        else:
            exist.remove(p)
            if p == 0:
                for i in exist: bless[i] += t-max(enter[p],enter[i])
            elif 0 in exist:
                bless[p] += t-max(enter[0],enter[p])
    print max(bless)
    

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

int main() {
    int n, k;
    cin >> n >> k;
//    cout << n << " " << k << endl;
    int a = 1;
    for(int i=0; i<n; i++){
        if(a < k) a = a*2;
        else a = a + k;
    }
    printf("%d\n", a);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>
#include <iomanip>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<int> a(N), c(3);
    for(auto& x: a){
        cin >> x;
        c[x-1]++;
    }

    vector<vector<vector<double> > > dp(N+1, vector<vector<double> >(N+1, vector<double>(N+1)));
    for(int k=0; k<=N; k++){
        for(int j=0; j<=N; j++){
            for(int i=0; i<=N; i++){
                int l = i + j + k;
                if(l>N) continue;
                dp[i][j][k] = (l==0) ? 0 : 1.0 * N / l;
                if(i>0) dp[i][j][k] += dp[i-1][j][k] * i / l;
                if(j>0) dp[i][j][k] += dp[i+1][j-1][k] * j / l;
                if(k>0) dp[i][j][k] += dp[i][j+1][k-1] * k / l;
                // cout << i << " " << j << " " << k << " "  << dp[i][j][k] << endl;
            }
        }
    }

    cout << setprecision(20) << dp[c[0]][c[1]][c[2]] << endl;
}

Measured memory_bytes: 216960
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#define Cin(T, x) T x; cin >> x
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) find(Range(c), x) != c.end()
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, vs, n, m) vector<vector<T>> vs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]

using namespace std;
using ll = long long;

int main(void){
    Cin(int, n);
    Cins(int, n, a);
    DeSort(a);
    int sign = 1, ans = 0;
    For(i, n){
        ans += sign * a[i];
        sign *= -1;
    }
    Cout(ans);
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc049/tasks/arc065_a

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

//　見つかったら次の桁数、見つからなければ-1
int vsearch(string s, int i) {
    int ret = -1, len = s.size();
    if (len == i) {
        return i;
    }
    if (s.substr(i, 5) == "dream") {
        ret = vsearch(s, i + 5);
        if (len == ret) {
            return ret;
        }
    }
    if (s.substr(i, 7) == "dreamer") {
        ret = vsearch(s, i + 7);
        if (len == ret) {
            return ret;
        }
    }
    if (s.substr(i, 5) == "erase") {
        ret = vsearch(s, i + 5);
        if (len == ret) {
            return ret;
        }
    }
    if (s.substr(i, 6) == "eraser") {
        ret = vsearch(s, i + 6);
        if (len == ret) {
            return ret;
        }
    }
    return ret;
}

int main() {
    int ans = 0;
    string s;
    cin >> s;

    ans = vsearch(s, 0);
    if (ans == -1) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
int N, M, K, Q, T;

int main()
{
	int i, j,a ,b;
	scanf("%d%d", &a, &b);
	string s, t;
	for (i = 1; i <= a; ++i) {
		s.push_back(b + '0');
	}
	for (i = 1; i <= b; ++i) {
		t.push_back(a + '0');
	}
	if (s > t) cout << t;
	else cout << s;
}

Measured memory_bytes: 256
import java.util.*;
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 Y = sc.nextInt();
		int price1 = 0;
		int price2 = 0;
		if (X > Y) {
			price1 = (C * 2 * Y) + (A * (X - Y));
			price2 = C * 2 * X;
		} else {
			price1 = (C * 2 * X) + (B * (Y - X));
			price2 = C * 2 * Y;
		}
		int price3 = A * X + B * Y;
		int ans = Math.min(price1, price2);
		ans = Math.min(ans, price3);
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
import sys
input = sys.stdin.readline
# int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
# [int(i) for i in input().split()] # 配列で数字
s = input()

start = 0
end= 3
ans = float('inf')
while end < len(s):
    num = int(s[start:end])
    ans = min(ans, abs(num - 753))
    start += 1
    end += 1
print(ans)

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' ';
#define PRINT_ENTER() cout << endl;

int main() {
    /* code */
    int n;
    cin >> n;
    cout << n / 2 + n % 2 << endl;
    return 0;
}

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

#define rep(i, n)     for(auto i = 0; i != n; ++i)
#define REP(i, k, n)  for(auto i = k; i != n; ++i)
#define rrep(i, n)    for(auto i = n; i != 0; --i)
#define RREP(i, n, k) for(auto i = n; i != k; --i)

#define debug(x) cerr << #x << " " << x << endl
#define spc << " " <<

#define mp make_pair
#define mt make_tuple

using ll = long long;
using Pii = pair<int, int>;
using Tiii = tuple<int, int, int>;
template<typename T>using V = vector<T>;
using Vi = vector<int>;
using VVi = vector<vector<int>>;

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

    string s1, s2; cin >> s1 >> s2;
    s1 = " " + s1; s2 = " " + s2;
    int Y = s1.length(), X = s2.length();
    VVi dp(Y, Vi(X, INT_MAX));

    // 空文字から各 連続部分文字列
    REP(x, 0, X) {
        dp[0][x] = x;
    }

    // 各 連続部分文字列から空文字
    REP(y, 0, Y) {
        dp[y][0] = y;
    }

    REP(y, 1, Y) {
        REP(x, 1, X) {
            int tmp = INT_MAX;
            tmp = min(tmp, dp[y][x-1] + 1);  // 削除
            tmp = min(tmp, dp[y-1][x] + 1);  // 追加
            if (s1[y] == s2[x]) tmp = min(tmp, dp[y-1][x-1]);  // 入替（同じ文字を指す時）
            else tmp = min(tmp, dp[y-1][x-1] + 1);             // 入替（違う文字を指す時）

            dp[y][x] = tmp;
        }
    }

    cout << dp[Y-1][X-1] << endl;

//    REP(y, 0, Y) {
//        REP(x, 0, X) {
//            cout << dp[y][x] << " ";
//        }cout << endl;
//    }

    return 0;
}



Measured memory_bytes: 6804
/** Bismillahir Rahmanir Rahim **/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define Fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define print(x) cout << "x " << x;

int main()
{
    int a;
    cin >> a;
    vector<int> v(a), v1(a);
    for (int i = 0; i < a; i++) cin >> v[i];
    for (int j = 0; j < a; j++) cin >> v1[j];

    vector<int> vv = v, vs = v1;

    sort(v.begin(), v.end());
    sort(v1.begin(), v1.end());

    int cnt = 0, cnt1 = 0;
    while (v != vv) {
        cnt++;
        next_permutation(v.begin(), v.end());
    }

    while (v1 != vs) {
        cnt1++;
        next_permutation(v1.begin(), v1.end());
    }
    cout << abs(cnt1 - cnt) << endl;

    return 0;
}

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

using ll = long long;

long long ext_gcd(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long q = a / b;
    long long g = ext_gcd(b, a - q * b , x, y);
    long long z = x - q * y;
    x = y;
    y = z;
    return g;
}

// x ≡ r (mod m) の (r,m) を返す．m = lcm(m_1,m_2,...)
// 解なしの場合 (-1,-1) を返す．
pair<long long, long long> crt(const vector<long long> &b, const vector<long long> &m) {
    long long r = 0, M = 1;
    for (int i = 0; i < (int)b.size(); ++i) {
        long long p, q;
        long long d = ext_gcd(M, m[i], p, q);
        if ((b[i] - r) % d)
            return make_pair(-1, -1);
        long long tmp = (b[i] - r) / d * p % (m[i] / d);
        r += M * tmp;
        M *= m[i] / d;
    }
    r %= M;
    if (r < 0) r += M;
    return make_pair(r, M);
}

int N;
int P[210], Q[210];
int pos[210];   // i列目に最初にiが現れる時刻
int gap[210];   // i列目の周期

int main() {
    cin >> N;
    REP(i, N) cin >> P[i], P[i]--;
    REP(i, N) cin >> Q[i], Q[i]--;

    REP(i, N) {
        int now = P[i];
        pos[i] = -1;
        REP(j, 2 * N) {
            if (pos[i] < 0 && now == i) {
                pos[i] = j;
            }
            if (j > 0 && now == P[i]) {
                break;
            }
            now = Q[now];
            gap[i]++;
        }

        // i列目にiが現れないなら-1
        if (pos[i] < 0) {
            cout << -1 << endl;
            return 0;
        }
    }

    vector<ll> b, m;
    REP(i, N) {
        b.push_back(pos[i]);
        m.push_back(gap[i]);
    }
    auto p = crt(b, m);
    cout << p.first << endl;
}


Measured memory_bytes: 3148
fun main(args:Array<String>) {
  val map = mutableMapOf<String, Int>()
  val m = readLine()!!.toInt()
  (1..m).map { 
    val e = readLine()!!
    if( map.get(e) == null ) 
      map[e] = 0
    map[e] = map[e]!! + 1 
  }
  val n = readLine()!!.toInt()
  (1..n).map { 
    val e = readLine()!!
    if( map.get(e) == null ) 
      map[e] = 0
    map[e] = map[e]!! - 1 
  }

  val max = map.toList().sortedBy { 
    it.second 
  }.last()

  val maxnum = max.second
  when {
    maxnum <= 0 -> 0
    else -> maxnum
  }.let(::println)
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	map<long, bool> num;
	for(int i = 0; i < n; ++i){
		long temp;
		cin >> temp;
		if(num.find(temp) != num.end() ){
			num[temp] = !num[temp];
		}
		else{
			num[temp] = true;
		}
	}
	int ans = 0;
	for(map<long,bool>::iterator it = num.begin(); it != num.end(); ++it){
		if(it->second)ans++;
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 6528
#include<stdio.h>
int main(void)
{
    int n,syou=0,i;
    scanf("%d",&n);
    for(i=1;i<=9;i++){
        if(n%i==0){
            syou=n/i;
            if(syou<=9){
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main(void){
    char s[11];
    scanf("%s",s);
    long long num;
    long long sum,tmp,ans=0;
    for (int i=0; i<(1<<(strlen(s)-1)); i++){
        num=atoll(s);
        tmp=0;
        sum=0;
        for (int j=0; j<strlen(s); j++){
            tmp+=s[j]-'0';
            if (j==strlen(s)-1){
                sum+=tmp;   
            
            } else if((1&i>>j)==1){
                sum+=tmp;
                tmp=0;
            } else {
                tmp*=10;
            }       
            
        } 
        ans+=sum;
    }
    printf("%lld\n",ans);
	return 0 ;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    vector<pair<long long, long long>> v;
    for (int i = 0; i < n; i++) {
        long long a, b; cin >> a >> b;
        v.emplace_back(a, b);
    }
    sort(v.begin(), v.end());
    map<pair<int, int>, int> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            m[{v[i].first-v[j].first, v[i].second-v[j].second}]++;
        }
    }
    int maxi = 0;
    for (auto x: m) {
        maxi = max(maxi, x.second);
    }
    cout << n - maxi << endl;
    return 0;
}

Measured memory_bytes: 384
/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/
#include<bits/stdc++.h>
#define mod 1000000007
#define modc 998244353
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define deb(x) cout << #x << " " << x << endl;
#define deb2(x,y) cout << #x << " " << x << " " <<  #y << " " << y << endl
#define deb3(x,y,z) cout << #x << " " << x << " " << #y << " " << y << " " << #z << " "  << z << endl;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
using namespace std;
template <class T>
string to_binary(T n)
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
template<class T>
bool perfectSq(T n)
{
	if(sqrt(n) == floor(sqrt(n)))
		return true;
	else
		false;
}
void solve()
{
	int i,j;
	ll sum = 0,prod = 1;
	int n;
	ll a,b,c;
	cin >> n >> a >> b >> c;
	vector<string>v(n);
	for(i=0;i<n;i++)
		cin >> v[i];
	string s;
	for(i=0;i<n;i++)
	{
		if(v[i] == "AB")
		{
			if(a == 1 && b == 1 && i < n-1)
			{
				if(v[i+1] == "AC")
				{
					a++;b--;s+="A";
				}
				else
				{
					a--;b++;s+="B";
				}
			}
			else if(a < b)
			{
				a++;
				b--;
				s+="A";
			}
			else
			{
				a--;
				b++;
				s+="B";
			}
		}
		else if(v[i] == "AC")
		{
			if(a == 1 && c == 1 && i < n-1)
			{
				if(v[i+1] == "AB")
				{
					a++;c--;s+="A";
				}
				else
				{
					a--;c++;s+="C";
				}
			}
			else if(a < c)
			{
				a++;
				c--;
				s+="A";
			}
			else
			{
				a--;
				c++;
				s+="C";
			}
		}
		else
		{
			if(b == 1 && c == 1 && i < n-1)
			{
				if(v[i+1] == "AB")
				{
					b++;c--;s+="B";
				}
				else
				{
					b--;c++;s+="C";
				}
				continue;
			}
			if(b < c)
			{
				b++;
				c--;
				s+="B";
			}
			else
			{
				b--;
				c++;
				s+="C";
			}
		}
		if(a < 0 || b < 0 || c < 0)
		{
			cout << "No" << endl;
			return;
		}
	}
	if(a < 0 || b < 0 || c < 0)
		cout << "No" << endl;
	else
	{
		cout << "Yes" << endl;
		for(i=0;i<s.length();i++)
			cout << s[i] << endl;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	while(t--)
	{
		solve();
	}
}



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

using namespace std;

#define MAX_N 100005


int n, m, dp[MAX_N];

vector<int> adh[MAX_N];

int f_imp(int);

int f(int p)
{
	if (dp[p] == 0)
		dp[p] = f_imp(p) + 1;
	return dp[p] - 1;
}

int f_imp(int p)
{
	int rs = 0;
	for (auto& i: adh[p])
		rs = max(rs, f(i) + 1);
	return rs;
}

int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		t1--;
		t2--;
		adh[t1].push_back(t2);
	}
	int rs = 0;
	for (int i = 0; i < n; i++)
	{
		rs = max(rs, f(i));
	}
	printf("%d\n", rs);
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case(){
	int a, b, x, y;
scanf("%d%d%d%d", &a, &b, &x, &y);
 printf("%lf %d\n", double(a)*double(b) / 2, x + x == a&&y + y == b);
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(9);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3824
{-# LANGUAGE OverloadedStrings #-}

import           Data.Char
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed   as U
import qualified Data.IntMap           as M

main :: IO ()
main = do
  abs <- U.unfoldrN 6 (B.readInt . B.dropWhile isSpace) <$> B.getContents
  B.putStrLn $ if solve abs then "YES" else "NO"

solve :: U.Vector Int -> Bool
solve = (<= 2) . M.size . M.filter odd . U.foldr (flip (M.insertWith (+)) 1) M.empty

Measured memory_bytes: 380
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			System.out.println(IntStream.range(0, n).map(i -> {
				int l = scanner.nextInt(), r = scanner.nextInt();
				return r - l + 1;
			}).sum());
		}
	}
}


Measured memory_bytes: 26984
# coding: utf-8
# Here your code !
count = 1

while 1:
    W = int(input())
    if W == 0:
        break
    N = int(input())
    data =[]
    dp = [[[-1,0]for i in range(W+1)]for i in range(N+1)]
    for i in range(N):
        data.append(input().split(","))

    for i in range(W+1):
        dp[N][i][0] = 0
    for i in reversed(range(N)):
        for capa in range(W+1):
            if int(data[i][1]) > capa:
                dp[i][capa][0] = dp[i+1][capa][0]
                dp[i][capa][1] = dp[i+1][capa][1]
            else:
                dp[i][capa][0] = max(int(data[i][0])+dp[i+1][capa-int(data[i][1])][0],dp[i+1][capa][0])
                dp[i][capa][1] = dp[i+1][capa][1]
                if dp[i][capa][0] != dp[i+1][capa][0]:
                    dp[i][capa][1] = int(data[i][1])+dp[i+1][capa-int(data[i][1])][1]
    print("Case " + str(count) +":")
    print(max(max(dp))[0])
    print(max(max(dp))[1])
 
    count += 1

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

int main() {
    uint N, M;
    cin >> N >> M;
    vector<int> towns(N+1);

    for (size_t i=0; i<M; ++i) {
        uint a, b;
        cin >> a >> b;
        towns[a]++;
        towns[b]++;
    }

    for (size_t i=1; i<towns.size(); ++i) {
        cout << towns[i] << endl;
    }
}


Measured memory_bytes: 3604
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int T = Integer.parseInt(sc.next());
    int A = Integer.parseInt(sc.next());
    
    double min = 10000.0;
    int ans = 0;
    for(int i = 1; i <= N; i++){
      int x = Integer.parseInt(sc.next());
      double d = T - x*0.006;
      double e = Math.abs(A-d);
      if(e < min){
        min = e;
        ans = i;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define rep(i,x) for(int i=0;i<x; i++)
typedef long long  ll;
using namespace std;
int main(){
	ll X,ans=0;;
  cin>>X;
  ans+=(X/500)*1000 + ((X%500)/5)*5;
  cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;

int main(){
  for(int i = 1; i <= 5; i++){
    int x; cin >> x;
    if(x == 0){
      cout << i << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h> 
#define ll long long
#define pb push_back
using namespace std;

const int mod = 1e9+7;

int main(){
  int n,m;
  cin>>n;
  vector<int> a(n),b(n),c(n);
  
  for(int i=0;i<n;i++)
    cin>>a[i]>>b[i]>>c[i];
  
  ll dp [3][n];
  
  dp[0][0]=a[0];
  dp[1][0]=b[0];
  dp[2][0]=c[0];
  
  for(int i=1;i<n;i++){
    dp[0][i] = a[i] + max(dp[1][i-1],dp[2][i-1]);
    dp[1][i] = b[i] + max(dp[0][i-1],dp[2][i-1]);
    dp[2][i] = c[i] + max(dp[1][i-1],dp[0][i-1]);
  }
 
  cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]))<<"\n";
  return 0;
}

Measured memory_bytes: 6696
#include <stdio.h>
int main(void){
  int m;
  int p500;
  int p5;
  int happy;
  scanf("%d",&m);
  p500=m/500;
  p5=(m%500)/5;
  happy=p500*1000+p5*5;
  printf("%d",happy);
  
  return 0;
}

Measured memory_bytes: 128