akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

typedef long long ll;

void solve(std::string S, std::string T, long long A, long long B,
           std::string U)
{
    if (U == S)
    {
        A--;
    }
    else
    {
        B--;
    }
    cout << A << " " << B << endl;
}

int main()
{
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    std::string U;
    std::cin >> U;
    solve(S, T, A, B, U);
    return 0;
}


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

int n, x;
int a[107];
LL sum[107];

int main() {
	while(cin >> n >> x) {
		for(int i = 1; i <= n; i++) cin >> a[i];
		sort(a + 1, a + n + 1);
		sum[0] = 0LL;
		for(int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
		int ans = 0;
		for(int i = 1; i <= n; i++) {
			int num = 0;
			int now = i;
			while(num < x && now <= n) {
				num += a[now];
				now++;
			}
			now--;
			if(num != x || now > n) now--;
			ans = max(ans, now - i + 1);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds ;
#define ll long long
#define ld long double
#define pp pair<ll,ll>
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define sz(a) int((a).size())
#define hell 998244353
#define F first
#define S second
#define sll(x) scanf("%lld",&x)
#define si(x) scanf("%d",&x)
typedef tree<ll , null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update > ordered_set ;
ll t = 1 ;
void solve()
{
    ll n ;
    cin >> n ;
    ll dp[n+1][3] , a[n+1][3] ;
    rep( i , 1 , n + 1 )
    {
        rep( j , 0 , 3 )
            cin >> a[i][j] ;
    }
    memset(dp,0,sizeof(dp));
    dp[1][0] = a[1][0] ;
    dp[1][1] = a[1][1] ;
    dp[1][2] = a[1][2] ;
    rep( i , 2 , n + 1 )
    {
        rep( j , 0 , 3 )
        {
            rep( k , 0 , 3 )
            {
                if( j != k )
                {
                    dp[i][j] = max(dp[i][j],dp[i-1][k]+a[i][j]);
                }
            }
        }
    }
    cout << max(dp[n][0],max(dp[n][1],dp[n][2]));
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // cin>>t;
    while(t--)
        solve() ;
    return 0 ;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define min(p,q)((p)<(q)?(p):(q))
#define zahyoutype double
typedef struct Point{zahyoutype x,y;}P;
int jisho(const void*p,const void*q){
	P *pp=(P*)p,*qq=(P*)q;
	if(pp->y<qq->y)return -1;
	if(pp->y>qq->y)return  1;
	return pp->x>qq->x;
}
double distPP(P p,P q){return hypot(p.x-q.x,p.y-q.y);}
void readpoint(P*p){zahyoutype x=1;scanf(x/2?"%lf%lf":"%ld%ld",&p->x,&p->y);}
void printpoint(P p){zahyoutype x=1;printf(x/2?"%.9lf %.9lf\n":"%ld %ld\n",p.x,p.y);}

P p[100010];
int main(){
	int n;
	scanf("%d",&n);
	double r=rand();
	for(int i=0;i<n;i++){
		P t;
		readpoint(&t);
		p[i].x=t.x*cos(r)-t.y*sin(r);
		p[i].y=t.x*sin(r)+t.y*cos(r);
	}
	qsort(p,n,sizeof(P),jisho);
	double ans=1e10;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n&&p[j].y-p[i].y<ans;j++){
			ans=min(ans,distPP(p[i],p[j]));
		}
	}
	printf("%.9f\n",ans);
}


Measured memory_bytes: 4952
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

long long factorial(int a) // ツ階ツ湘ヲ
{
    long long ret = 1;
    while(a > 0)
        ret *= a--;
    return ret;
}

int main()
{
    int n;
    cin >> n;
    cout << factorial(n) << endl;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<math.h>

int main(void){
	int i,n,x[100],y[100];
	int d1=0,di=0;
	double d2=0.0,d3=0.0;
	
	scanf("%d",&n);
	
	for(i=0; i<n; i++) scanf("%d",&x[i]);
	for(i=0; i<n; i++) scanf("%d",&y[i]);
	for(i=0; i<n; i++){
		d1 += abs(x[i]-y[i]);
		d2 += abs((x[i]-y[i])*(x[i]-y[i]));
		d3 += abs((x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]));
		if(di<abs(x[i]-y[i])) di = abs(x[i]-y[i]);
	}
	printf("%d\n%lf\n%lf\n%d\n",d1,sqrt(d2),pow(d3,1.0/3.0),di);
	return 0;
}

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

#define ALL(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0, __##i##_length = (n); i < __##i##_length; i++)
#define rep_reverse(i, n) for (ll i = (n)-1; 0 <= i; i--)
#define FOR(i, from, to) for (ll i = (from), __##i##_end = (to); i < __##i##_end; i++)
#define FOR_REVERSE(i, from, to) for (ll i = (to)-1, __##i##_end = (from); __##i##_end <= i; i--)
#define foreach(e, v) for (const auto e : (v))
#define vfree(v) std::vector<int>().swap(v)
#define DEBUG(x) cout << #x << " = " << (x) << endl

using namespace std;
typedef int64_t ll;
typedef vector<ll> llv;
typedef vector<llv> llvv;

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

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

ll powmod(ll x, ll p, ll m)
{
    if (p == 0)
        return 1;
    if (p & 1)
        return powmod(x, p - 1, m) * x % m;
    ll r = powmod(x, p / 2, m);
    return r * r % m;
}

constexpr ll MOD = 1000000007;

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


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

int main(){
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    pair<int,int> m;
    m=make_pair(100*a,0);
    int best[5];
    for(int i=0;i<=f/(100*a);i++){
        for(int j=0;j<=(f-100*a*i)/(100*b);j++){
            for(int k=0;k<=(f-100*a*i-100*b*j)/c;k++){
                for(int l=0;l<=(f-100*a*i-100*b*j-c*k)/d;l++){
                    int water=100*a*i+100*b*j;
                    int sugar=c*k+d*l;
                    if(water*e/100>=sugar){
                        if(m.first*sugar>m.second*(sugar+water)){
                            m.first=sugar+water;
                            m.second=sugar;
                        }
                    }
                }
            }
        }
    }
    cout<<m.first<<" "<<m.second<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
int dp[1 << 16][16];
int t[16][17];

bool in_bit(int bit_set, int ind){
  return ((bit_set >> ind) & 1) == 1;
}

int remove_bit(int bit_set, int ind){
  return bit_set ^ (1 << ind);
}

int main(){
  while(true){
    int N;
    cin >> N;
    if(N == 0){
      break;
    }

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

    for(int i = 0; i < N; i++){
      for(int j = 0; j < (1 << N); j++){
        dp[j][i] = INT_MAX;
      }
    }

    for(int i = 0; i < N; i++){
      dp[0][i] = t[i][0];
    }

    for(int bitset = 1; bitset < (1 << N); bitset++){
      for(int i = 0; i < N; i++){
        if(!in_bit(bitset, i)){
          int cur_stage_cost = t[i][0];
          for(int j = 1; j < N + 1; j++){
            if(in_bit(bitset, j - 1)){
              cur_stage_cost = min(cur_stage_cost, t[i][j]);
            }
          }
          for(int j = 0; j < N; j++){
            if(in_bit(bitset, j)){
              int prev_bitset = remove_bit(bitset, j);
              dp[bitset][i] = min(dp[bitset][i], dp[prev_bitset][j] + cur_stage_cost);
            }
          }
        }
      }
    }

    int all_bitset = (1 << N) - 1;
    int ans = INT_MAX;
    for(int i = 0; i < N; i++){
      int tmp = remove_bit(all_bitset, i);
      ans = min(ans, dp[tmp][i]);
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 7160
def main():
    N, W = (int(i) for i in input().split())
    WV = [[int(i) for i in input().split()] for j in range(N)]
    for i in range(1, N):
        WV[i][0] -= WV[0][0]
    w0 = WV[0][0]
    WV[0][0] = 0
    V = {i: [] for i in range(4)}
    for w, v in WV:
        V[w].append(v)
    for i in range(4):
        V[i].sort(reverse=True)
    S = [[0] for i in range(4)]
    for i in range(4):
        for b in V[i]:
            S[i].append(S[i][-1] + b)
    ans = 0
    for i, v0 in enumerate(S[0]):
        for j, v1 in enumerate(S[1]):
            for k, v2 in enumerate(S[2]):
                for m, v3 in enumerate(S[3]):
                    w_cur = w0*(i+j+k+m) + j + 2*k + 3*m
                    if W < w_cur:
                        continue
                    ans = max(ans, v0+v1+v2+v3)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41708
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a[105],b[105],c[105],ans,n;
    int i,f;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(i=1;i<=n;i++)
        scanf("%d",&b[i]);
        f=a[1];
    for(i=1;i<=n;i++)
        f+=b[i];
    ans=f;
    for(i=2;i<=n;i++)
    {
        f=f+a[i]-b[i-1];
        if(f>ans)
            ans=f;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = [input() for _ in range(N)]
    c = Counter(S)
    print("AC x {}".format(c["AC"]))
    print("WA x {}".format(c["WA"]))
    print("TLE x {}".format(c["TLE"]))
    print("RE x {}".format(c["RE"]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 16536
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	// length, _ := strconv.Atoi(sc.Text())

	var min, diff, i int
	for sc.Scan() {
		input, _ := strconv.Atoi(sc.Text())
		if i == 0 {
			min = input
		} else if i == 1 {
			diff = input - min
			if input < min {
				min = input
			}
		} else {
			if diff < input-min {
				diff = input - min
			}
			if input < min {
				min = input
			}
		}
		// fmt.Printf("%d %d\n", min, diff)
		i++
	}
	fmt.Println(diff)
}



Measured memory_bytes: 4128
#include <stdio.h>

int main() {
	int official_house[4][3][10] = { 0 };
	int n=0,b=0,f=0,r=0,v=0;

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d %d %d %d", &b, &f, &r, &v);
		official_house[b - 1][f - 1][r - 1] += v;


	}

	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < 10; k++)
			{
				printf(" %d", official_house[i][j][k]);
			}
			printf("\n");
		}
		if (i < 3) {
			for (int l = 0; l < 20; l++)
			{
				printf("#");
			}
			printf("\n");
		}
	}
	return 0;
}

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

const int64_t INF = 1e18;

int main() {
    int a, b, q;
    cin >> a >> b >> q;
    vector<int64_t> s(a + 2, INF), t(b + 2, INF);
    for(int i = 0; i < a; ++i) cin >> s[i + 1];
    for(int i = 0; i < b; ++i) cin >> t[i + 1];
    s[0] = -INF;
    t[0] = -INF;
    while(q--) {
        int64_t x; cin >> x;
        auto sr = lower_bound(s.begin(), s.end(), x);
        auto sl = prev(sr);
        auto tr = lower_bound(t.begin(), t.end(), x);
        auto tl = prev(tr);
        auto d = [&](int64_t y) -> int64_t { return abs(x - y); };
        int64_t ans = min(max(d(*sr), d(*tr)), max(d(*sl), d(*tl)));
        ans = min(ans, 2 * d(*sl) + d(*tr));
        ans = min(ans, d(*sl) + 2 * d(*tr));
        ans = min(ans, 2 * d(*sr) + d(*tl));
        ans = min(ans, d(*sr) + 2 * d(*tl));
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 2944
#include <stdio.h>

int main() {
    int m, d;
    scanf("%d %d", &m, &d);
    int count = 0;

    for (int i = 22; i <= d; i++) {
        if ((i % 10) < 2) continue;
        if ((i / 10) < 2) continue;
        if ((i % 10) * (i / 10) > m) continue;
        count++;
    }

    printf("%d\n", count);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl

//-----
const int N = 1e5 + 7;
int dp[N];
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
  string s; cin >> s;
  vector<string> v = {"dream", "dreamer", "erase", "eraser"};
  rep(i, 0, sz(s)) {
  	for (auto e : v) if (i - sz(e) + 1 >= 0 && s.substr(i - sz(e) + 1, sz(e)) == e) {
  		if (i - sz(e) < 0 || dp[i - sz(e)]) dp[i] = true;
		}
	}
	cout << (dp[sz(s) - 1] ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 848
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            while (true)
            {
                var inputs = Console.ReadLine().Split(' ');
                var H = int.Parse(inputs[0]);
                var W = int.Parse(inputs[1]);
                if (H==0 && W==0) return;

                const char blockA = '#';
                const char blockB = '.';
                var lineA = new char[W];
                var lineB = new char[W];
                AppendCheck(ref lineA, blockA, blockB);
                AppendCheck(ref lineB, blockB, blockA);

                for (int i = 0; i < H; i++)
                {
                    if ((i & 1) == 0) Console.WriteLine(new string(lineA));
                    else Console.WriteLine(new string(lineB));
                }
                Console.WriteLine();
            }
        }

        public static void AppendCheck(ref char[] str, char first, char second)
        {
            var togle = false;
            str = Array.ConvertAll(str, x =>
            {
                togle = !togle;
                if (togle) return first;
                else return second;
            });
        }
    }
}

Measured memory_bytes: 5388
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <complex>
#include <cassert>

#define enp     puts("**chkchkchkchkchk**")
#define A       first
#define B       second
#define MP      make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;

const int INF = 0x60000000;
const int MINF = -1000000000;
const int mod = 1000000007;
const ll cons = 100000;
const double pi = 3.141592653589793;


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

	int g = 0;
	int p = 0;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == 'p')p++;
		else g++;
	}

	printf("%d\n", (g - p) / 2);

	return 0;
}

Measured memory_bytes: 512
def ConectCities():
    from collections import deque
    n, m = map(int, input().split())
    a = [[] for _ in range(n)]
    route = set()
    ans = 0
    q = deque()

    for i in range(m):
        x, y = map(int, input().split())
        a[x-1].append(y-1)
        a[y-1].append(x-1)

    for i in range(n):
        if i in route:
            continue
        elif i != 0:
            ans += 1
        route.add(i)
        q.append(i)
        
        while q:
            k = q.pop()
            route.add(k)
            for j in a[k]:
                if j in route:
                    continue
                route.add(j)
                q.append(j)
        if len(route) == n:
            print(ans)
            break

if __name__ == '__main__':
    ConectCities()



Measured memory_bytes: 93780
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) for(auto x:obj)cout<<x<<' ';cout<<endl;
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int N;


int main(){
	cin>>N;
	vector<ll> A(N);
	ll minus = 1LL;
	rep(i,N){
		cin>>A[i];
		if(A[i]%2 == 0)minus *= 2;
	}
	ll ans = pow(3,N);
	cout<<ans-minus<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,k;
    cin>>a>>b>>k;
    if(a-k<=0){
      	if(b-(k-a)>=0){
        cout<<0<<' '<<b-(k-a);
        }
      	else{
          cout<<0<<' '<<0;
        }
    }
    else{
        cout<<a-k<<' '<<b;
    }
    return(0);
}

Measured memory_bytes: 256
using System;

namespace ABC122_A
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string input = Console.ReadLine();

			if (input == "A")
			{
				Console.WriteLine("T");
			}else if (input == "T")
			{
				Console.WriteLine("A");
			}else if(input == "C")
				Console.WriteLine("G");
			else Console.WriteLine("C");
				
			
		}
	}
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 long double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007LL
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  101LL
#define tmod             998244353LL
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll Powb(ll b,ll n,ll m);
ll BS(vector<pair< ll ,ll > > &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
ll P[N+1];
void Sieve(int n=N);

int main()
{
fast;
ll q=1,t;
//cin >> q; t = q;
while(q--)
{
    ll i,j,n,m,k,l=0,r=0,a=1,b=0,c=0,d=0,e,g=1,p,u,v,w,x,y,flag=1;
    //n=m=k=i=j=l=r=a=b=c=d=u=v=w=p=x=y=0;
    cin >> n;
    ll ans = n-1;
    for(i=1;i*i<=n;i++)
    {
        if(n%i==0)
            ans = min(ans,i+n/i - 2);
    }
    cout << ans;
}

    return 0;
}

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

ll Powb(ll b,ll n,ll m)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2,m);
    if(n%2==0){return (temp*temp)%m;}
    else{return (b*((temp*temp)%m))%m;}
}

ll BS(vector<pair<ll,ll> > &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid].F==ser)
    {
        return mid;
    }
    else if(PS[mid].F > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

void Sieve(int n)
{
    //memset(P,true,sizeof(P));
    //P[0] = false;
    //P[1]= false;
    for(int i=1;i<=n;i++) P[i] = i;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i]==i)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                if(P[j]==j)
                    P[j]=i;
            }
        }
    }

}



Measured memory_bytes: 3700
#include <stdio.h>
#define MAX 10000

int Parent(int i){
  return i/2;
}

int Left(int i){
  return 2*i;
}

int Right(int i){
  return 2*i+1;
} 

main(){

  int n, j,k,u[MAX], p, l, r;
  scanf ("%d", &n);

  for(j=1;j<=n;j++){
    scanf("%d", &u[j]);
  }

  for(k=1;k<=n;k++){
    printf("node %d: key = %d, ", k, u[k]);
    p = Parent(k);
    l = Left(k);
    r = Right(k);

    if(p >= 1){
      printf("parent key = %d, ", u[p]);
    }

    if(l <= n){
      printf("left key = %d, ", u[l]);
    }

    if(r <= n){
      printf("right key = %d, ", u[r]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 608
#include <cstdio>
using namespace std;
const int maxn=1e5+10;

int n,a[maxn];
int ans,s;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	
	int pos=1;
	while(pos<=n)
	{
		s=0;
		while(pos<=n && a[pos]==pos) pos++,s++;
		ans+=(s+1)/2;
		pos++;
	}
	printf("%d\n",ans);
	return 0; 
}

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

#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

inline int read(){
	int f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll readll(){
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=5005,MOD=1e9+7;
inline int mod(int x){return x<MOD?x:x-MOD;}
int n,sz[MAXN],dp[MAXN][MAXN],tmp[MAXN],f[MAXN];
vector<int>G[MAXN];
void dfs(int u,int fa){
	sz[u]=dp[u][1]=1;
	for(int i=0;i<(int)G[u].size();++i){
		int v=G[u][i];
		if(v==fa)continue;
		dfs(v,u);
		for(int j=0;j<=sz[u]+sz[v];++j)tmp[j]=0;
		for(int j=1;j<=sz[u];++j){
			for(int k=0;k<=sz[v];++k){
				tmp[j+k]=mod(tmp[j+k]+(ll)dp[u][j]*dp[v][k]%MOD);
			}
		}
		sz[u]+=sz[v];
		for(int i=1;i<=sz[u];++i)dp[u][i]=tmp[i];
	}
	for(int i=1;i<=sz[u];++i){
		dp[u][0]=mod(dp[u][0]+(ll)dp[u][i]*f[i]%MOD);
	}
	dp[u][0]=mod(MOD-dp[u][0]);
}
int main() {
	n=read();
	for(int i=1,u,v;i<n;++i)u=read(),v=read(),G[u].pb(v),G[v].pb(u);
	f[0]=1;
	for(int i=2;i<=n;i+=2)f[i]=(ll)f[i-2]*(i-1)%MOD;
	dfs(1,0);
	cout<<mod(MOD-dp[1][0])<<endl;
	return 0;
}

Measured memory_bytes: 97536
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for i in range(n)]
INF = 10**12

def calc_cost(l):
    ret = 0
    rikai = [0 for _ in range(m)]
    for i in range(len(l)):
        c = l[i][0]
        ret += c
        a = l[i][1:]
        for j in range(m):
            rikai[j] += a[j]

    for i in range(m):
        if rikai[i] < x:
            ret = INF
    return ret

ans = INF
for i in range(2**n):
    l = []
    for j in range(n):
        if i >> j & 1:
            l.append(ca[j])
    ans = min(ans, calc_cost(l))
if ans == INF:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 68988
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		
		int max = 0;
		if (A >= B) {
			max = (A >= C) ? A*10+B+C : C*10+A+B;
		} else {
			max = (B >= C) ? B*10+A+C : C*10+B+A;
		}
		
		System.out.println(max);
	}
}

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

using namespace std;

const int N = 1e5 + 5;

int n;
int cnt[2][N];
pair<int, int> b[2];

void update(pair<int, int>& a, int num, int type) {
  if (cnt[type][num] > cnt[type][a.first]) a.second = a.first, a.first = num;
  else if (cnt[type][num] > cnt[type][a.second]) a.second = num;
}

int calc(int x, int y) {
  return n - cnt[0][x] - cnt[1][y];
}

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x; cin >> x; 
    cnt[i % 2][x]++;
  }
  for (int i = 1; i <= 100000; i++) update(b[0], i, 0), update(b[1], i, 1);
  int ans = 0x3f3f3f3f;
  if (b[0].first != b[1].first) ans = min(ans, calc(b[0].first, b[1].first)); 
  if (b[0].second != b[1].first) ans = min(ans, calc(b[0].second, b[1].first));
  if (b[0].first != b[1].second) ans = min(ans, calc(b[0].first, b[1].second)); 
  if (b[0].second != b[1].second) ans = min(ans, calc(b[0].second, b[1].second));
  cout << ans << '\n';
  return 0; 
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var blues = new Dictionary<string, long>();
            for (var i = 0; i < N; ++i)
            {
                var s = ReadLine();
                if (blues.ContainsKey(s))
                    ++blues[s];
                else
                    blues[s] = 1;
            }
            var M = Sarray()[0];
            var reds = new Dictionary<string, long>();
            for (var i = 0; i < M; ++i)
            {
                var t = ReadLine();
                if (reds.ContainsKey(t))
                    ++reds[t];
                else
                    reds[t] = 1;
            }
            var ans = 0L;
            foreach (var kv in blues)
            {
                var red = reds.ContainsKey(kv.Key) ? reds[kv.Key] : 0;
                ans = Max(ans, kv.Value - red);
            }
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

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

int main() {
  char a;
  int b, c, d;
  cin >>b >>a >>c; 
  
  if(a=='+') {
    d = b+c;
  }
  else {
    d = b-c;
  }
  
  
  cout <<d <<endl;
}


Measured memory_bytes: 256
#define inf 9223372036854775807
#define ll long long
#define pii pair<ll,ll>
#define m_p  make_pair
#define ull unsigned long long
#define spd  ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;

    cin>>s;
    int sum=0;
    for(int i=0;i<s.size();i++)
    {
        sum+=(s[i]-'0');
    }

    if(sum%9)cout<<"No"<<endl;

    else
        cout<<"Yes"<<endl;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	ll n;
	cin >> n;
	mll pf;
	for (ll i = 2;i * i <= n;i++) {
		while (n % i == 0) {
			pf[i]++;
			n /= i;
		}
	}
	if (n > 1)
		pf[n]++;
	int ans = 0;
	for (auto &x : pf) {
		if (x.se < 3)
			ans++;
		else if (x.se < 6)
			ans += 2;
		else if (x.se < 10)
			ans += 3;
		else if (x.se < 15)
			ans += 4;
		else if (x.se < 21)
			ans += 5;
		else if (x.se < 28)
			ans += 6;
		else if (x.se < 36)
			ans += 7;
		else
			ans += 8;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3656
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

//std::cout << std::fixed << std::setprecision(10)
constexpr long long MOD = 1000000007;

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

int main()
{
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  std::cin >> k;
  std::cout << a[k-1] << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main () {
	int p, q, r, min = 100;
	scanf("%d %d %d", &p, &q, &r);
	if(q < p){
		min = q;
		q = p;
		p = min;
	}
	if(r < q){
		min = q;
		q = r;
		r = min;
	}
	printf("%d\n", p + q);

	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

typedef int64_t ll;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;

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; }

using namespace std;


class B {
	int n, x;
	int mi{ INTMAX };
public:
	B()
	{
		cin >> n >> x;
		int tmp;
		REP(i, n)
		{
			cin >> tmp;
			x -= tmp;
			chmin(mi, tmp);
		}
	}
	void solve()
	{
		int ans{ n };
		ans += x / mi;

		cout << ans << endl;
		
	}
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

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

int main (){
  string T;
  cin>>T;
  rep(i,T.length()){
    if(T[i]=='?'){
      cout<<'D';
    }
    else cout<<T[i];
  }
}


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

bool card[4][14];
char mk[] = { 'S','H','C','D' };

int main() {
	memset(card, true, sizeof(card));
	int	n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		char mark;
		int num;
		cin >> mark >> num;

		if (mark == 'S') {
			card[0][num] = false;
		}
		if (mark == 'H') {
			card[1][num] = false;
		}
		if (mark == 'C') {
			card[2][num] = false;
		}
		if (mark == 'D') {
			card[3][num] = false;
		}
	}

	for (int i = 0; i < 4; ++i) {
		for (int i2 = 1; i2 <= 13; ++i2) {
			if (card[i][i2]) {
				cout << mk[i] << ' ' << i2 << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3064
def inpl(): return [int(i) for i in input().split()]
class UnionFind():
    def __init__(self, num):
        self.par = [-1 for _ in range(num)]
    
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            x = self.par[x]
            return self.find(x)
    
    def union(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        if rx != ry:
            if self.par[rx] < self.par[ry]:
                self.par[ry] = rx
            if self.par[rx] > self.par[ry]:
                self.par[rx] = ry
            else:
                self.par[rx] -= 1
                self.par[ry] = rx
        return

from collections import defaultdict
H = defaultdict(lambda: set([]))
H1 = defaultdict(lambda: set([]))
N, M = inpl()
p = inpl()
deer = UnionFind(N)
for _ in range(M):
    x, y = inpl()
    deer.union(x-1,y-1)

for i in range(N):
    H[deer.find(i)].add(i+1)
    H1[deer.find(i)].add(p[i])
    
ans =0
for i in H:
    ans += len(H[i] & H1[i])
print(ans)

Measured memory_bytes: 71820
#include <bits/stdc++.h>
using namespace std;
int main () {
    int s;
    cin >> s;
    bool b[1000000];
    for(int  i = 0; i < 1000000; i++)
    {
        b[i] = false;
    }
    b[s] = true;
    int a = s;
    int i = 1;
    while(true){
        i++;
        if(a %2 == 0){
            a = a/2;
        }else{
            a = 3 * a + 1;
        }
        if(b[a]){
            cout << i << endl;
            break;
        }else{
            b[a] = true;
        }
    }
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
    long long N, M;
    cin >> N >> M;

    vector<vector<long long>> neighbors(N);
    vector<long long> labels(N, -1);

    for (long long i = 0; i < M; ++i) {
        long long A, B;
        cin >> A >> B;

        neighbors.at(A - 1).push_back(B - 1);
        neighbors.at(B - 1).push_back(A - 1);
    }

    queue<long long> q;

    q.push(0);

    long long count = 0;

    while (q.size() > 0) {
        long long current = q.front();
        q.pop();

        for (long long n : neighbors.at(current)) {
            if (labels.at(n) == -1) {
                labels.at(n) = current;
                count++;
                q.push(n);
            }
        }
    }

    if (count < N - 1) {
        cout <<  "No" << endl;
    } else {
        cout << "Yes" << endl;

        for (long long i = 1; i < N; ++i) {
            cout << labels.at(i) + 1 << endl;
        }
    }

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++){
        a.at(i) = i + 1;
    }
    
    long long totalNumber = 0;
    
    for (int i = 0; i < n; i++){
        if (a.at(i) % 3 == 0 || a.at(i) % 5 == 0){
            continue;
        }else{
            totalNumber += a.at(i);
        }
    }
    
    cout << totalNumber << endl;
}

Measured memory_bytes: 7132
#include<iostream>
#include<cstdio>
using namespace std;
int a[50],n;
int solve(int i,int m)
{
  if(m == 0) return 1;
  if(i>=n) return 0;
  int res = solve(i+1,m) || solve(i+1,m-a[i]);
  return res;
  }
int main()
{
  int q,M,i;
  scanf("%d",&n);
  for( i = 0;i<n;i++)
     scanf("%d",&a[i]);
  scanf("%d",&q);
  for(i = 0;i<q;i++)
  {
      scanf("%d",&M);
      if(solve(0,M)) printf("yes\n");
      else printf("no\n");
  }
 return 0 ;
}



Measured memory_bytes: 3016
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 2e5 + 5, M = 2 * N + 5;

ll lim(1e18);

bool isOver(ld x, ld y){
    return x * y > 1e18;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
#endif
    int n;
    cin >> n;

    ld res = 1;
    bool ok = true;
    bool zero = false;

    while(n--){
        ld x;
        cin >> x;

        if(isOver(res, x))
            ok = false;

        if(ok)res *= x;

        if(!x)zero = true;
    }

    if(zero)res = 0, ok = 1;

    if(ok)cout << fixed << setprecision(0) << res << endl;
    else puts("-1");
}


Measured memory_bytes: 3752
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
  int n;
  cin >> n;
  map<string, int> m;
  string s1;
  cin >> s1;
  m[s1]++;

  string s2;
  for (int i = 1; i < n; i++) {
    cin >> s2;
    m[s2]++;
    if (m[s2] > 1) {
      cout << "No" << endl;
      return 0;
    }

    if (s1.back() != s2.front()) {
      cout << "No" << endl;
      return 0;
    }
    s1 = s2;
  }
  cout << "Yes" << endl;
  
  return 0;
}


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

int main(void)
{
	char yaki[100];
	scanf("%s", yaki);
	if(yaki[0] == 'Y'
		&& yaki[1] == 'A'
		&& yaki[2] == 'K'
		&& yaki[3] == 'I')
	{
		printf("Yes");
	}
	else{
		printf("No");
	}
}

Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}



#[allow(non_snake_case, unused_variables)]
fn main() {
    input!{
        N: usize,
        a: [usize;N],
    }
    let mut cnt: u32 = 0;
    for i in 0..N {
        if a[a[i]-1]==i+1 {
            cnt += 1;
        }
    }
    println!("{}", cnt/2);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define inf 1e18
#define err(x) cout<<x<<endl
#define all(x) x.begin(),x.end()
#define input_from_file  freopen("input.txt", "r", stdin);
#define sz 100005
using namespace std;

ll a[sz];
ll b[sz];

int main()
{

    FASTIO
    ll n;
    cin >> n;
    for(ll i=1;i<=n;i++)
    cin >> a[i],b[i]= a[i];
    sort(a+1,a+n+1);
    bool ok = true;
    for(ll i=1;i<=n;i++)
    {
      if(abs(b[i]-a[i]) >1)
      ok= false;
    }
    if(ok)
    cout <<"Yes";
    else
    cout <<"No";





return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <climits>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP1(i,n) for(ll i=1;i<=(ll)(n);i++)

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

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

ll power(ll a, ll n)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2);
    p = (p * p);
    if (n % 2)
        return (p * a);
    else
        return p;
}

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

  int n;

  cin >> n;

  int one = n % 10;
    
  if( one == 2 || one == 4 || one == 5 || one == 7 || one == 9){
      cout << "hon" << endl;
  } else if( one == 0 || one == 1 || one == 6 || one == 8 ) {
      cout << "pon" << endl;
  } else {
      cout << "bon" << endl;
  }
  return 0;
}




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

int main()
{
    int N;
    cin >> N;
    vector<long double> A(N, 0), B(N, 0);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i] >> B[i];
    }
    ll ans = 0;
    for (int i = N - 1; i >= 0; i--)
    {
        ans += ceil((ans + A[i]) / B[i]) * B[i] - (ans + A[i]);
    }
    cout << ans << endl;

    return 0;
}

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

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

    int cnt = 700;
    for (char x : s)
    {
        if (x == 'o')
        {
            cnt += 100;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

#define MAX_N 300000

int main()
{
    bool isMonFri[MAX_N+1];
    REP(i, 6, MAX_N+1){
        if (i % 7 == 1 || i % 7 == 6)
            isMonFri[i] = true;
    }
    vi v;
    REP(i, 6, MAX_N+1){
        if (isMonFri[i]) {
            v.pb(i);
            for (int j = i+i; j < MAX_N+1; j += i){
                isMonFri[j] = false;
            }
        }
    }
    int n;
    while (cin >> n, n != 1) {
        cout << n << ":";
        rep(i, v.size()){
            if(n % v[i] == 0)
                cout << " " << v[i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1640
#include<bits/stdc++.h>
using namespace std;
int H ,W ,D , A ;
int Q ,L , R ;
int px [90001] , py [90001];
int d [90001];
int main ()
{
cin>>H>>W>>D;
for ( int i =0; i < H ; i ++)
{
for ( int j =0; j < W ; j ++)
{
cin>>A;
px [ A ]= i , py [ A ]= j ;
}
}
for ( int i = D +1; i <= H * W ; i ++)
d[ i ]= d [i - D ]+ abs ( px [ i ] - px [i - D ])+ abs ( py [ i ] - py [i - D ]);
cin>>Q;
while (Q--){
cin>>L>>R;
  cout<<d[R]-d[L]<<endl;
}
}


Measured memory_bytes: 2176
import sys
from collections import defaultdict
class UnionFind():
    def __init__(self,size):
        self.table = [-1 for _  in range(size)]
    def find(self,x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x

    def union(self,x,y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] != self.table[s2]:
                if self.table[s1] < self.table[s2]:
                    self.table[s2] = s1
                else:
                    self.table[s1] = s2
            else:
                self.table[s1] += -1
                self.table[s2] = s1
        return
n,k,l = map(int, sys.stdin.readline().split())
p = []
for i in range(k):
    p.append(list(map(int, input().split())))
do = [[] for i in range(n+1)]
for pi in p:  #0-originedに注意
    do[pi[0]].append(pi[1])
p = []
for i in range(l):
    p.append(list(map(int, input().split())))
te = [[] for i in range(n+1)]
for pi in p:  #0-originedに注意
    te[pi[0]].append(pi[1])
dou = UnionFind(n)
for i in range(n+1):
  a = do[i]
  for j in a:
    dou.union(i-1,j-1)
douro = [-1] * n
for i in range(n):
  douro[i] = dou.find(i)
tet = UnionFind(n)
for i in range(n+1):
  a = te[i]
  for j in a:
    tet.union(i-1,j-1)
tetu = [-1] * n
for i in range(n):
  tetu[i] = tet.find(i)
d = defaultdict(int)
for i in range(n): 
  d[(douro[i],tetu[i])] += 1
ans = []
for i in range(n):
  ans.append(d[(douro[i],tetu[i])])
print(" ".join(map(str,ans)))

Measured memory_bytes: 114560
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,k,n;
    scanf("%d",&n);
    long long  a[n+10],x=0,y=0;
    for(i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        if(i==0)
        {
            x+=a[i];
        }
        else
        {
            y+=a[i];
        }

    }
    long long ans,ansmin;
    ans=abs(x-y);
    ansmin=ans;
    i=1;
    while(i<n-1)
    {
        x+=a[i];
        y-=a[i];
        ans=abs(x-y);
        if(ans<ansmin)
        {
            ansmin=ans;
        }
        i++;
    }
    printf("%lld",ansmin);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#include <algorithm>
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define MOD 1000000007;
using namespace std;

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

    size_t n {};
    string s;
    cin >> n >> s;

    if (n%2) cout<<"No"<<endl;
    else {
    	string a {s.substr(0, n/2)};
    	string b {s.substr(n/2, n/2)};
    	cout<<((a == b) ? "Yes": "No")<<endl;
    }
    return 0;
}


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    string s, t;
    cin >> s >> t;
    if (s[0] == t[2] && s[1] == t[1] && s[2] == t[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
array = Array.new
while true
	a = gets.split(" ").map{|e|e.to_i}
	break if a[0] == 0 && a[1] == 0
	array.push a
end

array.each{|a|
	a[0].times{|a0|
		a[1].times{|a1|
			if a0 == 0 || a0 == a[0]-1 || a1 == 0 || a1 == a[1]-1
				print "#"
			else
				print "."
			end
		}
		puts ""
	}
	puts ""
}

Measured memory_bytes: 6112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

int main(){
    int n;cin>>n;
    vector<bool> v=prime_table(n*10);
    for(int i=0;i<n*10;i++){
        if(v[i]==true&&i>=n){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 384
import numpy as np

n, x = map(int,input().split())
size = [1]
full_p = [1]
for i in range(n):
    size.append(size[i]*2+3)
    full_p.append(full_p[i]*2+1)

# print(size)
def num_p(x,n):
    if n == 0:
        return 1
    burg = size[n-1]
    if x == 1:
        return 0
    elif x == burg+2:
        return full_p[n-1]+1
    elif x < burg +2:
        return num_p(x-1,n-1)
    elif x > burg+2:
        return full_p[n-1]+1+num_p(x-(burg+2),n-1)

# print(size)
ans = num_p(x,n)

print(ans)


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

int main()
{
	ll A,B,N;ll sum=0;
  	pair<ll,ll> somepair;
	cin>>N;vector<pair<ll,ll>> vect;
  	for(ll i=0;i<N;i++)
    {
      cin>>A>>B;
      vect.push_back(make_pair(B,A));
    }
  	sort(vect.begin(),vect.end());
  	for(ll i=0;i<N;i++)
    {
      sum+=vect[i].second;
      if(sum>vect[i].first)
      {cout<<"No"<<endl;
      	return 0;}
    }
  	cout<<"Yes"<<endl;
  	return 0;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,x,n) for (int i = x; i < n; i++)
using ll = long long int;
int main() {
    int n; cin >> n;
    vector<int> x(n,0),y(n,0),z(n,0),w(n,0);
    rep(i,n) {
        cin >> x[i] >> y[i];
        z[i] = x[i] + y[i];
        w[i] = x[i] - y[i];
    }
    sort(z.begin(),z.end());
    sort(w.begin(),w.end());
    int ans = max(z[n-1]-z[0], w[n-1]-w[0]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6408