akhauriyash/Code-Regression huggingface dataset:
open Printf
open Str

type node = {p : int option; cs : int list; d : int}
              
let read_list f =
  split (regexp " +") (read_line ()) |> List.map f

let string_of_list ls =
  let s = List.map string_of_int ls |> String.concat ", " in "[" ^ s ^ "]"

let int_of_parent n = match n.p with
    None -> (-1)
  | Some x -> x

let type_of_node = function
    {p = None} -> "root"
  | {cs = []} -> "leaf"
  | _ -> "internal node"

let find_root tr =
  let n = Array.length tr in
  let rec iter i =
    if i = n then failwith "find_root"
    else match tr.(i) with
           {p = None} -> i
         | _ -> iter (i+1)
  in iter 0

let set_depth tr r =
  let rec iter i d =
    let n = tr.(i) in tr.(i) <- {n with d = d};
                      match n.cs with
                        [] -> ()
                      | l -> List.iter (fun x -> iter x (d+1)) l
  in iter r 0
  
let () =
  let n = read_int () in
  let tree = Array.make n {p = None; cs = []; d = 0} in
  let rec read n =
    if n = 0 then ()
    else begin
        begin
          match read_list int_of_string with
            id::_::rs -> begin
              tree.(id) <- begin let n = tree.(id) in {n with cs = rs} end;
              List.iter (fun x -> let n = tree.(x) in tree.(x) <- {n with p = Some id}) rs
            end
          | _ -> failwith "read"
        end;
        read (n-1)
      end
  in
  read n;
  begin let r = find_root tree in set_depth tree r end;
  Array.iteri (fun i x -> let pi = int_of_parent x in
                          let sl = string_of_list x.cs in
                          let tn = type_of_node x in
                          let dn = x.d in
                          printf "node %d: parent = %d, depth = %d, %s, %s\n" i pi dn tn sl) tree

Measured memory_bytes: 26544
from sys import stdin, stdout

input = lambda: stdin.readline().rstrip()
write = stdout.write

def main():
    N = int(input())

    cake = 0
    dounut = 0
    while 1:
        dollars = N - cake * 4
        if dollars < 0:
            print('No')
            break
        elif not dollars % 7:
            print('Yes')
            break
        cake += 1

main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std ;
int main(){
  string s;
  cin>>s;
  if(s=="SUN") cout<<7<<endl;
  if(s=="MON") cout<<6<<endl;
  if(s=="TUE") cout<<5<<endl;
  if(s=="WED") cout<<4<<endl;
  if(s=="THU") cout<<3<<endl;
  if(s=="FRI") cout<<2<<endl;
  if(s=="SAT") cout<<1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  int ac=0, wa=0, tle=0, re=0;
  rep(i, N) {
    string s; cin >> s;
    if(s == "AC") ac++;
    if(s == "WA") wa++;
    if(s == "TLE") tle++;
    if(s == "RE") re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int A,B;
   cin>>A>>B;
   int ans=max(A+B,max(A-B,A*B));
   cout<<ans<<endl;
 
}

Measured memory_bytes: 3568
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))

n = load()
A = []
for _ in range(n):
    A.append(load(str))

cnt = defaultdict(int)
mx = 0
mxl = []

for a in A:
    cnt[a] += 1

for key, value in cnt.items():
    if value == mx:
        mxl.append(key)
        continue
    if value > mx:
        mx = value
        mxl = [key]
        continue

for m in sorted(mxl):
    print(m)


    

Measured memory_bytes: 36972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

ll n;
vector<vector<pair<ll, ll>>> e(100010);
ll dist[100010];
ll q, k;

void dfs(ll v, ll p, ll sum) {
    dist[v] = sum;
    rep(i, 0, (int)e[v].size()) {
        if (e[v][i].first == p) continue;
        dfs(e[v][i].first, v, sum + e[v][i].second);
    }
}

int main() {
    cin >> n;

    rep(i, 0, n - 1) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        e[a].push_back(make_pair(b, c));
        e[b].push_back(make_pair(a, c));
    }

    cin >> q >> k;
    k--;

    rep(i, 0, 100010) dist[i] = -1;
    dist[k] = 0;
    dfs(k, k, 0);

    rep(i, 0, q) {
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        cout << dist[x] + dist[y] << endl;
    }

    return 0;
}


Measured memory_bytes: 14336
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, q, m, d, max_key, max_count;

        while (true) {
            int ans = 0;
            max_key = 0;
            max_count = 0;
            HashMap<Integer, Integer> dayCounts = new HashMap<>();
            n = Integer.parseInt(sc.next());
            q = Integer.parseInt(sc.next());
            if (n == 0 && q == 0)
                break;

            for (int i = 0; i < n; i++) {
                m = Integer.parseInt(sc.next());
                for (int j = 0; j < m; j++) {
                    d = Integer.parseInt(sc.next());
                    int c = dayCounts.containsKey(d) ? dayCounts.get(d) : 0;
                    dayCounts.put(d, ++c);
                    if (c > max_count || (c == max_count && d < max_key)) {
                        max_key = d;
                        max_count = c;
                    }
                }
            }
            if (max_count >= q)
                ans = max_key;

            System.out.println(ans);
        }

    }
}

Measured memory_bytes: 55656
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#define long long
using namespace std;

int main(){
	long long n,ma,sum=0;
	cin>>n;
	long long a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	ma=a[0];
	for(int i=1;i<n;i++){
		if(a[i]<ma){
			sum+=ma-a[i];
		}
		if(a[i]>ma){
			ma=a[i];
		}
	}
	cout<<sum;
}


Measured memory_bytes: 5104
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX;
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;



int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	ll n,m;
	cin>>n>>m;
	if(n==m&&n==1)cout<<1<<endl;
	else if(n==1||m==1){
		if(n==2||m==2)cout<<0<<endl;
		else cout<<max(n,m)-2<<endl;
	}
	else cout<<(n-2)*(m-2)<<endl;
	
	
	
	
//////////////////////////////////////////////////////
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
int n, s;
vector<int> used(10);
int memo[11][1000];
int sum;
void dfs(int d){
    memo[d][sum]++;
    if(d == 10) return;

    rep(i, 10){
        if(used[i]) continue;

        used[i] = true;
        sum += (d + 1) * i;

        dfs(d + 1);

        used[i] = false;
        sum -= (d + 1) * i;
    }
}

int main(void){
    dfs(0);
    while(cin >> n >> s){
        if(s >= 1000) cout << 0 << endl;
        else         cout << memo[n][s] << endl;
    }

	return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> p1(n);
    vector<int> p2(n);
    vector<int> v(n);
    for (int i = 0; i < n; ++i) cin >> p1[i];
    for (int i = 0; i < n; ++i) {
        cin >> p2[i];
        v[i] = i+1;
    }

    int a = 0, b = 0, cnt = 0;
    while(next_permutation(v.begin(),v.end())) {
        cnt++;
        if (p1 == v) a = cnt;
        if (p2 == v) b = cnt;
    }
    cout << abs(a-b) << '\n';
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  string s;
  cin >> s;
  int f = 0;
  rep(i, 0, 3){
    if(s[i] == 'o'){
      f++;
    }
  }
  
  cout << 700 + 100 * f << "\n";
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=2005;
int xx[N],yy[N],father[N],jjj[N],ans,n,m,vis[N],rev[N],x[N],y[N];
vector<int> e[N];
void Swap(int x,int y){
	swap(xx[x],xx[y]); swap(yy[x],yy[y]); swap(rev[x],rev[y]);
}
inline int qiu(int x,int y){
	memset(jjj,0,sizeof(jjj)); 
	for(int i=x;i;i=father[i])jjj[i]=1; 
	for(int i=y;i;i=father[i])if(jjj[i])return i;
}
void dfs(int p,int fa){
	father[p]=fa;
	for(auto i:e[p])if(i!=fa)dfs(i,p);
}
void solve(int dep){
	if(dep==1)return;
	for(int i=1;i<=m;i++)if(xx[i]==yy[i]){
		Swap(i,m); m--; solve(dep); m++; Swap(i,m); return;
	}
	//puts("");
	//for(int i=1;i<=m;i++)cout<<xx[i]<<" jjl "<<yy[i]<<endl;
//	writeln(ans);
	for(int i=1;i<=n;i++)if(!vis[i]){
		int tot=0,v;
		for(auto j:e[i])if(!vis[j]){tot++; v=j;}
		if(tot==1){
			int u=i; tot=0;
			for(int i=1;i<=m;i++){
				if(yy[i]==u){ swap(xx[i],yy[i]);  solve(dep); rev[i]^=1; return;}
				if(xx[i]==u)tot++;
			} 
			//cout<<vis[i]<<" "<<i<<" wzp "<<tot<<endl;
			if(tot<2){
				vis[u]=1;
				if(tot==0)solve(dep-1);
				else{
					for(int i=1;i<=m;i++){
						if(xx[i]==u){xx[i]=v; solve(dep-1); return;}
					}
				}
				return;
			}else{
				for(int i=1;i<=m;i++)if(xx[i]==u){
					for(int j=i+1;j<=m;j++)if(xx[j]==u){
						xx[i]=yy[i]; yy[i]=yy[j]; Swap(j,m); m--;
						solve(dep);
						m++; Swap(j,m); rev[i]^=1; rev[j]^=rev[i]^1;  //cout<<i<<" "<<j<<" "<<rev[1]<<" "<<rev[2]<<" "<<rev[3]<<endl;
						return;
					}
				}
			}
		}
	}
}
int ddd[N];
int main(){
	n=read(); m=read();
	for(int i=1;i<n;i++){
		int s=read(),t=read();
		e[s].push_back(t); e[t].push_back(s);
	}
	dfs(1,0);
	for(int i=1;i<=m;i++){
		x[i]=read(); y[i]=read();
		xx[i]=x[i]; yy[i]=y[i];
		int t=qiu(x[i],y[i]);
		for(int j=x[i];j!=t;j=father[j])ddd[j]++;
		for(int j=y[i];j!=t;j=father[j])ddd[j]++;
	}
	for(int i=1;i<=n;i++)ans+=min(ddd[i],2);
	writeln(ans);
	solve(n);
	for(int i=1;i<=m;i++)if(rev[i])cout<<y[i]<<" "<<x[i]<<endl; else cout<<x[i]<<" "<<y[i]<<endl;
}

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

int main()
{
	int n,m,l;
	int i,j,k;
	
	cin >> n >> m >> l;

	long long A[n][m];
	long long B[m][l];
	long long C[n][l];
	
	for(i = 0; i < n; i++)
	{
		for(j = 0; j < l; j++)
		{
			C[i][j] = 0;
		}
	}
	
	for(i = 0; i < n; i++)
	{
		for(j = 0; j < m; j++)
		{
			cin >> A[i][j];
		}
	}
	for(i = 0; i < m; i++)
	{
		for(j = 0; j < l; j++)
		{
			cin >> B[i][j];
		}
	}
	
	for(i = 0; i < n; i++)
	{
		for(j = 0; j < l; j++)
		{
			for(k = 0; k < m; k++)
			{
				C[i][j] += A[i][k] * B[k][j];
			}
			cout << C[i][j];
			if(j < l - 1)
			{
				cout << " " ;
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 3336
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
# read = sys.stdin.buffer.read
# readline = sys.stdin.buffer.readline
# readlines = sys.stdin.buffer.readlines
input = sys.stdin.readline

A, B = map(int, input().split(" "))

print(A*B)


Measured memory_bytes: 9464
a,b=map(int,input().split())
A=str(a)
B=str(b)

for i in range(b-1):
  A+=str(a)

for i in range(a-1):
  B+=str(b)

for i in range(min(a,b)):
  if int(A[i])<int(B[i]):
    print(A)
    exit()
  elif int(B[i])<int(A[i]):
    print(B)
    exit()
    
print(A)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int Q = sc.nextInt();
		int[] L = new int[M];
		int[] R = new int[M];
		int[] p = new int[Q];
		int[] q = new int[Q];

		int[][] LR = new int[N+1][N+1];

		for(int i=0;i<M;i++){
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			LR[L[i]][R[i]] +=1;
		}
		for(int i=0;i<Q;i++){
			p[i] = sc.nextInt();
			q[i] = sc.nextInt();
//			pq[][]
		}
		sc.close();

		for(int x=1; x<=N; ++x){
			for(int y=1; y<=N; ++y){
				LR[x][y] += LR[x][y-1] +LR[x-1][y] -LR[x-1][y-1];
			}
		}

		for(int i=0;i<Q;i++){
			int sum = LR[q[i]][q[i]] - LR[p[i]-1][q[i]] - LR[q[i]][p[i]-1] + LR[q[i]-1][p[i]-1];
			System.out.println(sum);
		}

	}

}



Measured memory_bytes: 169276
#include<iostream>
#include<vector>
using namespace std;
#define ll long long
ll n,ans=0;
signed main(){
	cin>>n;
	vector<int> v;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			ll cnt=0;
			while(n%i==0){
				cnt++; n/=i;
			}
			v.push_back(cnt);
		}
	}
	if(n!=1)v.push_back(1);
	for(int x : v){
		for(int i=1;;i++){
			if(i*(i+1)/2>x){
				ans+=i-1;
				break;
			}
		}
	}
	cout<<ans<<endl; 
	return 0;
} 

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

// #define fi first
// #define se second
#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pi;

const ll M=1000000007ll;
const ll MOD=1000000007ll;
const ll MAX=100000001ll;
//const ll M = 1000000000+7;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
   return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(ll n){
  if(n==0) return 1;
  mint ans = f(n/2);
  ans *= ans;
  if(n%2==1) ans*= 2;
  return ans;
}

mint choose(ll n, ll k){
  mint x=1, y=1;
  rep(i,k){
    x *= (n-i);
    y *= (i+1);
  }
  return x / y;
}

struct BIT {
  private:
   vector<ll> bit;
   ll N;
 
  public:
   BIT(ll size) {
     N = size;
     bit.resize(N + 1);
   }
 
   // 一点更新です
   void add(ll a, ll w) {
     for (ll x = a; x <= N; x += x & -x) bit[x] += w;
   }
 
   // 1~Nまでの和を求める。
   int sum(ll a) {
     ll ret = 0;
     for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
     return ret;
   }
 };
 
ll fff(ll n, vector<ll>& v, ll i, ll j, ll rl){
  ll can = 0;
  ll can_i = 0;

  cout << v[0]<<endl;
  
  // right
  if(rl == 0){
    rep(k, n){
      if(v[k]*(j-k)>can){
	can = v[k]*(j-k);
	can_i = k;
      }
      //cout << can<<endl;
    }
    v[can_i] = 0;
    return can;
  }
  // left
  else{
    rep(k, n){
      if(v[k]*(k-i)>can){
	can = v[k]*(k-i);
	can_i = k;
      }
      //cout << can<<endl;

    }
    v[can_i] = 0;
    return can;
  }
  
}


int main(){
  ll n;

  cin>>n;

  map<ll, ll> m;
  ll tmp, cnt=0;
  rep(i, n){
    cin>>tmp;
    if(tmp<3200) m[tmp/400]++;
    else cnt++;
  }
  
  if(cnt==n) cout << 1 << " "<< cnt<<endl;
  else{
    tmp=0;
    for(auto x:m){
      tmp++;
    }
    cout << tmp << " "<< tmp+cnt <<endl;
  }
}


Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let n=read::<i32>();
    let a=read::<i32>();
    let b=read::<i32>();
    let mut cnt=0;
    for i in 1..n+1{
        let s=i.to_string();
        let mut sum=0;
        for c in s.into_bytes(){sum+=c as i32-48}
        if a<=sum&&sum<=b{cnt+=i}
    }
    println!("{}",cnt)
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
typedef long long ll;
ll N,M;
string S,T;

ll gcd(ll n,ll m){
	if(n%m==0) return m;
	else return gcd(m,n%m);
}

int main(){
	cin >> N >> M >> S >> T;
	ll L = N/gcd(N,M)*M, n = N/gcd(N,M), m = M/gcd(N,M);
	ll i = 0,j = 0;
	bool judge = true;
	while(i<N && j<M){
		if(S[i]!=T[j]) judge = false;
		i += n; j += m;
	}
	cout << (judge? L:-1) << endl;
}

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

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

int main()
{
    int n, ans = 0;
    cin >> n;
    vector<int> a(n), m(n), rtmp(n + 1), ltmp(n + 1);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }

    rtmp[0] = ltmp[n] = 0;
    for(int i = 0;i < n;i++){
        rtmp[i + 1] = gcd(rtmp[i],a[i]);
    }
    for(int i = n - 1;0 < i;i--){
        ltmp[i] = gcd(ltmp[i + 1],a[i]);
    }

    for(int i = 0;i < n;i++){
        m[i] = gcd(rtmp[i],ltmp[i + 1]);
    }

    for(int i = 0;i < n;i++){
        ans = max(ans,m[i]);
    }   
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 1792
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

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




using namespace std;

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

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}

int p[M+4];
bool sml_ok[M+4];
bool big_ok[M+4];
 struct MinQ
{ int window;deque<pair<int,int> >dq;
  MinQ(int x){window=x;}
  void push(int idx,int x)
  {while(!dq.empty() && dq.back().first>=x)dq.pop_back();dq.push_back(make_pair(x,idx));}
  int qry(int idx){while(idx-dq.front().second>=window)dq.pop_front();return dq.front().first;}
};

int bam_mn[M+2];
int bam_mx[M+2];
 main()

{
    fast
    int n,k;
    cin>>n>>k;
    f(i,1,n)cin>>p[i];
    MinQ a(k-1),b(k-1),c(k);
    f(i,1,k)c.push(i,p[i]);
    f(i,1,k-1)
    {
        a.push(i,p[i]);
        b.push(i,-p[i]);
    }
    bam_mn[k-1]=a.qry(k-1);
    bam_mx[k-1]=-b.qry(k-1);
    int extra=0;
    if(a.dq.size()==k-1)sml_ok[k-1]=true;
    if(c.dq.size()==k)big_ok[k]=true,extra++;
    f(i,k+1,n)
    {
        c.push(i,p[i]);
        c.qry(i);
        if(c.dq.size()==k)big_ok[i]=true,extra++;
    }
    f(i,k,n)
    {
        a.push(i,p[i]);
        b.push(i,-p[i]);
        bam_mn[i]=a.qry(i);
        bam_mx[i]=-b.qry(i);
        if(a.dq.size()==k-1)sml_ok[i]=true;
    }
    int cnt=1;
    p[n+1]=inf;
    int yo=0;
    f(i,k+1,n)
    {
        int lft=p[i-k];
        int rgt=p[i];
        if(lft<bam_mn[i-1] && rgt>bam_mx[i-1])
        {
            if(sml_ok[i-1]==true)
            {
                yo++;
            }
            continue;
        }
        cnt++;
    }
    int ses=cnt-extra+yo;
    if(extra>=1)ses++;
    cout<<ses<<endl;
    return 0;

}













Measured memory_bytes: 9856
using namespace std;
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
void solve()
{
int n;
cin>>n;
double p[n];
for(int i=0;i<n;i++)
cin>>p[i];
double dp[n+1][n+1];
memset(dp,0.0,sizeof(dp));
dp[0][0]=1.0;
// j for the heads 
// n for the total no of coins used till now
for (int i = 1; i <=n; i++)
{
    for (int j = 0; j <=n; j++)
    {
        if(j==0)
        dp[i][j]=(1-p[i-1])*(dp[i-1][j]);
        else
        dp[i][j]=dp[i-1][j-1]*p[i-1]+dp[i-1][j]*(1-p[i-1]);
    }
}
double ans=0;
// for (int i = 0; i <=n; i++)
// {
//     for (int j = 0; j <=n; j++)
//     {
//         cout<<dp[i][j]<<" ";
//     }
//     cout<<endl;
// }
for (int i = (n+1)/2; i <=n; i++)
{
ans+=dp[n][i];
}
cout<<fixed<<setprecision(10)<<ans<<endl;
}
int main()
{
FASTIO
 long long int t;
 t=1;
 while(t--)
  solve();
  return 0;
}


Measured memory_bytes: 74096
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    ll N; cin >> N;
    int ans = 0;
    FOR(i, 2, 1000010) {
        int cur = 0;
        while (N % i == 0) {
            cur++;
            N /= i;
        }
        FOR(j, 1, 10000) {
            if (cur < j) break;
            ans++; cur -= j;
        }
    }
    if (N > 1) ans++;
    cout << ans << nl;
	
	return 0;
}
 

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
typedef pair<int, int> P;
typedef long long int ll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

Vp vec;
int ans[101];
int rank = 1;

int main(){
	while(true){
		int temp1, temp2; char trash; scanf("%d%c%d", &temp1, &trash, &temp2);
		if(temp1 == 0 && temp2 == 0) break;
		vec.pb(P(temp2,temp1));
	}
	sort(vec.begin(), vec.end(), greater<P>());
	ans[vec[0].sec] = rank;
	for(int i = 1; i < vec.size(); i++){
		if(vec[i].fi == vec[i-1].fi) ans[vec[i].sec] = rank;
		else{
			rank++;
			ans[vec[i].sec] = rank;
		}
	}
	int temp;
	while(cin >> temp){
		cout << ans[temp] << endl;
	}
}

Measured memory_bytes: 1248
N = int(input())
A = list(map(int, input().split()))

result = 0
for bit in range(60):
    m = 1 << bit
    bits = sum((a & m for a in A))
    bits >>= bit
    result += (bits * (N -  bits)) << bit 
    result %= 1000000007
print(result)


Measured memory_bytes: 43692
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<utility>
#include<map>
#define ll long long
using namespace std;
ll a[4];

int main()
{
	ll i,j;
	for(i=1;i<=3;i++) scanf("%lld",&a[i]);
	sort(a+1,a+4);
	if(a[1]%2==0 || a[2]%2==0 || a[3]%2==0) printf("0");
	else printf("%lld",a[1]*a[2]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define MOD 100000007
long long N;
long long M;
int k;
using Graph = vector<vector<int>>;
vector<int> color(100000,0);
vector<bool> used(100000,false);
//vector<bool> ans(100000,false);

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};
int ans = 0;

int solve(int a,int b)
{
    int ans = 0;
    for(int i=0;i<a;i++)
    {
        for(int j=i+1;j<a;j++)
        {
            for(int k=j+1;k<a;k++)
            {
                if(i+j+k+3 == b)
                {
                    ans++;
                }
            }
        }
    }
    return ans;
}
int main()
{
    string S;
    cin >> S ;
    //cin >> M;
    
    //Graph data(1000);
    vector<int> atcg(S.size(),0);
    
    for(int i=0;i<S.size();i++)
    {
        if(S[i] == 'A' ||S[i] == 'T' ||S[i] == 'C' ||S[i] == 'G' )
        {
            if(i==0)
            {
                atcg[i] = 1;
            }
            else
            {
                atcg[i] = atcg[i-1]+1;
            }
        }
    }
   
    int ans = 0;
    for(int i=0;i<S.size();i++)
    {
        ans = max(ans,atcg[i]);
    }
    
    
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

namespace Tzh{
	
	const int maxn=200010,mx=200000;
	typedef long long ll;
	const ll p=1e9+7;
	ll fac[maxn],inv[maxn],ans,n,a,b,c,aa,bb;

	ll qpow(ll a,ll b){ ll sum=1;
		while(b){
			if(b&1) sum=sum*a%p;
			a=a*a%p; b>>=1;
		}
		return sum;
	}

	ll cc(ll n,ll m){
		return fac[n]*inv[m]%p*inv[n-m]%p;			
	}

	void work(){
		scanf("%lld%lld%lld%lld",&n,&a,&b,&c); fac[0]=1;
		for(int i=1;i<=mx;i++) fac[i]=fac[i-1]*i%p;
		inv[mx]=qpow(fac[mx],p-2);
		for(int i=mx;i;i--) inv[i-1]=inv[i]*i%p;
		aa=qpow(a+b,p-2)*a%p; bb=qpow(a+b,p-2)*b%p;
		for(int i=n;i<=2*n-1;i++)
			ans=(ans+i*((cc(i-1,n-1)*qpow(aa,n)%p*qpow(bb,i-n)%p+cc(i-1,n-1)*qpow(bb,n)%p*qpow(aa,i-n)%p)%p)%p)%p;
		ans=ans*qpow(a+b,p-2)%p*(a+b+c)%p;
		printf("%lld",ans);
		return ;
	}
}

int main(){
	Tzh::work();
	return 0;	
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };


signed main() {
	int n, m, k, maxn = 0;
	vector<int>list;

	cin >> n >> k;

	for (int i = 1; i <= n; i++) {
		int cnt = 0;
		for (int j = i; j < k; j *= 2, cnt++) {

		}
		list.push_back(cnt);
	}

	double num = 1.00 / (double)n;
	double sum = 0;

	for (int i = 0; i < n; i++) {
		//sum += num * (1.0 / 2 )(double)list[i]);
		sum += num * pow(0.5, list[i]);
	}


	cout << fixed << setprecision(13)<< sum << endl;



	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 1400
#include "iostream"
#include "vector"
using namespace std;
int main()
{
    int r,d,x200;
    cin>>r>>d>>x200;
    
    int result[11];
    result[0]=x200;
    
    for(int i=1;i<=10;i++)
    {
        result[i]=result[i-1]*r-d;
        cout<<result[i]<<endl;
    }
    
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=2e5+7;
int fa[maxn];
vi G[maxn];
bool vis[maxn];
bool lp[maxn];
int a[maxn];
void dfs(int u)
{
    vis[u]=1;
    set<int> all;
    for(auto v:G[u])
    {
        if(vis[v]) continue;
        dfs(v);
        all.insert(a[v]);
    }
    for(int i=0;;i++)
    {
        if(!all.count(i))
        {
            a[u]=i;
            return;
        }
    }
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>fa[i];
        G[fa[i]].push_back(i);
    }
    int rt;
    for(rt=1;!vis[rt];rt=fa[rt]) vis[rt]=1;
    memset(vis,0,sizeof(vis));
    int len=0;
    for(;!vis[rt];rt=fa[rt]) vis[rt]=1,lp[rt]=1;
    for(int i=1;i<=n;i++)if(lp[i]) dfs(i),len++;
    memset(vis,0,sizeof(vis));
    bool ok=0;
    for(;!vis[rt];rt=fa[rt])
    {
        vis[rt]=1;
        if(a[fa[rt]]!=a[rt])
        {
            ok=1;
            break;
        }
    }
    //for(int i=1;i<=n;i++) dbg(i,a[i]);
    if(ok||(len%2==0)) cout<<"POSSIBLE\n";
    else cout<<"IMPOSSIBLE\n";
    
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	int x = 0;
	rep(i, n) x += ((i & 1) ? -a[i] : a[i]);
	x /= 2;

	vector<int> ans(n, 0);
	ans[0] = x;
	rep(i, 1, n) ans[i] = a[i - 1] - ans[i - 1];

	rep(i, n) cout << (i?" ":"") << 2 * ans[i];
	cout << endl;

	return 0;
}

Measured memory_bytes: 2048
# coding=utf-8
from math import sqrt


def main():
    d = input()
    x = map(int, raw_input().split())
    y = map(int, raw_input().split())
    z = [abs(x - y) for x, y in zip(x, y)]
    print sum(z)
    print sqrt(sum([w ** 2 for w in z]))
    print sum([w ** 3 for w in z]) ** (1.0 / 3)
    print max(z)


if __name__ == '__main__':
    main()

Measured memory_bytes: 4440
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
int main(void){
    char str[1201],init[1]={};    //input string 
    int  asum[26] = {};       //each sum of the alphabet 
    int i,j,len;

    while((scanf("%s",str)) != EOF){
        len = strlen(str);
        for(i = 0; i <26; i++){
            for(j = 0; j < len; j++){
                if(str[j] == 97 + i || str[j] == 65 + i){
                    asum[i]++;
                }
            }
        }
    }
    for(i = 0; i < 26; i++){
        printf("%c : %d\n",97 + i, asum[i]);
        }

    return 0;
    }

Measured memory_bytes: 540
#include <map>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
    string s; cin >> s;
    map<char, bool> m;
    for (char c : s) m[c] = true;
    cout << ((m['N'] == m['S'] && m['E'] == m['W']) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, x;
  std::vector<int> l;
  cin >> n >> x;
  int tmp;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    l.push_back(tmp);
  }
  int ans = 1;
  int p = 0;
  for (int i = 0; i < n; i++) {
    p += l[i];
    if (p <= x)
      ans++;
    else {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       int n=s.nextInt();
      int[][] dp=new int[6][n+1];
      for(int i=0;i<=n;i++){
      	if(i%100==0){dp[0][i]=1;}
      }
      for(int i=0;i<6;i++){
      	dp[i][0]=1;
      }
      for(int i=1;i<6;i++){
      	for(int j=1;j<=n;j++){
      		if(j<100+i){
      			dp[i][j]=dp[i-1][j];
      		}
      		else{
      			dp[i][j]=dp[i-1][j]+dp[i][j-100-i];
      		}
      	}
      }
      if(dp[5][n]==0){
      	System.out.println("0");
      }
      else{System.out.println("1");}
        }
    }


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

#define int long long

using namespace std;


int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N;
    cin >> N;

    vector<int> vect;

    for(int i = 0 ; i < N ; i++)
    {
    	int n;
    	cin >> n;
    	vect.push_back(n);
    }

    for(int x = 0 ; x < 31 ; x++)
    {
    	int c0 = 0, c1 = 0;
    	for(int i = 0 ; i < N ; i++)
    	{
    		if(vect[i]&(1<<x))c1++;
    	}

    	if(c1&1)
    	{
    		for(int i = 0 ; i < N ; i++)
			{
				vect[i] ^= (1<<x);
			}
    	}
    }

    for(int i = 0 ; i < N ; i++)
    {
    	cout << vect[i] << " ";
    }
    cout << '\n';

    return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
	int n; cin >> n;
	vector<ll> a(n), b(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	reverse(a.begin(), a.end()), reverse(b.begin(), b.end());

	ll cur = 0;
	for(int i = 0; i < n; i++) {
		a[i] += cur;
		ll to = (b[i] + a[i] - 1) / b[i];
		cur += (b[i] * to - a[i]);
		//cout << to << " " << to * b[i] << endl;
	}
	cout << cur << endl;

}	

Measured memory_bytes: 1920
x,y,a,b,c = list(map(int,input().split()))
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p = sorted(p,reverse=True)
q = sorted(q,reverse=True)
r = sorted(r,reverse=True)
ans = p[:x]+q[:y]+r
ans = sorted(ans,reverse=True)
print(sum(ans[:x+y]))

Measured memory_bytes: 29348
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define YESNO(i) puts((i)?"YES":"NO");
#define YesNo(i) puts((i)?"Yes":"No");
#define yesno(i) puts((i)?"yes":"no");
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s,t;cin>>s>>t;
  YesNo(t.substr(0,s.length())==s);
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define PF first
#define PS second
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 100000007;
const ll INF = 10e9;
#define PI 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main() {
  IN(ll,N);
  bool ans = false;
  REP(i,10){
    REP(j,10){
      if(N == i*j)
        ans = true;
    }
  }
  BOUT(ans);
}



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

int main() {
  int n,m; cin>>n>>m;
  vector<pair<pair<int, int>, int>> X(m);
  rep(i, m) {
    int a,b; cin>>a>>b;
    X[i].second=i;
    X[i].first.second=a;
    X[i].first.first=b;
  }
  sort(X.begin(), X.end());
  vector<pair<int, int>> ans(m);
  vector<int> tmp(n, 0);
  rep(i, m) {
    tmp[X[i].first.second]++;
    ans[X[i].second].second=tmp[X[i].first.second];
    ans[X[i].second].first=X[i].first.second;
  }
  rep(i, m) {
    ll output=(ll)ans[i].first*1000000+ans[i].second;
    printf("%012lld\n", output);
  }
  return 0;
}

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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    int n=s.size();
    int pr[n+1];
    pr[0]=0;
    int u=1;
    for(int i=0;i<n;++i)
    {
        pr[i+1]=pr[i]+(u*(s[i]-'0'));
        pr[i+1]%=2019;
        u*=10;
        u%=2019;
    }
    map <int,int> z;
    int ans=0;
    for(int i=0;i<=n;++i)
    {
        //cout<<pr[i]<<endl;
        if(z.count(pr[i]))
        {
            ans+=z[pr[i]];
            z[pr[i]]++;
        }
        else
        {
            z[pr[i]]=1;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 5256
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <math.h>
#include <numeric>
#include <math.h>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <climits>
#include <string>

using namespace std;

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

	int m, d;
	cin >> m >> d;
	int ans = 0;
	for(int j = 1; j <= m; j++)
	for(int i = 1; i <= d; i++)
		if((i % 10) >= 2 && (i / 10) >= 2 && (i % 10) * (i / 10) == j) ans++;
	cout << ans;
}

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

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

    static class NSlimes {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = in.nextInt();
            long[] sum = new long[n + 1];
            for (int i = 0; i < n; i++) {
                sum[i + 1] = sum[i] + a[i];
            }

            long[][] dp = new long[n][n]; // [starting index][ending index], only defined for starting index <= ending index
            for (int i = 0; i < n; i++) {
                dp[i][i] = 0;
            }

            for (int k = 1; k < n; k++) {
                for (int i = 0; i + k < n; i++) {
                    dp[i][i + k] = Long.MAX_VALUE;
                    for (int split = i; split < i + k; split++) {
                        dp[i][i + k] = Math.min(dp[i][i + k], dp[i][split] + dp[split + 1][i + k] + sum[i + k + 1] - sum[i]);
                    }
                }
            }

            out.println(dp[0][n - 1]);
        }

    }

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

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

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

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

    }
}



Measured memory_bytes: 23892
#include<iostream>
#include<string>

using namespace std;

int A[110]={};

int main(void)
{
	int n,m,x;
	int tmp;
	int ans1=0;
	int ans2=0;
	cin >> n >> m >> x;
	for(int i =0; i<m; i++){
	 cin >> tmp;
	 A[tmp] = 1;
	}
	for(int i = x; i < n; ++i){
		ans1 += A[i];
	}
	for(int i = x; i > 0; --i){
		ans2 += A[i];
	}
	if(ans1 < ans2){
		cout << ans1 << endl;
	}else{
		cout << ans2 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
#ifdef WAAUTOMATON
#define debug(args...)            {dbg,args; cerr<<endl;}
#else
#define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
	template<typename T> debugger& operator , (const T& v)
	{
		cerr<<v<<" ";
		return *this;
	}
} dbg;
#define MAXN 2000
struct Edge
{
	int to,next;
}e[2*MAXN+10];
int head[MAXN+10];
void addEdge(int a,int b)
{
	static int c=0;
	e[++c]=(Edge){b,head[a]};
	head[a]=c;
	e[++c]=(Edge){a,head[b]};
	head[b]=c;
}
bool b[MAXN+10];
void dfs(int now,int d,int fa)
{
	if (d<0) return;
	b[now]=true;
	for(int i=head[now]; i!=0; i=e[i].next) {
		int v=e[i].to;
		if (v==fa) continue;
		dfs(v,d-1,now);
	}
}
void solve(long long N, long long K, vector<long long> A, vector<long long> B){
	for(int i=0; i<N-1; ++i) {
		addEdge(A[i],B[i]);
	}
	int ans=0;
	if (K%2==0) {
		for(int i=1; i<=N; ++i) {
			memset(b,false,sizeof(b));
			dfs(i,K/2,0);
			int cnt=0;
			for(int j=1; j<=N; ++j) {
				if (b[j]) ++cnt;
			}
			ans=max(ans,cnt);
		}
	} else {
		for(int i=0; i<N-1; ++i) {
			memset(b,false,sizeof(b));
			dfs(A[i],K/2,0);
			dfs(B[i],K/2,0);
			int cnt=0;
			for(int j=1; j<=N; ++j) {
				if (b[j]) ++cnt;
			}
			ans=max(ans,cnt);
			debug(cnt);
		}
	}
	cout<<N-ans<<endl;
}

int main(){
	//freopen("in.txt","r",stdin);
	long long N;
	long long K;
	scanf("%lld",&N);
	vector<long long> B((N-1)-1+1);
	vector<long long> A((N-1)-1+1);
	scanf("%lld",&K);
	for(int i = 0 ; i <= (N-1)-1 ; i++){
		scanf("%lld",&A[i]);
		scanf("%lld",&B[i]);
	}
	solve(N, K, A, B);
	return 0;
}



Measured memory_bytes: 512