akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    deque<ll> dq;
    rep(i, 0, n) {
        ll a;
        cin >> a;
        if (i % 2 == 0) dq.push_front(a);
        else dq.push_back(a);
    }
    if (n % 2 == 0) reverse(dq.begin(), dq.end());
    rep(i, 0, n) {
        cout << dq[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 3840
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll K,X;cin>>K>>X;
  ll s = X-K+1;
  for(int i = s; i<s+2*K-1; i++){
    cout<<i<<" ";
  }

  cout<<endl;
}


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

int main() {
	
	ll n, k; cin >> n >> k;
	if (k == 0) {
		cout << n * n << endl;
		return 0;
	}
	ll ans = 0;
	for (ll i = 1; i <= n ; i++) {
		ll quo = n / i;
		ll mod = n % i;
		ans +=quo * max(0LL, i - k);
		ans += max(0LL, mod - k + 1);
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main
{

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

		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());


		System.out.println(Math.min(c, b / a));
		sc.close();
	}
}

Measured memory_bytes: 23380
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map> 
using namespace std;
typedef long long ll;
const double pi=acos(-1.0);


int main()
{
	double a;
	scanf("%lf",&a);
	printf("%.20f",a*2*pi);
	
}



Measured memory_bytes: 1752
// fn read_vec<T: std::str::FromStr>() -> Vec<T> {
//     let mut s = String::new();
//     std::io::stdin().read_line(&mut s).ok();
//     s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
// }

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn call(n: i32) {
    for i in 3..(n+1) {
        if i % 3 == 0 {//3の倍数
            print!(" {}", i);
        } else {
            let mut tmp:i32 = i;
            loop{
                if tmp % 10 == 3 {
                    print!(" {}", i);
                    break;
                }
                tmp /= 10;
                if tmp == 0 { break; }
            }
        }
    }
    println!("");
}

fn main() {
    let i = read();
    call(i);
}


Measured memory_bytes: 5028
<?php
fscanf(STDIN, "%d", $N);

const CMAX = 100 / 4; // 買えるケーキの最大値
const DMAX = 100 / 7; // 買えるドーナツの最大値
$ans = 'No';
for ($i = 0; $i <= CMAX; $i++) {
 for ($j = 0; $j <= DMAX; $j++) {
  if ($i * 4 + $j * 7 == $N) {
   $ans = 'Yes';
  }
 }
}
echo $ans;

Measured memory_bytes: 4728
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();

        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                if(i*j == n){
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }



    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}



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

string p[5];
int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int i;
	string s[n+2];
	int f,ans;
	ans=0;
	for (i=1;i<=n;i++)
	{
		cin>>s[i];
		//cout<<s[i]<<" ";
	}
	for (i=1;i<=n;i++)
	{
		f=0;
		for (int j=1;j<=4;j++)
		{
			if (s[i]==p[j])
			{
				f=1;
				break;
			}
		}
		if (f==0)
		{
			ans++;
			p[ans]=s[i];
		}
	}
	if (ans==3)
	{
		cout<<"Three"<<endl;
	}
	else
	{
		cout<<"Four"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace  std;
typedef long long int ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define rsz(a,n) a.resize(n)
#define test(t) ll t;cin>>t;while(t--)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define fillv(a,k) memset(a,k,sizeof(a))
#define filla(a,k,n) memset(a,k,sizeof(a[0])*n)
#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
#define sp cout<<" "
#define spaceprint(a,i,s,n) {forsn(i,s,n) { cout<<a[i]; sp;}}
#define lineprint(a,i,s,n) {forsn(i,s,n) {cout<<a[i]; ln;}}
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
#define all(c) c.begin(),c.end()
#define trav(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element)  (find(all(container),element) != container.end())// check the presence of element
//copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 1e5+5, MOD = 1e9+7;
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
long double dp[305][305][305];
ll a[305];
ll n,a1,a2,a3;
void solve(ll i,ll j,ll k)
{
	if(dp[i][j][k]!=-1)
		return;
	if(i==0 and j==0 and k==0)
	{
		dp[i][j][k]=0;
		return;
	}
	dp[i][j][k]=0;
	dp[i][j][k]+=((long double)n)/((long double)(i+j+k));
	if(i>0)
	{
		solve(i-1,j,k);
		dp[i][j][k]+=(((long double)i)/((long double)(i+j+k)))*dp[i-1][j][k];
	}
	if(j>0)
	{
		solve(i+1,j-1,k);
		dp[i][j][k]+=(((long double)j)/((long double)(i+j+k)))*dp[i+1][j-1][k];
	}
	if(k>0)
	{
		solve(i,j+1,k-1);
		dp[i][j][k]+=(((long double)k)/((long double)(i+j+k)))*dp[i][j+1][k-1];
	}
}
int main()
{
	ll i;
	cin>>n;
	a1=a2=a3=0;
	for(ll i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]==1)
		{
			a1++;
		}
		if(a[i]==2)
		{
			a2++;
		}
		if(a[i]==3)
		{
			a3++;
		}

	}
	for(ll i=0;i<=a1+a2+a3;i++)
		for(ll j=0;j<=a1+a2+a3;j++)
			for(ll k=0;k<=a1+a2+a3;k++)
				dp[i][j][k]=-1;
	//cout<<a1<<a2<<a3;
	solve(a1,a2,a3);
	cout<<setprecision(20)<<dp[a1][a2][a3];




}


Measured memory_bytes: 438528
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
#include<iomanip>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
typedef vector<int> vi;
typedef vector<pii> vpii;
 
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define so(v) sort(v.begin(),v.end())
#define re(s) reverse(s.begin(),s.end())
#define lb(v,a) lower_bound(v.begin(),v.end(),a)
#define ub(v,a) upper_bound(v.begin(),v.end(),a)
#define mp1(a,b,c) piii(a,pii(b,c))
 
const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const ll mod=1e9+7;

int main(){

  int n,k,d[20]={0};
  cin>>n>>k;
  rep(i,k){int a; cin>>a; d[a]=1;}
  for(;;){
    int t=n;
    while(t){
      if(d[t%10]) break;
      t/=10;
    }
    if(!t){ cout<<n<<endl; break;}
    n++;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

#define M 10000000

int main(int argc, char **argv)
{
    ll A, B;
    cin >> A >> B;

    set<ll> da, db;
    ll t = A;
    ll i = 2;
    da.insert(1);
    while (i != M) {
        if (t % i == 0) {
            da.insert(i);
            t = t / i;
        }
        else {
            i++;
        }
        if (t == 1) {
            break;
        }
    }
    da.insert(t);
    t = B;
    i = 2;
    db.insert(1);
    while (i != M) {
        if (t % i == 0) {
            db.insert(i);
            t = t / i;
        }
        else {
            i++;
        }
        if (t == 1) {
            break;
        }
    }
    db.insert(t);

    set<ll> dc;
    for (auto itr = da.begin(); itr != da.end(); ++itr) {
        if (db.find(*itr) != db.end()) dc.insert(*itr);
    }

    cout << dc.size() << endl;

    return 0;
}


Measured memory_bytes: 256
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools
    import functools
    
    n = int(input())
    ss = [input() for _ in range(n)]
    target_chars = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
    # n_names = [0] * 5
    for name in ss:
        if name[0] in target_chars.keys():
            target_chars[name[0]] += 1
    
    ans = 0
    for comb in itertools.combinations(target_chars, 3):
        ans += functools.reduce(lambda x, y: x * target_chars[y], comb, 1)

    print(ans)
            

if __name__ == '__main__':
    main()

Measured memory_bytes: 10280
// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

fun main(args: Array<String>) {
  val (n, k) = fastReadInts(2)
  val xs = fastReadInts(n)
  val min = (0 until n - (k - 1))
      .map {
        val x1 = xs[it]
        val x2 = xs[it + k - 1]
        when {
          x2 <= 0 -> -x1
          x1 <= 0 -> {
            val a1 = -x1
            val a2 = x2
            Math.min(a1, a2) * 2 + Math.max(a1, a2)
          }
          else -> x2
        }
      }
      .min()!!
  println(min)
}

Measured memory_bytes: 39076
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<map>
#define ll long long
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    ll a[100005],i;
    for(i=0; i<n; i++)
        scanf("%lld",&a[i]);
    if(a[0]!=0)
            printf("0\n");
    else
    {
        ll ans=1;
        map<long long,long long> b;
        for(int i=0;i<n;i++) b[a[i]]++;
        for(i=1;i<n;i++)
        {
            ans*=b[a[i]-1];
            ans%=998244353;
        }

        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 7296
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = INT_MAX;
const ll MOD = 1'000'000'007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

// 0-indexed RMQ segment tree
template <typename T = int>
struct SegmentTree {
    using F = function<T(T, T)>;
    int n;
    vector<T> dat;
    F func;
    T UNIT;

    SegmentTree(int n_, F func_, T UNIT_) : func(func_), UNIT(UNIT_) {
        n = 1;
        // full binary tree: num of leaves = n = 2^k >= n_
        while (n < n_)
            n *= 2;
        dat.assign(2 * n - 1, UNIT);
    }
    SegmentTree(vector<T> v_, F func_, T UNIT_) : func(func_), UNIT(UNIT_) {
        n = 1;
        while (n < v_.size())
            n *= 2;
        dat.assign(2 * n - 1, UNIT);
        for (int i = 0; i < v_.size(); ++i) {
            dat[n - 1 + i] = v_[i];
        }
        for (int i = n - 2; i >= 0; --i) {
            dat[i] = func(dat[2 * i + 1], dat[2 * i + 2]);
        }
    }
    void update(int k, int a) {
        // leaves are at index n-1 to 2*n-2
        k += n - 1;
        dat[k] = a;
        while (k > 0) {
            // k -> parent node
            k = (k - 1) / 2;
            // func(child nodes)
            dat[k] = func(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }
    T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l)
            return UNIT;
        if (a <= l && r <= b)
            return dat[k];
        else {
            T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
            T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return func(vl, vr);
        }
    }
    // get result of func() in [a, b)
    T query(int a, int b) { return query(a, b, 0, 0, n); }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    auto f = [](int l, int r) { return min(l, r); };
    SegmentTree<int> seg(n, f, INF);
    vector<int> com(q), x(q), y(q);
    for (int i = 0; i < q; ++i) {
        cin >> com[i] >> x[i] >> y[i];
    }
    for (int i = 0; i < q; ++i) {
        if (com[i] == 0) {
            seg.update(x[i], y[i]);
        } else {
            cout << seg.query(x[i], y[i] + 1) << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 4896
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,p=0;
  while(cin>>a>>b,b){
    if(p)cout<<endl;
    p++;
    int s=0;
    for(int i=a;i<=b;i++){
      if(i%4==0){
        if(i%400==0)cout<<i<<endl;
        else if(i%100==0)continue;
        else cout<<i<<endl;
        s++;
      }
    }
    if(!s)cout<<"NA"<<endl;
  }
}

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

int main(){
    ll n,cnt=0,ans=0;
    cin >> n;
    vector<ll> h(n);
    rep(i,n){
        cin >> h.at(i);
    }
    rep(i,n-1){
        if(h[i]>=h[i+1]) cnt++;
        else{
            ans=max(ans,cnt);
            cnt=0;
        }
        ans = max(ans,cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	string s;int m,n;
	cin>>m>>n;
	for(int i=1;i<=m;i++)
	{
		cin>>s;
		cout<<s<<endl<<s<<endl;
	}
	return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(N);
  vector< int > s(N);
  int mn = INF;
  ll sm = 0ll;
  REP(i, N) {
    cin >> s[i];
    sm += s[i];
    if (s[i] % 10 == 0) continue;
    mn = min(mn, s[i]);
  }

  if (sm % 10 == 0) {
    sm -= mn;
  }
  if (sm <=  0) {
    sm = 0;
  }
  cout << sm << endl;

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/
#include <stdbool.h>/*bool型*/
#include <limits.h>/*限界*/

//---------------------------------------------------
//a


#define rep(i, n) for(int  i = 0; i < (n); i++)
#define max(a,b) ((a>b)?a:b)
#define ABS(a) (((a)>(0))?a:-(a))
#define LL long long
#define MOD 1000000007//10^9+7(素数)

int main(void)
{
  int n, m;
  scanf("%d %d",&n , &m );
  printf("%d\n", n*m);
  return 0;
}


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

using namespace std;

int main() {
	long long n,k,m;
	cin >> n >> k;
	if(k==1){
		m=0;
	}
	else {
		m=n%k;
		m=min(m,k-m);
	}
	cout << m <<endl;
return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int cnt=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(i*500+j*100+k*50==d){
                    cnt++;
                }
            }
        }
    }
    cout<<cnt<<endl;
}


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

int main(){
	int t[5], off[5], k = 0;
	while (k < 5) {
		cin >> t[k];
		off[k] =  10 - t[k] % 10;
		if (off[k] == 10) {
			off[k] = 0;
		}
		k++;
	}
	int i, j, tmp = 0, tm = 0;
	for (i = 0; i < 5; i++) {
		int c = i;
		for (j = i; j < 5; j++) {
			if (off[c] > off[j]) {
				c = j;
			}
		}
		tmp = off[c];
		off[c] = off[i];
		off[i] = tmp;
		tm = t[c];
		t[c] = t[i];
		t[i] = tm;
	}
	int l = 0, ans = 0;
	while (l < 5) {
		ans = ans + off[l] + t[l];
		l++;
	}
	ans -= off[4];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main()
{
    int n;
    int i, j, k, l, m;
    int tmp;
    int count=0;
     
    cin >> n;
    int Dice[n][6];
     
    for(i=0;i<n;i++){
        for(j=0;j<6;j++){
            cin >> Dice[i][j];
        }
    }
 
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            for(k=0;k<4;k++){
                tmp=Dice[j][0];
                Dice[j][0]=Dice[j][1];
                Dice[j][1]=Dice[j][5];
                Dice[j][5]=Dice[j][4];
                Dice[j][4]=tmp;
                if(Dice[j][1]==Dice[i][1])
                    goto Break;
                else{
                    for(l=0;l<4;l++){
                        tmp=Dice[j][0];
                        Dice[j][0]=Dice[j][3];
                        Dice[j][3]=Dice[j][5];
                        Dice[j][5]=Dice[j][2];
                        Dice[j][2]=tmp;
                        if(Dice[j][0]==Dice[i][1]){
                            tmp=Dice[j][0];
                            Dice[j][0]=Dice[j][4];
                            Dice[j][4]=Dice[j][5];
                            Dice[j][5]=Dice[j][1];
                            Dice[j][1]=tmp;
                            goto Break;
                        }
                    }
                }
            }
            Return:;
        }
    }
    goto Exit;
     
    Break:;
    for(m=0;m<4;m++){
        tmp=Dice[j][0];
        Dice[j][0]=Dice[j][3];
        Dice[j][3]=Dice[j][5];
        Dice[j][5]=Dice[j][2];
        Dice[j][2]=tmp;
        if(Dice[j][0]==Dice[i][0]){
            if(Dice[i][0]==Dice[j][0]&&Dice[i][1]==Dice[j][1]&&Dice[i][2]==Dice[j][2]&&Dice[i][3]==Dice[j][3]&&Dice[i][4]==Dice[j][4]&&Dice[i][5]==Dice[j][5]){
                cout << "No" << endl;
                return 0;
            }
            else{
                goto Return;
            }
        }
    }
    goto Return;
     
    Exit:;
    cout << "Yes" << endl;
    return 0;
}

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

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

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

const int mod = 998244353;
const ll inf = 3e18 + 5;

int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }  

int main(){
    int n;
    cin >> n;
    vi a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    
    int mx = a[0];
    ll sol = 0;
    for(int i = 1; i < n; i++){
        mx = max(mx, a[i]);
        if(a[i] < mx)
            sol += mx - a[i];
    }
    cout << sol;
}


Measured memory_bytes: 4044
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n,m = readline() |> split |> parseMap
	p = [Array{Int}(m) for i in 1:n]
	for i in 1:n
		a = readline() |> split |> parseMap
		for j in 1:m
			p[i][a[j]] = j
		end
	end
	chk = ones(Int,m)
	minim = 300
	for i in 1:m-1
		z = zeros(Int,m)
		for j in 1:n
			z[indmin(p[j])] += 1
		end
		x = indmax(z)
		minim = min(minim, z[x])
		for j in 1:n
			p[j][x] = 301
		end
	end
	println(m == 1?1:minim)
end
main()


Measured memory_bytes: 132556
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)

	d := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&d[i])
	}

	ans := exec(N, d)
	fmt.Println(ans)
}

func exec(N int, d []int) int {
	var count int

	sort.Ints(d)

	a := d[N/2]
	b := d[N/2-1]

	if a != b {
		count = a - b
	}

	return count
}


Measured memory_bytes: 5504
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! p {
    ($($x:expr),*) => {
        $(println!("{:?}", $x);)*
    };
}
macro_rules! pr {
    ($($x:expr),*) => {
        $(println!("{}", $x);)*
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
#[allow(unused_imports)]
use std::cmp::*;
trait Each: Iterator {
    fn each<F>(self, mut f: F)
    where
        Self: Sized,
        F: FnMut(Self::Item),
    {
        self.fold((), move |(), item| f(item));
    }
}
impl<T: Iterator> Each for T {}

fn main() {
    input! {
        n:usize,
        a:[i32;n]
    }
    let res = a
        .iter()
        .filter(|&&x| x % 2 == 0)
        .all(|&x| x % 3 == 0 || x % 5 == 0);
    print!("{}", if res { "APPROVED" } else { "DENIED" });
}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
vector<ll> v;
void dfs(ll a)
{
    v.push_back(a);
    if(a > 3234566667)
    {
        return;
    }
    for(int i = 0;i <= 9;i++)
    {
        if(fabs(a % 10 - i) <= 1)
        {
            dfs(a * 10 + i);
        }
    }
}
int main()
{
    int k;
    cin >> k;
    for(int i = 1;i <= 9;i++)
    {
        dfs(i);
    }
    sort(v.begin(),v.end());
    cout << v[k - 1] << "\n";

    return 0;
}

Measured memory_bytes: 6512
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
class BIT
{
public:
	int a[N * 2];
	void init()
	{
		MEM(a, 0);
	}
	void add(int x, int val)
	{
		while (x < N * 2)
		{
			a[x] += val;
			x += x & -x;
		}
	}
	int sum(int x)
	{
		int ret = 0;
		while (x)
		{
			ret += a[x];
			x -= x & -x;
		}
		return ret;
	}
} b;
int a[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	LL tot = 1LL * n * (n + 1) / 2;
	for (int i = 1; i <= n; i++) cin >> a[i];
	int l = 1, r = INF;
	int ans = INF;
	while (l <= r)
	{
		int mid = (l + r) / 2;
		b.init();
		LL sum = 0;
		int cur = N;
		b.add(cur, 1);
		for (int i = 1; i <= n; i++)
		{
			cur += a[i] >= mid ? 1 : -1;
			sum += b.sum(cur);
			b.add(cur, 1);
		}
		if (sum * 2 >= tot) ans = mid, l = mid + 1;
		else r = mid - 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n; cin >> n;
    vector<double> v(n);
    
    for(int i=0; i<n;i++) cin >> v[i];
    sort(v.begin(), v.end());
    for(int i=0;i<n-1; i++){
        v[i+1]=(v[i]+v[i+1])/2;
    }
    cout << v[n-1] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);

      String s = sc.next();
      char[] ch = s.toCharArray();
      
      int cnt = 0;
      if(ch[0] == '1') {
        cnt++;
      }
      if(ch[1] == '1') {
        cnt++;
      }
      if(ch[2] == '1') {
        cnt++;
      }
      
      System.out.println(cnt);
      
      


	}
}

Measured memory_bytes: 22228
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
using namespace std;

int main(){
    long long N, A, B;
    cin >> N >> A >> B;
    
    cout << max(A+B*(N-1)-(A*(N-1)+B)+1,0ll) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main() {
  int N; cin >> N;
  map<string, int> mp;
  string str; cin >> str;
  mp.emplace(str, 1);
  for(int i = 1; i < N; i++) {
    string input; cin >> input;
    if(str[int(str.size()) - 1] != input[0]) continue;
    str = input;
    mp.emplace(str, i + 1);
  }
  if(mp.size() == N) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define scan(n) scanf("%d",&n)
#define ls(n) scanf("%lld",&n)
#define print(n) printf("%d ",n)
#define pln(n) printf("%d\n",n)
#define lpln(n) printf("%lld\n",n)
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rev(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define tc           ll t1; cin>>t1; while(t1--)
#define inp         ll n; cin>>n; ll arr[n]; rep(i,0,n) cin>>arr[i];
#define vect vector<ll>
#define sortv(v)       sort(v.begin(),v.end())
#define lower(v,n)    lower_bound(v.begin(),v.end(),n)-v.begin()
#define upper(v,n)    upper_bound(v.begin(),v.end(),n)-v.begin()
#define bitcount(n) __builtin_popcount(n)
#define ln <<endl
#define inf          1e12
#define ninf         LONG_MIN
#define fast()         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const   ll mod=1e9+7;
const ll N=1e5+5;




int main() 
{ 
         fast();
        
         int n;
         cin >> n;
         std::vector<int> v[2];
         string s;
         cin >> s;
         rep(i,0,n)
         {
           if(s[i]=='W')
            v[0].pb(i);
          else v[1].pb(i);
         }
         if(v[1].size()==0 || v[0].size()==0)
         {
          cout<<0;
          return 0;
         }
         int count=0;
         int p=0,q=0,len=v[1].size();
         int i=v[0][p],j=v[1][len-1-q];
       //  cout<<i<<" "<<j<<endl;
         rep(k,0,n)
         {
          if(i>=j)
            break;
            if(s[k]=='W'){
              swap(s[i],s[j]);
              p++;
              q++;
              i=v[0][p];
              j=v[1][len-1-q];
              //cout<<i<<" "<<j<<endl;
              count++;
              if(i>=j || p>=(int)v[0].size() || q>=(int)v[1].size())
                break;
            }
         }
         cout<<count;



  return 0; 
} 


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

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> listS(N, 0);
    for (int i = 0; i < N; i++)
    {
        if (S[i] == '#')
        {
            listS[i] = 1;
        }
    }
    vector<int> ans;
    ans.push_back(count(listS.begin(), listS.end(), 0));
    int i = 0;
    int m = ans[0];
    while (i < N)
    {
        if (listS[i] == 0)
        {
            m--;
        }
        else
        {
            m++;
        }
        ans.push_back(m);
        i++;
    }
    cout << *min_element(ans.begin(), ans.end()) << endl;
}

Measured memory_bytes: 2428
#include <stdio.h>
int main(){
	int i = 0;
	int x[10000];

	scanf("%d",&x[0]);
	while(x[i] != 0){
		i++;
		scanf("%d",&x[i]);
	}

	i = 0;

	while(x[i] != 0){
		printf("Case %d: %d\n", i + 1, x[i]);
		i++;
	}

	return 0;
}

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

int main() {
  string s, t = "";
  cin >> s;
  rep(i, (s.size()-1)/2+1) t += s[i*2];
  cout << t << endl;
  return 0;
}

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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 500005
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rt return
using namespace std;

const string yy = "Yes";
const string nn = "No";

int32_t main(){
	IOS;
	int tt = 1; 
	//cin >> tt;
	while(tt--){

    

    
    
    string s; cin >> s;
    int sum = 0;
    for(auto x : s){
      sum += (x - '0');
      sum %= 9;
    }
    
    if(!sum){
      cout << yy;
    }
    else cout << nn;
    
    
	}
	return 0;
}


Measured memory_bytes: 3772
A, B, C, D = gets.chomp.split.map(&:to_i)

# we calculate the numbers which can dividable by C, D, C*D

# (0, 3) -> 0
# (2, 3) -> 0
# (3, 3) -> 1
# (5, 3) -> 1
# (6, 3) -> 2
# numbers dividable by c under a.
# number of (i) .. i: 0 - a, i % c == 0
def nums(a, c)
  a / c
end

def gcd(a, b) 
  if (a < b) 
    # swap(a, b)
    tmp = a
    a = b
    b = tmp
  end

  if (b == 0) 
    return a
  end
  
  gcd(b, a % b)
end

cd = C * D / gcd(C, D) # lcm(C, D)

# 0..B
b = B - nums(B, C) - nums(B, D) + nums(B, cd)
# 0..A-1
a = (A-1) - nums(A-1, C) - nums(A-1, D) + nums(A-1, cd)

p b - a

Measured memory_bytes: 1788
from itertools import permutations
N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))

p=q=0
for i,a in enumerate(permutations(range(1,N+1))):
    if a==P:
        p=i
    if a==Q:
        q=i
print(abs(p-q))

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define pi (acos(-1))


int main()
{
    int x;
    std::cin >> x;
    // should be enough
    for (int i = 1; i != 2000; ++i)
    {
        if ((360 * i) % x == 0)
        {
            std::cout << ((360 * i) / x) << std::endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define F first
#define S second
#define REP(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	if(n==1) cout<<"Hello World\n";
	else
	{
		int a,b; cin>>a>>b;
		cout<<a+b<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pcont(x) for(auto i: x){cout << i << " ";} cout << "\n";

int main(){
    IOS;
    int a;
    cin >> a;
    cout << (a + pow(a, 2) + pow(a, 3)) << "\n";
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w; cin>>h>>w;
    int n; cin>>n;
    cout<<(n+max(h,w)-1)/max(h,w)<<endl;
    return 0;
}


Measured memory_bytes: 256
import itertools

def resolve():
    N = int(input())
    P = tuple(map(int, input().split()))
    Q = tuple(map(int, input().split()))
    l = list(itertools.permutations(range(1, N+1)))
    p_idx = l.index(P)
    q_idx = l.index(Q)
    print(abs(p_idx - q_idx))

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 8052
n,k=map(int,input().split())

import sys
sys.setrecursionlimit(2147483647)

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
p = 10**9+7 #割る数
N = 2*n+1  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ans=1

if k>n:
    ans=cmb(n+n-1,n,p)

else:

    for i in range(1,k+1):
        ans+=(cmb(n, i, p)*cmb(n-1,n-i-1,p))%p
        
        #print(i,cmb(n, i, p),cmb(n-1,n-i-1,p))

print(ans%p)
    


Measured memory_bytes: 50832
#pragma GCC optimize(2)
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <queue>
#define all(v) (v).begin(),(v).end()
#define rep(x,y) for(ull i = (x);i<=(y);i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int inf = 0x3f3f3f3f;
int dir8[8][2] = {-1,0,1,0,0,1,0,-1,-1,-1,-1,1,1,-1,1,1};
//int dir4[4][2] = {0,1,1,0,0,-1,-1,0};
int dir4[4][2] = {1,0,0,-1,-1,0,0,1};
char dir4show[4] = {'R','D','L','U'};
string dir4s = "RDLU";
const double eps = 1e-6;

int N,M,a,b;
vector<pii> ve;
priority_queue<int> q;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>N>>M;
    rep(1,N){
        cin>>a>>b;
        ve.pb({M-a+1,b});
    }
    sort(all(ve),less<pii>());
    ull idx = ve.size()-1,res = 0;
    for(int i = M;i>=1;i--){
        while(ve[idx].first == i) {
            q.push(ve[idx].second);
            idx--;
        }
        if(q.size())
            res += q.top(),q.pop();
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1908
#include <iostream>
using namespace std;
int n,a[100005],b[100005];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	long long d=0;
	for(int i=n-1;i>=0;i--){
		d+=(b[i]-(a[i]+d)%b[i])%b[i];
	}
	cout<<d<<endl;
	return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var X = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray();
        int N = X[0];
        int D = X[1];
        var count = Enumerable.Range(0, N).Select(e =>
        {
            var a = Console.ReadLine().Split();
            return (X: Double.Parse(a[0]), Y: Double.Parse(a[1]));
        }).Count(e => Math.Sqrt((e.X * e.X) + (e.Y * e.Y)) <= D);
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 41276
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
 
class DandA {
    static void Main(string[] args) {
        int n = ReadLineInt();
        string s = ReadLineStr();
        int index = 0;
        int cnt = 0;
        while (index != -1) {
            index = s.IndexOf("ABC", index);
            if (index != -1) {
                cnt++;
                index++;
            }
        }
        Console.WriteLine(cnt);
    }
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}
}

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

int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  
  vector<int> v(3);

  v[0] = a * x + b * y;
  if (x < y){
    v[1] = c * 2 * x + b * (y - x);
    v[2] = c * 2 * y;
  } else {
    v[1] = c * 2 * y + a * (x - y);
    v[2] = c * 2 * x;
  }
  int ans = 4e9;
  rep(i, 3){
    if (v[i] < ans) ans = v[i];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3628
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [n, k] <- getIntList
  v <- VM.new n
  VM.set v (0::Int)

  replicateM k $ do
    d <- getInt
    as <- getIntList
    forM_ as $ \i -> do
      VM.write v (i-1) 1

  v' <- V.freeze v
  let ans = V.length $ V.filter (== 0) v'

  print ans


Measured memory_bytes: 5144
#include <stdio.h>

int main(void) {
  int n, m, l;
  scanf("%d %d %d", &n, &m, &l);

  int A[n][m];
  for (int i=0; i<n; i++) {
    for (int j=0; j<m; j++) {
      scanf("%d", &A[i][j]);
    }
  }

  int B[m][l];
  for (int i=0; i<m; i++) {
    for (int j=0; j<l; j++) {
      scanf("%d", &B[i][j]);
    }
  }

  for (int i=0; i<n; i++) {
    for (int j=0; j<l; j++) {
      long long sum=0;
      for (int k=0; k<m; k++) {
          sum+=A[i][k]*B[k][j];
      }
      if (j<l-1) {
        printf("%ld ", sum);
      } else {
        printf("%ld\n", sum);
      }
    }
  }
  return 0;
}


Measured memory_bytes: 2100
N = int(input())
l_x = list(map(int, input().split()))
d_min = 999999999999999
left = min(l_x)
right = max(l_x)
for p in range(left, right + 1):
  total = 0
  for x in l_x:
    total += (p - x) ** 2
  if total < d_min:
    d_min = total

print(d_min)    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll res[105][105];
void solve(){
	ll a,b,f=0;
	cin>>a>>b;
	if(a>b){
		swap(a,b);
		f=1;
	}
	ll tr=(a+48)/50;
	ll x=0,y=(tr%2==0?1:0),op=(tr%2==0?1:0),temp=a;
	while(a>1){
		res[x][y]=1;
		y+=2;
		if(y>=100){
			x++;
			if(!op)
				y=1;
			else
				y=0;
			op^=1;
		}
		a--;
	}
	if(x>=1)
		b=b-(temp-1)+50;
    b--;
    if(y==1)
    	y--;
	while(y<100){
		res[x][y]=1;
		y++;
	}
	y=0,x++;
	while(y<100){
		res[x][y]=1;
		y++;
	}
	x+=2,y=1,op=1;
	while(b){
		res[x][y]=1;
		y+=2;
		if(y>=99){
			x+=2;
			if(!op)
				y=1;
			else
				y=0;
			op^=1;
		}
		b--;
	}
	cout<<"100 100\n";
	for(ll i=0;i<100;i++){
		for(ll j=0;j<100;j++)
			if(res[i][j]^f)
				cout<<"#";
			else
				cout<<".";
		cout<<"\n";
	}
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 3808