akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<int>moji(5);
  for(int i=0;i<5;i++){
  cin>>moji.at(i);
  }
  for(int i=0;i<5;i++){
  if(moji.at(i)==0){
  cout<<i+1;
  }
  }
}

Measured memory_bytes: 3584
N = int(input())
H = list(map(int, input().split()))
count, m = 0,0
for i in range(N):
    if i==N-1:
        break
    else:
        if H[i]>=H[i+1]:
            count+=1
        else:
            count=0
    m = max(m,count)
print(m)

Measured memory_bytes: 15020
#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 dir,cnt;
bool dpx[8005][16100],dpy[8005][16100];

void doit_x(int i, int cnt){
    rep(j,16100){
        if(dpx[i][j]){
            if(dir!=0)dpx[i+1][j-cnt]=true;
            dpx[i+1][j+cnt]=true;
        }
    }
}

void doit_y(int i, int cnt){
    rep(j,16100){
        if(dpy[i][j]){
            dpy[i+1][j-cnt]=true;
            dpy[i+1][j+cnt]=true;
        }
    }
}

void dont_x(int i){
    rep(j,16100){
        if(dpx[i][j]){
            dpx[i+1][j]=true;
        }
    }
}

void dont_y(int i){
    rep(j,16100){
        if(dpy[i][j]){
            dpy[i+1][j]=true;
        }
    }
}

int main(){
    string s;
    int x,y;
    cin>>s>>x>>y;
    s+='T';
    int n=s.size();
    x+=8050; y+=8050;
    dpx[0][8050]=true;
    dpy[0][8050]=true;
    rep(i,n){
        if(s[i]=='T'){
            if(dir%2==0){
                doit_x(i,cnt);
                dont_y(i);
            }
            else{
                dont_x(i);
                doit_y(i,cnt);
            }
            dir++;
            cnt=0;
        }
        else{
            dont_x(i);
            dont_y(i);
            cnt++;
        }
    }
    if(dpx[n][x]&dpy[n][y])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 127972
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int N;
int t[101];
double v[101];
double maxv[40010];

int main()
{
	cin >> N;
	rep(i, N) {
		cin >> t[i];
		t[i] *= 2;
	}
	rep(i, N) cin >> v[i];

	fill(maxv, maxv + 40010, INF);

	int cur = 0;

	rep(i, N)
	{
		REP(j, cur, cur + t[i] + 1){
			maxv[j] = min(maxv[j], v[i]);
		}
		cur += t[i];
	}

	maxv[0] = 0; maxv[cur] = 0;

	for (int i = 0; i < cur - 1; i++) {
		maxv[i + 1] = min(maxv[i + 1], maxv[i] + 0.5);
	}

	for (int i = cur - 1; i >= 0; --i){
		maxv[i] = min(maxv[i], maxv[i + 1] + 0.5);
	}
	double ans = 0.0;

	rep(i, cur) {
		ans += maxv[i] + maxv[i + 1];
	}
	cout << setprecision(10) << ans / 4.0 << endl;
	return 0;
}

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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  int64 k;
  scanf("%lld",&k);
  printf("%d\n",(a-b)*(k%2==0?1:-1));
  /*
  int i;
  for(i=0;i<=k;i++){
    printf("%d %d %d, %d\n",a,b,c,a-b);
    int x=b+c;
    int y=a+c;
    int z=a+b;
    a=x;
    b=y;
    c=z;
  }
  */
  return;
}

int main(void){
  run();
  return 0;
}


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

int main(){
        
    int age;
    cin >> age;
    if(age == 3 || age == 5 || age == 7){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;        
    }

}

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

#define MAX 10000

struct Node {
	int p, l, r;
};

Node T[MAX];

void PreOrder(int id) {
	if(id != -1) {
		cout << ' ' << id;
		PreOrder(T[id].l);
		PreOrder(T[id].r);
	}
}

void InOrder(int id) {
	if(id != -1) {
		InOrder(T[id].l);
		cout << ' ' << id;
		InOrder(T[id].r);
	}
}

void PostOrder(int id) {
	if(id != -1) {
		PostOrder(T[id].l);
		PostOrder(T[id].r);
		cout << ' ' << id;
	}
}

int main(void) {
	int id, l, r;
	int n;
	int root = 0;
	
	cin >> n;
	for(int i = 0; i < n; ++i)   T[i].p = -1;
	
	for(int i = 0; i < n; ++i) {
		cin >> id >> l >> r;
		T[id].l = l;
		T[id].r = r;
		if(l != -1)   T[l].p = id;
		if(r != -1)   T[r].p = id;
	}
	
	while(T[root].p != -1)   ++root;
	
	cout << "Preorder" << endl;
	PreOrder(root);
	cout << endl;
	cout << "Inorder" << endl;
	InOrder(root);
	cout << endl;
	cout << "Postorder" << endl;
	PostOrder(root);
	cout << endl;
	return 0;
}



Measured memory_bytes: 3100
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
using namespace std;

#include<cstdio>

#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORq(i, m, n) for(int i = (m); i < (n); i++)
#define FORr(i, n) for (int i = (n); i >= 0; i++)


int main() {
	int N, K;
	string S;

	cin >> N;
	cin >> S;
	cin >> K;

	for (int i = 0; i < N; i++) {
		if (S[i] != S[K - 1]) {
			S[i] = '*';
		}
	}
	cout << S << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>

#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define IN(x) int (x); cin >> x
#define INS(x) string (s); cin >> s
#define INL(x) ll (x); cin >> x
#define VINT(a,n) vector<int> a(n)
#define VIN(a,n) VINT(a,n); REP(i,n){cin >> a[i];}
#define ALL(x) (x).begin(),(x).end()

int main () {
  IN(hall);
  IN(wall);
  vector<string> s(hall);
  REP(i,hall){
    cin>>s[i];
  }
  vector<vector<pair<int, int> > > ans(hall, vector<pair<int, int> >(wall, make_pair(0, 0)));
  REP(i, hall){
    REP(j, wall){
      if (s[i][j]=='#') ans[i][j]=make_pair(-1,-1);
      else{
	if (i==0||s[i-1][j]=='#'){
	  int k = i+1;
	  while(k<s.size() && s[k][j]=='.'){
	    k++;
	  }
	  ans[i][j].first = k-i;
	}
	else ans[i][j].first = ans[i-1][j].first;

	if (j==0||s[i][j-1]=='#'){
	  int k = j+1;
	  while(s[i][k]=='.'){
	    k++;
	  }
	  ans[i][j].second = k-j;
	}
	else ans[i][j].second = ans[i][j-1].second;
      }
    }
  }

  int res=0;
  REP(i, hall){
    REP(j, wall){
      //      cout<<ans[i][j].first<<','<<ans[i][j].second<<endl;
      res=max(res, ans[i][j].first+ans[i][j].second-1);
    }
  }
  cout<<res<<endl;
      

    
}


Measured memory_bytes: 35712
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long long int
#define inf 999999999999999999
#define pb push_back
#define fi first
#define se second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define pi pair<ll,ll>
#define mp make_pair
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
//freopen("explicit.in", "r", stdin);
//freopen("explicit.out", "w", stdout);
 
void SieveOfEratosthenes() 
{ 
    bool prime[10000001];
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=10000000; p++) 
    { 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (ll i=p*p; i<=10000000; i += p) {
                prime[i] = false; 
            }
        } 
    }  
} 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	if(b%a==0)
	   return a;
	return gcd(b%a,a);
}
ll power(ll x,ll y,ll p) 
{ 
    ll r = 1;
  
    x = x % p;
    while (y > 0) {
        if (y & 1) 
            r = (r * x) % p;
        y = y >> 1; 
        x = (x * x) % p; 
    } 
    return r; 
}  
ll modInverse(ll n, ll p) 
{ 
    return power(n, p - 2, p); 
} 
 
ll nCrModP(ll n,ll r, ll p) 
{ 
    ll fac[100005];
    if (r == 0) 
        return 1; 
  
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
}
int32_t main() 
{
    fio
	ll j,i,n,t,l,r,c,h,k,ma,m,mi,mini,maxi,d,x;
	cin>>n;
	mini=inf;
	ma=0;
	mi=inf;
	m=-inf;
	for(i=0;i<n;i++)
	{
		cin>>c>>d;
		mini=min(mini,c+d);
		ma=max(ma,c+d);
		mi=min(mi,c-d);
		m=max(m,c-d);
	}
	cout<<max(ma-mini,m-mi);
}


	

		

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
// #include <string>
// #include <set>

using namespace std;
typedef unsigned long long ull;

int main(int argc, char const *argv[]) {
    char c;
    cin >> c;
    if (c == 'a' || c == 'e' || c == 'i' || c == 'u' || c == 'o') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

class Crop
{
public:
  string name;
  double efficiency;
  Crop(string n, double e) {
    name = n;
    efficiency = e;
  }
};

int main() {
  int n, p, a, b, c, d, e, f, s, m;
  string l;
  while (cin >> n, n) {
    vector<Crop> crops;
    for (int i = 0; i < n; i++) {
      cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      int time = a + b + c, money = -p;
      while (m--){
        time += d + e;
        money += s * f;
      }
      crops.pb(Crop(l, (double)money/time));
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if ((crops[i].efficiency < crops[j].efficiency) || ((crops[i].efficiency == crops[j].efficiency) && crops[i].name > crops[j].name))
          swap(crops[i], crops[j]);
      }
    }
    for (int i = 0; i < n; i++) {
      cout << crops[i].name << el;
    }
    cout << "#" << el;
  }
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

void dfs(string s,ll res) {
  if(res==0) {
    cout << s << endl;
  }
  else {
    char lim='a';
    if(s!="") {
      for(ll i=0;i<s.size();i++) {
        lim=max(lim,s[i]);
      }
      lim++;
    }
    for(char i='a';i<=lim;i++) {
      dfs(s+i,res-1);
    }
  }
}

int main() {
  ll n;
  cin >> n;
  string s="";
  dfs(s,n);
}

Measured memory_bytes: 1536
#include<cstdio>
#include<queue>

using namespace std;

int main(void) {
    int t;
    scanf("%d",&t);
    for(int i=0; i<t; i++)
    {
        int n,k,last=0;
        priority_queue<int> pq;
        scanf("%d%d",&n,&k);

        scanf("%d", &last);
        pq.push(0);
        for(int j=1; j<n; j++) {
            int x;
            scanf("%d",&x);
            pq.push(x-last);
            last = x;
        }

        for(int j=0; j<k-1 && !pq.empty(); j++)
            pq.pop();

        int res=0;
        while(!pq.empty())
            res += pq.top(), pq.pop();

        printf("%d\n", res);
    }
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    long long ans=0;
    for(int i=0;i<n;i++){
        cin >> a.at(i);
        if(i>=1){
            if(a.at(i-1)>a.at(i)){
                ans+=a.at(i-1)-a.at(i);
                a.at(i)=a.at(i-1);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3984
#include<stdio.h>
#include<string.h>
int n;
int array[300000];
int main(void){
    int p[300000]={0};
    int size=0;
    array[0]=6;
    for(int i=1;;i++){
        array[i*2-1]=7*i+1;
        array[i*2]=7*i+6;
        size=2*i;
        if(array[i*2]>300000) break;
    }
    for(int i=0;i<=size;i++){
        if(p[array[i]]==1) continue;
        for(int j=2*array[i];j<300000;j+=array[i]){
            p[j]=1;
        }
    }
    while(1){
        int i;
        scanf("%d",&n);
        if(n==1) break;
        int judge[300000]={0};
        for(i=0;array[i]<=n;i++){
            if(!p[array[i]]&&n%array[i]==0){
                judge[i]=1;
            }
        }
        printf("%d:",n);
        for(int j=0;j<=i;j++)
            if(judge[j]==1)
                printf(" %d",array[j]);
        puts("");
    }
}



Measured memory_bytes: 4396
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[100];

ll l(ll n)
{
	
	if(n==0)
	{
		return dp[n]=2;
	}
	if(n==1)return dp[n] = 1;
	if(dp[n]!=0)return dp[n];
	return dp[n] = l(n-1)+l(n-2);
}

int main()
{
	ll n;
	cin >> n;
	cout << l (n)<<endl;
	return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include <random>
#include <bitset>
#include <chrono>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
	
#ifndef ONLINE_JUDGE
// #include "debug.h"
#else
// #define debug(...) 42
#endif

const int M = 3e3+1;
const int MD=998244353;


int ans[M];
int main() {
	fast_cin();
	int X,Y,A,B,C;
	int r=0,b=0,c=0;
	ll su=0;
	cin>>X>>Y>>A>>B>>C;
	priority_queue<pii>pq;
	for(int i=0;i<A;i++){
		int x;
		cin>>x;
		pq.push({x,0});
	}
	for(int i=0;i<B;i++){
		int x;
		cin>>x;
		pq.push({x,1});
	}
	for(int i=0;i<C;i++){
		int x;
		cin>>x;
		pq.push({x,2});
	}
	while(!pq.empty())
	{
		pii tp=pq.top();
		if(tp.second==0){
			if(r<X){
				su+=tp.first;
				r++;
			}
		}
		if(tp.second==1){
			if(b<Y){
				su+=tp.first;
				b++;
			}
		}
		if(tp.second==2){
			if(r+b+c<X+Y){
				su+=tp.first;
				c++;	
			}
		}
		if(r+b+c>=X+Y) break;
		pq.pop();
	}
	cout<<su;
	return 0;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define int long long
using namespace std;

typedef pair<int, int> Pii;

void readint(int N, vector<int> &a);
void readdouble(int N, vector<double> &a);
void readindex(int N, vector<int> &a);



signed main(){

    string S;
    cin >> S;

    if(S.find('a') != string::npos && S.find('b') != string::npos && S.find('c') != string::npos){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
    return 0;
}








void readint(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readdouble(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}
void readindex(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str()) - 1;
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str()) - 1;
}

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++)

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;
const int MOD = 1000000007;

typedef long long ll;

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll LCM(ll x, ll y)
{
    return x * y / GCD(x, y);
}

using Graph = vector<vector<int>>;

// typedef pair<int, int> P;
struct xy {
    double x, y;
};

double dist(xy p, xy q)
{
    return sqrt(pow((p.x - q.x), 2) + pow((p.y - q.y), 2));
}

int fact(int n)
{
    if (n == 1) {
        return 1;
    } else {
        return n * fact(n - 1);
    }
}
int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) v.at(i) = i;
    vector<xy> town(n);
    rep(i, n)
    {
        cin >> town.at(i).x >> town.at(i).y;
    }

    double avg = 0.0;
    do {
        double sum = 0.0;
        for (int i = 1; i < n; i++) {
            sum += dist(town.at(v.at(i)), town.at(v.at(i - 1)));
        }
        avg += sum;
    } while (next_permutation(v.begin(), v.end()));

    double ans = avg / fact(n);
    cout << fixed << setprecision(7) << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int ball[N],n,m,x,y,ans;
bool red[N];
int main(){
	scanf("%d %d",&n,&m);
	red[1]=1;
	for(int i=1;i<=n;i++)ball[i]=1;
	for(int i=1;i<=m;i++){
		scanf("%d %d",&x,&y);
		red[y]|=red[x];
		red[x]&=((--ball[x]>0));ball[y]++;
	}
	for(int i=1;i<=n;i++)if(red[i])ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 768
N = int(input())
p = [int(input()) for i in range(N)]

descending_p = sorted(p, reverse=True)
# print(descending_p)

# 一番の高額は半額
discount_price = descending_p[0] // 2
# print(discount_price)

# 他は定価で買う
list_price = sum(descending_p[1:])
# print(list_price)

total_price = discount_price + list_price
print(total_price)


Measured memory_bytes: 8984
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <functional>
#include <math.h>
#include <map>
#include <set>
#include <string>
using namespace std;
#define fio ios::sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;

const int INT_INF = 1e9;
const ll LL_INF = 1e18;
const int MAXN = 500003;

typedef struct GE{
	int to;
	ll w;
	GE(){};
}GE;

ll mod = 1e9+7;

ll n, k;
ll nCr[2002][2002];

ll nHr(ll a, ll b){
	return nCr[a+b-1][b];
}

int main() {
	scanf("%lld %lld", &n, &k);
	// int bcnt = k;
	// int rcnt = n-k;

	nCr[0][0] = 1;	
	nCr[1][0] = 1;
	for(int i=1;i<=2000;i++){
		nCr[i][0] = 1;
		for(int j=1;j<=2000;j++){
			nCr[i][j] = nCr[i-1][j] + nCr[i-1][j-1];
			nCr[i][j] %= mod;
		}
	}


	ll ans=0;


	for(ll i=1;i<=min(n-k+1,k);i++){
		ll h = nHr(i, k-i);
		ll c = nCr[n-k+1][i];
		printf("%lld\n", h*c%mod);
		// ans = h*c%mod;
	}
	
	ll rem = k - (min(n-k+1, k));
	while(rem--){
		printf("0\n");
	}

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

Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=1e9+7;
const ll ms=1e6+5;
const ll inf=-1e17;




int main()
{
    idfc;

    ll x,y;
    cin>>x>>y;

    ll ans=INT_MAX;

    if(x%3)ans=min(ans,x);
    else ans=0;
    if(y%3)ans=min(ans,y);
    else ans=0;

    int i;
    ll pp=x*y;
    ll a=0;
    ll b=0;
    int t=y/2;
    ll mx,mn;
    for(i=1;i<=x;i++)
    {
        pp-=y;
        a+=(y-t);
        b+=t;
        mx=max(pp,max(a,b));
        mn=min(pp,min(a,b));
        ans=min(ans,mx-mn);
    }
    a=0;
    b=0;
    pp=x*y;
    t=x/2;
    for(i=1;i<=y;i++)
    {
        pp-=x;
        a+=(x-t);
        b+=t;
        mx=max(pp,max(a,b));
        mn=min(pp,min(a,b));
        ans=min(ans,mx-mn);
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s, t;
  cin >> s >> t;
  ll ans = 0;
  for (ll i = 0; i < s.size(); ++i) {
    if (s.at(i) != t.at(i)) {
      ans += 1;
    }
  }
  cout << ans << "\n";
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n,m; cin>>n>>m;
    vector<ll> v(n);
    rep(i,n) v[i]=i;
    vector<vector<bool>> path(n,vector<bool>(n,false));
    rep(i,m){
        ll a,b; cin>>a>>b;
        a--; b--;
        path[a][b]=path[b][a]=true;
    }
    ll ans=0;
    do{
        bool ok=true;
        rep(i,n-1){
            if(path[v[i]][v[i+1]]) continue;
            ok=false;
            break;
        }
        if(ok) ans++;
    }while(next_permutation(v.begin()+1,v.end()));
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;
  vector<vector<int>> g(n);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    --a;
    if (i == 0 && a) ++ans;
    if (i) g[a].push_back(i);
  }
  function<int(int)> dfs = [&](int u) {
    int ret = 0;
    for (int v : g[u]) {
      int cur = dfs(v);
      if (cur >= k - 1 && u)
        ++ans;
      else
        ret = max(ret, cur + 1);
    }
    return ret;
  };
  dfs(0);
  cout << ans;

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 12032
s = ""
for i in range(1,int(input()) + 1):
    if i % 3 == 0:
        s += " {0}".format(i)
    else:
        x = i
        while x > 0:
           if x % 10 == 3:
               s += " {0}".format(i)
               break
           x = x // 10
print(s)


Measured memory_bytes: 5640
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define MAXN 1000007
#define fr(i, s, e, st) for(ll (i) = (s); (i) < (e); (i) += (st))
#define fre(i, s, e, st) for(ll (i) = (s); (i) <= (e); (i) += (st))
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
 
using namespace std;
int main()
{
    fastio;
    int T = 1;
    while(T--){
        ll n;
        string s, t;
        cin>>n;
        cin>>s>>t;
        fr(i, 0, n, 1)
            cout<<s[i]<<t[i];
        cout<<endl;
    }                                               
    return 0;
}

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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

using Graph = vector<vector<int>>;

ll kzyou(ll a,ll k){//aのk乗を返す
    ll zyou = 1;
    for(ll i = 1;i<=k;i++){
        zyou *= a;
    }
    return zyou;
}
typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

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

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	s := nextStr()

	cntR := 0
	for i := 0; i < n; i++ {
		if s[i] == 'R' {
			cntR++
		}
	}
	ans := 0
	for i := 0; i < cntR; i++ {
		if s[i] != 'R' {
			ans++
		}
	}

	fmt.Println(ans)

}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,ma,mb;
	cin >>n >>ma >>mb;
	
	vector<VI> id(n, VI(3));
	rep(i, n) cin >>id[i][0] >>id[i][1] >>id[i][2];
	
	const int INF = 1<<29;
	vector<VI> dp(440, VI(440, INF));
	dp[0][0] = 0;
	for(auto& z: id){
		vector<VI> np(440, VI(440, INF));
		rep(j, 405) rep(k, 405) if(dp[j][k]>=0){
			amin(np[j][k], dp[j][k]);
			if(j+z[0]<=400 &&  k+z[1] <=400)
				amin(np[j+z[0]][k+z[1]], dp[j][k] + z[2]); 
		}
		swap(dp, np);
	}
	int ans = INF;
	rep(i,  401) rep(j, 401){
		if(dp[i][j] >0 && dp[i][j] < INF && i * mb == j * ma){
			amin(ans,  dp[i][j]);
		}
	}
	cout << (ans<INF? ans: -1) <<endl;
	
	return 0;
}

Measured memory_bytes: 1856
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,a,b,c,d;
    cin >> a;
    vector<int>vec;
    while(a--)
    {
        cin >> b;
        vec.push_back(b);
    }
   sort(vec.begin(),vec.end());
   int m=0;
   for(i=1;i<=500000;i++)
   {

     auto it=upper_bound(vec.begin(),vec.end(),i-1);
     int l=it-vec.begin();
     int y=vec.end()-it;
     if(l==y)
        m++;


   }
   cout << m << endl;



}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) a.begin(),a.end()
typedef long long ll;
 
using P = pair<ll,ll>;
#define v first
#define w second
 
// v高い順（vが同じならw軽い方優先）
bool comp(P a, P b){
    return a.v == b.v ? a.w < b.w : a.v > b.v;
}
 
int main(void){
    ll N,W;
    cin>>N>>W;
    vector<P> a(N);
    rep(i,N){
        ll v,w;
        cin>>w>>v;
        a[i] = {v,w};
    }
    vector<P> dp = {{0,0}};
 
    rep(i,N){
        vector<P> tmp;
        for(auto& s : dp){
            tmp.push_back(s);
            tmp.push_back({s.v + a[i].v, s.w + a[i].w});
        }
 
        sort(all(tmp),comp);
        dp.clear();
        ll w_border = W+1;
        for(auto& s : tmp){
            if( w_border > s.w){
                w_border = s.w;
                dp.push_back(s);
            }
        }
    }
    cout<<dp[0].v<<endl;
    return 0;
}

Measured memory_bytes: 384
n = int(input())
ary = list(map(int, input().split()))
#print(n,ary)

ary_2 = [ary[0]]
for i in range(1, n):
    ary_2.append(ary[i] + ary_2[i-1])
ary_2 = [0] + ary_2
#print(ary_2)

from collections import Counter
c = Counter(ary_2)
v = (c.values())
#print(v)

from math import factorial
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

ans = 0
for j in v:
    if j >1:
        ans += combinations_count(j,2)

print(ans)

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


int main(){
    string s;cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}







Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int inf = 1000000007;
typedef pair <int, int> P;
typedef pair <int, P> PP;

vector <int> edge[100005];
int dp[100005][3];
// 頂点iにjステップ目でいける最短手数

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

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

    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;

        edge[u].push_back(v);
    }

    int s, t;
    cin >> s >> t;
    s--; t--;

    fill(dp[0], dp[n+1], inf);

    priority_queue <PP, vector<PP>, greater<PP> > q;
    dp[s][0] = 0;
    q.push(PP(0, P(s, 0)));

    while (q.size()) {
        PP p = q.top();
        q.pop();

        int cost = p.first;
        int cur = p.second.first;
        int step = p.second.second;

        if (cost > dp[cur][step]) continue;

        for (int v : edge[cur]) {
            if (step < 2) {
                if (dp[v][step+1] > cost) {
                    dp[v][step+1] = cost;
                    q.push(PP(cost, P(v, step+1)));
                }
            } else {
                if (dp[v][0] > cost) {
                    dp[v][0] = cost + 1;
                    q.push(PP(cost + 1, P(v, 0)));
                }
            }
        }
    }

    if (dp[t][0] == inf) {
        cout << -1 << "\n";
    } else {
        cout << dp[t][0] << "\n";
    }

    return 0;
}

Measured memory_bytes: 6912
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int len, cnt=0;
    char s[max];
    
    scanf("%s", s);
    
    len=strlen(s);
    
    rep(i, len/2){
        if (s[i]!=s[len-i-1]) {
            cnt++;
        }
    }
    
    printf("%d", cnt);
    
    return 0;
}



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

#define INF 1000000009

vector<vector<int>> warshall_floyd(int n, vector<vector<int>>& E){
    vector<vector<int>> d = E;
    for (int k = 0; k < n; k++){
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                if (i == j) continue;
                int dk = d[i][k] + d[k][j];
                if (dk < d[i][j]){
                    d[i][j] = dk;
                }
            }
        }
    }
    return d;
}

int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<int>> E(10, vector<int>(10));
    for (int i = 0; i < 10; i++){
        for (int j = 0; j < 10; j++){
            cin >> E[i][j];
        }
    }
    vector<vector<int>> a(h, vector<int>(w));
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }
    vector<vector<int>> d;
    d = warshall_floyd(10, E);

    int ans = 0;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            int aij = a[i][j];
            if (aij < 0) continue;
            ans += d[aij][1];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.*;

//https://beta.atcoder.jp/contests/arc102/submissions/3118322

class Edge{
	int a,b,c;
	public Edge(int a,int b,int c){
		super();
		this.a=a;
		this.b=b;
		this.c=c;
	}
	@Override
	public String toString(){
		return a+" "+b+" "+c;
	}
}

class Main{
	static int nextBit(StringBuilder str,int idx){
		int v=str.indexOf("1",idx+1);
		return v==-1?str.length()-1:v;
	}

	public static void main(String[] $){
		int L=new Scanner(System.in).nextInt()-1;
		if(L==1){
			System.out.println("2 2\n1 2 0\n1 2 1");
			return;
		}

		StringBuilder sb=new StringBuilder();
		Map<Integer,Integer> m=new HashMap<>();
		
		int n=Integer.numberOfTrailingZeros(Integer.highestOneBit(L));
		for(int i=n;i>=0;i--){
			System.err.println(i);
			m.put(sb.length(),1<<i);
			sb.append((L&(1<<i))==0?0:1);
		}

		List<Edge> ret=new ArrayList<>();

		for(int i=1;i<sb.length();++i){
			ret.add(new Edge(i,i+1,0));
			ret.add(new Edge(i,i+1,m.get(i)));
		}

		int num=0;
		for(int i=0;i<sb.length();++i){
			if(sb.charAt(i)=='0')
				continue;
			num+=m.get(i);
			ret.add(new Edge(1,nextBit(sb,i)+1,num));
		}

		System.out.println(sb.length()+" "+ret.size());
		ret.forEach(System.out::println);
	}
}


Measured memory_bytes: 28880
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    X, N = map(int, input().split())
    if N == 0:
        print(X)
        exit(0)

    P = list(map(int, input().split()))
    i = 0

    while True:
        if X - i not in P:
            print(X - i)
            break
        elif X + i not in P:
            print(X + i)
            break
        i += 1


if __name__ == "__main__":
    main()


Measured memory_bytes: 9188
#include <bits/stdc++.h> 
using namespace std;
#define int long long int
#define float double
#define pb push_back
#define FF first
#define SS second
#define N 201000
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i++)
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define pii pair<int,int>
#define mp make_pair
#define INF 1000000000000000000
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)


signed main() 
{
    speed;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    
    int n;
    cin>>n;
    int i=100,ans=0;
    while(i<n)
    {
        int j=(0.01)*i;
        i+=j;
        ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);


		int N = sc.nextInt(); //問題数
		int M = sc.nextInt(); //回答数

		boolean[] bool = new boolean[N];
		int[]  miss= new int[N]; //間違った回数

		for(int i=0; i<N; i++) {
			bool[i] = false;
			miss[i] = 0;
		}
		for(int i = 0; i<M; i++) {
			//添え字を選択させる。
			int no = sc.nextInt()-1;
			String anser = sc.next();
			if(bool[no]) {
				continue;
			}else {
				if(anser.equals("AC")) {
					bool[no] = true;
				}else {
					miss[no]++;
				}
			}
		}
		int win = 0;
		int lose = 0;

		for(int i = 0; i<N; i++) {
			if(bool[i]) {
				win++;
				lose += miss[i];
			}
		}
		System.out.println(win + " " + lose);

	}

}


Measured memory_bytes: 64488
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		x: usize,
	}

	if x < 600 {
		println!("8");
		return;
	} 
	if x < 800 {
		println!("7");
		return;
	} 
	if x < 1000 {
		println!("6");
		return;
	} 
	if x < 1200 {
		println!("5");
		return;
	} 
	if x < 1400 {
		println!("4");
		return;
	} 
	if x < 1600 {
		println!("3");
		return;
	} 
	if x < 1800 {
		println!("2");
		return;
	} 
	println!("1");
}



Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5;
int a[5];
int main(){
	for(int i=0;i<3;i++){
		cin>>a[i];
	}
	sort(a,a+3);
	int ans=0;
	ans=a[2]*10+a[1]+a[0];
	cout<<ans;
	return 0;
}

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


using namespace std;
const int N=1e5+55;
int a[N][3];
int dp[N][3];

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
			cin>>a[i][j];
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<3;j++)
			dp[i][j]=max(dp[i-1][(j+1)%3]+a[i][j],dp[i-1][(j+2)%3]+a[i][j]);
	}
	int ans=0;
	ans=max(dp[n-1][0],ans);
	ans=max(dp[n-1][1],ans);
	ans=max(dp[n-1][2],ans);
	cout<<ans<<endl;
	
	
	return 0;
}


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

using namespace std;

int main() {
    cout.precision(20);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    while (n) {
        if (n % 10 == 7) {
            cout << "Yes";
            return 0;
        }
        n /= 10;
    }
    cout << "No";
}

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

#define mod 1000000007
using ll = long long;

int main(){

  int n,k;
  cin >> n >> k;

  if(n==k){
    ll ans=1;
    ll num;
    for(int i=0;i<n;i++){
      cin >> num;
      ans=ans*num%mod;
    }
    cout << (ans+mod)%mod;
    return 0;
  }

  priority_queue<ll> pos;
  priority_queue<ll> neg;
  ll num;
  for(int i=0;i<n;i++){
    cin >> num;
    if(num>=0){
      pos.push(num);
    }else{
      neg.push(-num);
    }
  }

  if(k%2==1 && pos.size()==0){
    ll ans=1;
    ll num;
    for(int i=0;i<n;i++){
      num=-neg.top();
      neg.pop();
      if(i>=n-k){
        num=num%mod;
        ans=ans*num%mod;
      }
    }
    cout << (ans+mod)%mod << endl;
    return 0;
  }

  ll posnum=1;
  ll negnum=1;
  bool posErase=1;
  bool negErase=1;
  ll ans=1;
  int i=0;
  if(k%2==1){
    ans=pos.top();
    pos.pop();
    i++;
  }
  while(1){
    if(i==k){
      cout << (ans+mod)%mod << endl;
      return 0;
    }
    if(pos.size()>=2 && posErase==1){
      posnum=pos.top();
      pos.pop();
      posnum=posnum*pos.top();
      pos.pop();
      posErase=0;
    }

    if(neg.size()>=2 && negErase==1){
      negnum=neg.top();
      neg.pop();
      negnum=negnum*neg.top();
      neg.pop();
      negErase=0;
    }

    if(posnum>=negnum){
      posErase=1;
      ans=ans*(posnum%mod)%mod;
      posnum=0;
    }else{
      negErase=1;
      ans=ans*(negnum%mod)%mod;
      negnum=0;
    }
    i+=2;
  }

}

Measured memory_bytes: 5432
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            int[] b = new int[n];
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
                b[i] = in.nextInt();
            }
            long extra = 0;
            for (int i = n - 1; i >= 0; --i) {
                long cur = a[i] + extra;
                long dest = (cur + b[i] - 1) / b[i] * b[i];
                extra += dest - cur;
            }
            out.println(extra);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 28356
#include <algorithm>
#include <cstdio>
typedef long long lld;
const int MAXL = 1001;
int cnt[MAXL];
int pre[MAXL];
int L, N;

void init() {
    for (int i = 0; i < MAXL; ++i) {
        cnt[i] = 0;
    }
}

lld solve() {
    pre[0] = cnt[0];
    for (int i = 1; i < MAXL; ++i) {
        pre[i] = pre[i-1] + cnt[i];
    }
    lld sum = 0;
    for (int i = 1; i < MAXL; ++i) {
        if (!cnt[i]) continue;
        for (int j = i; j < MAXL; ++j) {
            if (!cnt[j]) continue;
            int k = std::min(i+j, MAXL) - 1;
            if (i == j) {
                sum += 1LL * cnt[i] * (cnt[j] - 1) / 2 * (pre[k] - pre[j])
                    +  1LL * cnt[i] * (cnt[j] - 1) * (cnt[j] - 2) / 6;
            } else {
                sum += 1LL * cnt[i] * cnt[j] * (pre[k] - pre[j])
                    +  1LL * cnt[i] * cnt[j] * (cnt[j] - 1) / 2;
            }
        }
    }
    return sum;
}

int main() {
    scanf("%d", &N);
    init();
    for (int i = 0; i < N; ++i) {
        scanf("%d", &L);
        ++cnt[L];
    }
    printf("%lld\n", solve());
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  long long a[200200];
  cin >> n;
  long long s = 0;
  rep(i,n){
    long long t;
    cin >> t;
    s+=t;
    a[i] = s;
  }
  long long mi=999999999999999;
  rep(i,n-1){
    if(abs(2*a[i]-a[n-1])<mi){
      mi = abs(2*a[i]-a[n-1]);
    }
  }
  cout << mi << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	int A[100010] = {};
	multiset<int> S;  
	S.insert(0); 
	S.insert(0); 
	S.insert(N+1); 
	S.insert(N+1); 
	for(int i = 1; i <= N; i++){
		int a; cin >> a; 
		A[a] = i; 
	}
	long long ans = 0; 
	for(int i = N; i >= 1; i--){
		auto it = S.lower_bound(A[i]); 
		int a2 = *it; 
		it ++; 
		int a1 = *it; 
		it --; it --; 
		int a3 = *it; 
		it --;
		int a4 = *it; 
		ans += (long long) i * (A[i] - a3) * (a1 - a2); 
		ans += (long long) i * (a2 - A[i]) * (a3 - a4); 
		S.insert(A[i]);
	}
	cout << ans << endl; 
}

Measured memory_bytes: 5376
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
list($A,$B,$C,$D) = explode(" ",trim(fgets(STDIN)));
//$A  = explode(" ",trim(fgets(STDIN)));

if (abs($A-$B)<=$D && abs($B-$C)<=$D) {
  printf("Yes\n");
}
else {
  if (abs($A-$C)<=$D) {
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }
}


Measured memory_bytes: 3828
#include<stdio.h>
#include<stdlib.h>
void merge(long long int arr[],long long int l,long long int m,long long int r)
{
    long long int i, j, k;
    long long int n1 = m - l + 1;
    long long int n2 = r - m;

    /* create temp arrays */
    long long int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1 + j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2) {
        if (L[i] <= R[j]) {
            arr[k] = L[i];
            i++;
        }
        else {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1) {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2) {
        arr[k] = R[j];
        j++;
        k++;
    }
}

/* l is for left index and r is right index of the
   sub-array of arr to be sorted */
void mergeSort(long long int arr[],long long int l,long long int r)
{
    if (l < r) {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        long long int m = l + (r - l) / 2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m + 1, r);

        merge(arr, l, m, r);
    }
}
int main()
{
    long long int n;
    scanf("%lld",&n);
    long long int ans=0;
    long long int* arr;
    arr=(long long int*)malloc(n*sizeof(long long int));
    for(long long int i=0;i<n;i++)
    {
        scanf("%lld",&arr[i]);
    }
    mergeSort(arr,0,n-1);
    ans+=arr[n-1];
    long long int x=n-2;
    long long int count=n-2;
    for(;;)
    {
        if(count==0)
        {
            break;
        }
        if(count!=1){
            ans+=2*arr[x];
            count-=2;
            x--;
        }
        else{
            ans+=arr[x];
            count--;
        }
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 4852
#pragma once
#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 <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
ll dp[2][4];
int now = 0;

void i18n() {
	string s;
	cin >> s;
	cout << (s[0]) << (s.size() - 2) << s[s.size() - 1] << endl;
}

int main() {
	i18n();
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<string> S(N);
  for(int i=0;i<N;i++)  cin >> S.at(i);

  vector<int> cnt(4,0);
  for(int i=0;i<N;i++){
    if(S.at(i)=="AC") cnt.at(0)++;
    else if(S.at(i)=="WA")  cnt.at(1)++;
    else if(S.at(i)=="TLE") cnt.at(2)++;
    else  cnt.at(3)++;
  }
  cout << "AC x " << cnt.at(0) << endl;
  cout << "WA x " << cnt.at(1) << endl;
  cout << "TLE x " << cnt.at(2) << endl;
  cout << "RE x " << cnt.at(3) << endl;

  return 0;
}

Measured memory_bytes: 6336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 400 + 5;
ll dp[N][N];
ll arr[N];
int n;
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    auto calc = [&](int L, int R) {
        ll tot = 0;
        for (int i = L; i <= R; i++)
            tot += arr[i];
        return tot;
    };
    for (int L = n - 1; L > -1; L--) {
        for (int R = L + 1; R < n; R++) {
            ll sum = calc(L, R);
            dp[L][R] = 1e18;
            for (int i = L; i < R; i++)
                dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R] + sum);
        }
    }
    cout << dp[0][n - 1];
    return 0;
}


Measured memory_bytes: 1536
L, R = map(int, input().split())

# 2019 = 3 * 673

def f():
    if L % 2019 == 0 or R % 1029 == 0:
        return 0

    p_L = L // 2019
    p_R = R // 2019
    if p_L != p_R:
        return 0
    # (2 * 10^3) ** 2 = 4 * 10^6
    S = [(i * j) % 2019 for i in range(L, R) for j in range(i + 1, R + 1)]
    return min(S)

print(f())


Measured memory_bytes: 75312