akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll,pair<ll, ll>> lpll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

#define deg_to_rad(deg) (((deg)/360)*2*PI)

const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;

const ld PI = (acos(-1));
const ld EPS = 0.0000000001;
// cout << fixed << setprecision(10) << middle << endl;

int main() {
    // input, ready
    int N,K;
    cin >> N >> K;
    vector<pll> sushi(N);
    for (int i=0; i<N; i++) {
        ll t,d;
        cin >> t >> d;
        sushi[i] = {d,t};
    }
    sort(sushi.begin(),sushi.end());
    reverse(sushi.begin(),sushi.end());
    map<ll,ll> sushi_type;

    //resolve
    ll ans=0;
    priority_queue<pll, vector<pll>, greater<pll>> pq;
    for (int i=0; i<K; i++) {
        pll st = sushi[i];
        ans += st.first;
        if (sushi_type[st.second]>0) pq.push(st);
        sushi_type[st.second]++;
    }
    ans += pow(sushi_type.size(),2);

    ll tmp = ans;
    for (int i=K; i<N; i++) {
        if (pq.size() == 0) break;
        if (sushi_type[sushi[i].second]>0) continue;
        auto st = pq.top(); pq.pop();
        tmp -= st.first;
        tmp -= pow(sushi_type.size()-1,2);
        //cout << tmp << endl;
        tmp += sushi[i].first;
        sushi_type[sushi[i].second]++;
        tmp += pow(sushi_type.size(),2);
        ans = max(ans,tmp);
        //cout << tmp << endl;
    }

    // output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6648
a = input().split()
b = input().split()

K=int(a[0])
N=int(a[1])

#print(K, N)

b = [int(s) for s in b]

c=0
d=[]
for i in b:
  #print(i-c)
  d.append(i-c)
  c=i
d[0]=d[0]+K-b[N-1]
#print(d)
print(K-max(d))

Measured memory_bytes: 26444
#include<iostream>
#include<string>
using namespace std;
class Dice{
public:
	int dice[6];
	int getAns(){
		return dice[0];
	}
	int getAns2(){
		return dice[1];
	}
	int getAns3(){
		return dice[2];
	}
	void input(){
		for (int i = 0; i < 6; i++){
			cin >> dice[i];
		}
	}
	void moveS(){
		int dice2[6];
		int index_list[6] = { 4, 0, 2, 3, 5, 1 };
		for (int i = 0; i < 6; i++){
			int idx = index_list[i];
			dice2[i] = dice[idx];
		}
		for (int i = 0; i < 6; i++){
			dice[i] = dice2[i];
		}
	}
		void moveE(){
			int dice2[6];
			int index_list[6] = { 3,1, 0, 5,4, 2 };
			for (int i = 0; i < 6; i++){
				int idx = index_list[i];
				dice2[i] = dice[idx];
			}
			for (int i = 0; i < 6; i++){
				dice[i] = dice2[i];
			}
		}
		void moveX(){
			int dice2[6];
			int index_list[6] = {0,3,1,4,2,5};
			for (int i = 0; i < 6; i++){
				int idx = index_list[i];
				dice2[i] = dice[idx];
			}
			for (int i = 0; i < 6; i++){
				dice[i] = dice2[i];
			}
		}
		
};
int main(){
	Dice dice;
	dice.input();
	int q,a,b;
	cin >> q;
	for (int i = 0; i < q; i++){
		cin >> a >> b;
		for (int j = 0; j < 4; j++){
			if (dice.getAns() == a)break;
			dice.moveS();
		}
		for (int k = 0; k < 4; k++){
			if (dice.getAns() == a)break;
			dice.moveE();
		}
		for (int l = 0; l < 4; l++){
			if (dice.getAns2() == b)break;
			dice.moveX();
		}
		cout << dice.getAns3() << endl;
	}
	return 0;
}

Measured memory_bytes: 3116
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
string t[4] = {"maerd", "remaerd", "esare", "resare"};

int main()
{
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    while(!s.empty()){
        bool flag = false;
        rep(i, 4)
        {
            string str;
            str=s.substr(0, t[i].size());
            if(str==t[i]){
                s.erase(0, t[i].size());
                //cout << s << endl;
                flag = true;
            }
        }
        if(!flag){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
int sum[200005];
vector<int> adj[200005];

void dfs(int a,int b) {
    sum[a]+=sum[b];
    for (auto i : adj[a]) {
        if (i != b) dfs(i, a);
    }
}
int32_t main(){
    boost;
    int n,q;
    cin>>n>>q;
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    memset(sum,0,sizeof(sum));
   for(int i=0;i<q;i++){
        int x,y;
        cin>>x>>y;
        sum[x]+=y;
    }
    dfs(1,0);
    for(int i=1;i<=n;i++){
        cout<<sum[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 24320
import sys
readline = sys.stdin.buffer.readline

w,h,n = map(int,readline().split())

lst1 = [0,w,0,h] #←x,x→,y↓,y↑
for i in range(n):
    x,y,a = map(int,readline().split())
    if a==1 or a==3: #max
        if a==1: #x
            lst1[a-1] = min(lst1[1],max(lst1[a-1],x))
        else: #y
            lst1[a-1] = min(lst1[3],max(lst1[a-1],y))
    
    else:
        if a==2: #x
            lst1[a-1] = max(lst1[0],min(lst1[a-1],x))
        else: #y
            lst1[a-1] = max(lst1[2],min(lst1[a-1],y))

print(w*h
    - lst1[0]*h
    - (w-lst1[1])*h
    - lst1[2]*w
    - (h-lst1[3])*w
    + lst1[0]*lst1[2]
    + lst1[0]*(h-lst1[3])
    + (w-lst1[1])*lst1[2]
    + (w-lst1[1])*(h-lst1[3])
     )


Measured memory_bytes: 38256
# C - Build Stairs

n = int(input())
h = list(int(x) for x in input().split())

ans = 'Yes'
flg = 0 #下がった状態フラグ
for i in range(1, n):
    # 2段以上下がってる場合
    if h[i-1]-h[i]>1:
        ans = 'No'
        break
    if h[i-1]-h[i]==1:
        if flg==0:
            flg = 1
        else:
            ans = 'No'
            break
    if h[i-1]-h[i]<0:
        flg = 0

print(ans)


Measured memory_bytes: 15020
#include <cstdio>
const int MAXN=2E5+10;
typedef long long LL;
LL mod;
LL powi(LL a,LL b) {
	LL ans=1;
	while(b) {
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}return ans;
}
LL inv(LL x) {
	return powi(x,mod-2);
}
LL tong[MAXN],a[MAXN];
int main() {
	LL n;scanf("%lld%lld",&n,&mod);
	for(int i=1;i<=n;++i) {
		scanf("%1lld",&a[i]);
	}
	if(mod==2 || mod==5) {
		LL ans=0;
		for(int i=1;i<=n;++i) {
			if(a[i]%mod==0) {
				ans+=i;
			}
		}printf("%lld\n",ans);
	}else {
		LL hx=0,pi=1,inv10=inv(10),ans=0;
		tong[hx]++;
		for(int i=1;i<=n;++i) {
			hx=(hx*10+a[i])%mod;
			pi=pi*inv10%mod;
			ans+=tong[hx*pi%mod];
			tong[hx*pi%mod]++;
		}printf("%lld\n",ans);
	}
	return 0;
} 

Measured memory_bytes: 3364
#include <bits/stdc++.h>
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define f first
#define s second
using namespace std;
int h,w;
const int MOD = 1e9+7;
int memo[1002][1002];
bool grid[1002][1002];
int solve(int i, int j){
    if(i==h-1 && j==w-1)
        return 1;
    int &res = memo[i][j];
    if(res != -1)
        return res;
    res = 0;
    if(i+1< h && grid[i+1][j])
        res = solve(i+1, j)%MOD;
    if(j+1<w && grid[i][j+1])
        res = (res+solve(i, j+1))%MOD;
    return res;
}
int main() {
    IO;
    memset(memo, -1, sizeof memo);
    cin >> h >> w;
    for(int i = 0; i < h; ++i)
        for(int j = 0; j < w; j++){
            char c;
            cin >> c;
            if(c=='#')
                grid[i][j] = 0;
            else
                grid[i][j] = 1;
        }
    cout << solve(0, 0);
    return 0;
}


Measured memory_bytes: 5248
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 100005
#define PI 	3.14159265358979323846

int main()
{
	cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,T;
    cin >> N >> T;
    ll c,t;
    ll ans = INF;
    REP(i,N){
        cin >> c >> t;
        if(t<=T){
            ans = min(ans,c);
        }
    }
    if(ans == INF){
        cout << "TLE" << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  int data[N];
  rep(i,N){
	cin >> data[i];
  }
  sort(data,data+N,greater<int>());
  double sum = 0;
  rep(i,N-1){
	sum += (double)data[i]/pow(2,i+1);
  }
  sum += data[N-1]/pow(2,N-1);
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	string s;
	cin >> s;
	cout << s.substr(0, 3) << '\n';
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, (b), sizeof(a))
#define fore(i,a) for(int i=0;i<a;i++)
#define fore1(i,j,a) for(int i=j;i<a;i++)
#define print(ar) for(int i=0;i<ar.size();i++)cout<<ar[i]<<" ";
#define END cout<<'\n'
const double pi=acos(-1.0);
 
typedef pair<int, int> PII;
 
typedef vector<long long> VI;
 
typedef vector<string> VS;
 
typedef vector<PII> VII;
 
typedef vector<VI> VVI;
 
typedef map<int,int> MPII;
 
typedef set<int> SETI;
 
typedef multiset<int> MSETI;
 
typedef long int li;
 
typedef unsigned long int uli;
 
typedef long long int ll;
 
typedef unsigned long long int  ull;
ll fastexp (ll a, ll b, ll n) {
  ll res = 1;
  while (b) {
      if (b & 1) res = res*a%n;
      a = a*a%n;
      b >>= 1;
  }
  return res;
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
 {  fast();
	int t, n, k;
	t=1;
	while(t--) {
	    cin >> n;
	    VI arr(n+1);
	     fore(i,n)cin>>arr[i+1];
          int dp[n+1];
           dp[1]=0;
           if(n>1)dp[2]=abs(arr[2]-arr[1]);
            fore1(i,3,n+1){
              dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
                        }
                        cout<<dp[n]<<endl;
	}}

Measured memory_bytes: 1408
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include<set>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*約数*/vector<ll>div(ll a){vector<ll>b;ll i;rep(i,1,a){if(!a%i)push(b,a);}return b;}
llfor;///////////////////////////////////////////////////////////
int main(){
 ll n,k;
 ll r,s,p;
 sc(n);sc(k);sc(r);sc(s);sc(p);
 char t[n+10];
 sc(t);
 ll ans=0;
 bool ok[n+10]={0};
 rep(i,0,n){
  if(i>=k){
   if(ok[i-k]==false&&t[i]==t[i-k]){
    ok[i]=true;
    continue;
   }
  }
  if(t[i]=='r')ans+=p;
  if(t[i]=='s')ans+=r;
  if(t[i]=='p')ans+=s;
 }
 pr(ans);
return 0;}



Measured memory_bytes: 3780
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<62;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;

int main(){
	cin>>n;
	ll res=1,tmp=1;
	for(int i=0;i<n;i++) res*=3;
	for(int i=0;i<n;i++){
		int A;
		cin>>A;
		if(A%2==0) tmp*=2;
	}
	cout<<res-tmp<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.Ia;
		var h=new int[n];
		for(int i = 0;i<n;i++) {
			h[a[i]-1]=i+1;
		}
		Console.WriteLine("{0}",String.Join(" ",h));
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 32988
N = int(input())
T,A = map(int,input().split())
H = [int(i) for i in input().split()]

res = - 1
res_val = 100000
for i in range(N):
    av_temp = T - H[i] * 0.006
    if res_val > abs(av_temp - A):
        res = i
        res_val = abs(av_temp - A)

print(res+1)


Measured memory_bytes: 3064
#include <stdio.h>
#define MAX 100000
#define NIL -1

struct Node{

  int parent;
  int left;
  int right;
};
struct Node t[MAX];
int Depth[MAX];
int n;

void getDepth(int, int);
void printType(int);

int main(){

  int i, d, vec, l=0,  j, r, chi;

  scanf("%d", &n);

  for(i=0; i<n; i++) t[i].parent=t[i].left=t[i].right=NIL;//必要?

  for(i=0; i<n; i++){
    scanf("%d %d", &vec, &d);
    
    for(j=0; j<d; j++){
      scanf("%d", &chi);
      
      if(j==0) t[vec].left=chi;
      else t[l].right=chi; //d!=0
      
      l=chi;
      t[chi].parent=vec;
    }

  }  
  for(i=0; i<n; i++){
    if(t[i].parent==NIL) r=i;
  }
  
  getDepth(r, 0); //error

  for(i=0; i<n; i++){

    printf("node %d: ", i);
    printf("parent = %d, ", t[i].parent); // printParent(i);
    printf("depth = %d, ", Depth[i]);  //printDepth(i);
    printType(i);
  }

  return 0;
}

void getDepth(int x, int p){ //節点xの深さ。親をたどり、根までの長さ

  Depth[x]=p;
  if(t[x].right!=NIL){
    getDepth(t[x].right, p);
  }
  if(t[x].left!=NIL){
    getDepth(t[x].left, p+1);
  }
}
void printType(int i){
  
  int j, child;

  if(t[i].parent==NIL){
    printf("root, ");
    printf("[");
    for(j=0, child=t[i].left; child!=NIL; j++, child=t[child].right){
      if(j) printf(", ");
      printf("%d", child);
    }
    printf("]\n");
  }
  else if(t[i].left==NIL)printf("leaf, []\n");

  else{
    printf("internal node, ");
    printf("[");
    for(j=0, child=t[i].left; child!=NIL; j++, child=t[child].right){
      if(j) printf(", ");
      printf("%d", child);
    }
    printf("]\n");
  }
}



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

using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	int rn[n];
	memset(rn, 0, sizeof rn);
	for (int i = 0; i < m; i++){
		int u, v;
		cin >> u >> v;
		rn[u-1]++;
		rn[v-1]++;
	}
	for (int i = 0; i <  n; i++){
		cout << rn[i] << endl;
	}
	return 0;
}


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const LL INF = 1e18;

LL lpow(LL a, LL b){
  if(!b) return 1;
  return lpow(a*a, b/2) * (b&1?a:1);
}

LL dp[1000100];
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  LL N, A; cin >> N >> A;
  LL ans = 1e18;
  for(int t=1;t<40;++t){
	LL lb = 1, ub = pow(N, 1./t)+3;
	while(ub - lb > 1){
	  LL m = (lb + ub)/2;
	  LL p = lpow(m,t);
	  if(p >= N) ub = m;
	  else lb = m;
	}

	LL prod = 1;
	vector<LL> xs(t);
	REP(i,t)
	  xs[i] = ub, prod *= ub;
	REP(i,t){
	  if(prod / xs[i] * (xs[i] - 1) >= N){
		prod /= xs[i];
		xs[i]--;
		prod *= xs[i];
	  }
	}

	LL sum = 0;
	REP(i,t){
	  sum += xs[i];
	}
	assert(prod >= N);
	ans = min(ans, sum+A*(t-1));
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
import collections
import sys
n,m,k = map(int,sys.stdin.readline().split())
parent = range(0, n+1)
sizes = [1] * (n + 1)
hd = [1] * (n + 1) 

def f(parent, u):
	if parent[u] != u:  parent[u] = f(parent, parent[u])
	return parent[u]

for a,b in [map(int,sys.stdin.readline().split()) for _ in range(m)]:

	pa,pb = f(parent, a), f(parent, b)
	hd[a] +=1
	hd[b] +=1

	if pa != pb:
		if sizes[pa] <= sizes[pb]: pa,pb = pb,pa
		parent[pb] = pa
		sizes[pa] += sizes[pb]
		

for c,d in [map(int,sys.stdin.readline().split()) for _ in range(k)]:
	pc,pd = f(parent, c), f(parent, d)
	if (pc == pd):
		hd[c] += 1
		hd[d] += 1

print ' '.join([str(sizes[f(parent,u)] - hd[u])  for u in range(1, n+1)])

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

long long pow5(long long a){
	return a*a*a*a*a;
}

void tes(){
	long long a=1;
	while (pow5(a)-pow5(a-1)<1000000000) a++;
	cout << a << "\n";
}

long long x;

int main(){
//	tes();
	cin >> x;
	for (long long i=-2000;i<=2000;i++){
		for (long long j=-2000;j<=2000;j++){
			if (pow5(i)-pow5(j)==x){
				cout << i << " " << j <<"\n";
				return 0;
			}
		}
	}
}

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

int main(void){
    int n;
    cin >> n;
    int a[n],ans = 0;
    bool check = true;
    
    for(int i = 0;i < n;i++)cin >> a[i];
    for(int i = 0;i < n-1;i++){
        ans = max(ans,a[i]);
        if(a[i]-1 > a[i+1] || ans-1 > a[i+1])check = false;
    }
    //cout << ans;
    if(check)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
struct card{
    char suit;
    int value;
};
int part (vector<card> &a, int p, int r){
    int xi = p;
    for (int i = p; i < r; i++){
        if (a[i].value <= a[r].value){
            swap(a[i], a[xi]);
            xi++;
        }
    }
    swap(a[xi], a[r]);
    return xi;
}
void quickSort (vector<card> &a, int p, int r){
    int q;
    if (p < r){
        q = part(a, p, r);
        quickSort(a, p, q-1);
        quickSort(a, q+1, r);
    }
}
void merge1(vector<card> &s, int l1, int r1, int l2, int r2){
    int i = l1, j = l2;
    vector<card> temp;
    while (i <= r1 && j <= r2){
        if (s[i].value <= s[j].value){
            temp.push_back(s[i++]);
        }
        else
            temp.push_back(s[j++]);
    }
    while (i <= r1)
        temp.push_back(s[i++]);
    while (j <= r2)
        temp.push_back(s[j++]);
    for (int i = 0; i < temp.size(); i++){
        s[l1++] = temp[i];
    }
    temp.clear();
}
void mergeSort(vector<card> &s, int index_start, int index_end){
    if (index_start < index_end){
        int mid = (index_start + index_end) / 2;
        mergeSort(s, index_start, mid);
        mergeSort(s, mid+1, index_end);
        merge1(s, index_start, mid, mid+1, index_end);
    }
}
int main()
{
    vector<card> a,b;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        card temp;
        cin >> temp.suit;
        cin >> temp.value;
        a.push_back(temp);
    }
    b = a;
    quickSort(a, 0, n-1);
    mergeSort(b, 0, n-1);
    int stable = 1;
    for (int i = 0; i < a.size(); i++){
        if (a[i].suit != b[i].suit){
            stable = 0;
            break;
        }
    }
    if (stable == 0)
        cout << "Not stable" << endl;
    else
        cout << "Stable" << endl;
    for (int i = 0; i < a.size(); i++){
        cout << a[i].suit << " " << a[i].value << endl;
    }
    return 0;
}



Measured memory_bytes: 5792
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;

int main()
{
    int a, b, c, d;
    int ans = 0;
    
    cin >> a >> b >> c >> d;
    
    if(a <= b) {
        ans += a;
    } else {
        ans += b;
    }
    
    if(c <= d) {
        ans += c;
    } else {
        ans += d;
    }
    
    cout << ans << endl;
    
    return 0;
}


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

int main()
{
	int n,h,a,b;
	pair< int, pair<int, int> > p;
	set<pair< int, pair<int, int> > > s;
	string c;
	
	while( cin >> n >> h, (n||h) )
	{
		s.clear();
		
		for(int j = 0; j < h; j++)
		{
			
			cin >> c >> a >> b;
			
			if( c == "xy" )
			{
				for( int i = 1; i <= n; i++)
				{
					p.first = a;
					p.second.first = b;
					p.second.second = i;
					s.insert(p);
				}
			}
			else if( c == "xz" )
			{
				for( int i = 1; i <= n; i++)
				{
					p.first = a;
					p.second.first = i;
					p.second.second = b;
					s.insert(p);
				}
			}
			else if( c == "yz" )
			{
				for( int i = 1; i <= n; i++)
				{
					p.first = i;
					p.second.first = a;
					p.second.second = b;
					s.insert(p);
				}
			}
		}
		
		
		cout << n*n*n - s.size() << endl;
	}
	
	
	return 0;
}

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

using namespace std;

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

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    vp a(6);
    rep(i,6){
        cin >> a[i].first >> a[i].second;
        if(a[i].first > a[i].second)swap(a[i].first,a[i].second);
    }
    sort(all(a));
    if(a[0] != a[1] || a[2] != a[3] || a[4] != a[5]){
        cout << "no" << endl;
    }else{
        if(a[0].first == a[2].first && a[0].second == a[4].first && a[2].second == a[4].second)
            cout << "yes" << endl;
        else 
            cout << "no" << endl;
    }
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;

int to[N << 1],nex[N << 1],beg[N],col[N << 1],vis[N << 1],Vis[N << 1];
int e;

char str[N];

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

inline void add(int x,int y,int z) {
	to[++e] = y,nex[e] = beg[x],beg[x] = e,col[e] = z;
}

inline void dfs(int id,int x) {
	for(int i = beg[x];i;i = nex[i]) {
		if(!vis[i] && col[i] ^ col[id]) {
			vis[i] = Vis[i] = 1;
			dfs(i,to[i]);
			vis[i] = 0;
		}
		else if(vis[i] && col[i] ^ col[id]) {
			puts("Yes");
			exit(0);
		}
	}
}

int main() {

	int n = read(),m = read();
	scanf("%s",str + 1);
	For(i,1,m) {
		int x = read(),y = read();
		int Col = (str[x] == str[y]);
		add(x,y,Col),add(y,x,Col);
	}

	For(i,1,m << 1) if(!Vis[i]) dfs(i,to[i]);

	puts("No");
	return 0;
}

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

using namespace std;

int n,a[100001];

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=n;i>=1;i--)
	{
		if(a[i]-a[i-1]<-1)
		{
		//	cout<<i<<' '<<a[i]<<' '<<a[i-1];
			cout<<"No";
			return 0;
		}
		if(a[i]-a[i-1]==-1)
			a[i-1]--;
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 1000000007  # type: int


def solve(N: int, M: int, a: "List[int]"):

    # 0段目一通り
    dp = [None]*(N+1)
    dp[0] = 1
    for i in a:
        dp[i] = 0
    for i in range(1, N+1):
        # print(i, dp)
        if dp[i] == None:
            b = dp[i-1]
            if i-2 >= 0:
                b += dp[i-2]
                b %= MOD
            dp[i] = b
    print(dp[N])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 7840
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

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

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{a:i64,b:i64,c:i64};
    for i in 1..b+1 {
        if (a*i)%b == c {
            println!("YES");
            return ();
        }
    }
    println!("NO");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

ll gcd(ll a, ll b)
{
	if (a < b) swap(a, b);
	return (a%b ? gcd(a%b, b) : b);
}

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

void extgcd(ll a, ll b, ll& x, ll& y)
{
	if (b != 0) { extgcd(b, a % b, y, x); y -= a / b * x; }
	else { x = 1; y = 0; }
}


int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	ll q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	chmin(h, q * 2);
	chmin(s, h * 2);
	chmin(d, s * 2);
	if (n % 2 == 0) cout << n * d / 2 << endl;
	else cout << min(n / 2 * d + s, n * s) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
 
int main() {
  int x,a;
  cin >> x >> a;
  if(x<a)cout << 0 << endl;
  else cout << 10 << endl;
}



Measured memory_bytes: 256
N = int(input())
A_list = list(map(int, input().split()))

total = sum(A_list)

table = {}
for A in A_list:
	if A in table:
		table[A] += 1
	else:
		table[A] = 1

Q = int(input())
for _ in range(Q):
	B, C = map(int, input().split())
	if B in table:
		count = table[B]
		total -= count * B
		total += count * C
		if C in table:
			table[C] += count
		else:
			table[C] = count
		del table[B]
	print(total)



Measured memory_bytes: 20688
($H, $W) = split / /, <>; @masu;
for (0..$H-1) {
    push @{ $masu[$_] }, split //, <>;
}

for my $h (0..$H-1) {
    for my $w (0..$W-1) {
        next if $masu[$h][$w] eq '#';

        my $bakudan = 0;
        for my $diffh (qw/-1 0 1/) {
            my $dh = $h + $diffh;
            next if ($dh < 0 || $dh > $#masu);

            my @masuh = @{ $masu[$dh] };
            for my $diffw (qw/-1 0 1/) {
                my $dw = $w + $diffw;
                next if ($dw < 0 || $dw > $#masuh);

                $bakudan++ if $masu[$dh][$dw] eq '#';
            }
        }

        $masu[$h][$w] = $bakudan;
    }
}

for (0..$#masu) {
    for my $c (@{ $masu[$_] }) {
        print $c;
    }

    print "\n";
}


Measured memory_bytes: 768
// B - Making Triangle
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

int main(){
	int N; cin>>N;
	vector<int> L(N); rp(i, 0, N) cin>>L[i];
	int c = 0;
	rp(i, 0, N) rp(j, i+1, N){
		if(L[i] == L[j]) continue;
		rp(k, j+1, N){
			if(L[j] == L[k] || L[k] == L[i]) continue;
			if(L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j]) c++;
		}
	}
	cout<< c <<endl;
}


Measured memory_bytes: 3632
#import sys
#input = sys.stdin.readline
def find(A,x):
    p = A[x]
    if p == x:
        return x
    a = find(A,p)
    A[x] = a
    return a
 
def union(A, x, y):
#    bx, by = sorted([find(A,x), find(A,y)]) # bx, by = find(A,x), find(A,y)だと無限ループ。
    if find(A,x) > find(A,y):
        bx, by = find(A,y), find(A,x)
    else:
        bx, by = find(A,x), find(A,y)
    A[y] = bx
    A[by] = bx

def main():
    N = int( input())
    XY = []
    for i in range(N):
        x, y = map( int, input().split())
        XY.append( (x,y,i))
    
    XY.sort(key=lambda x:x[0])
    A = [ i for i in range(N)]
    my = N+1
    myi = N+1
    for x,y,i in XY:
        if y < my:
            my = y
            myi = i
            continue
        union(A, i , myi)
    My = 0
    Myi = N+1
    for x, y, i in XY[::-1]:
        if y > My:
            My = y
            Myi = i
            continue
        union(A, i, Myi)

    XY.sort(key=lambda x:x[1])
    mx = N+1
    mxi = N+1
    for x,y,i in XY:
        if x < mx:
            mx = x
            mxi = i
            continue
        union(A, i , mxi)
    Mx = 0
    Mxi = N+1
    for x, y, i in XY[::-1]:
        if x > Mx:
            Mx = x
            Mxi = i
            continue
        union(A, i, Mxi)
 
    T = [0]*N
    for i in range(N):
        T[find(A,i)] += 1
   
    
    ANS = [0]*N
    for i in range(N):
        ANS[i] = T[ find(A,i)]
    print("\n".join( map( str, ANS)))
                 
if __name__ == '__main__':
    main()


Measured memory_bytes: 147052
#include<time.h>
struct tm t,T;main(y,m,Y,M){for(;scanf("%d%d%d%d%d%d",&y,&m,&t.tm_mday,&Y,&M,&T.tm_mday),~Y;printf("%d\n",(mktime(&T)-mktime(&t))/86400))t.tm_year=y-1900,t.tm_mon=m-1,T.tm_year=Y-1900,T.tm_mon=M-1;exit(0);}

Measured memory_bytes: 652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;

int main(){
  ll n;
  cin >> n;
  vector<vector<ll>>a(n,vector<ll>(n));
  for(int i=0; i<n; i++){
   for(int j=0; j<n; j++) cin >> a[i][j];
  }
  
  ll count=0;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      bool judge=true;
      for(int k=0; k<n; k++){
        if(k==i || k==j)continue;
        if(a[i][j]==a[i][k]+a[k][j])judge=false;
        if(a[i][j]>a[i][k]+a[k][j]){
          cout << -1 << endl;
          return 0;
        }
      }
      if(judge)count+=a[i][j];
    }
  }
  
  cout << count << endl;
  
  return 0;
  
}
  
  
  
  


Measured memory_bytes: 1024
#include<iostream>
    #include<algorithm>
    using namespace std;
     
    int main()
    {
    	int N;
    	int M = 0;
    	int Q = 0;
    	cin >> N;
    	int p[20];
    	for (int i = 0; i < N; i++) {
    		cin >> p[i];
    	}
        M = p[0];
    	for (int i = 0; i < N - 1; i++) {
    		M = max(M, p[i + 1]);
    	}
    	for (int i = 0; i < N; i++) {
    		Q += p[i];
    	}
    	cout << Q - M / 2<<endl;
    	return 0;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
#define mod 1e9
int a[100005];
int32_t main() {
	int n,m,i;
	cin>>n>>m;
	int l,r;
	for(i=0;i<m;i++)
	{
		cin>>l>>r;
		a[l]++;
		a[r+1]--;
	}
	int ans=0;
	for(i=1;i<=n;i++)
	{
		a[i]+=a[i-1];
		if(a[i]==m)
			ans++;
	}
	cout<<ans;
}
						

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

using namespace std;

const int N = 1e5 + 7;

int n, a[N], b[N];

int main() {
	long long ans = 0, cur = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &a[i], &b[i]);
	}
	for (int i = n - 1; i >= 0; i--) {
		a[i] = (a[i] + cur) % b[i];
		int delta = (b[i] - a[i]) % b[i];
		ans += delta;
		cur += delta;
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
    int64_t h;
    cin>>h;
    int c=0;
    while(h>1){
        c++;
        h=h/2;
    }
    int64_t sum=0;
    for(int i=0; i<c+1;i++){
        sum+=pow(2,i);
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;
bool isIntDistance(vector<int> a,vector<int> b){
	double distance = 0;
	for(int i = 0; i < a.size(); i++){
		distance += (a[i] - b[i])*(a[i] - b[i]);
	}
	int d2 = sqrt(distance);
	//cout<<d2*d2<<":"<<distance<<endl;
	if( abs(d2*d2 - distance) <= 0.0000001){
		return true;
	}else{
		return false;
	}
}

int main(){
	int n,d;
	cin>>n>>d;
	vector<vector<int>> x(n);
	for(int i = 0; i < n; i++){
		x[i] = vector<int>(d);
		for(int j = 0; j < d; j++){
			cin>>x[i][j];
		}
	}
	int ans = 0;
	for(int i = 0; i < n; i ++){
		for(int j = i + 1; j < n; j++){
			if( isIntDistance(x[i],x[j]) == true) ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN = 2e5 + 100;
char S[MAXN];
VI e[MAXN];

int cnt[MAXN][2];
bool out[MAXN];

int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  scanf("%s", S);
  for (int i = 0; i < M; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    e[x].PB(y);
    e[y].PB(x);
  }
  for (int i = 0; i < N; i++) {
    for (int u : e[i])
      cnt[i][S[u] - 'A']++;
  }
  VI bad;
  for (int i = 0; i < N; i++)
    if (cnt[i][0] == 0 || cnt[i][1] == 0) {
      out[i] = true;
      bad.PB(i);
    }
  while (!bad.empty()) {
    int t = bad.back();
    bad.pop_back();
    for (int u : e[t]) {
      if (out[u])
        continue;
      cnt[u][S[t] - 'A']--;
      if (cnt[u][0] == 0 || cnt[u][1] == 0) {
        out[u] = true;
        bad.PB(u);
      }
    }
  }
  bool good = false;
  for (int i = 0; i < N; i++)
    if (!out[i])
      good = true;
  puts(good ? "Yes" : "No");
  return 0;
}


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

using namespace std;

#define f first
#define s second

int main(){
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

	int n;

	scanf("%d", &n);

	pair<int, int> v[10];

	for (int i = 0; i < n; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		v[i] = {x, y};
	}

	sort(v, v+n);

	double ansV = 0.00, ansQ = 0.00;

	do {
		double dist = 0.00;
		for (int i = 0; i < n-1; i++){
			dist += sqrt( (v[i].f - v[i + 1].f) * (v[i].f - v[i + 1].f) + 
					(v[i].s - v[i + 1].s) * (v[i].s - v[i + 1].s) );
		}
		ansV += dist;
		ansQ += 1;
	} while (next_permutation(v, v+n));

	printf("%lf\n", ansV / ansQ);

	return 0;
}

Measured memory_bytes: 3884
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main() {
    int a,b,c;
    cin>>a>>b>>c;
    int ans=3;
    if(a==b){
        ans--;
    }
    if(b==c){
        ans--;
    }
    if(a==c){
        ans--;
    }
    if(ans==0){
        ans++;
    }
    cout<<ans<<endl;
}   



Measured memory_bytes: 256
// Aizu Vol-1 0151: Grid
// 2017.8.17 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
char *gets();

#define MAX 256
char a[MAX+5][MAX+5];
int n, max;

void maxOnes(int r0, int c0, int w, int dir)
{
	int r, c, k, f;
	if (w < max) return;
	if (dir == 0) {
		for (f = 0, c = 0; c < n; c++) {
			if (a[r0][c] & 1) f++;
			else { if (f > max) max = f; f = 0; }
		}
		if (f > max) max = f;
		return;
	}
	if (dir == 1) {
		for (f = 0, r = 0; r < n; r++) {
			if (a[r][c0] & 1) f++;
			else { if (f > max) max = f; f = 0; }
		}
		if (f > max) max = f;
		return;
	}
	if (dir == 2) {
		for (f = 0, r = r0, c = c0, k = 0; k < w; k++, r--, c++) {
			if (a[r][c] & 1) f++;
			else { if (f > max) max = f; f = 0; }
		}
		if (f > max) max = f;
		return;
	}
	for (f = 0, r = r0, c = c0, k = 0; k < w; k++, r++, c++) {
		if (a[r][c] & 1) f++;
		else { if (f > max) max = f; f = 0; }
	}
	if (f > max) max = f;
	return;
}

int main()
{
	int r, c, k;
	char buf[10];

	while (1) {
		gets(buf); if (!(n = atoi(buf))) break;
		for (r = 0; r < n; r++) gets(a[r]);
		max = 0;
		for (k = 1; k <= n; k++)   maxOnes(k - 1, 0, k, 2);
		if (max == n) goto Done;
		for (k = n-1; k >= 1; k--) maxOnes(n - 1, n - k, k, 2);
		for (k = 1; k <= n; k++)   maxOnes(0, n - k, k, 3);
		if (max == n) goto Done;
		for (k = n-1; k >= 1; k--) maxOnes(n - k, 0, k, 3);
		for (r = 0; r < n; r++) {
			maxOnes(r, 0, n, 0);
			if (max == n) goto Done;
		}
		for (c = 0; c < n; c++) {
			maxOnes(0, c, n, 1);
			if (max == n) goto Done;
		}
	Done: printf("%d\n", max);
	}
return 0;
}

Measured memory_bytes: 588
def main():
    A, B, C, D = list(map(int, input().split(' ')))
    
    isFinish = False
    while not isFinish:
        # print(A, B, C, D)
        c = C - B
        if c <= 0:
            print('Yes')
            isFinish = True
            break

        C = c
        
        a = A - D
        # print(a)        
        if a <= 0:
            print('No')
            isFinish = True
            break
        A = a
        
        
    
    
    

main()

Measured memory_bytes: 61784
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
	
		int[] on_take = {4, 1, 4, 1, 2, 1, 2, 1};
		for(; scanner.hasNext();)
		{
			int[] on_guest = new int[8];
			int min_take = 0;
			for(int i=0; i<8; i++)
			{
				on_guest[i] = scanner.nextInt();
				min_take += on_guest[i];
			}
			
			String output="";
			for(int i=0; i<8; i++)
			{
				int not_take = 0;
				String array="";
				for(int j=0; j<8; j++)
				{
					int n = i+j;
					if(n >= 8)
					{
						n -= 8;
					}
					array += on_take[n];
					
					if(on_guest[j]-on_take[n] > 0)
					{
						not_take += on_guest[j]-on_take[n];
					}
				}
				
				if(min_take >= not_take)
				{
					boolean updata = false;
					if(i>0 && min_take==not_take)
					{
						if(Integer.parseInt(output)>Integer.parseInt(array))
						{
							updata = true;
						}
					}
					else
					{
						updata = true;
					}
					
					if(updata)
					{
						min_take = not_take;
						output = array;
					}
				}
			}
			
			for(int i=0; i<8; i++)
			{
				System.out.print(output.substring(i, i+1)+(i<7?" ":"\n"));
			}
		}
	}
}

Measured memory_bytes: 30640
#include <iostream>
#include <string>
#include <set>
#include <cstdlib>
using namespace std;

int main()
{
    int n,m;
    while(cin >> m >> n, m || n){
        set<int> t;
        for(int i = 0; i < m; ++i) t.insert(i+1);
        
        set<int>::iterator it = t.begin();
        for(int i = 1; i <= n; ++i){
            string s;
            cin >> s;
            if(t.size() != 1){
            if(i % 3 == 0 && i % 5 == 0){
                if(s != "FizzBuzz"){
                    t.erase(it++);
                }
                else {
                    it++;
                }
            } else if(i % 3 == 0){
                if(s != "Fizz"){
                    t.erase(it++);
                } else {
                    it++;
                }
            }  else if(i % 5 == 0){
                if(s != "Buzz"){
                    t.erase(it++);
                }
                else {
                    it++;
                }
            } else if(i != atoi(s.c_str())){
                t.erase(it++);
            } else {
                it++;
            }
            if(it == t.end()){
                it = t.begin();
            }
            }
        }
        
        for(it = t.begin(); it != t.end(); ++it){
            if(it != t.begin()) cout << ' ';
            cout << *it;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1268
K = int(input())
N = 50
a = [0] * N
for i in range(K % N):
    a[i] = N-1-K+(N+1)*(K//N+1)
for i in range(K % N, N):
    a[i] = N-1-K+(N+1)*(K//N)
print(N)
print(' '.join(map(str, a)))


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, s, n) for(int i = s; i < n; i++)
#define rRep(i, n) for(int i = n - 1; i >= 0; i--)
#define pii pair<int, int>
#define vii vector<pair<int, int>>
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define endl "\n"

const int MAXN = 1e7 + 2;
int spf[MAXN];
map<int, int> ma;

void precomp() {
    spf[1] = 1;
    REP(i, 2, MAXN) {
        if(spf[i] == 0) {
            for(int j = i; j < MAXN; j += i) {
                if(spf[j] == 0)
                    spf[j] = i;
            }
        }
    }
}


 void get(int num) {
    while(num != 1) {
        ma[spf[num]]++;
        num /= spf[num];
    }
 }

void solve() {
    int n;
    cin >> n;
    precomp();
    int ans = 1;
    REP(i, 2, n + 1) {
        get(i);
        int div = 1;
        for(auto i: ma) {
            div *= (i.second + 1);
        }
        ans += i*div;
        ma.clear();
    }
    cout << ans << endl;
    
}

int32_t main() {
    FAST
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //int t; cin >> t; while(t--)
    {
        solve();
    }   
}

Measured memory_bytes: 81760