akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

int main() {
    long long int n, h, a, b;
    std::cin >> n >> h;
    std::vector<std::pair<long long int, long long int>> v;
    for (long long int i = 0; i < n; i++) {
        std::cin >> a >> b;
        v.push_back(std::make_pair(a,b));
    }

    auto amax = (std::max_element(v.begin(), v.end(), 
        [](std::pair<long long int, long long int> a, std::pair<long long int, long long int> b) {
            return a.first < b.first;
        }))->first;
    long long int c = 0, bsum = 0;
    for (long long int i = 0; i < n; i++) {
        if (v[i].second > amax) {
            c++;
            bsum += v[i].second;
        }
    }
    
    if (h > bsum) {
        auto remain = h - bsum;
        std::cout << c + remain / amax + ((remain % amax != 0)?1:0) << std::endl;
    } else {
        std::sort(v.begin(), v.end(), 
            [](std::pair<long long int, long long int> a, std::pair<long long int, long long int> b) {
                return a.second > b.second;
            });
        long long int current = 0;
        for (long long int i = 0; i < n; i++) {
            current += v[i].second;
            if (current >= h) {
                std::cout << i + 1 << std::endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  string g = "";
  
  for(int i = 0; i < s.size(); i++){
    if(i%2 == 0){
      g += s.at(i);
    }
  }
  cout << g << endl;
  return 0;
}

Measured memory_bytes: 512
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, K;
	cin >> N >> K;

	if (K == 1) {
		cout << 0 << endl;
	}
	else {
		cout << N - K << endl;
	}
	
	return 0;
}


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


int main(void) {
  int n;
  cin >> n;
  long long ans = 1;
  rep2(i,1,n+1) {
    ans *= i;
    ans %= 1000000007;
  }
  cout << ans << endl;
  
               
   
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int operate(int n)
{
  vector<int> v(4);
  for(int i = 0; i<4; i++){
    v[i] = n % 10;
    n /= 10;
  }
  int L = 0,S = 0;
  sort(v.begin(),v.end());
  for(int i=0; i<4; i++){
    L *= 10; L += v[3-i];
    S *= 10; S += v[i];
  }
  return L - S;
}
int main()
{
  for(;;){
    int n;
    cin >> n;
    if(n == 0) break;
    if(n == 6174){
      cout << 0 << endl;
      continue;
    }
    if(n % 1111 == 0){
      cout << "NA" << endl;
      continue;
    }
    int ret = 1;
    for(;;){
      n = operate(n);
      if(n == 6174) break;
      ret++;
    }
    cout << ret << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
while True:
  r, a = input().split()
  if r == "0":
    break
   
  h = 0
  for x, y in zip(r, a):
    if x == y:
      h += 1
   
  b = -h
#  print(b)
  for x in r:
    if x in a:
      b += 1
 
  print(h, b)



Measured memory_bytes: 5572
#include <queue>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>

struct Barrier {
  double x;
  double y;
  double r;

  Barrier() : x(0), y(0), r(-1) {
  }

  Barrier(double x_, double y_, double r_) : x(x_), y(y_), r(r_) {
  }
};

Barrier barriers[1002];
double costs[1002][1002];
double costFromStart[1002];
const int start = 0;
const int goal = 1001;
const double inf = HUGE_VAL;

void prepare() {
  for (int i = 0; i < 1002; i++) {
    for (int j = 0; j < 1002; j++) {
      auto from = barriers[i];
      auto to = barriers[j];

      if (from.r < 0 || to.r < 0) {
        costs[i][j] = inf;
      }

      auto dx = from.x - to.x;
      auto dy = from.y - to.y;

      auto distance = std::sqrt(dx * dx + dy * dy);
      auto cost = std::max(0.0, distance - from.r - to.r);

      costs[i][j] = cost;
    }
  }
}

void solve() {
  // (cost, barrier_index)
  std::priority_queue<std::pair<double, int>, std::vector<std::pair<double, int> >, std::greater<std::pair<double, int> > > q;

  costFromStart[start] = 0;
  for (int i = 1; i < 1002; i++) {
    costFromStart[i] = inf;
  }

  q.push(std::make_pair(0.0, 0));
  while (!q.empty()) {
    double costFrom = q.top().first;
    int from = q.top().second;
    q.pop();

    for (int to = 0; to < 1002; to++) {
      double edgeCost = costs[from][to];
      if (edgeCost >= inf) {
        break;
      }

      double costTo = costFrom + edgeCost;
      if (costTo < costFromStart[to]) {
        costFromStart[to] = costTo;
        q.push(std::make_pair(costTo, to));
      }
    }
  }
}

int main() {
  int xs, ys, xt, yt;
  int N;
  scanf("%d%d%d%d", &xs, &ys, &xt, &yt);
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    int x, y, r;
    scanf("%d%d%d", &x, &y, &r);
    barriers[i] = Barrier(x, y, r);
  }
  barriers[start] = Barrier(xs, ys, 0);
  barriers[goal] = Barrier(xt, yt, 0);

  prepare();
  solve();

  printf("%.10f\n", costFromStart[goal]);

  return 0;
}


Measured memory_bytes: 12272
#ifdef __APPLE__

    #include <cassert>
    #include <iostream>
    #include <iomanip>
    #include <ctime>
    #include <cstdio>
    #include <vector>
    #include <algorithm>
    #include <utility>
    #include <queue>
    #include <stack>
    #include <string>
    #include <cstring>
    #include <sstream>
    #include <map>
    #include <set>
    #include <unordered_map>
    #include <unordered_set>

#else

    #include <bits/stdc++.h>

#endif

using namespace std;

#define ll long long int
#define MAXN 200000

vector<ll> adj[MAXN+5];
ll dist[MAXN+5];
bool visited[MAXN+5];

ll bfs(ll n)
{
    ll i,u,v;
    for(i=1;i<=n;i++) dist[i] = n+1, visited[i] = false;
    queue<ll> Q;
    dist[1] = 0;
    Q.push(1);
    while(!Q.empty())
    {
        u = Q.front();
        visited[u] = true;
        Q.pop();
        for(i=0;i<adj[u].size();i++)
        {
            v = adj[u][i];
            if(!visited[v])
            {
                if(dist[v] > dist[u] + 1)
                {
                    dist[v] = dist[u] + 1;
                    Q.push(v);
                }
            }
        }

    }
    return dist[n];
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,m;
    cin >> n >> m;
    ll a,b;
    while(m--)
    {
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    ll ans = bfs(n);
    if(ans == 2) printf("POSSIBLE\n");
    else printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 15336
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] s = br.readLine().split(" ");
        int[] a = new int[6];

        for(int i = 0; i < s.length; i++){
            a[i] = Integer.parseInt(s[i]);    
        }

        Dice dice = new Dice(a);

        int num = Integer.parseInt(br.readLine());

        for(int i = 0; i < num; i++){
            String[] input = br.readLine().split(" ");
            int top = Integer.parseInt(input[0]);
            int front = Integer.parseInt(input[1]);
            dice.setTop(top);
            dice.setFront(front);
            System.out.println(dice.RIGHT);
        }
        
    }
}

class Dice{
    int TOP,BOTTOM,LEFT,RIGHT,FRONT,BACK;

    Dice(int[] a){
        this.TOP = a[0];
        this.FRONT = a[1];
        this.RIGHT = a[2];
        this.LEFT = a[3];
        this.BACK = a[4];
        this.BOTTOM = a[5];
    }

    void setTop(int top){
        if(this.FRONT == top)           this.turnN();
        else if(this.RIGHT == top)      this.turnW();
        else if(this.LEFT == top)       this.turnE();
        else if(this.BACK == top)       this.turnS();
        else if(this.BOTTOM == top)    {this.turnN(); this.turnN();}
    }

    void setFront(int front){
        if(this.RIGHT == front)         this.turnL();
        else if(this.LEFT == front)     this.turnR();
        else if(this.BACK == front)    {this.turnR(); this.turnR();}
    }

    void turnS(){
        int tmp = this.TOP;
        this.TOP = this.BACK;
        this.BACK = this.BOTTOM;
        this.BOTTOM = this.FRONT;
        this.FRONT = tmp;
    }

    void turnN(){
        int tmp = this.TOP;
        this.TOP = this.FRONT;
        this.FRONT = this.BOTTOM;
        this.BOTTOM = this.BACK;
        this.BACK = tmp;
    }

    void turnW(){
        int tmp = this.TOP;
        this.TOP = this.RIGHT;
        this.RIGHT = this.BOTTOM;
        this.BOTTOM = this.LEFT;
        this.LEFT = tmp;
    }

    void turnE(){
        int tmp = this.TOP;
        this.TOP = this.LEFT;
        this.LEFT = this.BOTTOM;
        this.BOTTOM = this.RIGHT;
        this.RIGHT = tmp;
    }

    void turnL(){
        int tmp = this.FRONT;
        this.FRONT = this.RIGHT;
        this.RIGHT = this.BACK;
        this.BACK = this.LEFT;
        this.LEFT = tmp;
    }

    void turnR(){
        int tmp = this.FRONT;
        this.FRONT = this.LEFT;
        this.LEFT = this.BACK;
        this.BACK = this.RIGHT;
        this.RIGHT = tmp;
    }

}

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


int main(){
    string s;
    cin >> s;
    bool n=0,so=0,w=0,e=0;
    for(char c:s){
        if (c=='N') n=1;
        if (c=='S') so=1;
        if (c=='W') w=1;
        if (c=='E') e=1;
        if (n && so && w && e) break;
    }
    if(n && so && w && e){
        cout << "Yes" << endl;
    }
    else if(n && so && !w && !e){
        cout << "Yes" << endl;
    }
    else if(!n && !so && w && e){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

using namespace std;

#define ll long long
const int N = 300005;

int n, m , ans;

int main()
{
    cin >> n >> m;
    ans = (n+m)*(n+m-1);
    ans/=2;
    ans-= (n*m);

    cout << ans;

    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

const int MOD = 1e6 + 3;

i64 powMod(i64 x, i64 n = MOD - 2) {
	i64 ret = 1;
	while(n) {
		if(n & 1) (ret *= x) %= MOD;
		(x *= x) %= MOD;
		n >>= 1;
	}
	return ret;
}

int main() {
	int q; scanf("%d", &q);
	
	std::vector<i64> fact(MOD + 1, 1), inv(MOD + 1, 1);
	for(i64 i = 0; i < (int)fact.size() - 1; i++) fact[i + 1] = fact[i] * (i + 1) % MOD;
	for(int i = 0; i < fact.size(); i++) inv[i] = powMod(fact[i]);
	
	while(q--) {
		i64 x, d, n; scanf("%lld%lld%lld", &x, &d, &n);
		
		i64 ans = 0;
		if(d == 0) ans = powMod(x, n);
		else {
			(x *= powMod(d)) %= MOD;
			
			if(MOD <= x + n - 1) ans = 0;
			else {
				ans = fact[x + n - 1];
				if(x) (ans *= inv[x - 1]) %= MOD;
				(ans *= powMod(d, n)) %= MOD;
			}
		}
		printf("%lld\n", ans);
	}
	
	return 0;
}


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

int main(void){
    int N;
    cin >> N;
    N = N%10;

    if(N==3){
        cout << "bon" << endl;
    }
    else if(N==0 or N==1 or N==6 or N==8){
        cout << "pon" << endl;
    }
    else{
        cout << "hon" << endl;
    }
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

/*
0-index
functionの中を書いて使う
segtree<ll> seg(n, [](ll a, ll b){return a + b;}, 0);
*/
template<typename T>
struct segtree{
	int n;
	vector<T> dat;
	T ZERO;
	function<T(T,T)> func;//要素と要素をマージする関数

	segtree(int n_, function<T(T,T)> func_, T zero):func(func_), ZERO(zero){
	  n = 1;
	  while(n < n_)n*=2;
	  dat.resize(2*n);
	  for(int i = 0;i < 2*n;i++)dat[i] = ZERO;
	}

	void update(int k, T a){
	  k += n - 1;dat[k] = a;
	  while(k > 0){
		k = (k-1)/2;
		dat[k] = func(dat[k*2+1],dat[k*2+2]);
	  }
	}

	void set(int k, T a) {
		k += n - 1;dat[k] = a;
	}

	void build(){
		for(int i = n - 2;i >= 0;i--){
			dat[i] = func(dat[2 * i + 1], dat[2 * i + 2]);
		}
	}

	T get(int k){return dat[k+n-1];}

	T que(int a,int b){
		T L = ZERO,R = ZERO;
		int A = a + n - 1;
		int B = b + n - 1;
		while(A < B){
			if((A & 1) == 0)L = func(L,dat[A++]);
            if((B & 1) == 0)R = func(dat[--B],R);
            A = A >> 1;
            B = B >> 1;
		}
		return func(L,R);
	}
};

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
	segtree<ll> seg(2222, [](ll a, ll b){return a + b;}, 0);

	ll n;cin >> n;
	vector<ll> v(n);
	REP(i, n){
		cin >> v[i];
		seg.update(v[i], seg.get(v[i])+1);
	}

	ll ans = 0;
	REP(i, n){
		seg.update(v[i], seg.get(v[i])-1);
		REP(j, i){
			seg.update(v[j], seg.get(v[j])-1);
			ll l = abs(v[i] - v[j]) + 1;
			ll r = v[i] + v[j];
			ans +=seg.que(l, r);
			seg.update(v[j], seg.get(v[j])+1);
		}
		seg.update(v[i], seg.get(v[i])+1);
	}

	cout << ans/3 << endl;

	return 0;
}


Measured memory_bytes: 384
#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 K, X;
	cin >> K >> X;

	if (K * 500 >= X) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

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

int main()
{
vector<int>vec;
for(int i=0;i<10;i++)
{
int n;
cin>>n;
vec.push_back(n);
}
sort(vec.begin(),vec.end());
cout<<vec[9]<<endl;
cout<<vec[8]<<endl;
cout<<vec[7]<<endl;
return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

int main()
{
	int64_t N, K;
	cin >> N >> K;

	int64_t res = (N / K) * (N / K) * (N / K);

	if (K % 2 == 0) {
		int64_t val = 0;
		for (int32_t a = 1; a <= N; a++) {
			if (a % K == (K / 2))
				val++;
		}
		res += val * val * val;
	}

	cout << res << endl;

	return 0;
}


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

using namespace std;

int n, k, cnt[200200];

int main() {
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++)
        cnt[i%k]++;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        int x = (k - (i%k)) % k;
        if ((2*x)%k == 0) {
            ans += cnt[x]*1ll*cnt[x];
        }
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

typedef long long ll;
int main(void)
{
    int n;
    cin >> n;
    ll a[n + 1];
    ll b[n];
    REP(i, n + 1)
    {
        cin >> a[i];
    }
    REP(i, n)
    {
        cin >> b[i];
    }
    ll ans = 0;
    REP(i, n)
    {
        if (a[i] <= b[i])
        {
            ans += a[i];
            ll amari = b[i] - a[i];
            ans += min(a[i + 1], amari);
            a[i + 1] -= min(a[i + 1], amari);
        }
        else
        {
            ans += b[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
using namespace std;

int n, k;
int a[10000];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
                
    #ifndef _LOCAL          
    #endif // _LOCAL

    cin >> n >> k;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a, a + n);
    int ans = 0;
    for (int i = 0; i < k; ++i)
        ans += a[i];
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
#define chmin(x,y) x = min(x,y)

int main(){
    int l,r,d;
    cin >> l >> r >> d;
    int ans = r/d;
    ans -= (l-1)/d;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
from fractions import gcd
import sys
input = sys.stdin.readline
def lcm(a,b):
    return a*b // gcd(a,b)

def main():
    N = int(input())
    A = list(map(int,input().split()))
    M = 10**9+7
    l = 1
    for a in A:
        l = lcm(l,a)
    ans = 0
    for a in A:
        ans += l//a
    print(ans%M)
if __name__ == '__main__':
    main()


Measured memory_bytes: 6112
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

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

int main(void) {
  int N, X;
  cin >> N >> X;
  
  vi x(N);
  rep(i, N) cin >> x[i];
  
  rep(i, N) x[i] = abs(X - x[i]);
  if(N == 1) {
    fin(x[0]);
    return 0;
  }
  
  int g = gcd(x[0], x[1]);
  for (size_t i = 2; i < N; i++)
  {
    g = gcd(g, x[i]);
  }
  
  fin(g);
  return 0;
}

Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var n int
	var u string
	var x, ans float64
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x, &u)
		if u == "JPY" {
			ans += x
		} else {
			ans += x * 380000.0
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
//#pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define Max 100000+5
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define pb push_back
int mod = 1000000007;
int mod1 = 998244353;
vector<int> g[Max];
bool vis[Max];
int d, x, y;
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
void ex(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        ex(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}


void dfs(int u){

	vis[u]=1;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(vis[v]!=1)
			dfs(v);
	}
}



int power(int a,int b){
    if(b==1)return a;
    if(a>mod)a%=mod;
    int r=1;
    while(b){
        if(b&1)r=r%mod*a%mod;
        a=a%mod*a%mod;
        b/=2;
    }
    return r;
}
class uf{
    vector<int> v;
    vector<int> sz;
    
    
    public :
    uf(int n){
        v.resize(n+1);
        iota(v.begin()+1,v.end(),1);
        sz.resize(n+1,1);
        //1 to sz
    }
    int root(int b){
        while(v[b]!=b){
            b = v[b];
        }   
        return b;
    }
    void u(int a, int b){
        //combine a and b
        
        int ra=root(a);
        int rb=root(b);
        if(ra==rb)return ;
        if(sz[ra]<sz[rb]){
            v[ra] = v[rb];
            sz[rb]+=sz[ra];
        }else{
            v[rb]=v[ra];
            sz[ra]+=sz[rb];
        }
    }
    bool f(int a,int b){
        //same set
        return (root(a)==root(b));
    }
   
    
};
vector<int> matmul(vector<int> a,vector<int> b){
    vector<int> c(4,0);
    c[0] = (a[0]%mod*b[0]%mod + a[1]%mod*b[2]%mod)%mod;
    c[1] = (a[0]%mod*b[1]%mod + a[1]%mod*b[3]%mod)%mod;
    c[2] = (a[2]%mod*b[0]%mod + a[3]%mod*b[2]%mod)%mod;
    c[3] = (a[2]%mod*b[1]%mod + a[3]%mod*b[3]%mod)%mod;
    return c;
}
vector<int> id={1,0,0,1};

int32_t main(){
	IO
	//freopen("input.txt","r",stdin);
    	//freopen("output.txt","w",stdout);
	int n;
  	cin>>n;
  	map<int,int> m;
  	m[n]=1;
   	int i=2;
  	int prev = n;
  	while(1){
      int next = prev%2?prev*3+1:prev/2;
      if(m[next]){cout<<i;break;}
      else m[next]=1;
      i++;
      prev = next;
    }
}


Measured memory_bytes: 5972
N = int(input())
X = list(map(int, input().split()))
original_X = X

X = sorted(X)
#2つの値しか出力されない
B = X[int(N/2-1)]
B_te = X[int(N/2)]

for i in range(N):
    if B < original_X[i]:
        print(B)
    else:
        print(B_te)

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

int main()
{
    int a, b, c;
    int answer = 0;
    cin >> a >> b >> c;

    vector<int> vec;
    vec.push_back(a);
    vec.push_back(b);
    vec.push_back(c);

    while (vec[0] != vec[1] || vec[1] != vec[2])
    {
        sort(vec.begin(), vec.end());
        if (vec[1] - vec[0] > 1)
        {
            vec[0] += 2;
        }
        else if (vec[2] - vec[1] > 1)
        {
            vec[1] += 2;
        }
        else
        {
            ++vec[0];
            ++vec[1];
        }
        
        ++answer;
    }

    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n,m;cin>>n>>m;
  vector<int> a(n);
  int sum=0;
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  bool ans=false;
  int cnt=0;
  rep(i,n){
    if(sum>a[i]*4*m){
      continue;
    }
    cnt++;
  }
  cout<<yesno(cnt>=m)<<endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int n;
    cin >> n;
    switch(n%10)
    {
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << endl;
            break;
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon" << endl;
            break;
        case 3:
            cout << "bon" << endl;
            break;
    }

    return 0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;

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

    if (a >= 3200) {
        cout << s << endl;
    }
    else {
        cout << "red" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,k;
  int n;
  while(cin>>n){
    vi v(2005,0);
    rep(i,min(n+1,1001))rep(j,min(n+1,1001)) v[i+j]++;
    ll ans=0;
    rep(i,2001)if(n-i<=2000 && n>=i)ans+=v[i]*v[n-i];
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3136
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define DOUT(obj,n) cout << fixed << setprecision(n) << obj << endl

#define PI 3.14159265359

using namespace std;
typedef long long unsigned int ll;

int main() {
	long long signed int a, b, k;
	cin >> a >> b >> k;
	if (a < k) {
		k -= a;
		if (b - k < 0)k = b;
		cout << 0 <<" " << b - k;
	}
	else cout << a - k << " " << b;
}

Measured memory_bytes: 256
# from line_profiler import LineProfiler
from collections import deque

def main():
    while(True):
        W, H = map(int, input().split())
        if not W: break
        tx,ty = map(int, input().split())
        kx,ky = map(int, input().split())
        ma = [[False]*(W+2) for _ in range(H+2)]
        for i in range(1,H+1):
            for j,a in enumerate(input().split()):
                ma[i][j+1] = bool(1-int(a))
        from pprint import pprint
        que = deque([[tx,ty,kx,ky,0]])
        pas = set()
        ans = "NA"
        while(que):
            tx,ty,kx,ky,c = que.popleft()
            if c > 100: break
            if tx == kx and ty == ky:
                ans = c
                break
            for dx,dy in [[-1,0],[0,-1],[1,0],[0,1]]:
                tdx, tdy = [ dx, dy] if ma[ty+dy][tx+dx] else [0,0]
                kdx, kdy = [-dx,-dy] if ma[ky-dy][kx-dx] else [0,0]
                if (tx+tdx,ty+tdy,kx+kdx,ky+kdy) in pas: continue
                que.append([tx+tdx,ty+tdy,kx+kdx,ky+kdy,c+1])
                pas.add((tx+tdx,ty+tdy,kx+kdx,ky+kdy))
        print(ans)

if __name__ == "__main__":
    # prf = LineProfiler()
    # prf.add_function(main)
    # prf.runcall(main)
    # prf.print_stats()
    main()


Measured memory_bytes: 35880
class NormalInput {
  input: string[];
  pointer: number;
  constructor(raw: string) {
    this.input = raw.split(/ |\n/);
    this.pointer = 0;
  }
  int = (): number => {
    const ret = parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  };
  str = (): string => {
    const ret = this.input[this.pointer];
    this.pointer++;
    return ret;
  };
  strs = (length: number): string[] => {
    let ret: string[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.str());
    }
    return ret;
  };
  ints = (length: number): number[] => {
    let ret: number[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.int());
    }
    return ret;
  };
}
function rep(n: number) {
  let a = [];
  for (let i = 0; i < n; i++) a.push(i);
  return a;
}
function Main({ int, str, strs, ints }: NormalInput) {
  const S = str();
  const N = S.length;
  console.log(
    rep((N - 1) / 2).every(
      i =>
        S[i] === S[N - 1 - i] &&
        S[i] === S[(N - 3) / 2 - i] &&
        S[i] === S[i + (N + 1) / 2]
    )
      ? "Yes"
      : "No"
  );
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
int main() {
	std::string name1, name2;
	std::cin >> name1 >> name2;
	int count = 0;
	int n = name1.size();
	for (int x = 0; x < n; x++) {
		if (name1[x] != name2[x])count++;
	}
	std::cout << count;
	
}


Measured memory_bytes: 3844
#!/usr/bin/env pypy3

import math, itertools, operator
from math import *
from math import factorial as fact
from itertools import permutations, combinations
from functools import reduce
from statistics import mean, median, median_low, median_high, mode
# Before Python 3.5
from fractions import gcd

#import numpy
#import scipy, scipy.special
#from sympy import isprime, nextprime
#from sympy.ntheory import factorint

inf = float('inf')

def lcm(a, b):
    return a * b // gcd(a,b)

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

def dfact(n):
    import scipy.special
    return scipy.special.factorial2(n, exact = True)

def prod(l):
    return reduce(operator.mul, l)

def input_ints(inp = input, sep = ' ', conv = int):
    return map(conv, inp().split(sep = sep))

################################################################################


R, G, B, N = input_ints()

cnt = 0
for r in range(N // R + 1):
    for g in range(N // G + 1):
        rest = N - r * R - g * G
        if rest < 0:
            break
        if rest % B == 0:
            cnt += 1

print(cnt)


Measured memory_bytes: 5744
d = int(input())
C = list(map(int, input().split()))
S = []
for i in range(d):
    S.append(list(map(int, input().split())))
T = [0]
for i in range(d):
    T.append(int(input()))
#print(S)
#print(T)

#最終開催日
Last = [0] * 26

#各Scores
Scores = [0] * 26

for day in range(1, d+1):
    contest = T[day] - 1
    Last[contest] = day
    Scores[contest] += S[day-1][contest]
    for num in range(26):
        Scores[num] -= C[num] * (day - Last[num])
    print(sum(Scores))

Measured memory_bytes: 68640
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 500001
#define pll pair<ll,ll>
#define pii pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define get(n) ll (n); scanf("%lld",&(n));
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);


int main() {

    get(a);
    for(int i=1;i<10;i++)
    for(int j=1;j<10;j++)
        if(i*j==a){
            cout<<"Yes"<<endl;
            return 0;
        }
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
total = 1
total8 = 1
total9 = 1
MOD = 1000000007

if n == 1:
    print(0)
    exit()

if n == 2:
    print(2)
    exit()

for i in range(n):
    total *= 10
    total9 *= 9
    total8 *= 8
    total %= MOD
    total8 %= MOD
    total9 %= MOD


ans = total + total8 - (2 * total9) % MOD
if ans < 0:
    ans += MOD

print(ans)


Measured memory_bytes: 9156
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)

left = Array.new(n+1, 0)
right = Array.new(n+1, 0)
n.times do |i|
    left[i+1] = left[i].gcd(a[i])
end
(n-1).downto(0) do |i|
    right[i] = right[i+1].gcd(a[i])
end

ans = -1

n.times do |i|
    tmp = left[i].gcd(right[i+1])
    ans = tmp > ans ? tmp : ans
end

puts ans

Measured memory_bytes: 11268
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def solve(N,A,C):
    uf = UnionFind(N)
    ans = [0]*N
    for a in A:
        u,v = a
        uf.union(u-1,v-1)
        ans[u-1] -= 1
        ans[v-1] -= 1
    for i in range(N):
        ans[i] += uf.size(i) - 1
    for c in C:
        s,t = c
        if uf.same(s-1,t-1):
            ans[s-1] -= 1
            ans[t-1] -= 1
    return ans
def main():
    N,M,K = map(int,input().split(" "))
    A = [list(map(int,input().split(" "))) for _ in range(M)]
    C = [list(map(int,input().split(" "))) for _ in range(K)]
    ans = solve(N,A,C)
    print(*ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 59652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
{
  class Program
  {
    static void Main(string[] args)
    {
      string input;
      int sum = 0, digit = 1;
      while ( (input = Console.ReadLine()) != null)
      {
        foreach (string num in input.Split())
        {
          sum += int.Parse(num);
        }
        while ((sum /= 10) >= 1)
        {
          digit++;
        }
        Console.WriteLine(digit);
        digit = 1;
        sum = 0;
      }
      return;
    }
  }
}

Measured memory_bytes: 9172
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
typedef long long ll;
using namespace std;
typedef pair<int,int> pint;
typedef vector<int> vint;
int INF=2e+9+1;
int main(){
	int N;
	int A[100002]={0};
	int kyorisum[100002][2]={0};
	scan(N);
	rep1(i,N){
		scan(A[i]);
	}
	A[N+1]=0;
	rep1(i,N+1){
		kyorisum[i][0]=kyorisum[i-1][0]+abs(A[i]-A[i-1]);
		kyorisum[i][1]=(A[i]-A[i-1]>0)-(A[i]-A[i-1]<0);
	}
	rep1(i,N){
		int kane=kyorisum[N+1][0]-min(abs(A[i+1]-A[i]),abs(A[i]-A[i-1]))*2*(kyorisum[i+1][1]*kyorisum[i][1]<0 ? 1:0);
		prin(kane);
	}
	return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <cstdio>
using namespace std;
 
int n, mn, c[55][150];
string s;
int main()
{
	int i, j;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> s;
		for (j = 0; j < s.size(); j++) c[i][s[j]]++;
	}
	for (i = 'a'; i <= 'z'; i++) {
		for (j = 0, mn = 1e9; j < n; j++) mn = min(mn, c[j][i]);
		while (mn--) printf("%c", i);
	}
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        a: i64, b: i64
    }
    let mut p = a - 2;
    if p < 0 {
        p += 13;
    }
    let mut q = b - 2;
    if q < 0 {
        q += 13;
    }
    println!("{}", if p==q {"Draw"} else if p > q {"Alice"} else {"Bob"});
}


Measured memory_bytes: 4352
// https://atcoder.jp/contests/abc166/tasks/abc166_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  string S;
  cin >> S;

  if (S == "ABC") drop("ARC");
  if (S == "ARC") drop("ABC");
}


Measured memory_bytes: 3688
n = gets.to_i
tarou = 0
hanako = 0
n.times {
   tarou_hand,hanako_hand = gets.split(" ")
   if (tarou_hand <=> hanako_hand) == 1
      tarou += 3
   elsif (tarou_hand <=> hanako_hand) == -1
      hanako += 3
   else
      hanako += 1
      tarou += 1
   end
}
puts "#{tarou} #{hanako}"

Measured memory_bytes: 8704
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#include <map>
#include <vector>
#include <algorithm>
#include <functional>

#include <sstream>
#include <iostream>

using namespace std;
typedef long long llint;
const llint inf = 1000000000000000000LL;

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

#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " <<

const int MAXN = 100005;

int N;
llint A[MAXN], B[MAXN];

int main(void) 
{
  scanf("%d", &N);
  REP(i, N) scanf("%lld%lld", A+i, B+i);

  llint shift = 0;
  for (int i = N - 1; i >= 0; --i) {
    A[i] += shift;
    llint add = (B[i] - A[i] % B[i]) % B[i];
    shift += add;
  }

  printf("%lld\n", shift);

  return 0;
}




Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f;
long long a,b,v,i,n,m,k,l,an[100010],ans=0,vis[10000],j;
long long ma[600][600],dist[6000],S,vis2[610][610],vis3[6000];
int flag=0;
void dijkstra(long long x)
{//printf("ok\n");
    for(i=1; i<=n; i++)
        dist[i]=(i==x)?0:INF;
    memset(vis,0,sizeof(vis));
   memset(vis3,0,sizeof(vis3));
    for(i=1; i<=n; i++)
    {
        int mark=-1,mindis=INF;
        for(j=1; j<=n; j++)
        {
            if(!vis[j]&&dist[j]<mindis)
            {
                mindis=dist[j];
                mark=j;
            }
        }
        vis[mark]=1;
        for(int j=1; j<=n; j++)
        {
            if(!vis[j])
            {
                if(dist[j]>=(dist[mark]+ma[mark][j])&&mark!=x&&mark!=j) {vis3[j]=1;}
                dist[j]=min(dist[j],dist[mark]+ma[mark][j]);
            }
        }
    }
    for(i=1; i<=n; i++)
    {  //printf("*%lld*",vis3[i]);
        if(dist[i]<=ma[x][i])
        {
            if(vis3[i]==1){vis2[x][i]=1;vis2[i][x]=1;}
            if(dist[i]<ma[x][i])
            {
                flag=1;
            }
        }
    }
   //printf("\n");
}
int main()
{
    scanf("%lld",&n);
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=n; j++)
        {
            scanf("%lld",&ma[i][j]);
        }

    }
    ans=0;
    flag=0;

    for(l=1; l<=n; l++)
    {
        dijkstra(l);
        if(flag==1) break;
    }
    if(flag==0)
    {
        for(i=1; i<=n; i++)

        {
            for(j=i+1; j<=n; j++)
            {
                if(vis2[i][j]!=1) ans+=ma[i][j];
            }
        }
        printf("%lld\n",ans);
    }
    else printf("-1\n");
    return 0;
}



Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 500010;

int main() {
    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    exrep(i, k, n+1) {
        ll a = (i*(i-1)/2)%mod;
        ll b = (n*(n+1)/2 - (n-i)*(n-i+1)/2)%mod;
        ll x = (b + mod - a + 1)%mod;
        ans += x;
        ans %= mod;
    }

    out(ans);
    re0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int a, b; cin >> a >> b;

    for (int i = 0; i < 100000; ++i) {
        if (i * 8 / 100 == a && i * 10 / 100 == b) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    let mut w: Vec<usize> = (0..n).collect();
    w.sort_by_key(|&x| v[x]);
    print!("{}", w[0] + 1);
    for i in 1..n {
        print!(" {}", w[i] + 1);
    }
    println!("");
}


Measured memory_bytes: 6908