akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
vector < pair<int,int> > v;
vector <int> perm;
int n,fact;
double sum;
double dist(pair<int,int> p,pair<int,int> q)
{
    return sqrt((q.first-p.first)*(q.first-p.first)+(q.second-p.second)*(q.second-p.second));
}
int main()
{
    fact=1;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        v.push_back({x,y});
        perm.push_back(i);
        fact*=i;
    }
    do
    {
        for(int i=0;i<n-1;i++)
            sum+=dist(v[perm[i]-1],v[perm[i+1]-1]);
    } 
    while(next_permutation(perm.begin(),perm.end()));
    cout<<fixed<<setprecision(6)<<sum/fact;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, K;
  cin >> N >> K;
  cout << ll(K * pow(K - 1, N - 1)) << endl;

  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
 
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e9
// #define ll long long ll
 
typedef long long ll;
ll mod = 998244353;
 
long long fast_exp(long long a, long long b)
{
    if(b <= 0)
       return 1;
    else
    {
       long long res = 1;
       res = fast_exp(a,b/2);
       res = (res*res)%mod;
       if(b%2 == 1)
          res = (res*a)%mod;
       return res;
 
    }
}
typedef long double ld;
const ll N = 2e5+5;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll x, y, a, b, c, val;
    cin >> x >> y >> a >> b >> c;
    vector <ll> g,r;
    for(ll i = 0; i<a ; i++)
    {
        cin >> val;
        r.pb(val);
    }
    for(ll i = 0; i<b ; i++)
    {
        cin >> val;
        g.pb(val);
    }
    vector <ll> rep;
    for(ll i = 0; i<c ; i++)
    {
        cin >> val;
        rep.pb(val);
    }

    sort(r.begin(),r.end());
    sort(g.begin(),g.end());
    sort(rep.begin(),rep.end(),greater<ll>());
    ll pr = a-x, pg = b-y,pc = 0;
    ll sum = 0;
    ll lr = r[pr], lg=g[pg];

    while(pc < rep.size() && min(lr,lg) < rep[pc])
    {
        if(pr >= a && pg >=b)
            break;
        if(lr < lg)
        {
            
                pr++;
                if(pr == a)
                    lr = 1e9+7;
                else
                    lr = r[pr];
                sum+=rep[pc];
                pc++;
        }
        else
        {
            pg++;
            if(pg == b)
                lg = 1e9+7;
            else
                lg = g[pg];
            sum+=rep[pc];
            pc++;
        }
    }
    for(ll i = pr ; i < a ; i++)
        sum += r[i];
    for(ll i = pg ; i< b ; i++)
        sum += g[i];

    cout << sum << endl; 

   
    return 0;
 
 
}

Measured memory_bytes: 3316
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        map<int, int> m;
        for(int i=0; i<n; ++i){
            int a;
            cin >> a;
            ++ m[a];
        }

        int ret = -1;
        for(map<int, int>::iterator it=m.begin(); it!=m.end(); ++it){
            if(it->second > n / 2)
                ret = it->first;
        }

        if(ret == -1)
            cout << "NO COLOR" << endl;
        else
            cout << ret << endl;
    }
}

Measured memory_bytes: 1936
import sys
from collections import defaultdict

def main():
    input = sys.stdin.readline
    n,m,k = map(int, input().split())
    d = list(map(int, input().split()))
    l = [-1] * n
    for i in range(m):
      l[d[i]-1] = i
    A = [list(map(int, input().split())) for _ in range(n)]
    a = [[l[A[i-1][j] - 1] if l[A[i-1][j] - 1] != -1 else None for i in d] for j in range(k)]
    c = [-1] * (1 << m)
    c[(1 << m) - 1] = 0
    D = [1 << i for i in range(m+1)]
    x = [-1] * m
    q = defaultdict(int)
    Range = range(m)
    K = 0
    q[0] = -1
    R = 1
    while 1:
        mask = q[K]
        K += 1
        score = c[mask] + 1
        x = [i for i in Range if mask & D[i]]
        for ai in a:
            tmp = 0
            for j in x:
                aji = ai[j] 
                if aji != None:
                	tmp |= D[aji]
            if c[tmp] == -1:
                c[tmp] = score
                q[R] = tmp
                R += 1
                if tmp == 0:
                    print(score)
                    return
if __name__ == "__main__":
    main()


Measured memory_bytes: 13368
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	
	while (true)
	{
	    c -= b;
	    if (c <= 0) {cout << "Yes"; return 0;}
	    a -= d;
	    if (a <= 0) {cout << "No"; return 0;}
	}
}














Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
  int n;
  cin >> n;
  vector<int> c(n-1), s(n-1), f(n-1), ans(n);
  rep(i,n-1) cin >> c[i] >> s[i] >> f[i];
  rep(i,n-1) {
    for(int j = i; j < n-1; j++) {
      if(ans[i]<s[j]) ans[i] = s[j];
      else if((ans[i]-s[j])%f[j]!=0) {
        ans[i] += f[j]-(ans[i]-s[j])%f[j];
      }
      ans[i] += c[j];
    }
  }
  rep(i,n) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int i,j,a[505][505];
int H,W,h,w;
int main()
{
	scanf("%d%d%d%d",&H,&W,&h,&w);
	if(H%h==0&&W%w==0)
	{
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	for(i=1;i<=H;i++)
	{
		for(j=1;j<=W;j++)
		{
			if(!(i%h==0&&j%w==0))
			{
				a[i][j]=500;
			}
			else
				a[i][j]=-500*h*w+499;
		}
	}
	for(i=1;i<=H;i++)
	{
		for(j=1;j<=W;j++)
			printf("%d ",a[i][j]);
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2304
N, A, B = gets.split.map(&:to_i)
 
def judge(number)
a = number / 10000
a_rem = number % 10000
b = a_rem / 1000
b_rem = a_rem % 1000
c = b_rem / 100
c_rem = b_rem % 100
d = c_rem / 10
d_rem = c_rem % 10
e = d_rem
sum_ae = a + b + c + d + e
if sum_ae >= A && sum_ae <= B then
  true
else
  false
end
end

ans = 0  

nums = (1..N).to_a

nums.each do |num|
  if judge(num) then
    ans += num
  end
end

p ans

Measured memory_bytes: 1916
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <queue>
using namespace std;

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

long long int dp[100005];
int main(){
    int n,we; cin >> n >> we;
    rep(i,100005) dp[i] = 0;
    vector<int> w(n),v(n); rep(i,n) cin >> w[i] >> v[i];
    for(int i=0;i<n;i++){
        for(int j=we;j>=w[i];j--){
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }
    long long  ans = 0;
    rep(i, we+1) ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15

//ここから編集する
struct edge{ll to,cost;};
typedef pair<ll,ll> P;//firstは最短距離、secondは頂点の番号

int V;//超点数
vector<vector<edge> > G;//グラフ
vector<ll> d; //最短距離

void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(d.begin(),d.end(),INFl);
    d[s] = 0;
    que.push(P(0,s));

    while(!que.empty()){
        P p = que.top();que.pop();
        ll v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }

}


int main() {
    int N;
    cin >> N;
    V = N;
    G = vector<vector<edge> >(N+1);
    d = vector<ll>(N+1);

    REP(i,1,N){
        int a,b,c;
        cin >> a >> b >> c;
        edge e;
        e.to = b;
        e.cost = c;
        G[a].push_back(e);
        e.to = a;
        G[b].push_back(e);
    }
    int Q,K;
    cin >> Q >> K;
    dijkstra(K);
    REP(i,0,Q){
        int x,y;
        cin >> x >> y;
        cout << d[x] + d[y] << endl;
    }

    return 0;
}


Measured memory_bytes: 11120
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
// fold was added in D 2.071.0.
template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
        static if (S.length < 2) {
            return reduce!fun(seed, r);
        } else {
            return reduce!fun(tuple(seed), r);
        }
    }
}

void main() {
    int a, b;
    char c;
    readf("%d %c %d\n", &a, &c, &b);
    writeln(c=='+' ? a+b : a-b);
}


Measured memory_bytes: 256
from bisect import bisect_left
import sys
input = sys.stdin.readline
a,b,q = map(int,input().split())
inf = float('inf')
S = [-inf]+[int(input()) for i in range(a)]+[inf]
T = [-inf]+[int(input()) for i in range(b)]+[inf]

def f(S,T):
    res = 10**30 
    s = bisect_left(S,x)

    ans = 0
    t = bisect_left(T,S[s-1])
    ans += abs(x-S[s-1])+min(abs(S[s-1]-T[t-1]),abs(S[s-1]-T[t]))
    if ans <= res:
        res = ans
    
    ans = 0
    t = bisect_left(T,S[s])
    ans += abs(x-S[s])+min(abs(S[s]-T[t-1]),abs(S[s]-T[t]))
    if ans <= res:
        res = ans

    return res


for i in range(q):
    x = int(input())
    print(min(f(S,T),f(T,S)))


Measured memory_bytes: 75868
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,k=map(int,readline().split())
    a=list(map(int,readline().split()))

    s=bin(max(k,max(a)))[2:]
    l=len(s)
    cnt_one=[0]*l

    for i in range(n):
        b=a[i]
        for j in range(l):
            if b&1==1:
                cnt_one[j]+=1
            b>>=1

    cnt_one.reverse()
    k_bin=bin(k)[2:]
    dp=[[-float("inf"),-float("inf")] for _ in range(l+1)]
    dp[0][0]=0
    for i in range(l):
        j=l-i
        if len(k_bin)<j:
            dp[i+1][0]=dp[i][0]+cnt_one[i]*2**(j-1)
        else:
            if k_bin[len(k_bin)-j]=="1":
                dp[i+1][0]=dp[i][0]+(n-cnt_one[i])*2**(j-1)
                if cnt_one[i]>=(n+1)//2:  #1の数が半数以上
                    dp[i+1][1]=max(dp[i][0]+cnt_one[i]*2**(j-1),dp[i][1]+cnt_one[i]*2**(j-1))
                else:  #1の数が半数未満
                    dp[i+1][1]=max(dp[i][0]+cnt_one[i]*2**(j-1),dp[i][1]+(n-cnt_one[i])*2**(j-1))
            else:
                dp[i+1][0]=dp[i][0]+cnt_one[i]*2**(j-1)
                if cnt_one[i]>=(n+1)//2:  #1の数が半数以上
                    dp[i+1][1]=dp[i][1]+cnt_one[i]*2**(j-1)
                else:  #1の数が半数未満
                    dp[i+1][1]=dp[i][1]+(n-cnt_one[i])*2**(j-1)

    print(max(dp[l][0],dp[l][1]))

if __name__=="__main__":
    main()

Measured memory_bytes: 14748
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;
ll M = 1000000007;

ll k;
int n;

struct edge
{
    int x,next;
};
edge e[400000];
int loc[400000];
int top=1;

void add_edge(int l,int r)
{
    e[top].x = r;
    e[top].next = loc[l];
    loc[l] = top;
    top++;
}
int flag[400000]={0};
ll f[400000];

ll dp(int x,int dep,int myk)
{
    flag[x] = 1;
    if (myk<=0) return 0;
    f[x] = myk;
    int tmpk;
    if (dep == 0)
        tmpk = k-1;
    else
        tmpk = k-2;
    for (int now = loc[x]; now; now=e[now].next)
        if (flag[e[now].x] == 0)
        {
            f[x] = (f[x] * dp(e[now].x, dep+1, tmpk))%M;
            tmpk--;
        }
    return f[x];
}

int main()
{
    cin>>n>>k;
    for (int i=1; i<=n-1; ++i)
    {
        int l,r;
        scanf("%d %d",&l,&r);
        add_edge(l,r);
        add_edge(r,l);
    }
    cout<<dp(1,0,k)<<endl;
    return 0;
}



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

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

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

int main() {
    ios::sync_with_stdio(false);
    int n;
    ll k;
    cin >> n >> k;

    vector<int> a(n);
    vector<int> visited(n, -1); // visited[x] ... whether if node x was visited.
                                // if visited, the number
    vector<int> l;              // list of visited node idx

    rep(i, n) {
        int t;
        cin >> t;
        a[i] = --t;
    }

    int counter = 0;
    int nextIdx;
    visited[0] = 0;
    l.push_back(0);
    nextIdx = a[0];

    counter++;
    int ans = 0;

    while (counter <= k) {
        if (visited[nextIdx] >= 0) {
            int loopStartIndex = nextIdx;
            int loopStartCounter = visited[loopStartIndex];
            int loop = (counter - loopStartCounter);
            int r = (k - loopStartCounter) % loop;
            ans = l[r + loopStartCounter];
            // printf("loop:%d, loopst:%d, r:%d\n", loop, loopStartIndex, r);
            break;
        } else {
            visited[nextIdx] = counter;
            l.push_back(nextIdx);
            nextIdx = a[nextIdx];
        }
        counter++;
    }

    if (counter > k) {
        // printf("counter:%D>k:%lld\n", counter, k);
        ans = l[k];
    }

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


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, x, y, z, w;
LL dp[41][1 << 17], MOD = 1e9 + 7;

bool f(int bit, int d) {
	int v = 1;
	v <<= x;
	v++;
	v <<= y;
	v++;
	v <<= z;
	v++;
	
	bit <<= d;
	bit++;
	
	return ((v & bit) == v);
}

int g(int bit, int d) {
	bit <<= d;
	bit++;
	bit &= ((1 << w) - 1);
	return bit;
}

int main() {
	cin >> n >> x >> y >> z;
	
	w = x + y + z;
	dp[0][1] = 1;
	inc(i, n) {
	inc(bit, 1 << w) {
	inc1(d, 10) {
		if(! f(bit, d)) {
			(dp[i + 1][g(bit, d)] += dp[i][bit]) %= MOD;
		}
	}
	}
	}
	
	LL ans = 1;
	inc(i, n) { (ans *= 10) %= MOD; }
	inc(bit, 1 << w) { (ans += MOD - dp[n][bit]) %= MOD; }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 41344
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep1(i,n) for(int i=1; i<(int)n; i++)
#define repa(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a / gcd(a, b)*b;}

int N, M, K, H, W, L, R, X;
//string S, T;
int csum (vi a,int asum){
  rep(i,N-1){
    if(a[i]<0){
      a[i] *= -1;
      a[i+1] *= -1;
      asum += 2*(a[i]+a[i+1]);
    }
  }
  return asum;
}
signed main(){
  cin >> N;
  vi v(N), c(N);
  rep(i,N) cin >> v[i];
  rep(i,N) cin >> c[i];
  
  int ans = 0;
  rep(i,N){
    if(v[i]>c[i]) ans += v[i]-c[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#define N 200005
using namespace std;

typedef long long ll;
ll n, k, mx, s0, s1, s2, ans, l, r, md;
vector<ll> a1, a2;

ll f12(ll p) {
	ll re = 0, i, j;
	j = 0;
	for (i = s1 - 1; i >= 0; i--) {
		for (; j < s2; j++) {
			if (a1[i] * a2[j] <= p) break;
		}
		re += (s2 - j);
	}
	return re;
}

ll com(ll p) {return p * (p - 1) / 2;}
ll f1(ll p) {
	ll re = 0, i, j;
	j = s1 - 1;
	for (i =0; i < s1; i++) {
		for (; j > i; j--) {
			if (a1[i] * a1[j] <= p) break;
		}
		re += max((j - i), 0ll);
	}
	return re;
}

ll f2(ll p) {
	ll re = 0, i, j;
	j = s2 - 1;
	for (i =0; i < s2; i++) {
		for (; j > i; j--) {
			if (a2[i] * a2[j] <= p) break;
		}
		re += max((j - i), 0ll);
	}
	return re;
}

int main()
{
	ll i, t, cnt;
	cin >> n >> k;
	for (i = 0; i < n; i++) {
		scanf ("%lld", &t);
		if (t < 0) {
			a1.push_back(t);
		} else if (t == 0) {
			s0++;
		} else {
			a2.push_back(t);
		}
	}
	s1 = a1.size();
	s2 = a2.size();
	if (!a1.empty()) sort(a1.begin(), a1.end(), greater<ll>());
	if (!a2.empty()) sort(a2.begin(), a2.end());
	l = -1e18;
	r = 1e18 + 1;
	while (r - l > 2) {
		md = (l + r) / 2;
		cnt = 0;
		if (md < 0) cnt += f12(md);
		else {
			cnt += s1 * s2;
			cnt += s0 * (s0 - 1) / 2;
			cnt += (s0) * (s1 + s2);
			if (md > 0) cnt += f1(md);
			if (md > 0) cnt += f2(md);
		}
		if (cnt >= k) {ans = md; r = md;}
		else l = md + 1;
	}
	for (i = r - 1; i >= l; i--) {
		md = i;
		cnt = 0;
		if (md < 0) cnt += f12(md);
		else {
			cnt += s1 * s2;
			cnt += s0 * (s0 - 1) / 2;
			cnt += (s0) * (s1 + s2);
			if (md > 0) cnt += f1(md);
			if (md > 0) cnt += f2(md);
		}
		if (cnt >= k) ans = md;
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2420
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


a, b = Is()
if a > 9 or b > 9:
    print("-1")
else:
    print(a*b)

Measured memory_bytes: 38384
/** Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    char ch;
    cin>>ch;
    cout<<char(int(ch)+1);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int,int> pii;
char str[1000009];
int f[1000009];
int main()
{
    scanf("%s",str+1);
    int len=strlen(str+1);
    int answer=0;
    for(int i=1;i<=len;i++){
        f[i]=str[i]-'0';
    }
    for(int i=1;i<=len+10;i++)
    {
        if(f[i]>=10){
            f[i]-=10;
            f[i+1]++;
        }
        if(f[i]>=6){
            answer+=10-f[i];
            f[i+1]++;
        }
        else if(f[i]==5){
            answer+=5;
            if(f[i+1]>=5){
                f[i+1]++;
            }
        }
        else answer+=f[i];
    }
    cout<<answer<<endl;
    return 0;
}

Measured memory_bytes: 5120
n=gets.to_i
b=gets.split.map(&:to_i)
a = Array.new(n)
(n-1).times do |i|
  if a[i].nil?
    a[i] = b[i]
  elsif a[i] > b[i]
    a[i] = b[i]
  else
    a[i] = a[i]
  end
  a[i+1] = b[i]
end
p a.inject(:+)

Measured memory_bytes: 1788
import java.util.*;
import java.math.*;
class Main {
    //
    static final long MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        if(n >= 10){
            System.out.println(m);
        }else{
            System.out.println(m + 100*(10-n));
        }
    }
    

    
}

Measured memory_bytes: 23380
def main():
    n = int(input())
    # t, a = map(int, input().split())
    # h = list(map(int, input().split()))
    # s = input()

    p = []
    for i in range(n):
        p.append(int(input()))
    
    maxi = max(p)
    print(sum(p) - maxi//2)



if __name__ == '__main__':
    main()


Measured memory_bytes: 61464
import sys
input = sys.stdin.readline


def main():
    N = int(input().strip())
    s_list = [sorted(input().strip()) for _ in range(N)]
    s_list = sorted(s_list)
    ans = 0
    duplicate_num = 0
    for index in range(len(s_list)-1):
        if s_list[index] == s_list[index+1]:
            duplicate_num += 1
        else:
            ans += duplicate_num * (duplicate_num+1) // 2
            duplicate_num = 0
    ans += duplicate_num * (duplicate_num+1) // 2
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 95024
#include<iostream>
#include <algorithm>
using namespace std;
int a[200005]={0};
int main()
{
	long long n,h,k,sum=0;
	cin>>n>>k;
	for(long long i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n-k;i++)
		sum+=a[i];
	cout<<sum;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){

	int W = 0;
	int H = 0;
	int x = 0;
	int y = 0;
	int r = 0;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if ((x - r >= 0) & (x + r <= W) & (y - r >= 0) & (y + r <= H)){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    string s;cin >> s;
    bool ok = true;
    rep(i,2){
        if(s[i] != s[i+1])ok = false;
    }
    cout << (ok ? "No" : "Yes") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <numeric>
#include <string>
#include <cmath>

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


int main() {
	int a, b, c;
	int k;

	cin >> a >> b >> c;
	cin >> k;


	if (a == b and b == c) {
		if (k >= 3) {
			cout << "Yes" << endl;
			return 0;
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}

	int count4 = 0;
	if (a == c) {
		if (a > b) {
			while (a >= b)
			{
				b *= 2;
				count4++;
			}
			while (b >= c)
			{
				c *= 2;
				count4++;
			}
			if (count4 > k) {
				cout << "No" << endl;
				return 0;
			}
			else {
				cout << "Yes" << endl;
				return 0;
			}
		}
		else {
			while (b >= c)
			{
				c *= 2;
				count4++;
			}
			if (count4 > k) {
				cout << "No" << endl;
				return 0;
			}
			else {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	if (a == b) {
		if (c > b) {
			b *= 2;
			if (c > b) {
				cout << "Yes" << endl;
				return 0;
			}
			else {
				cout << "No" << endl;
				return 0;
			}
		}
		else
		{
			b *= 2;
			int count3 = 1;
			while (b >= c) {
				c *= 2;
				count3++;
			}
			if (count3 > k) {
				cout << "No" << endl;
				return 0;
			}
			else {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	int count2 = 0;
	if (b == c) {
		if (a < b) {
			cout << "Yes" << endl;
			return 0;
		}
		else {
			while (a >= b) {
				b *= 2;
				count2++;
			}
			while (b >= c) {
				c *= 2;
				count2++;
			}
			if (count2 > k) {
				cout << "No" << endl;
				return 0;
			}
			else {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	if (b > a and b > c) {
		c = c * 2 * k;
		if (c > b) {
			cout << "Yes" << endl;
			return 0;
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}

	int count1 = 0;
	if (c > a and c > b) {
		if (b > a) {
			cout << "Yes" << endl;
			return 0;
		}
		else {
			while (a >= b) {
				b *= 2;
				count1++;
			}
			if (count1 <= k and b < c) {
				cout << "Yes" << endl;
				return 0;
			}
			if (count1 <= k and c < b) {
				c = c * (k - count1) * 2;
				if (c > b) {
					cout << "Yes" << endl;
					return 0;
				}
				else {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}

	int count = 0;
	if (a > b and a > c) {
		while (a >= b) {
			b *= 2;
			count++;
		}
		while (b >= c) {
			c *= 2;
			count++;
		}
		if (count > k) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
	return 0;


}


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

int main()
{
    ll l, r;
    cin >> l >> r;

    ll ans = 2018;
    for (ll i = l; i <= min(r, l + 2019); i++)
    for (ll j = i + 1; j <= min(r, l + 2019); j++)
        ans = min(ans, (i * j) % MOD);
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define abs(a) ((a)>(0)?(a):-(a))
#define min(a,b) ((a)<(b)?(a):(b))
int main(){
  int n;
  scanf("%d",&n);
  int h[n],i,dp[n+1],a,b;
  for(i=0;i<n;i++)scanf("%d",&h[i]);
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  for(i=1;i<n-1;i++){
    a=dp[i]+abs(h[i+1]-h[i]);
    b=dp[i-1]+abs(h[i+1]-h[i-1]);
    dp[i+1]=min(a,b);
  }
  printf("%d",dp[n-1]);
}

Measured memory_bytes: 896
import java.util.*;

class Main {
	public static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int g = gcd(a, b);
			System.out.println(g + " " + a / g * b);
		}
	}
}

Measured memory_bytes: 25776
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define rep(i, a) for (int i = 0; i < a; i++)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define REPR(i, a, b) for (int i = a; i >= b; i--)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int N;
double p[3010];
double dp[3010][3010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  rep(i, N) cin >> p[i];
  dp[0][0] = 1;
  rep(i, N) rep(j, i+1) if (dp[i][j]) {
    dp[i+1][j] += dp[i][j]*(1-p[i]);
    dp[i+1][j+1] += dp[i][j]*p[i];
  }
  double ans = 0;
  rep(i, N+1) {
    int a = i, b = N-i;
    if (a > b) ans += dp[N][i];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 68992
#include<bits/stdc++.h> 
using namespace std;
int a,b;
int c[200000000];
long long ans;
int main()
{
    cin>>a>>b;
    for(int i=1;i<=b;i++){
    	cin>>c[i];
		ans+=c[i];
	} 
	if(ans>a)cout<<-1;
	else cout<<a-ans;
	return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    char alpha;
    cin >> alpha;
    if ('a' <= alpha && alpha <= 'z') {
        cout << "a\n";
        return 0;
    } else {
        cout << "A\n";
        return 0;
    }
}

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

int main()
{

	int n;
	cin>>n;
	vector<int> x(n);
	int max = 0;
	for(size_t i = 0; i<n; i++)
	{
		cin>>x[i];
		if(max<x[i])
		{
			max = x[i];
		}
	}
	int mip = 1000000;
	for(size_t i = 0; i<=max; i++)
	{
		int p=0;
		for(size_t ii = 0; ii<n; ii++)
		{
			p += (x[ii]-i)*(x[ii]-i);
		}
		if(mip>p)
		{
			mip = p;
		}
	}
	cout<<mip<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class E
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		int[,] A = new int[N, N - 1];
		for(int i = 0; i < N; i++)
			for(int j = 0; j < N - 1; j++)
				A[i, j] = GetInt() - 1;

		var dict = new Dictionary<int, int>();
		int cnt = 0;
		for(int i = 0; i < N; i++)
		{
			for(int j = i + 1; j < N; j++)
			{
				dict[i * N + j] = cnt;
				cnt++;
			}
		}

		var adj = Enumerable.Range(0, cnt).Select(_ => new List<int>()).ToArray();
		for(int i = 0; i < N; i++)
		{
			for(int j = 0; j < N - 2; j++)
			{
				int v = dict[Math.Min(i, A[i, j]) * N + Math.Max(i, A[i, j])];
				int u = dict[Math.Min(i, A[i, j + 1]) * N + Math.Max(i, A[i, j + 1])];
				adj[v].Add(u);
			}
		}
		
		var tpl = tplSort(adj);
		if(tpl.Count != cnt)
		{
			Console.WriteLine(-1);
			return;
		}

		long[] dp = new long[cnt];
		for(int i = 0; i < cnt; i++)
		{
			int v = tpl[i];
			foreach(int u in adj[v])
				dp[u] = Math.Max(dp[u], dp[v] + 1);
		}

		Console.WriteLine(dp.Max() + 1);
	}

	private List<int> tplSort(List<int>[] adj)
	{
		int N = adj.Length;
		int[] deg = new int[N];
		for(int v = 0; v < N; v++)
		{
			foreach(int u in adj[v])
				deg[u]++;
		}

		var res = new List<int>();
		var queue = new Queue<int>();
		for(int v = 0; v < N; v++)
			if(deg[v] == 0)
				queue.Enqueue(v);
		
		while(queue.Count > 0)
		{
			int v = queue.Dequeue();
			res.Add(v);
			foreach(int u in adj[v])
			{
				deg[u]--;
				if(deg[u] == 0)
					queue.Enqueue(u);
			}
		}

		return res;
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


Measured memory_bytes: 89936
#include<bits/stdc++.h>
#define INF 1073741824
#define ll long long
#define PI (2*acos(0.0))
#define Hare printf("here\n")
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define x first
#define y second
#define on(val,pos) val|(1<<pos)
#define off(val,pos) val&(~(1<<pos))
#define check(val,pos) (val&(1<<pos))

//first four adjacent,second four corner
//int row[8]={0,-1,0,1,1,-1,-1,1};
//int col[8]={-1,0,1,0,-1,-1,1,1};
using namespace std;

int main(){
    int i,j,k,n,m,val,t=0,cnt,test;
    //freopen("000input.txt","r",stdin);
	string s;
  	cin>>s;
  	string a="AAA",b="BBB";
  if(s==a or s==b)printf("No");
  else printf("Yes");
    //free();   //if pointer array
    return 0;
}


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

int main() {
	int a;
	while (cin >> a, a) {
		int time[10003];
		for (int i = 0;i < a;i++) {
			cin >> time[i];
		}
		sort(time, time + a);

		long long sum = 0;
		for (int i = 0;i < a;i++) {
			sum += time[i] * (a - i - 1);
		}
		cout << sum << endl;
	}
	return 0;
}

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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, alphabet_cnt[51][26] = {};
    cin >> n;
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, s.size()) {
            ++alphabet_cnt[i][s[j] - 'a'];
        }
    }

    int minimum_alphabet_cnt[26] = {};
    rep(i, 26) {
        int min_cnt = 51;
        rep(j, n) {
            min_cnt = min(min_cnt, alphabet_cnt[j][i]);
        }
        minimum_alphabet_cnt[i] = min_cnt;
    }

    string ans = "";
    rep(i, 26) {
        char tmp = 'a' + i;
        rep(j, minimum_alphabet_cnt[i]) {
            ans.push_back(tmp);
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define LOCAL 0

#define lli long long int
#define llu unsigned long long int
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define slli(n) scanf("%lld",&n);
#define ss(n) scanf("%s",n);

const long double EPS = 1e-10;
const int MOD = 1000000007ll;
const int mod1 = 1000000009ll;
const int mod2 = 1100000009ll;
int INF = (int)1e9;
lli INFINF = (lli)1e18;
int debug = 0;
long double PI = acos(-1.0);

using namespace std;

int bit_count(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
int bit(lli _mask,int _i){return (_mask&(1ll<<_i))==0?0:1;}
int powermod(lli _a,lli _b,int _m=MOD){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
int add(int a,int b,int m=MOD){int x=a+b;while(x>=m)x-=m;while(x<0)x+=m;return x;}
int sub(int a,int b,int m=MOD){int x=a-b;while(x<0)x+=m;while(x>=m)x-=m;return x;}
int mul(int a,int b,int m=MOD){lli x=a*1ll*b;x%=m;while(x<0)x+=m;return (int)x;}
int ldtoint(ld x){return (int)(x+0.5);}lli ldtolli(ld x){return (lli)(x+0.5);}

template<class T1,class T2>ostream&operator<<(ostream& os,const pair<T1,T2>&p){os<<"["<<p.first<<","<<p.second<<"]";return os;}
template<class T>ostream&operator<<(ostream& os,const vector<T>&v){os << "[";bool first=true;for (T it:v){if (!first)os<<", ";first = false;os<<it;}os<<"]";return os;}
template<class T>ostream&operator<<(ostream& os,set<T>&v){os<<"[";bool first=true;for (T it:v){if(!first)os<<", ";first=false;os<<it;}os<<"]";return os;}
template<class T1,class T2>ostream&operator<<(ostream& os,map<T1,T2>&v){os<<"[";bool first=true;for(pair<T1,T2> it:v){if(!first)os<<", ";first=false;os<<"("<<it.F<<","<<it.S<<")";}os<<"]";return os;}

lli N;
lli A[100010],B[100010];

int main()
{
if(LOCAL){
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    debug = 1;
}
    srand (time(NULL));

    cin>>N;
    for(int i=1;i<=N;i++){
        cin>>A[i]>>B[i];
    }
    lli ans = 0;
    lli sofar = 0;
    for(int i=N;i>=1;i--){
        A[i] += sofar;
        lli x = B[i]-A[i];
        x %= B[i];
        x += B[i];
        x %= B[i];
        sofar += x;
        ans += x;
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define lli long long
#define rep0(i,j) for(int i=0; i<j; i++)
#define rep1(i,j) for(int i=1; i<=j; i++)
#define all(a) a.begin(), a.end()
using namespace std;

void dfs(lli ed, lli num, vector<map<lli,lli>>& vec){
    lli n=1;
    for(auto e: vec[num]){
        if(n == ed)n++;
        if(e.second != -1)continue;
        vec[num][e.first] = n;
        vec[e.first][num] = n;   
        dfs(n, e.first, vec);
        n++;
    }
}

lli gcd(lli a, lli b){
    if(a < b)return gcd(b, a);
    lli temp;
    while((temp = a%b)){
        a=b;
        b=temp;
    }
    return b;
}

int main(){
    lli a,b;
    cin >> a >>b;
    cout << a*b/gcd(a,b);

}

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

int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    long long ans;
    if(a+b<2*c){
        ans = a*x+b*y;
    }
    else {
        ans = 2*c*min(x, y);
        if(x>y){
            if(a<2*c) ans += a*(x-y);
            else ans += 2*c*(x-y);
        }
        else {
            if(b<2*c) ans += b*(y-x);
            else ans += 2*c*(y-x);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	io, flush := NewIO()
	defer flush()

	n, m, x, y := io.ScanInt4()
	xlist := io.ScanInts(n)
	ylist := io.ScanInts(m)

	sort.Ints(xlist)
	sort.Ints(ylist)

	for i := xlist[len(xlist)-1]+1; i <= ylist[0]; i++ {
		if x < i && i <= y {
			fmt.Println("No War")
			return
		}
	}
	fmt.Println("War")
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 10000000), 10000000)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInt2() (int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt3() (int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt4() (int, int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 2184
n=int(input())

a = list(input().split())
a = [int(i) for i in a]
ans=1


if 0 in a:
  pass

elif len(a) % 2 == 1: 
  for i in range(1, int(len(a)/2)+2):
    #print(ans)
    if ans > 10**18 or ans == 0:
      break
    if i == int(len(a)/2) + 1:
      ans = ans*a[i-1]
    else:
      ans = ans*a[i-1]*a[-1*i]
    
else:
  for i in range(0, int(len(a)/2)):
    if ans > 10**18 or ans == 0:
      break
    ans = ans*a[i]*a[-1 - i]
    

if ans > 10**18:
  print('-1')
elif 0 in a:
  print(0)
else:
  print(ans)


Measured memory_bytes: 22468
#include<bits/stdc++.h>
using namespace std;
#define int long long
int pow_mod(int n,int k,int m){
	int r=1;
	for(;k>0;k>>=1){
    	if(k&1) r=(r*n)%m;
		n=(n*n)%m;
 	}
	return r;
}
int fact_mod(int n,int i,int m){
  int k = n;
  int ans=1;
  while(k > n-i){
    ans = ans*k%m;
    k--;
  }
  return ans;
}
signed main(){
  int n,a,b,m = 1000000007;
  cin >> n >> a >>b;
  int sum = pow_mod(2,n,m)-1;
  sum -= fact_mod(n,a,m)*pow_mod(fact_mod(a,a,m),m-2,m)%m;
  sum -= fact_mod(n,b,m)*pow_mod(fact_mod(b,b,m),m-2,m)%m;
  while(sum<0)
    sum+=m;
  cout << sum<< endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int l,a,b,c,d;
    cin>>l>>a>>b>>c>>d;
    if((a+c-1)/c>=(b+d-1)/d){
      cout<<l-(a+c-1)/c<<endl;
    }
    else{
          cout<<l-(b+d-1)/d<<endl;
    }
    return 0;
}


Measured memory_bytes: 3120
//解説読了後の実装
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;

vector<long long int> s;
vector<long long int> t;

// index が条件を満たすかどうか
bool isOKs(int index, long long key) {
    if (s[index] > key) return true;
    else return false;
}

bool isOKt(int index, long long key) {
    if (t[index] > key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
int binary_searchs(long long key) {
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = (int)s.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1) {
        int mid = left + (right - left) / 2;

        if (isOKs(mid, key)) right = mid;
        else left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}

int binary_searcht(long long key) {
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = (int)t.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1) {
        int mid = left + (right - left) / 2;

        if (isOKt(mid, key)) right = mid;
        else left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}



int main(){
    int A,B,Q;

    cin>>A>>B>>Q;
    long long st,tt;
    for(int i=0;i<A;i++){
        cin>>st;
        s.push_back(st);
    }
    for(int i=0;i<B;i++){
        cin>>tt;
        t.push_back(tt);
    }

    long long x;
    for(int i=0;i<Q;i++){
        cin>>x;
        int idxs = binary_searchs(x);        
        int idxt = binary_searcht(x);

        long long answer=1000000000000000000;
        for(int j = idxs - 1;j <= idxs; j++){
            for(int k = idxt - 1;k <= idxt; k++){
                if(j >= s.size() || k >= t.size()) continue;
                long long d1 = abs(s[j] - x) + abs(t[k] - s[j]);
                long long d2 = abs(t[k] - x) + abs(s[j] - t[k]);
                answer = min({answer, d1, d2});
            }
        }
        cout<<answer<<endl;
    }
    return 0;    
}

Measured memory_bytes: 3060