akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int y2, m2, d2;
int solve(int y1, int m1, int d1) {
	int r = 0;
	if (y1 == y2 && m1 == m2 && d1 == d2)return 0;
	if (y1 != y2 && m1 == 1 && d1 == 1) {
		r = 365;
		if (y1 % 4 == 0)r++;
		if (y1 % 100 == 0)r--;
		if (y1 % 400 == 0)r++;
		return r + solve(y1 + 1, m1, d1);
	}
	if (m1 == 12 && d1 == 31)return 1 + solve(y1 + 1, 1, 1);
	else {
		if (m1 == 2) {
			r = 28;
			if (y1 % 4 == 0)r++;
			if (y1 % 100 == 0)r--;
			if (y1 % 400 == 0)r++;
			if (d1 == r)return 1 + solve(y1, m1 + 1, 1);
			else return 1 + solve(y1, m1, d1 + 1);
		}
		else if (m1 == 4 || m1 == 6 || m1 == 9 || m1 == 11) {
			if (d1 == 30)return 1 + solve(y1, m1 + 1, 1);
			else return 1 + solve(y1, m1, d1 + 1);
		}
		else {
			if (d1 == 31)return 1 + solve(y1, m1 + 1, 1);
			else return 1 + solve(y1, m1, d1 + 1);
		}
	}
}
signed main() {
	int y1, m1, d1;
	while (cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2, m1 != -1)cout << solve(y1, m1, d1) << endl;
}


Measured memory_bytes: 3116
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

pair<int,int> operator+(const pair<int,int> &lhs, const pair<int,int> &rhs){
  pair<int,int> p = { lhs.first + rhs.first, lhs.second + rhs.second };
  return p;
}

bool operator==(const pair<int,int> &lhs, const pair<int,int> &rhs){
  return (lhs.first == rhs.first) && (lhs.second == rhs.second);
}

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int h,w;
  cin>>h>>w;
  vector<vector<int>> field(h,vector<int>(w));
  REP(i,h){
    string str;
    cin>>str;
    REP(j,w){
      int num=str[j]-'0';
      if(i%2==0 && j%2==0){
        if((i/2+j/2)%2==0){
          if(num==6)field[i][j]=1;
        }else{
          if(num==1)field[i][j]=1;
        }
      }
      if(i%2!=0 && j%2==0){
        if(i%4==1){
          if(num==2)field[i][j]=1;
        }
        if(i%4==3){
          if(num==5)field[i][j]=1;
        }
      }
      if(i%2==0 && j%2!=0){
        if(j%4==1){
          if(num==3)field[i][j]=1;
        }
        if(j%4==3){
          if(num==4)field[i][j]=1;
        }
      }
    }
  }

  queue<pair<int,int> > q;

  q.push(make_pair(0,0));

  const pair<int,int> moves[] = {
    { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 },
  };

  vector<vector<int>> field2(h,vector<int>(w, -1));
  field2[0][0]=0;

  while( !q.empty() ) {
    pair<int,int> cur = q.front(); q.pop();
    for(auto &move : moves){
      pair<int,int> next=cur+move;
      if(next.first<0||next.first>=h||next.second<0||next.second>=w)continue;
      if(field2[next.first][next.second]==-1 && field[next.first][next.second]==1){
        field2[next.first][next.second]=field2[cur.first][cur.second]+1;
        q.push(next);
      }
    }
  }
  if(field2[h-1][w-1]==-1){
    cout<<"NO"<<endl;
  }else{
    cout<<"YES"<<endl;
  }
}



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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, P;
  IN(N,P);
  string S;
  IN(S);

  ll ans = 0;

  if(P==2 || P==5){
    REP(i,N){
      ll v = S[i]-'0';
      if(v%P==0){
        ans += i+1;
      }
    }
  }else{
    vll dp(P, 0);
    ll shift = 1;
    ll shift2 = 0;
    dp[0] = 1;
    RREP(i,N-1){
      ll v = (S[i]-'0');
      shift2 = (shift2 + shift*v)%P;
      //ans += dp[shift2];
      dp[shift2]++;
      shift = (shift*10)%P;
    }

    REP(i,P){
      ans += (dp[i])*(dp[i]-1)/2;
    }
  }

  OUT(ans);

  return 0;
}

Measured memory_bytes: 720
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  int a, b;
  readf("%s %s\n", &a, &b);
  if (b % a) {
    writeln(b - a);
  } else {
    writeln(a + b);
  }
}


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

#define maxn 2501
#define maxd 1000000000

int n,m,p;
vector<int> adj[maxn];
vector<int> wt[maxn];
int dist[maxn];

int bellmanford(){
    for(int i=1;i<=n;i++){
        dist[i]=maxd;
    }
    dist[1]=0;
    int u,v,w;
    for(int i=1;i<n;i++){
        for(u=1;u<=n;u++){
            for(int k=0;k<adj[u].size();k++){
                v=adj[u][k],w=wt[u][k];
                if(dist[u]!=maxd && dist[u]+w<dist[v]){
                    dist[v]=dist[u]+w;
                }
            }
        }
    }
    int res=dist[n];
    for(int i=1;i<n;i++){
        for(u=1;u<=n;u++){
            for(int k=0;k<adj[u].size();k++){
                v=adj[u][k],w=wt[u][k];
                if(dist[u]!=maxd && dist[u]+w<dist[v]){
                    dist[v]=dist[u]+w;
                }
            }
        }
    }
    if(dist[n]!=res) return -1;
    return max(-res,0);
}

int main(){
    cin>>n>>m>>p;
    int u,v,w;
    for(int i=1;i<=m;i++){
        cin>>u>>v>>w;
        adj[u].push_back(v);
        wt[u].push_back(-w+p);
    }
    cout<<bellmanford()<<"\n";
    return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a[] = new long[n];
        long sum[] = new long[n+1];
        sum[n] = 0;
        for(int i=0; i<n; i++){
            a[i] = sc.nextLong();
            if(i==0){
                sum[0] = a[0];
            }else{
                sum[i] = sum[i-1] + a[i];
            }
        }
        sc.close();

        Arrays.sort(sum);

        long ans = 0;

        int same = 1;
        for(int i=1; i<n+1; i++){
            if(sum[i] == sum[i-1]){
                same++;
            }else{
                if(same > 1){
                    ans += (long)same * (long)(same-1) / 2;
                    same = 1;
                }
            }
        }
        if(same > 1){
            ans += (long)same * (long)(same-1) / 2;
        }

        System.out.println(ans);

    }
}

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

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")   */


//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 5e5 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 2e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

int fact[N], ofact[N];

int step (int x, int st) {
    if (st == 0) return 1;
    int k = step(x, st / 2);
    k *= k; k %= MOD;
    if (st % 2) k *= x;
    k %= MOD;
    return k;
}

signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k, tek = 1;
    cin >> n >> k;
    k = min(n - 1, k);
    for (int i = 0; i <= n; i++) {
        if (i != 0) tek = (tek * i) % MOD;
        fact[i] = tek, ofact[i] = step(tek, MOD - 2);
    }
    int ans = 0;
    for (int i = 0; i <= k; i++) {
        int x = ((fact[n] * ofact[i]) % MOD * ofact[n - i]) % MOD;
        int y = ((fact[n - 1] * ofact[i]) % MOD * ofact[n - i - 1]) % MOD;
        ans += (x * y) % MOD;
        ans %= MOD;
    }
    cout << ans;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    int N;
    cin >> N;
    vector<int> W(N);
    for (auto &i : W) {
        cin >> i;
    }

    int ans = (int)1E9;
    REP(i, N) {
        int sum1 = 0, sum2 = 0;
        REP(j, i) { sum1 += W[j]; }
        FOR(j, i, N) { sum2 += W[j]; }
        chmin(ans, abs(sum1 - sum2));
    }

    std::cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
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;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll a, b, c;
  cin >> a >> b >> c;

  if(a*c <= b) cout << c << endl;
  else cout << b / a << endl;

  return 0;
}

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

using namespace std;

int func(int v[9], int n){
	
	int k, index, vv[9];
	
	index = 0;
	
	for(int i=0; i<9; i++){
		vv[i] = v[i];
	}
	
	for(int i=0; i<5; i++){
		k = 0;
		if(i != n){
			while(vv[index] == 0) index++;
			if(vv[index] > 4) return 1;
			if(vv[index] >= 3) vv[index] -= 3;
			else if(index < 7 && vv[index + 1] != 0 && vv[index + 2] != 0){
				vv[index]--;
				vv[index + 1]--;
				vv[index + 2]--;
			}
			else return 1;
		}
		else{
			while(vv[index] == 0) index++;
			if(vv[index] >= 2) vv[index] -= 2;
			else return 1;
		}
	}
	
	return 0;
	
}

int main(){

	int cnt;
	int v[9] = {};
	string str; 

	while(cin >> str){
		cnt = 0;
	
		fill(v, v+9, 0);
		for(int i=0; i<13; i++){
			v[str[i] - '0' - 1]++;
		}

		for(int i=0; i<9; i++){
			v[i]++;
			if(v[i] < 5){
			
				for(int j=0; j<5; j++){
					if(func(v, j) == 0){
						if(cnt != 0) cout << " " << i + 1;
						else cout << i + 1;
						cnt++;
						break;
					}
				}
		
			}
			v[i]--;
		}
		if(cnt == 0) cout << 0;
		cout << endl;
	}

	return 0;

}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define D 1000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.14159265358979323
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"

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

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;
    x = x % p; 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 

int main() 
{
    FAST;
    ll n;
    cin>>n;
    ll a,b;
    map<pair<ll,ll>,ll> m;
    set<pair<ll,ll>> s;
    ll y=0;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        if(a==0 && b==0)
        {
            y++;
            continue;
        }
        if(a!=0 && b==0)
            a=1;
        if(a==0 && b!=0)
            b=1;
        if(a!=0 && b!=0)
        {
            ll x=gcd(a,b);
            a=a/x;
            b=b/x;
            if(b<0)
            {
                a=-1*a;
                b=-1*b;
            }
        }
        m[{a,b}]++;
        s.insert({a,b});
    }
    ll ans=1;
    while(s.size()!=0)
    {
        auto i=s.begin();
        pair<ll,ll> p=(*i),q=p;
        q.first=(-1)*p.second;
        q.second=p.first;
        if(q.second<0)
        {
            q.first*=-1;
            q.second*=-1;
        }
        if(q.first==0 && q.second!=0)
            q.second=1;
        if(q.first!=0 && q.second==0)
            q.first=1;
        ans=(ans*(power(2,m[p],A)+power(2,m[q],A)-1))%A;
        s.erase(p);
        s.erase(q);
    }
    ans=(ans+y-1)%A;
    ans=ans+A;
    ans%=A;
    cout<<ans;
    subt;
    return 0;
}

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

using namespace std;

#define int double//long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = DBL_MAX/3;//1LL << 55;
const int mod = 1e9 + 7;

struct edge
{
  int to, cost;
  edge(){}
  edge(int to, int cost):to(to), cost(cost){}
};

vector< vector<edge> > graph;
vector< vector<int> > mincost, routes;

int dijkstra(int s)
{
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  mincost[s][s] = 0; routes[s][s] = 1;
  while(!que.empty()) {
    int cost, now;
    tie(cost, now) = que.top(); que.pop();
    if(mincost[s][now] < cost) continue;
    for(edge& e : graph[now]) {
      if(cost + e.cost < mincost[s][e.to]) {
	mincost[s][e.to] = cost + e.cost;
	routes[s][e.to] = routes[s][now];
	que.push(P(mincost[s][e.to], e.to));
      } else if(cost + e.cost == mincost[s][e.to]) {
	routes[s][e.to] += routes[s][now];
      }
    }
  }
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, m, p;
  while(cin >> n >> m >> p, n) {
    graph.clear(); graph.resize(n);
    while(m--) {
      int a, b, c;
      cin >> a >> b >> c;
      graph[a].push_back(edge(b, c));
      graph[b].push_back(edge(a, c));
    }
    mincost.clear(); mincost.resize(n, vector<int>(n, inf));
    routes.clear(); routes.resize(n, vector<int>(n, 0));
    rep(i, n) dijkstra(i);
    while(p--) {
      int c; cin >> c;
      if(mincost[0][c] + mincost[c][n-1] == mincost[0][n-1]) {
	cout << (double)routes[0][c]*routes[c][n-1] / routes[0][n-1] << endl;
      } else {
	cout << 0 << endl;
      }
    }
    cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    int a; cin >> a;
    int b; cin >> b;
    int c; cin >> c;
    cout << max(0, b+c - a) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner; 
 public class Main {
   public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            int d = a/b;
            int r = a%b;
            double f = (double)a/b;
             System.out.println(d+" "+r+" "+String.format("%.5f",f));
   }
 }


Measured memory_bytes: 26648
#include<stdio.h>
int main (void){

int a;
int b;

scanf("%d %d",&a,&b);

if(a<b){
printf("a < b\n");
}

if(a>b){
printf("a > b\n");
}

if(a==b){
printf("a == b\n");
}

return 0;
}


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


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

#define INF bit(60)

#define DBGP 1


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

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

typedef pair<li, li> PI;

PI a[100100];

int main() {
    li n;
    cin >> n;
    rin{
        cin >> a[i].F;
        a[i].S = i;
    }
    sort(a, a + n);
    rin{
        cout << a[i].S + 1 << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <queue>
using namespace std;
int n,m,i,j,a[1005][1005];
int maxi;
char x;
struct now
{
    int x,y,len;
    now(int x, int y, int len)
    {
        this->x=x;
        this->y=y;
        this->len=len;
    }
};
queue <now> q;
int main()
{
    cin>>n>>m;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
    {
        cin>>x;
        if(x=='#')
            q.push(now(i,j,0));
    }
    while(!q.empty())
    {
        auto poz = q.front();
        if(poz.x<1 || poz.x>n || poz.y<1 || poz.y>m || a[poz.x][poz.y]==1)
        {
            q.pop();
            continue;
        }
        a[poz.x][poz.y]=1;
        maxi=poz.len;
        q.push(now(poz.x+1, poz.y, poz.len+1));
        q.push(now(poz.x-1, poz.y, poz.len+1));
        q.push(now(poz.x, poz.y+1, poz.len+1));
        q.push(now(poz.x, poz.y-1, poz.len+1));
        q.pop();
    }
    cout<<maxi;
    return 0;
}


Measured memory_bytes: 53832
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
const ll M=2e5+5,LG=19,SM=600+5,inf=1e18+1;
ll mod=1e9+7;

ll n;
ll a[3*M];

int main()
{
	ios::sync_with_stdio(0);
    cin >> n;
    For(i,0,3*n)
    {
        cin >> a[i];
    }
    ll res=0;
    sort(a,a+3*n);
    For(i,0,n)
    {
        res+=a[2*i+n];
    }
    RET(res);        
}    

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

int N, a[100100][3], dp[100100][3], ans;

int f(int n, int d) {
	if (n==0) return 0;
	if (dp[n][d] != -1) return dp[n][d];
	dp[n][d] = 0;
	for(int i=0; i<3; i++)
		if (i!=d)
			dp[n][d] = max(dp[n][d], f(n-1, i) + a[n][i]);
	return dp[n][d];
}

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

Measured memory_bytes: 10368
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n=N()
l=LL(n)
l.sort()
if n%2==1:
    a,b=l[n//2]
    l.sort(key=lambda x:x[1])
    c,d=l[n//2]
    print(d-a+1)
else:
    l.sort()
    a,_=l[n//2-1]
    b,_=l[n//2]
    l.sort(key=lambda x:x[1])
    _,c=l[n//2-1]
    _,d=l[n//2]
    print(c+d-a-b+1)

Measured memory_bytes: 48916
#include <bits/stdc++.h>  
using namespace std;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
using ll = long long int;
 
int main() {
  ll n;
  cin>> n;
  vector<ll> v(n);
  rep(i,n){cin >> v[i];}
  ll stock = 0;
  ll money = 1000;
  rep(i, n - 1){
 
    if(v[i] < v[i + 1]){
      if(stock == 0){
        stock = money / v[i];
        money = money % v[i];
      }
    }
    
    if(v[i] >= v[i + 1]){
      money += stock * v[i];
      stock = 0;
    }
    //cout << money << " " << stock << endl;
  }
  if(stock > 0){money = money + stock * v[n - 1];}
  cout<< money <<endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h> 
using namespace std;
const int N = 6000 + 5;

int main()
{
	int n;
	cin >> n;
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		int x;
		cin >> x;
		if(i % 2 == 1 && x % 2 == 1)
			cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3620
n=gets.to_i
s=[]
n.times do
  s << gets.chomp.chars.sort.join
end
s.sort!
a=0
c=1
(n-1).times do |i|
  if s[i+1]==s[i]
    c+=1
  else
    a+=c*(c-1)/2
    c=1
  end
end
a+=c*(c-1)/2
puts a


Measured memory_bytes: 24040
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = int.Parse(ReadLine());
        var a = ReadLine().Split().Select(int.Parse).ToArray();
        Sort(a);

        WriteLine(a[a.Length - 1] - a[0]);
    }
}



Measured memory_bytes: 19036
#include <iostream>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for(int (i) = (0); (i) < (n); (i)++)
//#define int long long
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>

using namespace std;

int main(){
  int N, P, ans = 0;
  cin >> N;
  int mini = 1e9;//1e9 == 10 ^ 9

  rep(i, N){
    cin >> P;
      if(mini >= P)ans++;
    mini = min(mini, P);
  }

  cout << ans << endl;
  //int N;
  //cin >> N;
  //vint P[1000000];
  //
  //int norm = 0;
  //rep(i, N){
  //  cin >> P[i];
  //  if(i = 0)norm++;
  //  else if(P[i])
  //}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 int n;
 cin>>n;
 vector<int> h(n);
 for(int i=0;i<n;i++) cin>>h[i];
 int runmax=h[0];
 int ans=1;
 for(int i=1;i<n;i++){
  if(h[i]>=runmax){
   ans++;
   runmax=h[i];
  }
 }
 cout<<ans<<endl;
 return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Something on It
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int N = 3;

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int sum = 700;
  for (int i = 0; i < N; i++)
    if (s[i] == 'o') sum += 100;

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


Measured memory_bytes: 256
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

int main() {
    FAST;
    ll n; cin >> n;
    ll ans = 0;
    map<ll, ll> m;
    for (ll i = 0; i < n; i++) {
      ll t; cin >> t;
      ans += m[i - t];
      m[i + t]++;
    }
    cout<<ans<<endl;
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 33292
N, x = map(int, input().split())
a_list = list(map(int, input().split()))

count = 0

if a_list[0] > x:
  count += a_list[0] - x
  a_list[0] = x

for i in range(1, N):
  if a_list[i] + a_list[i-1] > x:
    tmp = x - a_list[i-1]
    count += a_list[i] - tmp
    a_list[i] = tmp

print(count)

Measured memory_bytes: 14472
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	vector<vector<int>> grid_info(3, vector<int>(3, 0));

	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> grid_info[i][j];
		}
	}

	int dig = 0;
	for (int i = 0; i < 3; i++)
	{
		dig += grid_info[i][i];
	}

	int row[3];
	for (int i = 0; i < 3; i++)
	{
		int row_sum = 0;
		for (int j = 0; j < 3; j++)
		{
			row_sum += grid_info[i][j];
		}
		row[i] = row_sum;
	}

	int col[3];
	for (int i = 0; i < 3; i++)
	{
		int col_sum = 0;
		for (int j = 0; j < 3; j++)
		{
			col_sum += grid_info[j][i];
		}
		col[i] = col_sum;
	}

	if (dig * 3 == row[0] + row[1] + row[2] && dig * 3 == col[0] + col[1] + col[2])
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
# 入力
N = int(input())
count_list = []
# 計算
for i in range(N):
    r = i + 1
    count = 0
    while r % 2 == 0:
        r = r / 2
        count += 1
    else:
        count += 0
    count_list.append(count)

M = max(count_list)
l = count_list.index(M)
print(l + 1)





Measured memory_bytes: 2940
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int N = 1e6+10, S = N-2, T = N-1, INF = 0x3f3f3f3f;
const int M = 1e7+10;
int n, m, f[M];
struct edge {
    int to,w,next;
    edge(int to=0,int w=0,int next=0):to(to),w(w),next(next){}
} e[N];
int head[N], dep[N], vis[N], cur[N], cnt=1;
queue<int> Q;
int bfs() {
    REP(i,1,m) dep[i]=INF,vis[i]=0,cur[i]=head[i];
    dep[S]=INF,vis[S]=0,cur[S]=head[S];
    dep[T]=INF,vis[T]=0,cur[T]=head[T];
    dep[S]=0,Q.push(S);
    while (Q.size()) {
        int u = Q.front(); Q.pop();
        for (int i=head[u]; i; i=e[i].next) {
            if (dep[e[i].to]>dep[u]+1&&e[i].w) {
                dep[e[i].to]=dep[u]+1;
                Q.push(e[i].to);
            }
        }
    }
    return dep[T]!=INF;
}
int dfs(int x, int w) {
    if (x==T) return w;
    int used = 0;
    for (int i=cur[x]; i; i=e[i].next) {
        cur[x] = i;
        if (dep[e[i].to]==dep[x]+1&&e[i].w) {
            int f = dfs(e[i].to,min(w-used,e[i].w));
            if (f) used+=f,e[i].w-=f,e[i^1].w+=f;
            if (used==w) break;
        }
    }
    return used;
}
int dinic() {
    int ans = 0;
    while (bfs()) ans+=dfs(S,INF);
    return ans;
}
void add(int u, int v, int w) {
    e[++cnt] = edge(v,w,head[u]);
    head[u] = cnt;
    e[++cnt] = edge(u,0,head[v]);
    head[v] = cnt;
}

int chk(int x) {
	if (x<=2) return 0;
	int mx = sqrt(x+0.5);
	REP(i,2,mx) if (x%i==0) return 0;
	return 1;
}
int main() {
	scanf("%d", &n);
	REP(i,1,n) { 
		int t;
		scanf("%d", &t);
		f[t] = 1;
	}
	vector<pii> A, B;
	REP(i,1,M-1) if (f[i]!=f[i-1]) {
		if (i&1) A.pb(pii(i,++m)),add(S,m,1);
		else B.pb(pii(i,++m)),add(m,T,1);
	}
	for (auto t:A) for (auto tt:B) { 
		if (chk(abs(t.x-tt.x))) {
			add(t.y,tt.y,1);
		}
	}
	int flow = dinic();
	int ans = flow, x = A.size()-flow, y = B.size()-flow;
	ans += x/2*2, x %= 2;
	ans += y/2*2, y %= 2;
	if (x) ans += 3;
	printf("%d\n", ans);
}









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

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

	sort(a.begin(), a.end());
	if (a[0] >= 3200) {
		cout << 1 << ' ' << n << endl;
		return 0;
	}

	int count[9];
	for (int i = 0;i < 9;i++) {
		count[i] = 0;
	}
	for (int i = 0;i < n;i++) {
		if (a[i] >= 3200) {
			count[8]++;
		}
		else {
			count[a[i] / 400]++;
		}
	}
	int mi = 0;
	for (int i = 0;i < 8;i++) {
		if (count[i] > 0) {
			mi++;
		}
	}
	cout << mi << ' ' << mi + count[8] << endl;



	return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;


int main() {
	int n,a,ans=0;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a;
		while(!(a%2)){
			ans++;
			a/=2;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
//Code By CXY07
#include<bits/stdc++.h>
using namespace std;

#define ONLINE_JUDGE
//#define int long long
const int MAXN = 1;
const int INF = 2e9;
const int mod = 1e9 + 7;

int n;

template<typename T> inline void read(T &a) {
	a = 0; char c = getchar(); int f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') {a = a * 10 + (c ^ 48); c = getchar();}
	a *= f;
}

signed main () {
#ifndef ONLINE_JUDGE
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	for(register int i = 1,x;i <= 5; ++i)  {
		read(x);
		if(!x) cout << i << endl;
	}
	return 0;
}


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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    string s;
    cin >> s;
    
    bool flag = false;
    rep(i,s.size())
    {
        if( s[i] == 'C' ) flag=true;
        if( s[i] == 'F' && flag )
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

int main() {
	string s; int K; cin >> s >> K;
	for(int i=0; i<s.size(); ++i){
	    if(i+1<s.size()){
	        if('z'-s[i]<K && s[i]!='a'){
	            K -= ('z'-s[i])+1;
	            s[i]='a';
	        }
	    }
	    else s[i]='a'+(s[i]-'a'+K)%26;
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void)
{

int n, m;

scanf("%d %d", &n, &m);

if(n == m){
printf("%d\n", (n - 1) * (n - 1));
} else if(n < m) { 
printf("%d\n", (n - 1) * (n - 1) + (m - n) * (n - 1));
} else if(m < n){
printf("%d\n", (m - 1) * (m - 1) + (n - m) * (m - 1));
}

    return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

int main() {
int N, Q;
string S;
cin >> N >> Q >> S;
VP lr(Q); rep(i, 0, Q) scanf("%d %d", &lr[i].first, &lr[i].second);

// 累積和
VI acc(N+1, 0);
for (int i = 1; i < N+1; ++i){
    if (S.substr(i-1, 2) == "AC") acc[i+1] = acc[i] + 1;
    else acc[i+1] = acc[i];
}

rep(i, 0, Q){
    printf("%d\n", acc[lr[i].second] - acc[lr[i].first] );
    // cout << acc[lr[i].second] - acc[lr[i].first] << "\n";
}

return 0;
}

// 境界，出力文字列 チェック
// int は ± 2*10⁹.
// map[]は対数時間．unordered_map[]は一定時間．


Measured memory_bytes: 2176
/* 2017.3.18 Celicath */
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stdint.h>
#include <queue>

int nums[6000];
std::set<int> set;
int main()
{
	int N, K;
	scanf("%d %d", &N, &K);

	for (int i = 0; i < N; i++)
		scanf("%d", nums + i);

	std::sort(nums, nums + N);

	int knot = N;
	set.clear();
	set.insert(0);
	for (int i = N-1; i >= 0; i--)
	{
		std::set<int> temp;
		for (auto a : set)
		{
			int next = a + nums[i];
			if (next >= K)
				knot = i;
			else temp.insert(next);
		}
		for (auto a : temp)
			set.insert(a);
	}

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


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<ll>A(N),B(N);
  for(int i=0;i<N;i++)cin>>A[i]>>B[i];
  ll b=0;
  for(int i=N-1;i>=0;i--){
    ll d=(A[i]+b)%B[i];
    d=(B[i]-d)%B[i];
    b+=d;
  }
  cout<<b<<endl;
  return 0;
}


Measured memory_bytes: 1792
def main():
    H, N = map(int, input().split())
    AB = [tuple(map(int, input().split())) for i in range(N)]

    dp = [-1]*(H+1)
    dp[H] = 0

    for i in range(H, 0, -1):
        for a, b in AB:

            if dp[i] >= 0:
                next = max(i-a, 0)
                if dp[next] < 0:
                    dp[next] = dp[i] + b
                else:
                    if dp[next] > dp[i] + b:
                        dp[next] = dp[i] + b

    print(dp[0])
main()

Measured memory_bytes: 40832
if __name__ == "__main__":
    N = int(input())
    b = list(map(int, input().split()))

    ans = list()

    for i in reversed(range(N)):
        for j in reversed(range(i+1)):
            if b[j] is j+1:
                ans.append(b[j])
                b.pop(j)
                break

            if j is 0:
                print(-1)
                exit()
    for i in reversed(range(N)):
        print(ans[i])


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		int c = 0;
		for(int i = 1; i <= n; i++)
		{
			for(int j = i+1; j <= n; j++)
			{
				if(n%2==0)
				{
					if(i+j==n+1)continue;
				}
				else
				{
					if(i+j==n)continue;
				}
				c++;
				sb.append(i + " " + j + "\n");
//				System.out.println(i + " " + j);
			}
		}
		System.out.println(c);
		System.out.print(sb);


	}

}


Measured memory_bytes: 22100
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
using namespace std;
const long long N = 1000 * 1000;
const long long mod = 1000 * 1000 * 1000 + 7;
long long f[N];
long long k = 0, d[N];
vector<long long> primes;

typedef vector<long long> vi;

long long binpow(long long a, long long n) {
    if (n == 0)
        return 1;
    if (n % 2 == 1)
        return (binpow(a, n - 1) * a) % mod;
    else {
        long long b = binpow(a, n / 2);
        return (b * b) % mod;
    }
}

inline vi getFact(long long n)
{
    long long m = sqrt(n) + 2;
    vi ans(primes.size());
    for (auto p : primes) {
        long long k = 1;
        long long pp = p;
        if (p > 900 * 1000)
            long long a = 2;
        while (n / pp != 0) {
            ans[d[p]] += n / pp;
            pp *= p;
        }
    }
    return ans;
}

const long long INF = 2 * 1000 * 1000 * 1000;

inline vi multi(vi a, vi b)
{
    vi c(a.size());
    for (long long i = 0; i != a.size(); ++i)
        c[i] = a[i] + b[i];
    return c;
}

inline vi div(vi a, vi b)
{
    vi c(a.size());
    for (long long i = 0; i != a.size(); ++i)
        c[i] = a[i] - b[i];
    return c;
}

inline long long getLL(vi& a)
{
    long long s = 1;
    for (long long i = 0; i != a.size(); ++i)
        s = (s * binpow(primes[i], a[i])) % mod;
    return s;
}

inline long long comb(long long n, long long k)
{
    if (k == 0 || k == n)
        return 1;
    auto a = getFact(n);
    auto b = getFact(k);
    auto c = getFact(n - k);
    a = div(a, b);
    a = div(a, c);
    return getLL(a);
}

int main()
{
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n = 1000 * 1000;
    vector<char> prime(n + 1, true);
    prime[0] = prime[1] = false;
    primes.reserve(n + 1);
    for (long long i = 2; i <= n; ++i)
        if (prime[i]) {
            if (i * 1ll * i <= n)
                for (long long j = i * i; j <= n; j += i)
                    prime[j] = false;
            d[i] = k++;
            primes.push_back(i);
        }
    long long x, y;
    cin >> x >> y;
    if ((x + y) % 3) {
        cout << "0\n";
        return 0;
    }
    long long k = (x + y) / 3;
    if (k > x || k > y) {
        cout << "0\n";
        return 0;
    }
    long long a = x - k;
    cout << comb(k, a);
    return 0;
}

Measured memory_bytes: 15744
#include <bits/stdc++.h>
using namespace std;
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;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int D;
  cin>>D;

  const int A = 26;
  vector<int> cs(A+1);
  for(int j=1;j<=A;j++) cin>>cs[j];

  vector s(D+1,vector<int>(A+1));
  for(int i=1;i<=D;i++)
    for(int j=1;j<=A;j++)
      cin>>s[i][j];

  vector<int> ts(D+1);
  for(int i=1;i<=D;i++) cin>>ts[i];

  auto calcScore=[&](){
    int res=0;
    vector<int> ls(A+1,0);
    for(int i=1;i<=D;i++){
      res+=s[i][ts[i]];
      ls[ts[i]]=i;
      for(int j=1;j<=A;j++)
        res-=cs[j]*(i-ls[j]);
      cout<<res<<newl;
    }
  };

  calcScore();
  return 0;
}


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

int main() {
  int N;
  int S,H,T,O;
  cin >> N;

  S=N/1000;
  H=N%1000/100;
  T=N%100/10;
  O=N%10;
  
  if ((S == H && H == T) || (H == T && T == O)) 
    cout << "Yes" << endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
/**
 *    +--+--+--++--++--In the name of ALLAH--++--++--+--+--+
 *
 *    author:  skmonir
 *    created: 11-Jul-2020 18:00:58
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define len(x)              (int) x.size()
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void INT(T &n) {
    n = 0; int f = 1; int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void INT(T &x, W &y) {INT(x), INT(y);}
template <TN T, TN W, TN Q> inline void INT(T &x, W &y, Q &z) {INT(x, y), INT(z);}

const int N = 1e5 + 7;
const int inf = 1e9 + 7;


int solve() {
    int l, r, d; cin >> l >> r >> d;

    int res = (r / d) - ((l - 1) / d);

    cout << res << endl;

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0;
    // INT(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}


int main() {
	int a = ri();
	int64_t b, n;
	std::cin >> b >> n;
	
	auto calc = [&] (int64_t x) {
		return a * x / b - a * (x / b);
	};
	
	int64_t res = 0;
	
	if (b <= 10000) {
		for (int i = 1; i < b && i <= n; i++) res = std::max(res, calc(i));
	} else {
		for (int i = 1; ; i++) {
			int64_t x = (b * i - 1) / a + 1;
			if (x > n) break;
			res = std::max(res, calc(x));
		}
	}
	printf("%" PRId64 "\n", res);
	return 0;
}


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

int main(){
	
	int n,a;cin>>n>>a;
	
	cout<<n*n-a<<endl;
	
	return 0;
}

//cout << ans?"Yes":"No" << endl;

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
using pii = std::pair<int, int>;
#define SORT(v) std::sort(v.begin(), v.end())

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M,ans=0, count = 0,temp=0;
	
	cin >> N;
	vector<long long> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		if (a[i] % 4 == 0) {
			count++;
		}
		else if (a[i] % 4 == 2) {
			temp++;
			if (temp == 2) { count++, temp = 0; }
		}
	}
	if (count >= N / 2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
	
	int a,b,c,d;
	scanf("%d",&a);
	
	b=a/100;
	c=(a-b*100)/10;
	d=a%10;
	
	if(b==1)b=9;
	else b=1;
	
	if(c==1)c=9;
	else c=1;
	if(d==1)d=9;
	else d=1;
	
	printf("%d\n",b*100+c*10+d);
	return 0;
}


Measured memory_bytes: 128