akhauriyash/Code-Regression huggingface dataset:
#python3

def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x%y)

def lcm(x, y):
    return (x * y) //gcd(x, y) 

def f(x):
    res = 0
    while x % 2 == 0:
        x //= 2
        res += 1
    return res 

def main():
    n, m = map(int, input().split())
    a = [int(i)//2 for i in input().split()]

    t = f(a[0])
    for i in range(n):
        if f(a[i]) != t:
            print(0)
            return
        a[i] //= 2**t; 

    m //= 2**t
    l = 1
    for i in range(n):
        l = lcm(l, a[i])
        if l > m:
            print(0)
            return

    m //= l
    ans = (m+1)//2
    print(ans)
main()



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

int main()
{
	int n, m;
	while (cin >> n, n) {
		cin >> m;
		vector<int> x(m), y(m), res;
		for (int i = 0; i < m; i++) {
			cin >> x[i] >> y[i];
		}
		for (int i = m - 1; i >= 0; i--) {
			x[i] -= x[0];
			y[i] -= y[0];
		}
		for (int i = 0; i < n; i++) {
			cin >> m;
			vector<int> tx(m), ty(m);
			for (int j = 0; j < m; j++) {
				cin >> tx[j] >> ty[j];
			}
			for (int j = m - 1; j >= 0; j--) {
				tx[j] -= tx[0];
				ty[j] -= ty[0];
			}
			bool flag = false;
			for (int j = 0; j < 4; j++) {
				if (x == tx && y == ty) {
					flag = true;
					break;
				}
				for (int k = 0; k < m; k++) {
					swap(tx[k], ty[k]);
					tx[k] *= -1;
				}
			}
			reverse(tx.begin(), tx.end());
			reverse(ty.begin(), ty.end());
			for (int j = m - 1; j >= 0; j--) {
				tx[j] -= tx[0];
				ty[j] -= ty[0];
			}
			for (int j = 0; j < 4; j++) {
				if (x == tx && y == ty) {
					flag = true;
					break;
				}
				for (int k = 0; k < m; k++) {
					swap(tx[k], ty[k]);
					tx[k] *= -1;
				}
			}
			if (flag) {
				res.push_back(i + 1);
			}
		}
		for (auto ans : res) {
			cout << ans << endl;
		}
		cout << "+++++" << endl;
	}
	return 0;
}

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

using ll = long long;

const int MAX_N = 100010;
int par[MAX_N];
int rnk[MAX_N];

void init(int n) {
    rep(i,n) {
        par[i] = i;
        rnk[i] = 0;
    }
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rnk[x] < rnk[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rnk[x] == rnk[y]) rnk[x]++;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int main() {
    int N;
    cin >> N;
    vector<int> x(N), y(N);
    vector<pair<int, int>> xs(N), ys(N);
    rep(i, N) {
        cin >> x[i] >> y[i];
        xs[i] = make_pair(x[i], i);
        ys[i] = make_pair(y[i], i);
    }
    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());
    vector<vector<int>> d(2 * N - 2, vector<int>(4));
    rep(i, N - 1) {
        d[i][0] = xs[i + 1].first - xs[i].first;
        d[i][1] = 0;
        d[i][2] = xs[i].second;
        d[i][3] = xs[i + 1].second;
        d[N + i - 1][0] = ys[i + 1].first - ys[i].first;
        d[N + i - 1][1] = 1;
        d[N + i - 1][2] = ys[i].second;
        d[N + i - 1][3] = ys[i + 1].second;
    }
    sort(d.begin(), d.end());
    /*
    rep(i, d.size()) {
        rep(j, 4) {
            cout << d[i][j] << " ";
        }
        cout << endl;
    }
    */
    init(N);
    int i = 1, j = 0;
    ll ans = 0;
    while (i < N) {
        int dmin = d[j][0], xy = d[j][1], p = d[j][2], q = d[j][3];
        if (same(p, q)) {
            j++;
            continue;
        }
        ans += dmin;
        unite(p, q);
        i++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 14336
human_num, init_point, ans_public = gets.chomp.split(' ').map(&:to_i)

correct_persons = []
ans_public.times { |_i| correct_persons << gets.chomp.to_i }

correct_group = correct_persons.group_by{|cp| cp}
[*1..human_num].each do |human|
  ans_myself = correct_group[human]&.size.to_i
  if ans_public - ans_myself >= init_point
    puts 'No'
  else
    puts 'Yes'
  end
end

Measured memory_bytes: 14972
# -*- coding: utf-8 -*-

n = int(input())
a = [0 for i in range(n)]
b = [0 for i in range(n)]
s = []

for i in range(n):
    a[i], b[i] = map(int, input().split())
    s.append((i, a[i] + b[i]))

s.sort(key=lambda e: e[1], reverse=True)

turn = True
taka, aoki = 0, 0
for subs in s:
    if turn:
        taka += a[subs[0]]
    else:
        aoki += b[subs[0]]
    turn = not turn

print(taka - aoki)


Measured memory_bytes: 26092
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

long long int min(long long int a,long long int b){
  return a<b ?a:b;
}

long long int N,x;
int a[2001];
int b[2001];
int main(){
  long long int ans=0,res=0;
  scanf("%lld %lld",&N,&x);
  for(int i=1;i<=N;i++){
    scanf("%d",&a[i]);
    b[i]=a[i];
    ans+=b[i];
  }
 
  for(long long int k=0;k<N;k++){
    long long int B=0;
    for(int i=1;i<=N;i++){
      int t;
      if(i-k<=0)t=i+N-k;
      else t=i-k;
      b[i]=min(b[i],a[t]);
      B+=b[i];
    }
    // for(int j=1;j<=N;j++)printf("%d ",b[j]);
    // printf("\n");
    res=k*x+B;
    ans=min(ans,res);
    //printf("%lld %lld\n",B,ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
    lli a,b,c;
    cin >> a >> b >> c;
    if(a%2==0 || b%2==0 || c%2==0){
        cout << 0 << endl;
    }else{
        cout << min(a*b, min(b*c, c*a)) << endl;
    }
    return 0;
}


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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

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

  int cnt = 0;
  for(int i=0; i<n; ++i){
    while(a[i]%2==0){
      a[i]/=2;
      cnt++;
    }
  }
  cout << cnt << endl;

}

Measured memory_bytes: 3724
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using graph = vector<vector<int>>;
using wgraph = vector<vector<pair<int, long long int>>>;
long long int INF = 1001001001001001LL;
int inf = 100100100;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

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;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(int i = s; i < t; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){
  
  int n, k; cin >> n >> k;
  int ans = 0;
  for(int i = 0; i < n; i++) {
    int x; cin >> x;
    ans += (x >= k);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
A = list(map(int, input().split()))
N = A[0]
T = A[1]

L = []
for i in range(N):
    x = list(map(int, input().split()))
    c = x[0]
    t = x[1]
    a = {'cost': c, 'time': t}
    L.append(a)

min = 'TLE'
for i in L:
    if i['time'] <= T:
        if min == 'TLE':
            min = i['cost']
        elif i['cost'] < min:
            min = i['cost']

print(min)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    int a,b,c;
    cin >>a>>b>>c;
    for(int i=1;i<b;++i){
        if(a*i%b==c){
            cout << "YES" <<endl;
            return 0;
        }
    }
    cout << "NO"<<endl;
    return 0;
}

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

int main(){
  long long n, k; cin >> n >> k;
  vector<int> a(n);
  long long sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    sum += a.at(i);
  }
  priority_queue<long long> que;
  for(int i = 1; i < sqrt(sum) + 1; i++){
    if(sum % i == 0){
      que.push(i); que.push(sum / i);
    }
  }
  for(long long l = 1; l <= sum; l++){
    long long s = que.top();
    que.pop();
    long long pl = 0, mi = 0;
    priority_queue<long long> qm, qp;
    for(int i = 0; i < n; i++){
      long long ama = a.at(i) % s;
      if(ama > 0){
        if(ama <= s / 2){
          mi += ama;
          qm.push(ama);
        }else{
          pl += s - ama;
          qp.push(s - ama);
        }
      }else{
        if(-(ama) <= s / 2){
          pl += -(ama);
          qp.push(-(ama));
        }else{
          mi += s + ama;
          qm.push(s + ama);
        }
      }
    }
    long long hi, za;
    if(pl <= mi){
      hi = pl; za = mi - pl;
      long long no = 0;
      for(int j = 0; j < za / s; j++){
        no += qm.top();
        qm.pop();
      }
      hi += za;
      hi -= no;
    }else{
      hi = mi; za = pl - mi;
      long long no = 0;
      for(int j = 0; j < za / s; j++){
        no += qp.top();
        qp.pop();
      }
      hi += za;
      hi -= no;
    }
    if(k - hi >= 0){
      cout << s;
      return 0;
    }
  }
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
xx = gets.split.map(&:to_i).sort
if n >= m
    puts 0
else
    dif = xx.each_cons(2).map{ |x1, x2| x2 - x1 }.sort
    puts dif[0,m-n].reduce(:+)
end
    

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

int main() {
  long n;
  cin>>n;
  map<long ,long> sum;
  sum[0]=1;
  long sum1=0;
  for(long i=0;i<n;i++){
    long a;
    cin >>a;
    sum1 +=a;
    sum[sum1]+=1;
  }
  long ans=0;
  for(auto itr = sum.begin(); itr != sum.end(); ++itr) {
    long a = (itr->second)-1;
    ans += a*(a+1)/2;
  }
  cout <<ans;

}

Measured memory_bytes: 12800
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cini(N);
    vector<int> a(N),ans(N);
    rep(i,N) cin >> a[i];
    int xorTotal = 0;
    rep(i,N) xorTotal ^= a[i];
    rep(i,N) ans[i] = xorTotal ^ a[i];
    rep(i,N) cout << ans[i] << " ";
    cout << nn;
    return 0;
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main() {
	int S;
	cin >> S;
	S += 10000;
	rep(i, 3) {
		if(S%10==(S%100)/10) {
			cout << "Bad" << endl;
			return 0;
		}
		S = S/10;
	}

	cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 256
/*
                    Author: Ankit Kaul
**********************Code Belongs to Respective Author Only************************************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
            
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
        int result=1;
        while(n>0)
        {   if(n % 2 ==1)
            result=(result * x) % M;
            x=(x*x)% M;
            n=n/2;
        }
    return result % M;
    }     
signed main()
{   jaldi
    int n,k;
    cin>>n>>k;
    int a[n],i;
    for(i=0;i<n;i++)
    cin>>a[i];
    if(n<=k)
    cout<<0;
    else
    {   sort(a,a+n);
        int sum=0;
        for(i=0;i<n-k;i++)
        sum+=a[i];
        cout<<sum;
    }
}

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

int main() {
   int a, b, c, d;
   cin >> a >> b >> c >> d;

   if (a + b > c + d) {
       cout << "Left" << endl;
   } else if (a + b == c + d) {
       cout << "Balanced" << endl;
   } else {
       cout << "Right" << endl;
   }
}

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(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    string s;
    cin>>s;
    string ans="No";
    if(s[2]==s[3] &&s[4]==s[5])ans="Yes";
    cout<<ans<<endl;
    return 0;
}

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

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;


void solve() {
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif
	int n;
	cin >> n;
	VI v(n);
	rep(i, n) cin >> v[i];

	int ans = 1;
	rep(i, n) {
		if (v[i] % 2 == 0) ans *= 2;
	}
	ans = (int)pow(3, n) - ans;
	cout << ans << endl;

}



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

	solve();
#ifdef _WIN32
	system("PAUSE");
#endif
	return 0;
}

Measured memory_bytes: 640
def main():
    x = int(input())
    ans = (x // 500) * 1000 + ((x % 500) // 5) * 5
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 2940
s = input()
s = int(s)
number = 1
l = list()
l.append(s)
while 1:
	if s%2 == 0:
		s = s / 2
	else:
		s = 3 * s + 1
	number=number+1
	if s in l:
		print(number)
		break
	else:
	    l.append(s)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define vv vector<lli>
#define vp vector<pair<lli,lli>>
#define vpp vector<pair<lli,pair<lli,lli>>>
#define lims(w) (w).begin(),(w).end()
#define rlims(w) (w).rbegin(),(w).rend()
#define pb push_back
#define mp make_pair
#define f(i,a,b) for(lli i=a;i<b;i++)

int main()
{
	lli n;
	cin>>n;
	lli val = (n / 1000) * 1000;
	val += 1000;
	cout<<((val-n)%1000)<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
  char  m[52][53]={""};
  int  h, w, i, j, f = 0;

  scanf("%d %d", &h, &w);
  for( i = 1; i <= h; i++){
    scanf("%s", &m[i][1]);
  }

  for( i = 1; i <= h; i++){
    for( j = 1; j <= w; j++) { 
      if(m[i][j] == '#'){
        if(m[i-1][j] == '#' || m[i+1][j] == '#' || m[i][j-1] == '#' || m[i][j+1] == '#'){
        } else {
          f = 1;
        }
      }
    }
  }

  printf("%s\n", f ? "No" : "Yes");

  return 0;
}

Measured memory_bytes: 128
/* ex 5_4
   UMAboogie */

#include <stdio.h>
#include <string.h>

int main(void){
  char str[11]; //文字列をいれる要素数11の配列を宣言
  int length, count = 0, ans = 0;
  scanf("%s",str);
  length = strlen(str); //文字列の長さを計算しlengthに代入
  for(int i = 0;i < length;i++){ //文字列内の各文字について
    if(str[i] == 'A'||str[i] == 'T'||str[i] == 'G'||str[i] == 'C'){
      count ++; //その文字がA,T,G,Cのどれかならば連続数を1加算
      if(count >= ans){ //その連続数が最大連続数以上の時
        ans = count; //それを最大連続数とする
      }
    }
    else{
      count = 0; //その文字がA,T,G,C以外であれば連続が途切れるので連続数をリセット
    }
  }

  printf("%d\n",ans); //答え(最大連続数)を出力

  return 0; //プログラムを終了
}



Measured memory_bytes: 1708
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

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

int main() {

  int a, b, c; cin >> a >> b >> c;
  int x, y; cin >> x >> y;
  ll cost = 0;

  int m = min(x, y);
  int mx = 0, my = 0;
  if(x-m!=0) mx = x-m;
  else my = y-m;

  if(a+b>2*c) {
    cost += 2*c*m;
  }else {
    cost += a*m + b*m;
  }

  if(mx!=0) {
    if(a>2*c) cost += 2*c*mx;
    else cost += a*mx;
  }else {
    if(b>2*c) cost += 2*c*my;
    else cost += b*my;
  }

  cout << cost << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,minn=INT_MAX,a,ans; 
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		if(a<minn)
		ans++,minn=a;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int limit=8;
bool graph[limit][limit];
int dfs(int v,int n,bool visited[limit]){
  bool allvisited=true;
  for(int i=0;i<n;i++)if(visited[i]==false)allvisited=false;
  if(allvisited)return 1;
  int ret=0;
  for(int i=0;i<n;i++){
    if(graph[v][i]==false)continue;
    if(visited[i])continue;
    visited[i]=true;
    ret+=dfs(i,n,visited);
    visited[i]=false;
  }
  return ret;
}
int main(){
  int n,m;
  cin >> n >> m;
  int a[m],b[m];
  for(int i=0;i<m;i++){
    cin >> a[i] >> b[i];
    graph[a[i]-1][b[i]-1]=graph[b[i]-1][a[i]-1]=true;
  }
  bool visited[limit];
  for(int i=0;i<n;i++)visited[i]=false;
  visited[0]=true;
  cout << dfs(0,n,visited)<<endl;
}


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

using namespace std;

#define pb push_back
#define all(v) (v).begin(),v.end()
typedef long long ll;

int count_one(int x) {
    int cnt = 0;
    while (x) {
        x &= (x - 1);
        cnt++;
    }
    return cnt;
}

/*signed main() {
    int t;
    cin >> t;
    while (t--) {
        int a, b, n;
        cin >> n >> a >> b;
        int cnt = 0;
        set<int> s;
        for (int i = 0; i < (1 << n); ++i) {
            for (int j = 0; j < (1 << n); ++j) {
                if (count_one(i) == a && count_one(j) == b)s.insert(i ^ j);
            }
        }
        cout << s.size() << endl;
    }
    return 0;
}*/
int one(string s) {
    int cnt = 0;
    for (auto i:s) {
        if (s[i] == 1)cnt++;
    }
    return cnt;
};

signed main() {
    string s;
    cin >> s;
    int c = 0;
    for (int i = 0; i < s.length() / 2; ++i) {
        if (s[i] != s[s.length() - i - 1])c++;
    }
    cout << c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

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

    s=' '+s;

    vint sum(N+1);
    for(int i=1;i<=N;i++) sum[i]=sum[i-1]+(s[i]=='E');
    
    int ans=N;
    for(int i=1;i<=N;i++){
        int l=(i-1)-sum[i-1];
        int r=sum[N]-sum[i];
        ans=min(ans,l+r);
    }
    cout<<ans<<endl;
 
}

Measured memory_bytes: 3040
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

map<char, int> mps, mpt;
vector<int> vs, vt;

int
main(void){  
  string s, t;
  cin >> s >> t;
  int n = s.size();
  REP(i, n){
    mps[s[i]]++;
    mpt[t[i]]++;
  }

  for(auto itr=mps.begin(); itr!=mps.end(); ++itr){
    vs.push_back(itr->second);
  }
  for(auto itr=mpt.begin(); itr!=mpt.end(); ++itr){
    vt.push_back(itr->second);
  }  

  sort(vs.begin(), vs.end());
  sort(vt.begin(), vt.end());

  /*
  for(auto itr=vs.begin(); itr!=vs.end(); ++itr){
    
  }  
  */
  if(vs.size()!=vt.size()){
    cout << "No" << endl;
    return 0;
  }
  //cout << vs.size() << " " << vt.size() << endl;
  
  bool f = true;
  REP(i, vs.size()){
    if(vs[i] != vt[i]) f = false;
  }

  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
 
long long gcd(int a, int b) {
    if (b==0) {
        return a;
    } else {
        return gcd(b, a%b);
    }
}

int main() {
    long long K,result=0;
    cin >> K;
 
    for (int a=1 ; a<=K ;a++){
        for (int b=1 ; b<=K ;b++){
            for (int c=1 ; c<=K ;c++){
                result += gcd(c,gcd(a,b));
            }
        }
    }

    cout << result << endl;

  	return 0;
}



Measured memory_bytes: 3624
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
int n, m;

// UnionFind
#define MAXN 110
int par[MAXN], rank[MAXN];

void init(int n_) {
    for (int i = 0; i < n_; i++) {
        par[i] = i;
        rank[i] = 0;
    }
}

int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
}

void unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) par[x] = y;
    else {
        par[y] = x;
        if (rank[x] == rank[y]) rank[x]++;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

// kruskal
#define MAXM 100010
struct edge {
    int from, to, cost;
};

bool comp(const edge &e1, const edge &e2) {
    return e1.cost < e2.cost;
}

edge es[MAXM];

int kruskal(void) {
    sort(es, es+m, comp);
    init(n);
    int ret = 0;
    for (int i = 0; i < m; i++) {
        edge e = es[i];
        if (!same(e.from, e.to)) {
            unite(e.from, e.to);
            ret += e.cost / 100 - 1;
        }
    }
    return ret;
}


int main(void) {
    while (cin >> n && n) {
        cin >> m;
        for (int i = 0; i < m; i++) {
            int a, b, c;
            scanf("%d,%d,%d", &es[i].from, &es[i].to, &es[i].cost);
        }
        cout << kruskal() << endl;
    }
    return 0;
}

Measured memory_bytes: 1324
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

// #include <unordered_set>
// #include <unordered_map>

#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

#define pb push_back
#define mp make_pair

int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}

typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;

// #define int long long



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cin高速化

    

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

    int total=b*2;

    cout<<total-a<<endl;


    return 0;

}

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

int main(void){
    char s[11];
    int ans, min=1000;
    scanf("%s",s);
    int size = strlen(s);
    for(int i=0;i<size-2;i++){
        ans = (s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0');
        ans = abs(ans-753);
        if(ans < min) min = ans;
    }
    printf("%d\n", min);
    return 0;
}

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

class Program {
  static void Main() {
    int n = int.Parse(Console.ReadLine());
    int ans = 0;
    while (n-- > 0) {
      var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
      int L = arr[0];
      int r = arr[1];
      ans += r - L + 1;
    }
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 13268
//
//  main.cpp
//  AOJ1172
//
//  Created by aki33524 on 2014/07/06.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

#include <iostream>
using namespace std;

const int MAX_N = 250000;
bool is_prime[MAX_N];

void sieve(){
    for(int i=2; i<MAX_N; i++)
        is_prime[i] = true;
    for(int i=2; i<MAX_N; i++){
        if(is_prime[i]){
            for(int j=2*i; j<MAX_N; j+= i)
                is_prime[j] = false;
        }
    }
}

int main(int argc, const char * argv[])
{
    sieve();
    int n;
    while(cin>>n, n){
        int cnt = 0;
        for(int i=n+1; i<=2*n; i++)
            if(is_prime[i]) cnt++;
        cout << cnt << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1404
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

int main() {
  int n; cin >> n;
  string s; cin >> s;
  int m = 0;
  rep(i,n) {
    if (s[i] == '1') m++;
  }
  if (m == 0) {
    rep(i,n) {
      cout << 1 << endl;
    }
    return 0;
  } else if (m == 1) {
    rep(i,n) {
      if (s[i] == '1') cout << 0 << endl;
      else if (s[n-1] == '1' || i == n-1) cout << 2 << endl;
      else cout << 1 << endl;
    }
    return 0;
  }

  int rp = 0, rm = 0;
  rep(i,n) {
    rp = (rp*2 + (s[i]-'0')) % (m+1);
    rm = (rm*2 + (s[i]-'0')) % (m-1);
  }

  vec ans(n,1);
  int pp = 1, pm = 1;
  rep(i,n) {
    int r;
    if (s[n-i-1] == '1') {
      r = rm - pm;
      if (r < 0) r += m-1;
    } else {
      r = (rp + pp) % (m+1);
      if (r > m+1) r -= m+1;
    }
    while (r > 0) {
      r %= __builtin_popcount(r);
      ans[n-i-1]++;
    }

    pp = pp*2 % (m+1);
    pm = pm*2 % (m-1);
  }

  rep(i,n) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 4456
#include<stdio.h>

int main(void){
	int x,y,z,w,n,i;
	int sum,l;

	while(0==0){
		scanf("%d",&n);
		if(n==0)break;
		sum=0;
		for(i=0;i<n;i++){
		  scanf("%d %d %d %d",&x,&y,&z,&w);
		  l=x+y+z;
		  if(l<=60 && w<=2) sum+=600;
		  else if(l<=80 && w<=5) sum+=800;
		  else if(l<=100 && w<=10) sum+=1000;
		  else if(l<=120 && w<=15) sum+=1200;
		  else if(l<=140 && w<=20) sum+=1400;
		  else if(l<=160 && w<=25) sum+=1600;
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  int n,cnt=0,c=0;
  string s;
  cin >> n >> s;
  for(int i=0; i<n; i++) {
    if(s[i]=='(') {
      c++;
    }
    else {
      c--;
    }
    cnt=min(cnt,c);
  }
  for(int i=0; i<-cnt; i++) {
    cout << '(';
  }
  cout << s;
  for(int i=0; i<c-cnt; i++) {
    cout << ')';
  }
  cout << endl;
}


Measured memory_bytes: 256
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
INF = 10**18

N = ri()
ans = 1
t,x,y=0,0,0
for i in range(N):
    t_,x_,y_=rl()
    if t_%2 != (x_+y_)%2:
        ans = 0
    if (t_ - t) < abs(x_-x)+abs(y_-y):
        ans = 0
    t,x,y=t_,x_,y_

if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int num = 0;
vector<int> children[200];
int parent[200];
set<string> subtree[200];
string tree[200];
double val[200];
int win(int a, int b);
void dfs(int from) {
    //cerr << "DFS: " << from << endl;
    subtree[from].clear();
    tree[from].clear();
    val[from] = 0;
    if(children[from].empty()) {
        tree[from] = "()";
        subtree[from].insert("()");
        return;
    }
    vector<string> now;
    for(int i = 0; i < children[from].size(); i++) {
        int to = children[from][i];
        dfs(to);
        now.push_back(tree[to]);
        for(auto itr = subtree[to].begin(); itr != subtree[to].end(); itr++) {
            subtree[from].insert(*itr);
        }
    }
    sort(now.begin(), now.end());
    tree[from] = "(" + now[0] + now[1] + ")";
    subtree[from].insert(tree[from]);
    set<string> uni;
    set_intersection(subtree[children[from][0]].begin(), subtree[children[from][0]].end(), subtree[children[from][1]].begin(), subtree[children[from][1]].end(), inserter(uni, uni.end()));
    val[from] = (double)(uni.size()) / (double)(subtree[from].size() - 1);
    if(win(children[from][1], children[from][0]) == 1) swap(children[from][0], children[from][1]);
    //cerr << from << endl << tree[from] << endl << val[from] << endl;
}

void dfs2(int from, bool isleft) {
    if(children[from].empty()) return;
    if(!isleft) swap(children[from][0], children[from][1]);
    dfs2(children[from][0], true);
    dfs2(children[from][1], false);
}

int win(int a, int b) {
    if(val[a] + EPS < val[b]) return 1;
    if(val[a] > val[b] + EPS) return -1;
    if(children[a].empty()) return 0;
    int l = children[a][0];
    int r = children[b][0];
    int tmp = win(l, r);
    if(tmp != 0) return tmp;
    return win(children[a][1], children[b][1]);
}

void f(int from, string::iterator &itr) {
    num++;
    //cerr << num << " " << from << " " << *itr << endl;
    int now = num;
    children[now].clear();
    children[from].push_back(num);
    parent[num] = from;
    if(*itr == 'x') {
        itr++;
        return;
    }
    itr++;
    f(now, itr);
    itr++;
    f(now, itr);
    itr++;
    return;
}

void print(int from) {
    if(children[from].empty()) {
        cout << "x";
        return;
    }
    cout << "(";
    print(children[from][0]);
    cout << " ";
    print(children[from][1]);
    cout << ")";
}

int main() {
    //cout.precision(10);
    while(true) {
        string S;
        getline(cin, S);
        if(S == "0") break;
        num = 0;
        auto itr = S.begin();
        f(0, itr);
        dfs(1);
        dfs2(1, true);
        print(1);
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3332
/*main*/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;

const int N = 200050;
int a[N];
int n;
typedef long long LL;

void init()
{

}

void solve()
{
    cin >> n;
    LL sumX = 0,sumY = 0;
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
        sumY += a[i];
    }
    LL Min = abs(a[0] - (sumY-a[0]));
    for(int i=0; i<n-1; i++)
    {
        sumX += a[i];
        sumY -= a[i];
        if(Min > abs(sumX-sumY))
            Min = abs(sumX-sumY);
        if(Min == 0)
            break;
    }
    cout << Min << endl;
}

int main()
{
    /*init();*/
    solve();
    return 0;
}

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

#define f first
#define s second
#define ins insert
#define pb push_back
#define endl '\n'
#define ll long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define no cout << "NO" << endl 
#define yes cout << "YES" << endl
#define tc ll t; cin >> t; while (t--)
#define sz(c) (int) (c).size()
#define trav(x,c) for (auto &x : c)
#define all(c) (c).begin(), (c).end()
#define rll(c) (c).rbegin(), (c).rend()
#define db(x) cout << #x << ": " << x << endl;
#define _db(c) trav(x,c) cout << x << " "; cout << endl;
#define godspeed ios_base::sync_with_stdio(0); cin.tie(0);
ll cnt[102030];
int main() { 
    godspeed;
    ll n,q;
    cin >> n ;
    ll ans=0;
    for(ll i=0;i<n;i++){
        int a;
        cin >> a;
        cnt[a]+=1;
        ans+=a;
    }
    cin >> q;
    while(q--){
        ll b,c;
        cin >> b >> c;
        ans-=(cnt[b]*b);
        ans+=(cnt[b]*c);
        cnt[c]+=cnt[b];
        cnt[b]=0;
        cout << ans << '\n';
    }
}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>

using std::string;
using std::vector;
using std::unordered_map;
using std::map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  ui N{}, Q{}; cin >> N >> Q;
  unordered_map<ui, pair<ull, std::set<ui>>> tree{};
  for(size_t temporary = 0; temporary < N - 1; ++temporary)
  {
    ui a{}, b{}; cin >> a >> b;
    --a; --b;
    // tree[a].second.push_back(b);
    tree[a].second.emplace(b);
    tree[b].second.emplace(a);
  }

  typedef pair<ui, ui> Pair0;
  std::queue<pair<ui, ui>> queue0;
  for(const auto& v : tree[0].second)
  {
    queue0.push({v, 0});
  }
  while (!queue0.empty())
  {
    Pair0 p = queue0.front();
    queue0.pop();
    tree[p.first].second.erase(p.second);
    for(const auto& v : tree[p.first].second)
    {
      queue0.push({v, p.first});
    }
  }

  typedef pair<ui, ull> Pair;
  std::queue<pair<ui, ull>> queue{};
  for(size_t temporary = 0; temporary < Q; ++temporary)
  {
    ui p{}, x{}; cin >> p >> x;
    --p;
    tree[p].first += x;
  }
  for(const auto& v : tree[0].second)
  {
    queue.push({v, tree[0].first});
  }
  while(!queue.empty())
  {
    Pair p = queue.front();
    queue.pop();
    tree[p.first].first += p.second;
    for(const auto& v : tree[p.first].second)
    {
      queue.push({v, tree[p.first].first});
    }
  }

  cout << tree[0].first;
  for(ui i = 1; i < N; ++i)
  {
    cout << SPACE << tree[i].first;
  }
  cout << CRLF;

  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 42056
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n,k;
	int max=0;
	string s;
	cin>>n>>k>>s;
	for(int i=1;i<n;i++)
		if(s[i]==s[i-1]) max++;
	max=min(max+2*k,n-1);
	cout<<max;
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int check = 0;
        
        for(int i=A; i<=B; i++) {
        	if(i%K == 0) {
        		check = 1;
        	}
        }
        
        if(check == 1){
        	System.out.println("OK");
        }else{
        	System.out.println("NG");
        }
        
	}
}


Measured memory_bytes: 35804
// https://atcoder.jp/contests/dp/tasks/
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    ll ans;
    if ((b - a) % 2 == 0)
        ans = (b - a) / 2;
    else if ((a - 1) > (n - b))
        ans = n - b + 1 + (b - a - 1) / 2;
    else
        ans = a - 1 + 1 + (b - a - 1) / 2;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    a_list, b_list = [], []
    for _ in range(N):
        A, B = map(int, input().split())
        a_list.append(A)
        b_list.append(B)

    now = 0
    for a, b in zip(a_list[::-1], b_list[::-1]):
        a += now
        d = (b * ceil(a, b)) - a
        now += d

    print(now)


if __name__ == '__main__':
    main()


Measured memory_bytes: 13100
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;

 main()

{
    fast
    int n;
    cin>>n;
    vector<vector<int> >a(2,vector<int>(3));
    f(i,0,1)
    {
        f(j,0,2)
        {
            cin>>a[i][j];
        }
    }
    vector<int>dp(n+1,0);
    f(i,0,2)
    {
        f(j,0,n)
        {
            dp[j]=max(dp[j],j);
            if(j)
            {
                dp[j]=max(dp[j],dp[j-1]);
            }
            if(j-a[0][i]>=0)
            {
                dp[j]=max(dp[j],dp[j-a[0][i]]+a[1][i]);
            }
        }
    }
    n=dp[n];
    dp.assign(n+1,0);
    f(i,0,2)
    {
        f(j,0,n)
        {
            dp[j]=max(dp[j],j);
            if(j)
            {
                dp[j]=max(dp[j],dp[j-1]);
            }
            if(j-a[1][i]>=0)
            {
                dp[j]=max(dp[j],dp[j-a[1][i]]+a[0][i]);
            }
        }
    }
    cout<<dp[n]<<endl;
    return 0;

}





































Measured memory_bytes: 198532
a,b,n = map(int, input().split())

# for x in range(1, n+1):
#     print(x, end=' ')
#     tmp = (a*x)//b - a*(x//b)
#     print(tmp, end=' ')
#     print((a*x)//b, end=' ')
#     print(a*(x//b))

if n < b-1:
    x = n
else:
    x = b-1

print((a*x)//b - a*(x//b))

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

int main(){
  int N, C, K; cin >> N >> C >> K;
  vector<int> T(N);
  for(int i=0;i<N;i++){
    cin >> T[i];
  }
  sort(T.begin(), T.end());
  int ans=1;
  int count=0;
  int time=T[0];
  for(int i=0;i<N;i++){
    if(count<C && T[i]-time<=K){
      count++;
    }
    else{
      count=1;
      time=T[i];
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
long long h;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> h;
	long long ans = 1;
	long long p = 0;
	for (long long i = 1; i <= h; i *= 2)
	{
		if (i > h) break;
		p++;
	}
	cout << (1LL << p) - 1;
	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 FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  while (true)
  {
    int n, x;
    cin >> n >> x;
    if (n == 0 && x == 0)
      return 0;
    int ans = 0;
    for (int i_1 = 1; i_1 <= n; i_1++)
    {
      for (int i_2 = i_1 + 1; i_2 <= n; i_2++)
      {
        for (int i_3 = i_2 + 1; i_3 <= n; i_3++)
        {
          if (i_1 + i_2 + i_3 == x)
          {
            ans++;
          }
        }
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3092