akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

#define NUMBER 10 //区分の数+1
#define TRAIN 3 //電車の数+1

void initialize(int array[], int n);
void sigma(int sum_division[], int division[], int n);
int judge(double r_time, int velocity, int sum_velocity[]);

main()
{
	int division[NUMBER];
	int sum_division[NUMBER - 1];
	int velocity[TRAIN];
	
	double running_time = 0;
	int result = 0;
	
	initialize(division, NUMBER);
	initialize(sum_division, NUMBER);
	initialize(velocity, TRAIN);
	
	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &division[0], &division[1], &division[2], &division[3], &division[4], &division[5], &division[6], &division[7], &division[8], &division[9], &velocity[0], &velocity[1]) != EOF)
	{
		sigma(sum_division, division, NUMBER);
		velocity[2] = velocity[0] + velocity[1];
		//printf("velocity[2] = %d\n", velocity[2]); //デバッグ用
		running_time = (double)sum_division[9] / velocity[2];
		//printf("runnning_time = %lf\n", running_time); //デバッグ用
		result = judge(running_time, velocity[0], sum_division);
		printf("%d\n", result);
		
		initialize(division, NUMBER);
		initialize(sum_division, NUMBER);
		initialize(velocity, TRAIN);
	}
	return 0;
}

void initialize(int array[], int n)
{
	int i = 0;
	for(i = 0; i < n; i++)
	{
		array[i] = 0;
	}
}

void sigma(int sum_division[], int division[], int n)
{
	int i= 0;
	for(i = 0; i < n; i++)
	{
		if(i == 0)
		{
			sum_division[i] = division[i];
		}
		else
		{
			sum_division[i] = sum_division[i - 1] + division[i];
		}
		//printf("sum_division[%d] = %d\n", i, sum_division[i]); //デバッグ用
	}
}

int judge(double r_time, int velocity, int sum_division[])
{
	int i = 0, j = 0;
	double distance = 0;
	
	distance = (double)velocity * r_time;
	//printf("distance = %lf\n", distance); //デバッグ用
	for(i = 0; i < NUMBER; i++)
	{
		j = i + 1;
		//printf("i = %d j = %d\n", i, j); //デバッグ用
		if((sum_division[i] < distance) && (sum_division[j] >= distance))
		{
			return j + 1;
		}
	}
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;


int main(){
  ll N, A, B;
  cin >> N >> A >> B;
  ll res = min(N*A, B);
  cout << res << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n, k; cin >> n >> k;
    vint h(n);
    rep(i,n) cin >> h[i];
    vint dp(n,inf);
    dp[n-1] = 0;
    for (int i = n-2; i >= 0; i--) {
        REP(j,k+1) {
            if (i+j < n) chmin(dp[i],dp[i+j]+abs(h[i]-h[i+j]));
        }
    }
    cout << dp[0] << endl;
}

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, int> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

bool check(const vector<int> &arr, const vector<vector<bool>> &bridge) {
    for (int i = 1; i < arr.size(); i++) {
        int from = arr[i - 1];
        int to = arr[i];
        if (!bridge[from][to]) return false;
    }
    return true;
}

int main() {


    int n, m;
    cin >> n >> m;

    vector<vector<bool>> bridge(n, vector<bool>(n, false));
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        bridge[a][b] = true;
        bridge[b][a] = true;
    }

    vector<int> arr(n);
    rep(i, n)arr[i] = i;

    int ans = 0;
    do {
        if (arr[0] != 0) continue;
        bool b = check(arr, bridge);
        if (b) ans++;
    } while (std::next_permutation(arr.begin(), arr.end()));
    cout << ans << endl;
}


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

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

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


/*
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <ctype.h>
*/
typedef struct  llnode
{
	int x;
	struct llnode *next;
}
slnode;


using namespace std;

typedef pair<int , int > pii;
typedef pair<long , long> pll;
typedef pair<pii , int > piii;
typedef pair<pll , long > plll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector <pii> vii;
typedef vector<pll> vll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned long long int ulli;
typedef long long int lli;
typedef double d;
typedef float f;
typedef string s;
typedef char ch;
typedef pair<int,ll> pill;

#define loop(n) for(int i = 0; i < (n); i++)
#define lp(x , s , e) for(int x = (s); x < (e); x++)
#define lpe(x , s , e) for(int x = (s); x <= (e); x++)
#define readline(s) getline(cin,s)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define clr(x , val) memset((x) , (val) , sizeof(x))
#define endl '\n'

ll power(ll a, ll b)
{
    ll res = 1;
    for(int i = 0; i<b; i++)
       res *= a;

    return res;
}
int findSingle(int ar[], int ar_size)
    {
        int res = ar[0];
        for (int i = 1; i < ar_size; i++)
            res = res ^ ar[i];
        return res;
    }
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n , m;
    cin >> n >> m;
    ll sum = 0;
    int temp;
    while(m--)
    {
    	cin >> temp;
    	sum += temp;
    }
    if (sum > n)
    	cout << -1;
    else
    	cout << n - sum;
    return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

// a^n mod を計算する
long int modpow(long int a, long int n, long int mod) {
    long int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    const long int mod = 2019;
    string s;
    cin >> s;
    long int m[s.size()+1];
    m[0] = (s[s.size()-1] - '0') % mod;
    long int num = 1;
    for (int i = 1; i < s.size(); i++){
        num *= 10;
        num %= mod;
        m[i] = ((m[i-1]) + (s[s.size()-i-1] - '0') * num) % mod;
    }
    m[s.size()] = 0;
    sort(m, m + s.size() + 1);
    vector<long int> a;
    long int t = 1;
    for (int i = 1; i < s.size() + 1; i++){
        if(m[i] == m[i-1]){
            t++;
        }else{
            if(t >= 2){
                a.push_back(t);
                t = 1;
            }
        }
    }
    if(t >= 2){
        a.push_back(t);
    }
    long int ans = 0;
    rep(i, a.size()){
        ans += (a[i] * (a[i] - 1)) / 2;
    }
    cout << ans << endl;
}



Measured memory_bytes: 5264
#include<bits/stdc++.h>
#define ll long long
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define mod 1000000007
#define f first
#define sec second
#define gcd(x,y) __gcd(x, y)
using namespace std;
int main()
{
	int i,b=0,c=0;
	char s[5];
	scanf("%s",s);
	for(i=0;i<3;i++)
	{
		if(s[i]=='R')c++;
		else 
		c=0;
		b=c>b?c:b;
	}
	printf("%d\n",b);
}

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

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	cout << min(A * N, B);
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

ANとBのうち小さい方が最小の駐車料金なので解いておしまい
*/

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;
    n++;

    vector<array<int, 2>> p(n);
    p[0][0] = p[0][1] = 0;
    for (int i = 1; i < n; i++) {
        cin >> p[i][0] >> p[i][1];
    }

    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        b[i] = 1;
    }

    vector<int> a[2];
    for (int k = 0; k < 2; k++) {
        a[k] = vector<int>(n);
        for (int i = 0; i < n; i++) {
            a[k][i] = i;
        }
    }

    sort(a[0].begin(), a[0].end(), [&](const int& i0, const int& i1) {
        return p[i0][1] < p[i1][1];
    });
    sort(a[1].begin(), a[1].end(), [&](const int& i0, const int& i1) {
        return p[i0][0] > p[i1][0];
    });

    ll r = 0;
    int i0 = 0, i1 = 0;
    for (int i = 0; i < n / 2; i++) {
        while (i0 < n && !b[a[0][i0]]) i0++;
        while (i1 < n && !b[a[1][i1]]) i1++;
        int j0 = a[0][i0];
        int j1 = a[1][i1];
        b[j0] = b[j1] = 0;
        int t = p[j1][0] - p[j0][1];
        if (t <= 0) continue;
        r += t * 2;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define ll long long 
#define pb push_back
#define MAX 10000005
#define mod 1000000007
#define sp fixed<<setprecision(12)
using namespace std;
/*
vector<int> primes;
ll sumprime[MAX];
bool is_prime[MAX];
void sieve(){
	is_prime[0]=is_prime[1]=true;
	for(int i=4;i<MAX;i+=2){
		is_prime[i]=true;
	}
	for(int i=3;i*i<MAX;i+=2){
		if(!is_prime[i]){
			for(int j=i*i;j<MAX;j+=i){
				is_prime[j]=true;
			}
		}
	}
	for(int i=0;i<MAX;i++){
		if(!is_prime[i]){
			sumprime[i]=sumprime[i-1]+i;
		}else{
			sumprime[i]=sumprime[i-1];
		}
	}
}
*/


int main(){

	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	//double	pi=3.14159265358979323846;
	//sieve();
	
	
	int a[5];
	for(int i=0;i<5;i++){
		cin>>a[i];
	}
	for(int i=0;i<5;i++){
		if(a[i]==0){
			cout<<i+1<<endl;
			break;
		}
	}


		
	
	return 0;
	
	
	
}

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

int main () {
  int N;
  cin >> N;
  
  int a, b, c, d;
  a = N/1000;
  b = N % 1000/100;
  c = N % 1000 % 100/10;
  d = N % 10;
    
  if ( a == b && b == c ) {
    cout << "Yes" << endl;
  }
  else if ( b == c && c == d ){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 101
#define int ll


ll X,K,D;


int32_t main(){
	fast;
	
	cin>>X>>K>>D;
	X = abs(X);
	
	int amt = min(K,X / D);
	
	X -= amt * D;
	K -= amt;
	
	if (K % 2 == 0) cout<<abs(X);
	else cout<<abs(X - D);
	
	
	
	
	
	
}


Measured memory_bytes: 3648
public class Main {
  public static void main(String[] args) {
        java.util.Scanner scanner = new java.util.Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt(); 
        if (a==b) {
          System.out.println(c);
        } else if (b==c) {
           System.out.println(a);
        }else {
           System.out.println(b);
       }
 }

}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define P pair
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define endl '\n'
#define int ll

using namespace std;

typedef long long ll;
typedef P<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

int32_t main()
{
	IO_OP;
	
	int n, m;
	cin >> n >> m;
	priority_queue<int> pq;
	for(int i=0;i<n;i++) {
		int t;
		cin >> t;
		pq.push(t);
	}
	while(m--) {
		int x = pq.top(); pq.pop();
		pq.push(x>>1);
	}
	int ans = 0;
	while(pq.size()) {
		ans += pq.top(); pq.pop();
	}
	cout << ans << endl;
	
}





Measured memory_bytes: 1400
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
V ans;
ll cop[ohara];
int use;

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n){
        if(i+1>=a[i])continue;
        Cout(-1);
        return 0;
    }
    rep(i,n)cop[i]=a[i];
    tmp=n;
    rep(i,tmp){
        rep(j,n)a[j]=cop[j];
        rrrep(j,n-1,0){
            if(j+1==a[j]){
                use=j;
                ans.push_back(a[j]);
                break;
            }
        }
        cnt=0;
        rep(j,n){
            if(use==j)continue;
            cop[cnt++]=a[j];
            a[j]=0;
        }
        n--;
    }
    rrrep(i,Size(ans)-1,0)Cout(ans[i]);
    return 0;
}


Measured memory_bytes: 2304
from collections import defaultdict
num = defaultdict(lambda : 0)
n = int(input())
a = [int(i) for i in input().split()]
for i in a:
    num[i] += 1
memo = {i: 0 for i in num.keys()}
total = 0

for i, j in num.items():
    x = int(j * (j - 1) / 2 )
    memo[i] = x
    total += x

for i, j in enumerate(a):
    y = num[j]
    z = memo[j]

    if y == 1:
        print(total)
    else:
        print(total - z + int((y - 1) * (y - 2) / 2))

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

int x,y;
int main(){
cin>>x>>y;
	if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
		x=25;
	}else if(x==4||x==6||x==9||x==11){
		x=50;
	}else if(x==2){
		x=100;
	}
	if(y==1||y==3||y==5||y==7||y==8||y==10||y==12){
		y=25;
	}else if(y==4||y==6||y==9||y==11){
		y=50;
	}else if(y==2){
		y=100;
	}
	if(x==y){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

}

Measured memory_bytes: 256
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('\n');
   let xs1 = xs[1].trim().split(' ').map(v=>parseInt(v,10));
   let N = Number(xs[0]);
   let A = xs1.filter(v=>v % 2 === 0);
   let ans = 0;
   for(let i=0; i<A.length; i++){
     if(A[i]%3==0 || A[i]%5==0){
     ans+=1;
     }else{
     ans+=0;
     }
   }
   
   if(ans==A.length){ // && ans!=0
     console.log('APPROVED');
   }else{
     console.log('DENIED');
   }
   
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

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

struct UnionFind{
    vector<int>par;
    UnionFind(int n):par(n,-1){}

    int root(int x){
        if(par[x]<0)return x;
        else return par[x]=root(par[x]);
    }
    bool issame(int x,int y){
        return root(x)==root(y);
    }

    bool merge(int x,int y){
        x=root(x); y=root(y);
        if(x==y)return false;
        if(par[x]>par[y])swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }
    int size(int x){
        return -par[root(x)];
    }
};

using pint=pair<int,int>;
int main(){
    int N,M,K;
    cin>>N>>M>>K;
    vector<set<int> > dame(N);
    UnionFind uf(N);
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;a--,b--;
        dame[a].insert(b);
        dame[b].insert(a);
        uf.merge(a,b);
    }
    for(int i=0;i<K;i++){
        int c,d;cin>>c>>d;c--,d--;
        if(!uf.issame(c,d))continue;
        dame[c].insert(d);
        dame[d].insert(c);
    }
    for(int i=0;i<N;i++){
        int mem=uf.size(i)-1;
        mem-=dame[i].size();
        cout<<mem<<" ";
    }
    cout<<endl;
}

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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(STL) STL.begin(), STL.end()
#define stl_rep(itr, STL) for (auto itr = STL.begin(); itr != STL.end(); ++itr)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);

    llong n, t, a;
    cin >> n;
    llong ballot_Takahashi = 1, ballot_Aoki = 1;
    rep(i, n) {
        cin >> t >> a;
        llong k = max(ceil((long double)ballot_Takahashi / t), ceil((long double)ballot_Aoki / a));
        ballot_Takahashi = t * k;
        ballot_Aoki = a * k;
    }

    cout << ballot_Takahashi + ballot_Aoki << endl;

    return 0;
}

Measured memory_bytes: 256
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

long long gcd(long long a, long long b) {
	long long r = -1;
	if (a < b) {
		swap(a, b);
	}
	while (r != 0) {
		r = a % b;
		if (r == 0) {
			return b;
		}
		else {
			a = b;
			b = r;
		}
	}
}

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

int main() {
	int N;
	cin >> N;
	cout << N * 800 - N / 15 * 200 << endl;
}


Measured memory_bytes: 384
#include <complex>
#include <cmath>

using Real = long double;

const Real EPS = 1e-10;

// 宇宙船演算子
inline Real compare(Real a, Real b) {
    if (std::abs(a - b) < EPS) return 0;
    return a - b > 0 ? 1 : -1;
}

template <class T>
inline T sq(T x) { return x * x; }


using Point = std::complex<Real>;
using Segment = std::pair<Point, Point>;

inline Real length(Segment s) {
    return std::abs(s.second - s.first);
}

// inner product
inline Real dot(Point x, Point y) {
    return std::real(std::conj(x) * (y));
}

// outer product
inline Real cross(Point x, Point y) {
    return std::imag(std::conj(x) * (y));
}

// lに対するxの正射影
Point proj(Segment s, Point p) {
    Real ratio = dot(s.second - s.first, p - s.first) / sq(length(s));
    return s.first + (s.second - s.first) * ratio;
}

// lを軸としてxに対称な点
Point refl(Segment s, Point p) {
    Point t = proj(s, p);
    return t + (t - p);
}

// lに対するpの位置
// counter clockwise -> 1, clockwise   -> -1
// online front      -> 2, online back -> -2
// on segment        -> 0
int side(Segment s, Point p) {
    Real c = cross(s.second - s.first, p - s.first);
    if (compare(c, 0) != 0) return compare(c, 0);

    Real d = dot(s.second - s.first, p - s.first);
    if (compare(d, 0) < 0) return -2;

    return (compare(length(Segment(s.first, p)), length(s)) > 0 ? 2 : 0);
}

inline bool isorthogonal(Segment s1, Segment s2) {
    return compare(dot(s1.second - s1.first, s2.second - s2.first), 0) == 0;
}

inline bool isparallel(Segment s1, Segment s2) {
    return compare(cross(s1.second - s1.first, s2.second - s2.first), 0) == 0;
}

bool intersect(Segment s1, Segment s2) {
    return (side(s1, s2.first) * side(s1, s2.second) <= 0) &&
           (side(s2, s1.first) * side(s2, s1.second) <= 0);
}


#include <iostream>

using namespace std;

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

    for (int q = 0; q < Q; ++q) {
        Segment s[2];
        for (int i = 0; i < 2; ++i) {
            Point p[2];
            for (int j = 0; j < 2; ++j) {
                Real x, y;
                cin >> x >> y;
                p[j] = Point(x, y);
            }
            s[i] = Segment(p[0], p[1]);
        }
        cout << intersect(s[0], s[1]) << endl;
    }
    return 0;
}



Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 18;

int a[N], b[N], kol[N], res, i, j, k, tab[N], s, d, c, ok[N], act, n, l;

bool cmp(int a, int b) {
	if (tab[a] == tab[b]) return a < b;
	return tab[a] < tab[b];
}

int main() {
scanf("%d", &n);
for (i=0;i<n;i++) scanf("%d", &a[i]);
for (i=0;i<n;i++) scanf("%d", &b[i]);
for (i=0;i<n;i++) kol[i] = i;
res = INF;
for (k=0;k<(1<<n);k++) {
	for (i=0;i<n;i++) if ((1<<i) & k) tab[i] = b[i]; else tab[i] = a[i];
	sort(kol, kol + n, cmp);
	s = 0;
	for (i=0;i<n;i++) {
		d = abs(i - kol[i]) % 2;
		c = min(1, ((1<<kol[i]) & k));
		ok[i] = (d == c);
		s += ok[i];
	}
	for (i=0;i<n;i++) if (!ok[i]) {
		for (j=i+1;j<n && tab[kol[i]] == tab[kol[j]];j+=2) if (!ok[j]) {
			for (l=i+1;l<j;l+=2) swap(kol[l], kol[l + 1]);
			for (l=i;l<j;l+=2) swap(kol[l], kol[l + 1]);
			ok[i] = ok[j] = 1;
			s += 2;
			break;
		}
	}
	if (s != n) continue;
	act = 0;
	for (i=0;i<n;i++) for (j=i+1;j<n;j++) if (kol[i] > kol[j]) act++;
	/*if (act == 1) {
		printf("%d\n", k);
		for (i=0;i<n;i++) printf("%d ", kol[i]);
		printf("\n");
	}*/
	res = min(res, act);	
}

if (res == INF) res = -1;
printf("%d\n", res);
return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    LL k;
    cin >> k;

    vector<LL> ans(50, 49);
    REP(i, 50){
        ans[i] += k / 50;
    }
    
    REP(i, 50){
        if(i < k % 50){
            ans[i] += 50 - k % 50;
        }else{
            ans[i] -= k % 50;
        }
    }

    cout << 50 << endl;
    REP(i, 50) cout << ans[i] << " \n"[i == 50];
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <math.h>
#include <stdio.h>
#define INF 1000000000
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long int ll;
using namespace std;

ll kai(ll num, ll k) {
	if (num < k) { return num; }
	else { return k; }
}

int main() {

	ll n, k; cin >> n >> k;
	vector<ll> h(n,0);
	vector<ll> data(n, INF);
	for (ll i = 0; i < n; i++) { cin >> h[i]; }

	data[0] = 0;
	for (ll i = 1; i < n; i++) {
		for (ll j = 1; j <= kai(i, k); j++) {
			data[i] = min(data[i], data[i - j] + abs(h[i] - h[i - j]));
			//cout << i << " " << j  << " " << data[i]<< endl;
		}
	}
	//for (ll i = 0; i < n; i++) { cout << data[i] << " "; } cout << endl;
	cout << data[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 1792
def resolve():
    n,a,b = map(int, input().split())
    x = list(map(int, input().split()))

    ans = 0

    for i in range(1, n):
        walk = (x[i]-x[i-1])*a
        if walk >= b:
            ans += b
        else:
            ans += walk
    print(ans)
resolve()

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

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

void Solve(){
	int n,m;
	while(cin >> n >> m){
		int c[300],vdl[3][300];
		rep(i,0,n){
			string name;
			cin.ignore();
			getline(cin,name);
			cin >> c[i];
			rep(j,0,3) cin >> vdl[j][i];
		}

		int dp[3][300][301];
		fill_n((int*)dp,3*300*301,0);
		rep(i,0,3){
			rep(j,0,n){
				rep(k,0,m+1){
					if(j) dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k]);
					if(k-c[j]>=0){
						if(j) dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k-c[j]]+vdl[i][j]);
						dp[i][j][k]=max(dp[i][j][k],dp[i][j][k-c[j]]+vdl[i][j]);
					}
				}
			}
		}

		int ans=0;
		rep(i,0,3){
			rep(j,0,m+1) ans=max(ans,dp[i][n-1][j]);
		}

		cout << ans << endl;
	}
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

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

int main(void){
	int N;
	ll K;
	cin >> N >> K;
	vector<int> P(N+1);
	rep(i,N) cin >> P[i+1];
	vector<ll> C(N+1);
	rep(i,N) cin >> C[i+1];

	ll ans = -1e10;
	for (int i = 1; i <= N; i++) {
		ll tot = 0;
		int period = 0;
		int j = i;
		vector<ll> v;
		while (1) {
			j = P[j];
			tot += C[j];
			v.push_back(C[j]);
			period++;
			if (j == i) break;
		}

		ll cand;
		ll tmp = 0;
		int vsize = v.size();
		rep(j, vsize) {
			if (j+1>K) break;
			tmp+=v[j];
			cand = tmp;
			if (tot>0) {
				cand += tot*((K-j-1)/period);
			}
			ans = max(ans, cand);
		}
	}

	cout << ans << endl;

return 0;
}


Measured memory_bytes: 3760
#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 INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  vector<pair<ll, ll>> a(n);
  REP(i, n) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.begin(), a.end());
  ll m = (n + 1) / 2 - 1;
  vector<ll> ans(n);
  REP(i, n) {
    ll index = a[i].second;
    if (n % 2 == 0) {
      if (i <= m) {
        ans[index] = a[m + 1].first;
      } else {
        ans[index] = a[m].first;
      }
    } else {
      if (i <= m) {
        ans[index] = a[m].first;
      } else {
        ans[index] = a[m - 1].first;
      }
    }
  }
  REP(i, n) { cout << ans[i] << endl; }
  return 0;
}

Measured memory_bytes: 6912
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
agg = set()
for i in range(s1[0]):
  agg.add(tuple(s1[i * 2 + 1:i * 2 + 3]))
for i in range(s2[0]):
  agg.add(tuple(s2[i * 2 + 1:i * 2 + 3]))
agg = list(agg)
agg.sort()
print(*list(map(lambda t:str(t[0])+":"+str(t[1]).zfill(2), agg)))


Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

int main()
{
    string s, t;
    cin >> s >> t;
    s += t;
    reverse(s.begin(), s.end());
    int sum = 0;
    int cnt = 1;
    rep(i, 0, s.size()){
        sum += (s[i] - '0')*cnt;
        cnt *= 10;
    }
    rep(i, 1, 1000){
        if(i*i == sum){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3556
from __future__ import division, print_function
from sys import stdin
for line in stdin:
    h, w = (int(s) for s in line.split())
    if h == 0 and w == 0:
        break
    top_bottom = '#' * w
    mid_row = '#' + '.'*(w-2) + '#'
    print(top_bottom)
    for _ in range(h-2):
        print(mid_row)
    print(top_bottom, end='\n\n')

Measured memory_bytes: 4236
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int64_t A;
  double B;
  cin >> A >> B;
  
  int64_t T;
  T = A * (int)(B * 100 + 0.5) / 100;
  
  cout << T << endl;
}

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

int main(void){
    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    rep(i,m) cin >> a[i];
    cout << max(n - accumulate(all(a), 0), -1) << endl;
    return 0;
}


Measured memory_bytes: 3668
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main(){
  ll N; cin>>N;
  ll K; cin>>K;
  priority_queue<ll> pque;
  rep(i,N){
    ll a; cin>>a;
    pque.push(a);
  }
  
  rep(i,K){
    ll b=pque.top();
    pque.pop();
    pque.push(b/2);
  }
  ll ans=0;
  rep(i,N){
    ll c=pque.top();
    pque.pop();
    ans+=c;
  }
  
  cout<<ans<<endl;
}

  




Measured memory_bytes: 1400
# ABC79 D - Wall
H, W = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]

def f_warshall(C):
  for k in range(10):
    for i in range(10):
      for j in range(10):
        C[i][j] = min(C[i][j], C[i][k] + C[k][j])

f_warshall(C)

cost = 0
for i in range(H):
  for j in range(W):
    if A[i][j] == -1:
      continue
    else:
      cost += C[A[i][j]][1]

print(int(cost))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

const double PI=3.14159;

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

    cout << fixed << setprecision(8) << r * 2 * PI << endl;

    return 0;
}

Measured memory_bytes: 3780
#define i(a,b) a=a<b?a:b
d,a[101][101],b[101][101],u,v,c,k,l;main(n){for(scanf("%d%*d",&n);u++<n;)for(v=0;v++<n;)b[u][v]=1e8;for(;~scanf("%d%d%d",&u,&v,&c);a[u][v]=a[v][u]=b[u][v]=b[v][u]=c);for(;k++<n;)for(u=0;u++<n;)for(v=0;v++<n;)i(b[u][v],b[u][k]+b[k][v]);for(;l++<n;)for(c=l;c++<n;)d+=a[l][c]>b[l][c];printf("%d\n",d);}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;
ll N, X;
vector<ll> size, p;

ll rec(ll N, ll X){
    if(N == 0) {
        if(X <= 0) return 0;
        else return 1;
    }
    else if(X <= 1+size[N-1]) return rec(N-1, X-1);
    else return p[N-1] + 1 + rec(N-1, X - 2 - size[N-1]);
    
}


int main(){
    cin >> N >> X;
    size.resize(N+1);
    p.resize(N+1);
    size[0] = 1;
    for(int i = 1; i < N+1; i++) size[i] = 2*size[i-1]+3;
    p[0] = 1;
    for(int i = 1; i < N+1; i++) p[i] = 2*p[i-1]+1;
    cout << rec(N, X) << endl;;


}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		char[] s = sc.next().toCharArray();
		
		for(int i=0; i<s.length; i++) {
			s[i] = (char)('A' + ((s[i]-'A'+N)%26));
		}
		
		System.out.println(String.valueOf(s));

		sc.close();
	}
}


Measured memory_bytes: 22860
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdio>

class Node
{
public:
    Node()
      : next(nullptr)
      , str("")
    {
    }

public:
    std::string str;
    Node* next;
};

int main()
{
    std::size_t n;
    std::scanf("%lu", &n);

    Node nodeList[n];

    std::string cmd;
    std::string str;
    for (std::size_t i = 0; i < n; ++i) {
        std::cin >> cmd >> str;
        std::size_t hash = 0;
        for (std::size_t j = 0; j < str.size(); ++j) {
            hash += std::pow(5, j) * (str[j] - 'A' + 1);
        }
        std::size_t index = hash % n;
        if (cmd[0] == 'i') {
            if (nodeList[index].str == "") {
                nodeList[index].str = std::move(str);
                nodeList[index].next = new Node();
            } else {
                Node* pos = nodeList[index].next;
                while (pos->next != nullptr) {
                    pos = pos->next;
                }
                pos->str  = std::move(str);
                pos->next = new Node();
            }
        } else {
            Node* pos = &(nodeList[index]);
            if (pos->str == "") {
                std::cout << "no" << std::endl;
                continue;
            } else if (pos->str == str) {
                std::cout << "yes" << std::endl;
                continue;
            }

            bool isFound = false;
            while (pos->next != nullptr) {
                if (pos->str == str) {
                    std::cout << "yes" << std::endl;
                    isFound = true;
                    break;
                }
                pos = pos->next;
            }

            if (false == isFound) {
                std::cout << "no" << std::endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 68316
from math import factorial
N,M=map(int,input().split())
ans=0
if abs(N-M)>1:
    ans=0
else:
    if N==M:
        a=N
        b=M
        ans=factorial(a)*factorial(b)*2
    else:
        a=max(N,M)
        b=min(N,M)
        ans=factorial(a)*factorial(b)
print(ans%(10**9+7))

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

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int n;
int main(){
    int k,x;
    cin>>k>>x;
    if(500*k>=x)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}




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


int main(void){
int h,w;
char s[101][101];
scanf("%d %d",&h,&w);
for(int i=0;i<h;i++){
    scanf("%s",s[i]);
}

for(int i=0;i<w+2;i++){
printf("#");
}
printf("\n");

for(int i=0;i<h;i++){
printf("#");
printf("%s",&s[i]);
printf("#\n");
}

for(int i=0;i<w+2;i++){
printf("#");
}
printf("\n");

}


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

int main() {
  int n, a, s1 = 0, s2 = 0;
  cin >> n;
  priority_queue<int> v;
  rep(i, n) {
    cin >> a;
    v.push(a);
  }
  rep(i, n) {
    if(i%2 == 0) {
      s1 += v.top();
    } else {
      s2 += v.top();
    }
    v.pop();
  }
  cout << s1 - s2 << endl;
}



Measured memory_bytes: 3624
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine()
            .Split(' ')
            .Select(txt => int.Parse(txt))
            .ToList();
        var a = inputs[0];
        var b = inputs[1];
        var c = inputs[2];
        var d = inputs[3];

        var p1 = new Monster(a, b);
        var p2 = new Monster(c, d);

        while (true)
        {
            p2.Damage(p1.Power);
            if (p2.IsDead) break;
            p1.Damage(p2.Power);
            if (p1.IsDead) break;
        }

        Console.WriteLine(p2.IsDead ? "Yes" : "No");
    }

    public class Monster
    {
        public int Hp { get; private set; }
        public int Power { get; private set; }
        public bool IsDead => Hp <= 0;

        public Monster(int hp, int power)
        {
            Hp = hp;
            Power = power;
        }

        public void Damage(int power)
        {
            Hp -= power;
        }
    }
}

Measured memory_bytes: 28332
_x, _k, d = map(int, input().split())
x = abs(_x)
k = _k

if x >= d:
  i = x // d
  if i <= k:
    k -= i
    x -= i * d
  else:
    x -= k * d
    k = 0

if k % 2 != 0:
  x -= d

print(abs(x))


Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2")
int main()
{
	long long n,g=0,q=1000;
	cin>>n;
	int a[n+1];
	for(int i=1; i<=n; i++)	
		cin>>a[i];
	for(int i=1; i<n; i++)
	{
		if(a[i+1]>=a[i])
		{
			g+=q/a[i];
			q%=a[i];
		}
		else
		{
			q+=g*a[i];
			g=0;
		}
	}
	cout<<q+g*a[n];
	return 0;
}


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

int main (void){
    string s;
    cin >> s;
    if(s[0] == s[1] || s[1] == s[2] || s[2]== s[3]){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }
   
    return 0;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s;
	cin>>s;
	ll p=(s[0]-48)*10+s[1]-48;
	ll q=(s[2]-48)*10+s[3]-48;
	bool flg1=false,flg2=false;
	if (p>0 and p<13)
	{
		flg1=true;
	}
	if (q>0 and q<13)
	{
		flg2=true;
	}
	if (flg1 and flg2)
		cout<<"AMBIGUOUS";
	else if (flg1)
		cout<<"MMYY";
	else if (flg2)
		cout<<"YYMM";
	else
		cout<<"NA";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

char s[100005];

int main(void){
	lli k;
	scanf("%s%lld",s,&k);
	int ls=strlen(s);
	rep(i,ls){
		lli d=('z'-s[i]+1)%26;
		if(d<=k){
			k-=d;
			s[i]='a';
		}
	}
	k %= 26;
	s[ls-1] += k;
	printf("%s\n",s);
	return 0;
}






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

typedef long long ll;

int main(void){
    int n, k;
    cin >> n >> k;
    vector<ll> a(n+1), sum(n+1, 0);
    for(int i=1; i<=n; i++){
        cin >> a.at(i);
        sum.at(i) = sum.at(i-1) + a.at(i);
    }
    vector<ll> vec;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<=n; j++){
            vec.push_back(sum.at(j) - sum.at(i));
        }
    }

    sort(vec.begin(), vec.end());

    ll d = (ll)pow(2,(int)log2(vec.back()));

    while(d > 0){
        vector<ll> v;
        for(int i=0; i<vec.size(); i++){
            if((vec.at(i) & d) >= d){
                v.push_back(vec.at(i));
            }
        }

        if(v.size() >= k){
            vec = v;
        }

        d /= 2;
    }

    ll ans = vec.back();
    for(int i=1; i<k; i++){
        ans = ans & vec.at(vec.size() - i - 1);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6516
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int X;
  cin >> X;
  int Y = X / 100;
  int K = X % 100;
  int cnt = (K+4)/5;
  if(cnt>Y) {
    cout << 0 << endl;
    return 0;
  }
  cout << 1 << endl;
  return 0;
}

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  
  int cnt = 0;
  for (int i = a; i >= 1; --i) {
    if (a % i == 0 && b % i == 0) {
      ++cnt;
      if (cnt == k) {
        cout << i << endl;
        return 0;
      }
    }
  }
}

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

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

    for (int i = n - 1; i >= 0; i -= 2) {
        cout << a[i] << " ";
    }

    int j;
    if (n % 2 == 0) j = 0;
    else j = 1;
    for (; j < n - 1; j += 2) {
        cout << a[j] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 2944
import java.io.*;
import java.util.Scanner;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		for (int i= 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		for (int i= 0; i < n; i++) {
			b[i] = sc.nextInt();
		}
		for (int i= 0; i < n - 1; i++) {
			c[i] = sc.nextInt();
		}

		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (i > 0) {
				if (a[i] == a[i - 1] + 1) {
					ans += c[a[i - 1] - 1];
				}
			}
			ans += b[a[i] - 1];
		}
		
		pr.println(ans);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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

long long H, W, N;
long long a[10005];
long long ban[105][105];

int main(){
	cin >> H >> W >> N;
	for(long long i = 0; i < N; i++){
		cin >> a[i];
	}

	long long cur = 0;
	long long curnum = 0;
	for(int h = 0; h < H; h++){
		for(int w = 0; w < W; w++){
			if(curnum == a[cur]){
				cur++;
				curnum = 0;
			}
			ban[h][w] = cur;
			curnum++;
		}
		if(h != H - 1){
			h++;
			for(int w = W - 1; w >= 0; w--){
				if(curnum == a[cur]){
					cur++;
					curnum = 0;
				}
				ban[h][w] = cur;
				curnum++;
			}
		}
	}

	for(int h = 0; h < H; h++){
		for(int w = 0; w < W; w++){
			cout << ban[h][w] + 1;
			if(w != W - 1){
				cout << " ";
			}
		}
		cout << endl;
	}





}


Measured memory_bytes: 512