akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define name 10
#define N 100005
typedef struct{
 char s[name];
  int time;
}R;
R a[N+1];
int head,tail;
void Enqueue(R );
R Dequeue(void);
int main()
{
  int i,n,q,T=0;
  R y;
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s%d",y.s,&y.time);
    Enqueue(y);
  }
  while(n!=0){
    y=Dequeue();
    if(y.time>q){
      y.time=y.time-q; 
      T+=q;
      Enqueue(y);
    } 
    else{
      T=T+y.time;
      printf("%s %d\n",y.s,T);
      n--;
    }
  }
  return 0;
}

void Enqueue(R Y){
  if(N==tail) tail=0; 
    a[tail]=Y;
    tail++;
}

R Dequeue(void){
  if(head==N) head=0;
  return a[head++];
}

Measured memory_bytes: 2160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int a[] = new int [100];
		int i;
			for(i=0;i<n;i++) {
			a[i] = scan.nextInt();
			}
			for(i=n-1;i>=0;i--) {
				if(n-1>i) {
					System.out.printf(" ");
				}
				System.out.printf(""+a[i]);
			}
			System.out.println();
			scan.close();
}
}


Measured memory_bytes: 26388
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int n,d; cin >> n >> d;
    int x[n+1][d+1];
    for (int i=0; i<n; i++)
        for (int j=0; j<d; j++) cin >> x[i][j];

    double sum; int ans=0;
    int i,j,k,l;
    for (i=0; i<n-1; i++){
        
        for (j=i+1; j<n; j++){
            sum = 0;
            for (k=0; k<d; k++){
                sum += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
            }
            sum = sqrt(sum);
            for (l=1; l<=400; l++){
                if (sum==l) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func decomp_2(a int) (int, int) {
	fact_2 := 1
	other := a
	for {
		if other%2 == 1 {
			break
		}
		fact_2 *= 2
		other /= 2
	}
	return fact_2, other
}

func gcd(a int, b int) int {
	r := a % b
	if r == 0 {
		return b
	} else {
		return gcd(b, r)
	}
}

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

func least_common_multiple(N int, a []int, upper int) int {
	t := a[0]
	for i := 1; i < N; i++ {
		if t > upper {
			return -1
		}
		t = lcm(t, a[i])
	}
	return t
}

func semi_common_multiple(N int, M int, a []int) int {
	var f2, f2_temp int
	b := make([]int, N)
	f2, b[0] = decomp_2(a[0])
	for i := 1; i < N; i++ {
		f2_temp, b[i] = decomp_2(a[i])
		if f2_temp != f2 {
			return 0
		}
	}

	olcm := least_common_multiple(N, b, M*2/f2)
	if olcm == -1 {
		return 0
	}

	lscm := (f2 / 2) * olcm

	return ((M / lscm) + 1) / 2
}

func main() {
	var N, M int
	fmt.Scanf("%d %d\n", &N, &M)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&a[i])
	}

	fmt.Println(semi_common_multiple(N, M, a))
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
const int MOD=1e9+7;
const int INF=1e18;
void io(string s="file"){freopen((s + ".in").c_str(), "r", stdin);freopen((s + ".out").c_str(), "w", stdout);}


signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    vi x(n),y(n);
    vi xpy(n),xmy(n);
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
        xpy[i]=x[i]+y[i];
        xmy[i]=x[i]-y[i];
    }
    
    sort(all(xpy));
    sort(all(xmy));
    
    int ans=0;
    ans=max(ans,xpy[n-1]-xpy[0]);
    ans=max(ans,xmy[n-1]-xmy[0]);
    cout<<ans;
}

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

const int N = pow(10,7);

vector<bool> isp(N, true);

void sieve() {
  isp[0] = false;
  isp[1] = false;
  for (int i=2; pow(i,2)<=N; i++) {
    if (isp[i]) for(int j=2; i*j<=N; j++) isp[i*j] = false;
  }
}

int main(){
	int64_t A,B,N1,N2,work,R=0;
	cin >> A >> B;
	N1 = max(A,B);
	N2 = min(A,B);
	while (true){
		work = N1 % N2;
		if (work == 0){
			break;
		}
		else {
			N1 = N2;
			N2 = work;
		}
	}
	sieve();
	int j = 2;
	int k = N2;
	while (j<=1000000){
		if(isp[j])	{
			if(N2 % j == 0){
				R++;
				while (N2 % j == 0){
					N2 /= j;
				}
			}
		}
		if (N2 == 1){
			break;
		}
		j++;
		if (j==1000000){
			R++;
		}
	}
	cout << R+1 << endl;
}

Measured memory_bytes: 1408
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	vector<pll> a(n),b(n) ;
	for(int i=0;i<n;i++) cin >> a.at(i).first >> a.at(i).second ;
	for(int i=0;i<n;i++) cin >> b.at(i).first >> b.at(i).second ;
	sort(all(a)) ;
	sort(all(b)) ;
	ll ans = 0 ;
	vb used(n,true) ;
	for(int i=0;i<n;i++){
		ll pos = -1 ;
		for(int j=0;j<n;j++){
			if(a.at(j).first>=b.at(i).first) break ;
			if(used.at(j)&&a.at(j).second<b.at(i).second){
				if(pos==-1) pos = j ;
				else if(a.at(pos).second<=a.at(j).second) pos = j ;
			}
		}
		if(pos!=-1){
			ans++ ;
			used.at(pos) = false ;
		}
	}
	cout << ans << endl ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define si set <ll>
#define vi vector <ll>
#define popcount(x) __builtin_popcountll(x)
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,n) for( i=a ; i<n ; i++)
#define ld long double
#define rall(a) (a).rbegin(),(a).rend()

ll power(ll b,ll e,ll m)
{
  if(e==0) return 1;
  if(e&1) return b*power(b*b%m,e/2,m)%m;
  return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
  if(e==0) return 1;
  if(e&1) return b*power(b*b,e/2);
  return power(b*b,e/2);
}


void solve()
{
	ll A, B; cin >> A >> B;
    char C; cin >> C;
    int D; cin >> D;
    B *= 100; B += D;
    ll X = A*B; X /= 100;
    cout << X << "\n";
}

int main()       
{
 ll t=1;
 while(t--)
   solve();
 return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const int N = 5e5+10;

int main(){
fast;
int x,y;
cin>>x>>y;

int val = 4*x-y;

if(val>=0 and val%2==0 and val/2<=x) {
    cout<<"Yes"<<endl;
    return 0;
}
cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
#define bit(n) (1ll<<(n))


const ll MAXD = 50;

void mainsolve(){

	ll n,k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];

	vector<vector<ll>> dp(MAXD,vector<ll>(2,-1)); // max(f(x))

	// 最初のk,a[i]のビットは確実に0
	dp[0][0] = 0;
	rep(i,MAXD-1){
		ll mask = 1ll<<(MAXD-2-i); // MAXD-2 -> 0
		ll flugnum = 0;
		rep(j,n) if(mask & a[j]) flugnum++;
		ll score0 = mask * flugnum; // 0を選んだ場合のscore
		ll score1 = mask * (n - flugnum); // 1を選んだ場合のscore

		// 1 -> 1
		if(dp[i][1] != -1) dp[i+1][1] = max(dp[i+1][1], dp[i][1] + max(score0, score1));

		// 0 -> 1
		if((k & mask) && dp[i][0] != -1) dp[i+1][1] = max(dp[i+1][1], dp[i][0] + score0);

		// 0 -> 0
		if(dp[i][0] != -1){
			if(k & mask) dp[i+1][0] = max(dp[i+1][0], dp[i][0] + score1); // kが1
			else dp[i+1][0] = max(dp[i+1][0], dp[i][0] + score0); // kが0
		}
		
	}

	cout << max(dp[MAXD-1][0], dp[MAXD-1][1]) << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 1024
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

typedef db T;
const db eps = 1e-8;
int sgn(T x){return (x>eps)-(x<-eps);}
struct P{
    T x,y;
    P(){} P(T x,T y):x(x),y(y){}
    void read(){scanf("%lf%lf",&x,&y);}
    P operator - (const P&b) const {return P(x-b.x,y-b.y);}
    P operator + (const P&b) const {return P(x+b.x,y+b.y);}
    T operator * (const P&b) const {return x*b.x+y*b.y;}
    P operator * (const T&k) const {return P(x*k,y*k);}
    P operator / (const T&k) const {return P(x/k,y/k);}
    T operator ^ (const P&b) const {return x*b.y-y*b.x;}
    bool operator < (const P&b) const {return sgn(x-b.x)?x<b.x:y<b.y;}
    bool operator == (const P&b) const{return !sgn(x-b.x)&&!sgn(y-b.y);}
    P rot90() {return P(-y,x);}
};
T norm(P x){return x*x;}
T abs(P x){return sqrt(x*x);}
struct C{
    P o;T r;
    void read(){o.read();scanf("%lf",&r);}
};

vector<P> tanCP(C c,P p){
    db x = norm(p - c.o) , d = x - c.r * c.r;
    vector<P> res;
    if(sgn(d) < 0) return res;
    d = max(d,0.);
    P mid = c.o + (p - c.o) * (c.r * c.r / x) ,
      del = ((p-c.o)*(c.r*sqrt(d)/x)).rot90();
    return {mid - del ,mid + del}; // counter-clockwise
}

vector<pair<P,P> > tanCC(C c1,C c2){
    vector<pair<P,P> > res;
    // extan
    if(!sgn(c1.r-c2.r)){
        P dir = c2.o-c1.o;
        dir = (dir*(c1.r/abs(dir))).rot90();
        res.pb({c1.o+dir,c2.o+dir});
        res.pb({c1.o-dir,c2.o-dir});
    } else {
        P p = (c2.o * c1.r - c1.o * c2.r) / (c1.r - c2.r);
        vector<P> ps = tanCP(c1 , p) , qs = tanCP(c2 , p);
        rep(i,0,min(sz(ps),sz(qs))) res.pb({ps[i],qs[i]});
    }
    // intan
    P p = (c1.o * c2.r + c2.o * c1.r) / (c1.r + c2.r);
    vector<P> ps = tanCP(c1 , p) , qs = tanCP(c2 , p);
    rep(i,0,min(sz(ps),sz(qs))) res.pb({ps[i],qs[i]});
    return res;
}

int main(){
    C o1,o2;
    o1.read();
    o2.read();
    vector<pair<P,P> > res = tanCC(o1 , o2);
    sort(all(res));
    res.erase(unique(all(res)),res.end());
    for(auto e : res) printf("%.10f %.10f\n",e.fi.x,e.fi.y);
    return 0;
}

Measured memory_bytes: 3228
import queue
N, M = map(int,input().split())
D = [[] for i in range(N)]

for i in range(M):
  a,b = map(int,input().split())
  D[a-1].append(b)
  D[b-1].append(a)

print("Yes")

dist = [0 for i in range(N)]
prev = [0 for i in range(N)]
prev[0] == 1

q = queue.Queue()
q.put(1)

while not q.empty():
  t = q.get()
  for i in D[t-1]:
    if prev[i-1] == 0:
      prev[i-1] = t
      q.put(i)

for i in prev[1:]:
  print(i)

Measured memory_bytes: 35680
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#include<map>
#include <limits>
# include <iomanip>
#define INF 1000000009;

using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
int kaizyo(int a) {
	long long ans = 1;
	for (int i = a; i > 0; i--) {
		ans *= i;
		ans = ans % 1000000007;
		//cout << ans << endl;
	}
	ans = ans % 1000000007;
	return ans;
}

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


int main() {
	int N = 0;
	cin >> N;
	int a = 0;
	int ma = 0;
	int ko = 0;
	int kiroku;
	int manji[100005] = { 0 };
	for (int i = 0; i < N; i++) {
		cin >> a;
		
		manji[a]++;
		manji[a + 1]++;
		manji[a+2]++;
		ma = max(ma, a);
	}
	for (int i = 0; i <= ma; i++) {
		ko = max(ko, manji[i]);
	}
	cout << ko << endl;
	return 0;
}


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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    int ans;
    ans = min(N,K)*X + max(N-K,0)*Y;
    cout << ans << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;

typedef long long ll;

int32_t main() {

    ios_base::sync_with_stdio(0); cin.tie(0);

    int N,K; cin >> N >> K;

    ll res = 0;
    for (ll i = K; i <= N+1; ++i) {
        ll comb = ((N+1-i)*i+1)%MOD;
        res = (res+comb)%MOD;
    }

    cout << res << "\n";

}


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

int main(){
    double A,B,C;
    cin >> A >> B;
    if(B<10){
        C=10*A+B;
    }
    else if(B<100){
        C=100*A+B;
    }
    else{
        C=1000*A+B;
    }
    C=pow(C,0.5);
    if(ceil(C)==floor(C))
    cout << "Yes" << endl;
    else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
int main() {
    int n;cin>>n;
    map<string,int> sen;
    string s;
    rep(i,n){
        cin>>s;
        if(sen.count(s)) sen[s]++;
        else sen[s]=1;
    }
    int m;cin>>m;
    string t;
    rep(i,m){
        cin>>t;
        if(sen.count(t)) sen[t]--;
        else sen[t]=-1;
    }
    int ma=0;
    for(auto p:sen){
        ma=max(ma,p.second);
    }
    cout<<ma<<endl;
}

Measured memory_bytes: 256
s = int(input())
arr = list(map(int,input().split()))
count = 0
for i in range(s-2):
    if arr[i] < arr[i+1] < arr[i+2] or arr[i] > arr[i+1] > arr[i+2]:
        count += 1
    else:
        continue
print(count)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


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

int main() {
    string s,t;
    cin >> s >> t;
    int ans = 0;
    REP(i, s.size()){
        if(s[i] != t[i]){
            ans ++;
        }
    }
    cout << ans << endl;

}



Measured memory_bytes: 3916
import java.util.Scanner;

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

		String word = sc.next();
		int m = sc.nextInt();

		int h;

		while (true) {
			for (int i = 0; i < m; i++) {
				h = sc.nextInt();
				word = word.substring(h) + word.substring(0, h);
			}
			System.out.println(word);
			word = sc.next();
			if(word.equals("-")){
				break;
			}
			m = sc.nextInt();
		}

	}
}


Measured memory_bytes: 26420
#include<bits/stdc++.h>
using namespace std;
int n,k;
int in[55];
int memo[55][55][110];
int f(int left,int right,int sel){
    if(left>right) return 0;
    if(memo[left][right][sel]!=-1e9) return memo[left][right][sel];
    int RE=0;
    if(sel>=1) RE=max(RE,f(left+1,right,sel-1)+in[left]);
    if(sel>=2) RE=max(RE,f(left+1,right,sel-2));
    if(sel>=1) RE=max(RE,f(left,right-1,sel-1)+in[right]);
    if(sel>=2) RE=max(RE,f(left,right-1,sel-2));
    return memo[left][right][sel]=RE;
}
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>in[i];
    for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int l=0;l<=k;l++) memo[i][j][l]=-1e9;
    cout<<f(1,n,k);
}


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

int main() {
    pair<int, int> p1, p2;
    cin >> p1.first >> p1.second >> p2.first >> p2.second;
    int l, h;
    l = max(p1.first, p2.first);
    h = min(p1.second, p2.second);
    int duration = h - l;
    if (duration < 0) duration = 0;
    cout << duration << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll n;
	cin>>n;
	ll a[n];
	map<ll,int> mp;
	ll sm=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sm+=a[i];
		mp[a[i]]++;
	}
	ll q;
	cin>>q;
	while(q--)
	{
		ll b,c;
		cin>>b>>c;
		sm+=mp[b]*(c-b);
		int x=mp[b];
		mp.erase(b);
		mp[c]+=x;
		cout<<sm<<endl;
	}
	return 0;
}

Measured memory_bytes: 8328
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
using P = pair<int, int>;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1e9+7;
    int n,ans=0;
    cin>>n;
    vector<P> v(n);
    rep(i,n)cin>>v[i].first>>v[i].second;
    reverse(v.begin(),v.end());
    rep(i,n){
        int it=v[i].first+ans;
        if(it%v[i].second==0)continue;
        ans+=v[i].second-it%v[i].second;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main(){
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	int a = -110,b = 1000000000;
	for (int i = 0; i < n; i++) {
		int c;
		cin >> c;
		a = max(a, c);
	}
	for (int i = 0; i < m; i++) {
		int c;
		cin >> c;
		b = min(b, c);
	}
	for (int i = a + 1; i <= b; i++) {
		if (x < i&&i <= y && a < i&&i >= b) {
			puts("No War");
			return 0;
		}
	}
	puts("War");
}


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

#define FOR(i, x, n) for(int i = x; i < n; i++)

using namespace std;
typedef long long int ll;


long long int binPow(long long int a, long long int b, long long int m){
    a = a%m;
    long long int res = 1;
    while(b){
        if(b&1)res = res*a%m;
        a = a*a;
    }
    return res;
}

long long int binPow(long long int a, long long int b){
    a = a;
    long long int res = 1;
    while(b){
        if(b&1)res = res*a;
        a = a*a;
    }
    return res;
}

long long int gcd(long long int a, long long int b){
    while(a){
        long long int temp = a;
        a = b%a;
        b = temp;
    }
    return b;
}

int main(){
    int n, k;
    cin >> n >> k;
    int c = n;
    FOR(i, 1, n+1){
        int val;
        cin >> val;
        if(val < k)c--;
    }
    cout << c;
}


Measured memory_bytes: 256
#import numpy as np
import math
import sys
import itertools
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
x,y = IL()
N = len(s)

xlist = []
ylist = []

f = 0
cnt = 0
for i in range(N):
  if s[i] == "F":
    cnt += 1
  elif s[i] == "T":
    if f == 0:
      xlist.append(cnt)
      f = 1
    else:
      ylist.append(cnt)
      f = 0
    cnt = 0
else:
  if f == 0:
    xlist.append(cnt)
  else:
    ylist.append(cnt)

x -= xlist.pop(0)
Xsum = sum(xlist)
Ysum = sum(ylist)

if (Xsum-x)%2 != 0:
  print("No")
  exit()
else:
  Xnum = (Xsum-abs(x))//2
if (Ysum-y)%2 != 0:
  print("No")
  exit()
else:
  Ynum = (Ysum-abs(y))//2

#print(Xnum,Ynum)

XDP = [[0]*(abs(Xnum)+1) for _ in range(len(xlist)+1)]
YDP = [[0]*(abs(Ynum)+1) for _ in range(len(ylist)+1)]

XDP[0][0] = 1
YDP[0][0] = 1

for i in range(1,len(xlist)+1):
  for j in range(Xnum+1):
    if XDP[i-1][j] == 1:
      XDP[i][j] = 1
      if j+xlist[i-1] < Xnum+1:
        XDP[i][j+xlist[i-1]] = 1
#print(Xnum)
#print(xlist)
#print(XDP)

for i in range(1,len(ylist)+1):
  for j in range(Ynum+1):
    if YDP[i-1][j] == 1:
      YDP[i][j] = 1
      if j+ylist[i-1] < Ynum+1:
        YDP[i][j+ylist[i-1]] = 1
#print(Ynum)
#print(ylist)
#print(YDP)

if XDP[-1][-1] == 1 and YDP[-1][-1] == 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 43636
N = int(input())
w = list(map(int, input().strip().split()))
#s = N/2
s = 0
diff = []

for k in range(N):
    total_s1 = 0
    total_s2 = 0
    for i in range(N):
        if i < s:
            total_s1 += w[i]
        else:
            total_s2 += w[i]
    diff.append(abs(total_s1 - total_s2))
    s += 1
print(min(diff))


Measured memory_bytes: 3060
#!/usr/bin/env python
from collections import defaultdict
import math
import re

def main():
    #A, B, T = map(int, input().split())
    N = int(input())
    V_list = [int(v) for v in input().split()]
    C_list = [int(v) for v in input().split()]

    VC_diffs = [v - c for v, c in zip(V_list, C_list)]
    VC_diffs = [vc for vc in VC_diffs if vc > 0]

    if VC_diffs:
        print(sum(VC_diffs))
    else:
        print(0)

if __name__ == '__main__':
    main()


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

using namespace std;

int arr[100000];
int dp[1000001];
int main(){

    int N, K;
    cin >> N >> K;
    for(int i = 0; i < N; i++)
        cin >> arr[i];

    dp[0] = 0; dp[1] = abs(arr[1] -arr[0]);

    for(int i = 2; i < N; i++){

        dp[i] = dp[i-1] + abs(arr[i-1] - arr[i]);
        for(int j = 2; j <= K; j++)
            if(i - j >= 0)
                dp[i] = min(dp[i], dp[i-j]+abs(arr[i-j] - arr[i]));
    }

    cout << dp[N-1];

    return 0;
}


Measured memory_bytes: 2944
n,a,b = map(int, input().split())
s = input()
c = a+b

for i in range(n):
    if s[i]=='a':
        if c>0:
            print('Yes')
            c-=1
        else:
            print('No')
    elif s[i]=='b':
        if c>0 and b>0:
            print('Yes')
            c-=1
            b-=1
        else:
            print('No')
    else:
        print('No')

Measured memory_bytes: 52824
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
using LL = long long;
const LL mod = 1e9 + 7;

LL qmi(LL a, LL b)
{
	LL res = 1;
	while (b)
	{
		if (b & 1) res = (LL)res * a % mod;
		a = (LL)a * a % mod;
		b >>= 1;
	}
	return res;
}

int main()
{
	LL n, a, b;

	cin >> n >> a >> b;

	LL res = qmi(2, n) - 1;
	LL up = 1, down = 1;
	
	for (int i = 1, j = n; i <= a; ++i, --j)
	{
		up = up * j % mod;
		up = up * qmi(i, mod - 2) % mod;
	}

	for (int i = 1, j = n; i <= b; ++i, --j)
	{
		down = down * j % mod;
		down = down * qmi(i, mod - 2) % mod;
	}



	printf("%lld\n", ((res - up - down) % mod + mod) % mod);


	return 0;
}

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

using static Input;
using static Util;
class Program
{
    static int N;
    static long[] A;
    static void INPUT()
    {
        N = NextInt();
        A = LineLong();
    }

    static void OUT()
    {
        var dp = new long[N + 1, N + 1];
        for (int len = 1; len <= N; len++)
        {
            for (int i = 0; i + len <= N; i++)
            {
                var j = i + len;
                if ((N - len) % 2 == 0)
                    dp[i, j] = Math.Max(dp[i, j - 1] + A[j - 1], dp[i + 1, j] + A[i]);
                else
                    dp[i, j] = Math.Min(dp[i, j - 1] - A[j - 1], dp[i + 1, j] - A[i]);
            }
        }

        Console.WriteLine(dp[0, N]);
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 81888
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
const long long MOD = 1e9+7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll A, B;

int main() {
	cin >> A >> B;
	vector<vector<ll>> MAP;   //1->黒 0->白
	MAP.resize(100, vector<ll>(100, 0));
	if (A > 1) {
		ll x = 0;
		for (ll c = 0; c < floor((ld)(A - 1) / 50); c++, x += 2) {
			for (ll y = 0; y < 100; y += 2) {
				MAP[x][y + 1] = 1;
				MAP[x + 1][y] = 1;
				MAP[x + 1][y + 1] = 1;
			}
		}
		for (ll y = 0; y < (A - 1) % 50; y++) {
			MAP[x + 1][2 * y + 1] = 1;
			MAP[x + 1][2 * y] = 1;
			MAP[x][2 * y + 1] = 1;
		}
		x += 3;
		for (ll b = 2; b <= B; x += 2) {
			for (ll y = 0; y < 100 && b <= B; b++, y += 2) {
				MAP[x][y] = 1;
			}
		}
		cout << "100 100" << endl;
		for (ll y = 0; y < 100; y++) {
			for (ll x = 0; x < 100; x++) {
				if (MAP[x][y])cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
	}
	else {
		for (ll b = 1,x = 1; b <= B; x += 2) {
			for (ll y = 0; y < 100 && b <= B; b++, y += 2) {
				MAP[x][y] = 1;
			}
		}
		cout << "100 100" << endl;
		for (ll y = 0; y < 100; y++) {
			for (ll x = 0; x < 100; x++) {
				if (MAP[x][y])cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;



int main(){
  int x,y;
  cin>>x>>y;
  int ans=0;
  if(x==1 && y==1) ans+=400000;
  ans+=100000*(x==3)+200000*(x==2)+300000*(x==1);
  ans+=100000*(y==3)+200000*(y==2)+300000*(y==1);

  cout<<ans<<endl;
  
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

PI p[111];
li h[111];

li n;

inline li d(li y, li x, li i) {
    return abs(y - p[i].F) + abs(x - p[i].S);
}

inline li ok(li y, li x) {
    li res = 0;
    rin{
        if (h[i] > 0) {
            res = h[i] + d(y, x, i);
            break;
        }
    }
    rin {
        if (max(res - d(y, x, i), 0ll) != h[i]) {
            return 0;
        }
    }
    return res;
}

int main() {
    cin >> n;

    rin{
        cin >> p[i].S >> p[i].F;
        cin >> h[i];
    }

    rep(y, 101) {
        rep(x, 101) {
            if (ok(y, x) > 0) {
                cout << x << " " << y << " " << ok(y, x) << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define P pair<int,int>
struct edge{int to,cost;};
using namespace std;


class CompareDist
{
public:
    bool operator()(pair<int,int> n1,pair<int,int> n2) {
        return n1.second>n2.second;
    }
};

int V;
vector<vector<edge>> G;
vector<int> d;

void dijkstra(int s){
    priority_queue<P,vector<P>,CompareDist> q;
    //fill(d,d+V,INT_MAX);
    d=vector<int>(V,INT_MAX);
    d[s]=0;
    q.push(P(0,s));
    
    while(!q.empty()){
        P p=q.top();q.pop();
        int v=p.first;
        if(d[v]<p.second)continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                q.push(P(e.to,d[e.to]));
            }
        }
    }
}
int main(void){
    int n,in,t,c;
    cin>>n;
    V=n;
    G.resize(n);
    d.resize(n);
    for(int i=0;i<n;i++){
        cin>>in;
        int node=in;
        cin>>in;
        for(int j=0;j<in;j++){
            cin>>t>>c;
            G[node].emplace_back((edge){t,c});
        }
        
    }
    dijkstra(0);
    for(int i=0;i<d.size();i++){
        cout<<i<<" "<<d[i]<<endl;
    }
}



Measured memory_bytes: 7804
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k; cin >> n >> k;
	vector<int> a(k);
	for(int i = 0; i < k; i++) cin >> a[i];
	auto isGood = [&](int x){
		while(x){
			for(int i = 0; i < k; i++) if(a[i] == (x%10)) return false;
			x /= 10;
		}
		return true;
	};
	while(!isGood(n)) n++;
	cout << n << endl;
	return 0;
}


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

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

	for(int i=0;i<s.size()-2;i++)
	{
		string a;
		int x;
		a=s.substr(i,3);
		x=(a[0]-'0')*100+(a[1]-'0')*10+(a[2]-'0');
		ans=min(ans,abs(753-x));		
	}

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


Measured memory_bytes: 256
import sys

# import bisect
# import numpy as np
# from collections import deque
from collections import deque
# map(int, sys.stdin.read().split())
# import heapq
#import bisect
#import math


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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    l = list()
    for i in range(N):
        l.append((A[i],i+1))
    l.sort()
    for i in range(N):
        print(l[i][1],end=" ")

if __name__ == "__main__":
    main()


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

int N,Q;long L;int** child;

void init(int n) {
  for (int i=0;i<n-1;i++) {
    for (int j=0;j<N;j++) {
      child[i+1][j]=child[i][j]+child[i][j+child[i][j]];
    }
  }
}

int main() {
  cin >> N;vector<long> x(N);
  for (int i=0;i<N;i++) cin >> x[i];
  cin >> L >> Q;
  long y=2*(x[N-1]-x[0])/L;int n=0;
  while (y>0L) {
    n++;y/=2L;
  }
  child=new int*[n];
  for (int i=0;i<n;i++) {
    child[i]=new int[N];
  }
  for (int i=0;i<N;i++) {
    int d;
    auto ir=upper_bound(x.begin(),x.end(),x.at(i)+L);
    if (ir==x.begin()) d=1000005;
    else {
      ir--;
      d=distance(x.begin(),ir)-i;
    }
    child[0][i]=d;
  }
  init(n);
  for (int i=n-1;i>0;i--) {
    for (int j=0;j<N;j++) {
      if(child[i][j]+j==N-1) child[i][j]=100005;
    }
  }
  for (int i=0;i<Q;i++) {
    int result=0;
    int a,b;cin >> a >> b;a--;b--;
    if (a>b) swap(a,b);
    for (int j=n-1;j>=0;j--) {
      if (b-a>child[j][a]) {
        result+=pow(2,j);
        a=a+child[j][a];
        if (b-a>child[j][a]) {
          result+=pow(2,j);
          a=a+child[j][a];
        }
      }
    }
    cout << result+1 << endl;
  }
}

Measured memory_bytes: 8704
#include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
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;
}
int N;
long long h[100010][3];
long long dp[100010][3];

int main() {
    int N;
    cin >> N;
    rep(i, 0, N) {
        rep(r, 0, 3) { cin >> h[i][r]; }
    }

    rep(i, 0, N) {
        rep(r, 0, 3) { dp[i][r] = 0; }
    }

    rep(i, 0, N) {
        rep(r, 0, 3) {
            rep(k, 0, 3) {
                if(r!=k){
                chmax(dp[i+1][k], dp[i][r]+h[i][r]);}
            }
        }
    }

    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;
}

Measured memory_bytes: 4992
import java.util.*;

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

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int x = sc.nextInt();

        int[] a = new int[N];
        long sum = 0; // a[i] は 1≤ai≤109で、summation すると overflow するので注意
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            sum += a[i];
        }

        // ぴったり配れる場合は例外処理。
        if (x == sum) {
            System.out.println(N);
            return;
        }

        Arrays.sort(a);
        int cnt = 0;
        sum = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] + sum > x) {
                break;
            }
            sum += a[i];
            cnt++;
        }

        // N 人に配れるが、N人目にぴったり配るのに失敗してしまった場合。
        if (cnt == N) System.out.println(N - 1);
        else System.out.println(cnt);

        return;
    }

}

Measured memory_bytes: 23892
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int N=sc.nextInt();
		int sum=sc.nextInt();
		int s=0;
		for(int i=0; i<sum; i++) {
			s+=sc.nextInt();
		}
		pl((s+N)/(N+1));
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static int root(int a) {

		int ketasu=0;
		int tmp=a;
		while(tmp>0) {
			ketasu++;
			tmp/=10;
		}
		int constant=(ketasu+1)/2;	//よく使うので定数化
		if(ketasu>=1) {
			int[] suuji=new int[constant];
			tmp=a;
			for(int i=0; i<constant; i++) {
				suuji[constant-1-i]=a%100;
				a/=100;
			}
			int ans=0;
			int kai=0;
			int mae=0;
			if(constant<=1) {
				for(int i=10; i>=0; i--) {
					if(suuji[0]>=i*i) {
						return i;
					}
				}
			}
			else {
				for(int i=0; i<constant; i++) {
					mae+=kai*2;
					for(int j=9; j>=0; j--) {
						if((mae*10+j)*j<=suuji[i]) {
							ans=ans*10+j;
							mae*=10;
							kai=j;
							if(i+1<constant) {
								suuji[i+1]+=(suuji[i]-(mae+j)*j)*100;
							}
							break;
						}
					}
				}
			}
			return ans;
		}
		else {
			return 0;
		}
	}
}


Measured memory_bytes: 24360
a=gets.to_i
b=gets.to_i
c=gets.to_i
x=gets.to_i

count= 0

(0..a).each  do |i|
    (0..b).each do |j|
        (0..c).each do |k|
            if i*500 + j*100 + k*50 == x
                count += 1
            end
        end
    end     
end

puts count


Measured memory_bytes: 1788
def play(A,B,C,turn):
    if len(A)==0 and turn=="a":
        print("A")
        return
    elif len(B)==0 and turn=="b":
        print("B")
        return
    elif len(C)==0 and turn=="c":
        print("C")
        return
    else:
        if turn=='a':
            play(A[1:],B,C,A[0])
        elif turn=='b':
            play(A, B[1:], C, B[0])
        elif turn=='c':
            play(A, B, C[1:], C[0])

A=input()
B=input()
C=input()

play(A,B,C,A[0])

Measured memory_bytes: 3188
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define CONCAT_(x,y) x##y
#define CONCAT(x,y) CONCAT_(x,y)
#define _v1 CONCAT(qyw1, __LINE__) // unique name in same line (otherwise use __COUNTER__)
#define _v2 CONCAT(qyw2, __LINE__)
#define forbits(i, m) for (int _v1 = m, i = __builtin_ctz(_v1); _v1 != 0; _v1 ^= _v1 & -_v1, i = __builtin_ctz(_v1))
#define forsubm(s, m) for (int s = m; s >= 0; s = !s ? -1 : m & (s - 1))
int __nextXZW(int v){int t=v|(v-1);int w=(t+1)|(((~t&-~t)-1)>>(__builtin_ctz(v)+1));return w;}
#define ksets(i, n, k) for (int i = (1u << k) - 1, max = i << (n - k); i <= max; i = __nextXZW(i))
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9+7;
const ll N = 5e5+5, inf = 1e9+5000;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <atcoder/scc>
using namespace atcoder; 

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n, m; cin >> n >> m;
  scc_graph g(n);
  rep (i, m) {
    int u, v; cin >> u >> v;
    g.add_edge(u, v);
  }

  auto scc = g.scc();
  cout << scc.size() << '\n';
  for (auto comp : scc) {
    cout << comp.size() << ' ';
    for (int v : comp) {
      cout << v << ' ';
    }
    cout << '\n';
  }
  
  return 0;
}

Measured memory_bytes: 40612
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
  int i,j;
  int no1=0, no2=0, no3 = 0;
  int cur=0;
  for(i=0; i<10; i++){
    cin>>cur;
    if(cur>=no1){
      no3= no2;
      no2= no1;
      no1 = cur;
    }else if(cur>=no2){
      no3= no2;
      no2= cur;
    }else if(cur>=no3){
      no3= cur;
    }
  }
  cout << no1 << endl;
  cout << no2 << endl;
  cout << no3 << endl;

    return 0;
}

Measured memory_bytes: 3080
n, m = map(int, input().split())
a = list()
for i in range(n) :   
 a.append(list(map(int, input().split())))
b = list()
for j in range(m) :
 b.append(int(input()))
     
for i in range(n) :
 s = 0
 for j in range(m) :
   s += a[i][j] * b[j]
 print(s)


Measured memory_bytes: 6012
n, m, k = map(int, input().split())
a_ = list(map(int, input().split()))
b_ = list(map(int, input().split()))

a = [0]
for i in range(n):
    a.append(a[i]+a_[i])

b = [0]
for i in range(m):
    b.append(b[i]+b_[i])

j = m
ans = 0
for i in range(n+1):
    if a[i] > k:
        break
    while 1:#b[j] > k - a[i]:
        if b[j] <= k - a[i]:
            break
        j -= 1
    ans = max(ans, i + j)

print(ans)

Measured memory_bytes: 47492
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<string> grid(n);
    for(int i = 0; i < n; i++){
        cin >> grid[i];
    }  
    int answer = 0;
    for(int mask = 0; mask < (1<<n); mask++){
        for(int mask1 = 0; mask1 < (1<<m); mask1++){
            int black = 0;
            for(int i = 0; i < n; i++){
                for(int j = 0; j < m; j++){
                    if(((mask >> i)&1) == 0 && ((mask1 >> j)&1) == 0 && grid[i][j] == '#'){
                        black++;
                    }
                }
            }
            if(black == k){
                answer++;
            }
        }
    }
    cout << answer << "\n";
    return 0;

}

Measured memory_bytes: 3588
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

ll cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int h, w;
    cin >> h >> w;
    vector<vector<string>> s(h, vector<string>(w));
    rep(i, h){
        rep(j, w){
            cin >> s[i][j];
        }
    }

    rep(i, h){
        rep(j, w){
            if(s[i][j] == "snuke"){
                cout << (char)('A' + j) << i + 1 << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
import sys

N, W = map(int, sys.stdin.readline().strip().split())

weights = []
for _ in range(N):
    w, v = map(int, sys.stdin.readline().strip().split())
    weights.append((w, v))

MAX_WEIGHTS = 4 * 101
# iまでのものj個を使ってw1を基準とした重さkの時の価値の最大値
dp = [[[-1 for _ in range(MAX_WEIGHTS)] for _ in range(N+1)] for _ in range(N+1)]
dp[0][0][0] = 0

ans = 0
BASE = weights[0][0]
for i in range(N):
    for j in range(i+1):
        for k in range(MAX_WEIGHTS):
            if dp[i][j][k] < 0:
                continue
            w, v = weights[i]
            w -= BASE
            dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k])
            ans = max(ans, dp[i+1][j][k])
            if k + w + (j+1) * BASE <= W and k + w < MAX_WEIGHTS:
                dp[i+1][j+1][k+w] = dp[i][j][k] + v
                ans = max(ans, dp[i+1][j+1][k+w])

print(ans)

Measured memory_bytes: 76636
// ?????¬???????????¬??????

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

bool valid[510][510];

signed main() {
    string s; cin >> s;
    int len = s.length();
    rep(i,0,510) valid[i][i] = true;
    for(int d=3; d<=len; d++) {
        rep(i,0,len-d+1) {
            if(s[i] != 'm' || s[i+d-1] != 'w') continue;
            rep(k,i,i+d) {
                if(s[k] == 'e') {
                    if(valid[i+1][k] && valid[k+1][i+d-1]) {
                        valid[i][i+d] = true;
                    }
                }
            }
        }
    }
    cout << (valid[0][len] ? "Cat" : "Rabbit") << endl;
    return 0;
}

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

int main() {
	int V, E;
	cin >> V >> E;
	vector<vector<pair<int, int>>> G(V, vector<pair<int, int>>());
	for (int i=0;i<E;i++) {
		int s, t, w;
		cin >> s >> t >> w;
		pair<int, int> p_1 = make_pair(t, w);
		pair<int, int> p_2 = make_pair(s, w);
		G[s].push_back(p_1);
		G[t].push_back(p_2);
	}

	priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
	pair<long long, int> first = make_pair(0LL, 0);
	pq.push(first);
	vector<bool> visited(V, false);
	long long ans = 0LL;
	while (!pq.empty()) {
		pair<long long, int> rem = pq.top();
		pq.pop();
		if (visited[rem.second]) continue;
		visited[rem.second] = true;
		ans += rem.first;
		for (auto p : G[rem.second]) {
			if (visited[p.first]) continue;
			pair<long long, int> tmp = make_pair(p.second, p.first);
			pq.push(tmp);
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 7832