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

constexpr int alph = 26;

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

	string s;
	cin >> s;
	int n = s.size();
	vector<int> a(n);
	int cnt = 1;
	int ap = 0, mask = (1 << alph) - 1;
	for (int i = n - 1; i >= 0; i--) {
		int c = s[i] - 'a';
		ap |= (1 << c);
		if (ap == mask) {
			cnt++; ap = 0;
		}
		a[i] = cnt;
	}
	a.pb(0);
	int sz = a[0] - 1;
	int ng = 0; int u = alph; int idx = 0;
	string ans = "";
	rep(i, n) {
		if (a[i + 1] > sz) ng |= (1 << (s[i] - 'a'));
		else {
			while (i < n - 1 && a[i + 1] == sz) {
				int c = s[i] - 'a';
				if (!(ng&(1 << c)) && chmin(u, c)) idx = i;
				i++;
			}
			if (u != alph) {
				//cerr << '!' << idx << '\n';
				ans += s[idx]; sz--;
				i = idx; ng = 0; u = alph;
			}
		}
	}
	//rep(i, n) cerr << a[i] << '\n';
	rep(i, alph) {
		if (!(ng&(1 << i))) {
			ans += (char)'a' + i;
			break;
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 2196
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long A,B,C; cin >> A >> B >> C;
    if( A + B >= C)
    {
        cout << B + C << endl;
    }
    else
    {
        cout << A + 2*B + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int	main()
{
	char	S[11];
	int	sum;
	int	max;
	int	i;

	sum = 0;
	max = 0;
	i = 0;
	scanf("%s\n", S);
	while (S[i])
	{
		if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T')
			sum++;
		else
		{
			if (sum > max)
				max = sum;
			sum = 0;
		}
		i++;
	}
	if (sum > max)
		max = sum;
	printf("%d\n", max);
	return (0);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int initLen = S.length();

        int zero = S.replace("1", "").length();
        int one = S.replace("0","").length();
        System.out.println(S.length() -  Math.abs(zero - one));

    }

}


Measured memory_bytes: 36596
import java.util.Arrays;
import java.util.Scanner;

public final class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] stone = new int[n];
        int diff2 = Integer.MAX_VALUE;
        for(int i=0; i<n; i++){
          	stone[i] = sc.nextInt();
        }
        int[] dp = new int[n];
        for(int i=0; i<n; i++){
            if(i>0){
                if(i>1){
                    diff2 = dp[i-2]+Math.abs(stone[i]-stone[i-2]); 
                    // System.out.println(dp[i-1]+" "+dp[i-2]);
                }
                int diff = dp[i-1]+Math.abs(stone[i]-stone[i-1]);
                dp[i] = Math.min(diff,diff2);
            }
        }
        System.out.println(dp[n-1]);
        // for(int i=0; i<n; i++){
        //     System.out.print(dp[i]+" ");
        // }
        sc.close(); 
    }
}

Measured memory_bytes: 48604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define st first
#define nd second
#define rep(i,n) for (long long (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for(long long (i)=(a);(i)<(b);++(i))
#define pb push_back
#define mp make_pair
#define endl '\n'
const int mx=1e5+5;
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int n;cin >> n;
	vector <int > a(n);
	rep(i,n)cin >> a[i];
	vector <int > dp(n,0);
	dp[0]=0;
	for(int i=0;i<n;++i){
			if(a[i]<=a[i-1])dp[i]=max(dp[i-1]+1,dp[i]);
	}
	cout << *max_element(dp.begin(),dp.end());
}


Measured memory_bytes: 1024
import math

while True:
    n, x = list(map(int, input().split()))
    if n == 0 and x == 0:
        break
    count = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i == j:
                continue
            for k in range(j + 1, n + 1):
                if k == i or k == j:
                    continue
                if i + j + k == x:
                    count += 1
    print(count)



Measured memory_bytes: 5656
package main

import (
	"fmt"
)

func main() {
	n := SingleInt()
	ss := ScanNums(n)

	re := 1
	lim := ss[0]
	for i := 1; i < n; i++ {
		if lim <= ss[i] {
			re++
			lim = ss[i]
		}
	}
	fmt.Printf("%#v\n", re)
}

func SingleInt() int {
	var n int
	fmt.Scan(&n)
	return n
}

func ScanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 512
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
  long n, w;
  cin >> n >> w;
  long weights[n];
  long value[n];
  for(long i = 0;i<n;i++){
    cin >> weights[i] >> value[i];
  }
  
  long dp[n+1][w+1];
  for(long i = 0;i<=n;i++){
    dp[i][0] = 0;
  }
  for(long i = 0;i<=w;i++){
    dp[0][i] = 0;
  }
  
  for(long i = 1;i<=n;i++){
    for(long j = 1;j<=w;j++){
      if(weights[i-1] <= j){
        dp[i][j] = max(dp[i-1][j], value[i-1] + dp[i-1][j-weights[i-1]]);
      }
      else{
        dp[i][j] = dp[i-1][j];
      }
    }
  }
  
  cout << dp[n][w] << "\n";
  return 0;
  
}


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

int main() {
  int N,K,x=1;
  cin >> N >> K;
  for(int i=0; i<N; i++) {
    if(x*2<x+K) {
      x*=2;
    }
    else {
      x+=K;
    }
  }
  cout << x << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I n;
  cin >> n;
  int t = 0;
  if (n >= 9) t += 9;
  else t += n;

  if (n >= 100 && n <= 999) t += n - 99;
  else if (n >= 1000) t += 900;

  if (n >= 10000 && n <= 99999) t += n - 9999;
  else if (n >= 100000) t += 90000;

  cout << t << endl;
  return 0;
}



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

int abss(int x){
	if(x >= 0){
		return x;
	}else{
		return (-1) * x;
	}
}

int main() {
    string s;
    cin >> s;
    int size = s.size();
    int sa = 8000;

    for(int i = 0; i < size - 2; ++i){
    	int a = (s[i] - '0') * 100 + (s[i+1] - '0') * 10 + (s[i+2] - '0');

    	if(abss(a - 753) <= sa){
    		sa = abss(a - 753);
    	}
    }

    cout << sa << endl;
}

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

using namespace std;

int main(void){
    string a, b, c;
    char s1, s2, s3;
    cin >> a >> b >> c;
    transform(a.begin(), a.end(), a.begin(),  ::toupper);
    transform(b.begin(), b.end(), b.begin(), ::toupper);
    transform(c.begin(), c.end(), c.begin(), ::toupper);
    s1 = a[0];
    s2 = b[0];
    s3 = c[0];
    cout << s1 << s2 << s3 << endl;
}

Measured memory_bytes: 256
S= list(input())
Answer = "a"

for i in ['+','-']:
  for j in ['+','-']:
    for k in ['+','-']:
      if eval(S[0]+i+S[1]+j+S[2]+k+S[3])==7:
        Answer = S[0]+i+S[1]+j+S[2]+k+S[3]+'=7'
        break

print(Answer)

Measured memory_bytes: 3060
# https://atcoder.jp/contests/agc034/tasks/agc034_a

import itertools
from collections import Counter
from collections import defaultdict
import bisect
import math
import heapq

def main():
    N, A, B, C, D = map(int, input().split())
    S = list(input())

    blocks = 0
    for s in range(A - 1, C):
        if S[s] == '.':
            if blocks > 1:
                print('No')
                exit()
            blocks = 0
        else:
            blocks += 1

    blocks = 0
    for s in range(B - 1, D):
        if S[s] == '.':
            if blocks > 1:
                print('No')
                exit()
            blocks = 0
        else:
            blocks += 1

    if D < C:  # 追い越す場所が必要
        can_overtake = False
        for s in range(B - 1, D):
            if S[s-1] == '.' and S[s] == '.' and S[s+1] == '.':
                can_overtake = True
                break

        if not can_overtake:
            print('No')
            exit()

    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 61168
from collections import deque
from sys import stdin
input = stdin.readline


def main():
  S = input()[:-1]
  Q = int(input())

  q = deque([S])
  reverse = False
  for i in range(Q):
    line = input().split()
    if line[0] == '1':
      reverse = not(reverse)
    else:
      if reverse ^ (int(line[1])-1):
        # S = S + line[2]
        q.append(line[2])
      else:
        # S = line[2] + S
        q.appendleft(line[2])

  print(''.join(list(reversed(''.join(q)))) if reverse else ''.join(q))


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 94388
//a.c A-Maximize the Formula
#include<stdio.h>

int max3(int a,int b,int c){
    int max = a;
    if(b>max){
        max = b;
    }
    if(c>max){
        max = c;
    }
    return max;
}

int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    int max = max3(a,b,c);
    if(max == a){
        printf("%d\n",10*max+b+c);
    }else if(max == b){
        printf("%d\n",10*max+a+c);
    }else{
        printf("%d\n",10*max+a+b);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;

	vector<int> A(M*2);
	vector<int> res(N,0);
	for(int i=0;i<M*2;i++){
		cin >> A.at(i);
      	res.at(A.at(i)-1)++;
	}
	for(int i=0;i<N;i++){
		cout << res.at(i) << endl;
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

struct node{
  int key;
  node *left, *right, *p;
  node(){}
  node(int key):key(key){left=right=p=NULL;};
};
node *root;
void insert(node z){
  node *y=NULL;
  node *x=root;
  while(x!=NULL){
    y=x;
    if(z.key<x->key) x=x->left;
    else x=x->right;
  }
  z.p=y;
  if(y==NULL) root=new node(z);
  else if(z.key<y->key) y->left=new node(z);
  else y->right=new node(z);
}
void inorderTreeWalk(node *v){
  if(v==NULL) return;
  inorderTreeWalk(v->left);
  cout<<" "<<v->key;
  inorderTreeWalk(v->right);
}
void preorderTreeWalk(node *v){
  if(v==NULL) return;
  cout<<" "<<v->key;
  preorderTreeWalk(v->left);
  preorderTreeWalk(v->right);
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  root=NULL;
  FOR(i,0,n){
    string s;
    cin >> s;
    if(s[0] == 'i'){
      int x; cin >> x;
      insert(node(x));
    } else {
      inorderTreeWalk(root);
      cout<<endl;
      preorderTreeWalk(root);
      cout<<endl;
    }
  }
}


Measured memory_bytes: 26532
N,A,B = map(int,input().split())

ans = 0 
mod = 7+10**9

def expo(x,n):
  var = 1
  while n>0:
    if n%2 == 1:
      var = (var*x) % mod
    x = (x*x)%mod
    n = n>>1
  return var

def combi(n,k):
  N = 1
  K = 1
  for i in range(n-k+1,n+1):
    N = (N*i)%mod
  for i in range(1,k+1):
    K = (K * i)%mod
  return (N*expo(K,mod-2))%mod

print((expo(2,N)-1-combi(N,A)-combi(N,B))%mod)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(a,b,c) for (int a=b;a<=c;a++)
#define per(a,b,c) for (int a=b;a>=c;a--)
#define go(u) for (int o=ft[u],v;v=E[o].t;o=E[o].n)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> par;
const int N=100010;
struct edge{int t,l,n;}E[N<<2];
int n,m,h,tot,t,q[N],tp[N],vis[N],ft[N];
LL ans;
void add(int x,int y,int z){
	E[++tot]=(edge){y,z,ft[x]},ft[x]=tot;
}
LL solve(int u){
	LL s[4]={0,0,0,0},flag=0,s2=0;
	q[h=t=1]=u;
	vis[u]=1;
	while (h<=t){
		u=q[h++];
		s[3]++;
		s[tp[u]]++;
		go(u) { 
			++s2;if (!vis[v]){
			vis[v]=1;
			tp[v]=(tp[u]+E[o].l+3)%3;
			q[++t]=v;
		} else if (tp[v]!=(tp[u]+E[o].l+3)%3) flag=1;} 
	}
	if (flag) return s[3]*s[3];
	if (!s[0]||!s[1]||!s[2]) return s2/2;
	return s[0]*s[1]+s[1]*s[2]+s[2]*s[0];
}
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,m){
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y,1),add(y,x,-1);
	}
	rep(i,1,n) if (!vis[i]) ans+=solve(i);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4224
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] s = Console.ReadLine().Split(' ');
		int A = int.Parse(s[0]);
		int B = int.Parse(s[1]);
		int C = int.Parse(s[2]);
		string t = Console.ReadLine();
		int K = int.Parse(t);
		int sum = 0;
		if(A>=B && A>=C){
			for(var i=0;i<K;i++){
				A *= 2;
			}
		} else if(B>=A && B>=C){
			for(var i=0;i<K;i++){
				B *= 2;
			}
		} else {
			for(var i=0;i<K;i++){
				C *= 2;
			}
		}
		Console.WriteLine(A+B+C);
	}
}

Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,k,K,q,sz[100005],hv[100005],hd[100005],cn[100005],dp[100005],vs[100005],id[100005],ps[100005],sm[100005],seg[1<<18];
vector<P>g[100005];
void dfs1(int v,int p){
    sz[v]=1;
    for(int i=0;i<g[v].size();i++){
        ll u=g[v][i].F;
        if(u==p)continue;
        dfs1(u,v);
        if(hv[v]==-1||sz[hv[v]]<sz[u])hv[v]=u;
        sz[v]+=sz[u];
    }
}
void dfs2(int v,int p,int d,int h){
    hd[k]=h;
    cn[k]=cn[h];
    dp[k]=d;
    id[v]=k;
    vs[k++]=v;
    if(hv[v]!=-1)dfs2(hv[v],v,d+1,h);
    for(int i=0;i<g[v].size();i++){
        ll u=g[v][i].F;
        if(u==p||u==hv[v])continue;
        cn[k]=id[v];
        dfs2(u,v,d+1,k);
    }
}
int lca(int v,int u){
    while(hd[v]!=hd[u]){
        if(dp[hd[v]]<dp[hd[u]])swap(u,v);
        v=cn[v];
    }
    if(dp[v]<dp[u])swap(v,u);
    return u;
}
void up(int a,ll x){
    a+=(1<<17)-1;
    seg[a]=x;
    while(a>0){
        a=(a-1)/2;
        seg[a]=seg[a*2+1]+seg[a*2+2];
    }
}
ll sum(int a,int b,int l,int r,int o){
    if(r<a||b<l)return 0;
    if(a<=l&&r<=b)return seg[o];
    return sum(a,b,l,(l+r-1)/2,o*2+1)+sum(a,b,(l+r+1)/2,r,o*2+2);
}
ll query(int v){
    ll res=0;
    while(v!=0){
        res+=sum(hd[v],v,0,(1<<17)-1,0);
        if(hd[v]!=cn[v]&&(sm[cn[v]]+ps[hd[v]]+sm[hd[v]])%K!=0)res+=sm[cn[v]]+ps[hd[v]]+sm[hd[v]];
        v=cn[v];
    }
    return res;
}
int main(void){
    scanf("%lld%lld",&n,&K);
    for(int i=0;i<n-1;i++){
        ll a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        g[a].PB(P(b,c));
        g[b].PB(P(a,c));
    }
    for(int i=0;i<n;i++)hv[i]=-1;
    dfs1(0,-1);
    dfs2(0,-1,0,0);
    for(int i=0;i<n;i++){
        for(int j=0;j<g[i].size();j++){
            ll a=i,b=g[i][j].F,c=g[i][j].S;
            a=id[a];
            b=id[b];
            if(dp[a]<dp[b])continue;
            ps[a]=c;
            if(hd[a]==hd[b]&&c%K!=0)up(a,c);
        }
    }
    scanf("%lld",&q);
    while(q){
        char w[10];
        scanf("%s",w);
        if(w[0]=='s'){
            int v,u;
            scanf("%d%d",&v,&u);
            v=id[v];
            u=id[u];
            printf("%lld\n",query(v)+query(u)-query(lca(u,v))*2);
        }else{
            ll v,c;
            scanf("%lld%lld",&v,&c);
            v=id[v];
            sm[v]+=c;
            if(hd[v]==hd[v+1]){
                if((ps[v+1]+sm[v]+sm[v+1])%K==0)up(v+1,0);
                else up(v+1,ps[v+1]+sm[v]+sm[v+1]);
            }
            if(v!=0&&hd[v]==hd[v-1]){
                if((ps[v]+sm[v]+sm[v-1])%K==0)up(v,0);
                else up(v,ps[v]+sm[v]+sm[v-1]);
            }
        }
        q--;
    }
}



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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

#define MAX_V 100000

struct scc {

  int V;
  vector<vector<int>> G, rG;
  vector<int> vs, cmp;
  vector<bool> used;

  scc(int V) : V(V) {
    used.assign(V, false);
    G.resize(V), rG.resize(V);
    cmp.resize(V);
  }

  void add_edge(int from, int to) {
    G[from].push_back(to);
    rG[to].push_back(from);
  }

  void dfs(int v) {
    used[v] = true;
    for (int c : G[v]) if (not used[c]) dfs(c);
    vs.push_back(v);
  }

  void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    for (int c : rG[v]) if (not used[c]) rdfs(c, k);
  }

  int scc_run() {
    fill(used.begin(), used.end(), false);
    vs.clear();
    for (int v = 0; v < V; v++) if (!used[v]) dfs(v);
    fill(used.begin(), used.end(), false);
    int k = 0;
    for (int i = vs.size() - 1; i >= 0; i--) if (!used[vs[i]]) rdfs(vs[i], k++);
    return k;
  }
};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int V, E; cin >> V >> E;
  scc cc(V);

  REP(_, E) {
    int f, t; cin >> f >> t;
    cc.add_edge(f, t);
  }
  cc.scc_run();
  int Q; cin >> Q;
  REP(_, Q) {
    int x, y; cin >> x >> y;
    cout << (cc.cmp[x] == cc.cmp[y]) << endl;
  }
  return 0;
}

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

int main() {
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'C') {
			for (int j = i; j < S.size(); j++) {
				if (S[j] == 'F'){
				printf("Yes");
				return 0;
				}
			}
		}
	}
	printf("No");
	return 0;
}

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

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> d(k);
  int tmp;
  vector<int> a(n);
  rep(i,k){
    cin >> d.at(i);
    rep(j,d.at(i)){
      cin >> tmp;
      a.at((int)tmp-1) = 1;
    }
  }
  int count = 0;
  rep(i,n){
    if(a.at(i)==0){
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 3628
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

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;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll h,w;
    cin >> h >> w;
    if(h%3==0 || w%3==0) {cout << 0<<endl;return 0;}
    vl cand;
    if(h%2 == 0) cand.pb(h/2);
    if(w%2 == 0) cand.pb(w/2);
    if(h%2 == 1) cand.pb(max(1+h/2+w/3,2*(w/3)+1));
    if(h%2 == 1) cand.pb(max(1+h/2+w/3,2*(w/3)+1));
    if(w%2 == 1) cand.pb(max(1+w/2+h/3,2*(h/3)+1));
    cand.pb(h);
    cand.pb(w);
    sort(cand.begin(),cand.end());
    cout << cand[0] << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#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 <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> c(n+1), r(n+1);
    for(int i=1; i<=n; ++i)
        cin >> c[i] >> r[i];

    vector<vector<int> > edges(n+1);
    for(int i=0; i<k; ++i){
        int a, b;
        cin >> a >> b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    vector<vector<int> > dp(n+1, vector<int>(n+1, INT_MAX));
    multimap<int, pair<int, int> > mm;
    dp[1][0] = 0;
    mm.insert(make_pair(0, make_pair(1, 0)));
    while(!mm.empty()){
        int cost = mm.begin()->first;
        int pos = mm.begin()->second.first;
        int rest = mm.begin()->second.second;
        mm.erase(mm.begin());

        if(cost + c[pos] < dp[pos][r[pos]]){
            dp[pos][r[pos]] = cost + c[pos];
            mm.insert(make_pair(cost + c[pos], make_pair(pos, r[pos])));
        }
        if(rest > 0){
            for(unsigned i=0; i<edges[pos].size(); ++i){
                int next = edges[pos][i];
                if(cost < dp[next][rest-1]){
                    dp[next][rest-1] = cost;
                    mm.insert(make_pair(cost, make_pair(next, rest-1)));
                }
            }
        }
    }

    int ret = *min_element(dp[n].begin(), dp[n].end());
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 100004
using System;
					
public class Program
{
	public static void Main()
	{
		ulong N = ulong.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split(' ');
		int[] arr = new int[1000000];
		int cnt=0;
		int cnt2=0;
							
		for(ulong i=0; i<N; i++){
			if(arr[ulong.Parse(str[i])] == 0){
				cnt++;
				arr[ulong.Parse(str[i])]=1;
			}else{
				cnt2++;
			}
		}
		
		if(cnt2%2==0){
			Console.WriteLine(cnt);
		}else{
			Console.WriteLine(cnt-1);
		}
		
	}
}
 
public class Sol
{
	public double Solve(ulong A, ulong B, ulong x)
	{
		double ans;
		double tmp1 = (A*x)/B;
		double tmp2 = x/B;
		
		tmp1 = Math.Truncate(tmp1);
		tmp2 = Math.Truncate(tmp2);
		
		ans = tmp1 - (A*tmp2);
		
		return ans;
	}
}

Measured memory_bytes: 20576
def solve(N,K,A):
    visited = [None]*N
    cur = 0
    for i in range(K):
        if visited[cur] is None:
            visited[cur] = i
            cur = A[cur]-1
        else:
            break
    else:
        print(cur+1)
        return

    K -= i
    K %= i-visited[cur]

    for i in range(K):
        cur = A[cur]-1

    print(cur+1)


N,K = map(int,input().split())
A = tuple(map(int,input().split()))

solve(N,K,A)

Measured memory_bytes: 32404
#include <iostream>

using namespace std;

int main(void)
{
    int N, i, j, count, ans=0;
    
    cin >> N;

    for(i=1; i<=N; i++){
        count = 0;

        for(j=1; j<=i; j++){
            if(i % j == 0){
                count++;
            }
        }

        if(count == 8 && i%2==1){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    int x, y;
    cin >> x >> y;
    for(int i = 0; i <= x; i++){
        if(i * 2 + (x - i) * 4 == y) {cout << "Yes" << "\n"; return 0;}
    }
    cout << "No" << "\n";
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    int k;
    cin >> k;
    a.at(k)++;
  }
  
  long long ans = 1, mod = pow(10, 9) + 7;
  for(int i = 0; i < n; i++){
    if(n % 2){
      if(i == 0){
        if(a.at(i) == 1) continue;
        else ans = 0;
      }
      else if(i % 2){
        if(a.at(i) == 0) continue;
        else ans = 0;
      }
      else{
        if(a.at(i) == 2) ans = ans * 2 % mod;
        else ans = 0;
      }
    }
    else{
      if(i % 2){
        if(a.at(i) == 2) ans = ans * 2 % mod;
        else ans = 0;
      }
      else{
        if(a.at(i) == 0) continue;
        else ans = 0;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3748
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
       Scanner scan= new Scanner(System.in);

        for(int i=0;;i++){
            int H=scan.nextInt();
            int W=scan.nextInt();
            if(W==0 && H==0){
                break;
            }

            for(int j=0;j<H;j++) {
                for (int k = 0; k < W; k++) {
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}



Measured memory_bytes: 34408
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>

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

typedef long long ll;

using namespace std;

ll powMod(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

const int MOD = 1000000007;

ll dp[401][401], powsum[401][401];

int main() {
	int N, C, A[400], B[400], ans = 0;

	cin >> N >> C;
	rep(i, N)cin >> A[i];
	rep(i, N)cin >> B[i];

	// rep(i, N)if (A[i] != B[i])return 0;

	rep(i, C + 1)powsum[0][i] = 0;
	repl(i, 1, 401) {
		rep(j, 401) {
			powsum[i][j] = powsum[i - 1][j] + powMod(i, j, MOD);
		}
	}

	repl(i, 1, C + 1)dp[0][i] = 0;
	dp[0][0] = 1;
	repl(i, 1, N + 1) {
		rep(j, C + 1) {
			dp[i][j] = 0;
			rep(k, j + 1) {
				// dp[i][j] += dp[i - 1][j - k] * powMod(A[i - 1], k, MOD);
				dp[i][j] += dp[i - 1][j - k] * ((MOD + powsum[B[i - 1]][k] - powsum[A[i - 1] - 1][k]) % MOD);
				dp[i][j] %= MOD;
			}
		}
	}

	cout << dp[N][C] << endl;

	return 0;
}

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

using namespace std;

vector<bool> prime(1000005,true);

void isprime(){
  prime[0]=prime[1]=false;
  for(int i=2;i<1000000;++i){
    if(prime[i]){
      for(int j=i*2;j<1000000;j+=i)
	prime[j]=false;
    }
  }
}

int main() {
  isprime();
  int a,d,n;
  while(cin >> a >> d >> n && (a || d || n)){
    int tmp=0;
    while(tmp!=n){
      if(prime[a]) tmp++;
      a+=d;
    }
    cout << a-d << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3128
#include <iostream>
#define MARK_MAX 4
#define NUM_MAX 13
#define TF 1
#define GET_MAX 52
using namespace std;

struct mn
{
	char mark;
	int num;
	int tf;
};

int main()
{
	struct mn set[MARK_MAX][NUM_MAX];
	int m, n, i;

	for (m = 0; m < MARK_MAX;m++)
	{
		for (n = 0; n < NUM_MAX; n++){
			if (m == 0)
			{
				set[m][n].mark = 'S';
			}
			else if (m==1)
			{
				set[m][n].mark = 'H';
			}
			else if (m==2)
			{
				set[m][n].mark = 'C';
			}
			else if (m == 3)
			{
				set[m][n].mark = 'D';
			}
			set[m][n].num = n+1;
			set[m][n].tf = 1;
		}
	}

	int count;
	cin >> count;
	char mark;
	int number;
	for (int i = 0; i < count; i++)
	{
		cin >> mark >> number;
		for (m = 0; m < MARK_MAX; m++)
		{
			for (n = 0; n < NUM_MAX; n++)
			{
				if (set[m][n].mark == mark && set[m][n].num == number)
				{
					set[m][n].tf = 0;
				}
			}
		}
	}

	for (m = 0; m < MARK_MAX; m++)
	{
		for (n = 0; n < NUM_MAX; n++)
		{
			if (set[m][n].mark == mark && set[m][n].num == number)
			{
				set[m][n].tf = 0;
			}
		}
	}

	for (m = 0; m < MARK_MAX; m++)
	{
		for (n = 0; n < NUM_MAX; n++)
		{
			if (set[m][n].tf == 1)
			{
				cout << set[m][n].mark << ' ' << set[m][n].num << endl;
			}
		}
	}

	return 0;
}

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


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n, q = map(int, input().split())
    s = input().rstrip()
    before = ''
    start_cumsum = []
    now_val = 0
    for (i, c) in enumerate(s):
        if c == 'A':
            before = 'A'
        elif c == 'C' and before == 'A':
            now_val += 1
            before = ''
        else:
            before = ''
        start_cumsum.append(now_val)
    for _ in range(q):
        l, r = map(int, input().split())
        print(start_cumsum[r - 1] - start_cumsum[l - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 11580
"use strict";
main(require("fs").readFileSync("/dev/stdin", "UTF-8"));

function main(input) {
  input = input.split("\n");
  let exp = input[0].split("");
  let real = input[1].split("");
  let count = 0;
  for (let i = 0; i < exp.length; i++) {
    if (exp[i] === real[i]) {
      count++;
    }
  }
  console.log(count);
}


Measured memory_bytes: 21192
using System;

namespace BubbleSort
{
	class MainClass
	{
		public static void trace(ref int[] arr) {
			for (int i = 0; i < arr.Length; ++i) {
				if (i > 0)
					Console.Write (" ");
				Console.Write (arr [i]);
			}
			Console.WriteLine ();
		}

		public static void Main (string[] args)
		{
			int n = int.Parse (Console.ReadLine ());
			string[] nums = (Console.ReadLine ()).Split (' ');
			int[] arr = new int[n];
			for (int i = 0; i < n; ++i)
				arr [i] = int.Parse (nums [i]);

			bubbleSort (ref arr);
		}

		public static void bubbleSort(ref int[] arr) {
			int numSwap = 0;
			bool isDone = false;
			while (!isDone) {
				isDone = true;
				for (int i = arr.Length - 1; i > 0; --i) {
					if (arr [i] < arr [i - 1]) {
						int tmp = arr [i - 1];
						arr [i - 1] = arr [i];
						arr [i] = tmp;
						isDone = false;
						++numSwap;
					}
				}
			}

			trace (ref arr);
			Console.WriteLine (numSwap);
		}

	}
}

Measured memory_bytes: 9160
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
L = na()
L.sort()

ct = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if L[i] != L[j] and L[j] != L[k] and L[i] + L[j] > L[k]:
                ct += 1
print(ct)

Measured memory_bytes: 67856
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		if((B-A-1)%2 == 1){
			System.out.println("Alice");
			return;
		} else {
			System.out.println("Borys");
			return;
		}
	}
}


Measured memory_bytes: 23764
import bisect as bs
import sys

n = int(input())
array = []

for i in range(n):
  a,b = map(int, input().split())
  array.append((a,b,False))
  
for j in range(n):
  c,d = map(int, input().split())
  array.append((c,d,True))
  
array.sort()

blue = []

count = 0 
for v in array:
  if v[2]:
    index = bs.bisect_left(blue, v[1])
    if index != 0:
      blue[index-1] = sys.maxsize
      count += 1
      blue.sort()
      
  else:
    blue.append(v[1])
    blue.sort()
    
print(count)

Measured memory_bytes: 40612
// In the name of God

#include <bits/stdc++.h>

using namespace std;

vector<int> v[3];

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

	int n;
	cin >> n;

	string s;
	cin >> s;

	for(int i = 0; i < n; i++) {
		if(s[i] == 'R') v[0].push_back(i);
		if(s[i] == 'G') v[1].push_back(i);
		if(s[i] == 'B') v[2].push_back(i);
	}

	auto solve = [&](vector<int> &v1, vector<int> &v2, vector<int> &v3) {
		// take i, j from v1 and v2
		// take k from v3
		long long ret = 0;
		for(int i : v1) {
			for(int j : v2) {
				if(j < i) continue;
				ret += v3.end() - lower_bound(v3.begin(), v3.end(), j);
				if(j + (j - i) < n && s[j + (j - i)] != s[j] && s[j + (j - i)] != s[i]) ret--;
			}
		}
		return ret;
	};

	long long ans = 0;

	for(int i = 0; i < 3; i++) {
		for(int j = 0; j < 3; j++) {
			if(i == j) continue;
			ans += solve(v[i], v[j], v[3 - i - j]);
		}
	}

	cout << ans;
	

	return 0;
}


Measured memory_bytes: 3704
#!/usr/bin/env python3

n, m = list(map(int, input().split()))

if m != 0:
    a = [int(input()) for _ in range(m)]
else:
    a = [-1]

mod = 1000000007

if n == 1:
    print(1)
    exit()
elif n == 2:
    if a[0] == 1:
        print(1)
    else:
        print(2)
    exit()


if a[0] == 1:
    a_2, a_1 = 1, 0
    index = 1
else:
    a_2, a_1 = 1, 1
    index = 0

for i in range(2, n+1):
    if index < len(a):
        if i == a[index]:
            a_now = 0
            index += 1
            a_1, a_2 = a_now, a_1
            continue

    a_now = (a_1+a_2) % mod
    # print(a_now)
    a_1, a_2 = a_now, a_1
    # print(a_now)
print(a_now % mod)

# 0, 1, 2, 3, 4, 5, 6

# 1, 1, 2, 0, 2, 2, 4


Measured memory_bytes: 7080
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<list>
#include<math.h>
using namespace std;

#define ll long long

int func(ll A,ll B){
  int a=0,b=0;
  while(A!=0){
    a++;
    A/=10;
  }
  while(B!=0){
    b++;
    B/=10;
  }
  return max(a,b);
}

int main(){
  ll N;
  int res;

  cin >> N;
  res=func(N,1);

  for(ll i=1;i*i<=N;i++){
    if(N%i==0){
      res = min(res,func(i,N/i));
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int mod = 1e9 + 7;

struct matrix{
    vector <vector<long long> > a;
    void resize(int n, int m){
        a.resize(n, vector <long long>(m, 0));
    }
	matrix mult(matrix &m, matrix &n){
        matrix rtn;
        rtn.resize(m.a.size(), n.a[0].size());
        for(int i = 0 ; i < rtn.a.size() ; i++)
            for(int j = 0 ; j < rtn.a[i].size() ; j++)
                for(int k = 0 ; k < n.a.size() ; k++)
                    rtn.a[i][j] = (rtn.a[i][j]+(long long)m.a[i][k]*n.a[k][j])%mod;
        return rtn;
    }
    matrix expo(long long e){
        matrix ans;
        ans.resize(a.size(), a[0].size());
        for(int i = 0; i < a.size(); i++)
            ans.a[i][i] = 1;
        while(e){
            if (e & 1) ans = mult(ans, *this);
            e /= 2;
            *this = mult(*this, *this);
        }
        return ans;
    }
};

ll n, k;
matrix m;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    vector <vector <ll> > a;
    for(int i = 0 ; i < n ; i++){
        vector <ll> b;
        for(int j = 0 ; j < n ; j++){
            int x;
            cin >> x;
            b.push_back(x);
        }
        a.push_back(b);
    }
    m.a = a;
    m = m.expo(k);
    int ans = 0;
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            ans += m.a[i][j];
            if(ans >= mod) ans -= mod;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
H, W, A, B = map(int, input().split(" "))

map = []
for i in range(H):
    line = []
    for j in range(W):
        if i < B and j < A or B <= i and A <= j:
            line.append('1')
        else:
            line.append('0')
    map.append(line)

print('\n'.join([''.join(m) for m in map]))

Measured memory_bytes: 58972
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    N = int(input())
    Edge = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        Edge[u-1].append((v-1, w))
        Edge[v-1].append((u-1, w))

    Col = [-1] * N
    q = deque()
    q.append((0, 0, 0)) #now, pre, dist
    while q:
        nn, pn, dist = q.pop()
        if Col[nn] == -1:
            Col[nn] = dist % 2
            for nextN, addW in Edge[nn]:
                if pn != nextN:
                    q.append((nextN, nn, dist + addW))
    print("\n".join(map(str, Col)))

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 44920
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int n, m; cin >> n >> m;
	vector<int> x(m);
	for (int i = 0; i < m; ++i) cin >> x[i];
	sort(x.begin(), x.end());
	vector<int> d;
	for (int i = 1; i < m; ++i)
		d.push_back(x[i] - x[i - 1]);
	sort(d.begin(), d.end());
	long long ans = 0;
	for (int i = 0; i < m - n; ++i) ans += d[i];
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1276
N = int(input())
xyh = sorted([list(map(int,input().split())) for _ in range(N)], key = lambda x: -x[2])
for Cx in range(101):
  mx, my, mh = xyh[0]
  for Cy in range(101):
    H = mh + abs(mx - Cx) + abs(my - Cy)
    if(all(h == max(H - abs(x - Cx) - abs(y - Cy), 0) for x,y,h in xyh)):
      print(Cx, Cy, H)
      exit()

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

using namespace std;

const int N = 3e5+1;
const int O = 3e4+1;

#define ll long long
#define pb push_back
#define ppb pop_back
#define pu push
#define fr front
#define fi first
#define se second
#define setprecision
#define re return 0
#define fast ios_base::sync_with_stdio(false)

ll n, m, a[N], b[N], c[N], d[N], x, y, z, l, r, q, k, cnt, ans;

//vector<int> v;
//set<int> st[N];
//queue<int> q;

int main ()
{
    fast;

    cin >> n;

    for (int i = 1; i <= n; ++i) cin >> a[i];
    d[2] = abs(a[1]-a[2]);
    for (int i = 3; i <= n; ++i) d[i] = min(d[i-1]+abs(a[i]-a[i-1]), d[i-2]+abs(a[i]-a[i-2]));
    cout << d[n];
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
	int n;
	while (cin >> n)
	{
	    int count = 0;
	    rep(i, 10)
	    {
	        rep(j, 10)
	        {
	            rep(k, 10)
	            {
	                rep(l, 10)
	                {
	                    if (i + j + k + l == n) count++;
	                }
	            }
	        }
	    }
	cout << count << endl;
	}
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    REP(i, n) cin >> a[n - 1 - i] >> b[n - 1 - i];
    ll ans = 0;
    REP(i, n) {
        ll t = (b[i] - ((a[i] + ans) % b[i])) % b[i];
        ans += t;
    }
    cout << ans << endl;

}



Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){
    int H,W;
    char a[100][100];
    bool f[100];
    cin >> H >> W;
    for(int i=0;i<H;i++){
        f[i] = true;
        for(int j=0;j<W;j++){
            cin >> a[i][j];
            if(a[i][j]!=46){
                f[i]=false;
            }
        }
    }
    bool g[100];
    for(int i=0;i<W;i++){
        g[i] = true;
        //cerr << a[i] << endl;
        for(int j=0;j<H;j++){
            if(a[j][i]!=46){
                g[i]=false;
                break;
            }
        }
    }
    for(int i=0;i<H;++i){
        if(f[i]) continue;
        for(int j=0;j<W;j++){
            //cerr << g[j] << " ";
            if(g[j]) continue;
            else  cout << a[i][j];
        }
        cout << "" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
//Int mod = 1e6+3;

int main() {
    double w, h;
    double x, y;
    cin >> w >> h >> x >> y;
    printf("%.12lf ", (w * h) / 2.0);
    if ((w / 2.0) == x && (h / 2.0) == y) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <map>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)	
using namespace std;
int n,a[105],sum;
int main ()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	   cin>>a[i];
	sort(a+1,a+n+1);
	for (int i=1;i<=n-1;i++)
	   sum+=a[i];
	if (a[n]<sum)
	  cout<<"Yes\n";
	else
	  cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
for i in range(n):
    b[i] = [a[i], i+1]
sortf = lambda val : val[0]
b.sort(key=sortf)
for i in range(n):
    print(str(b[i][1]) + " ",end="")
print("")

Measured memory_bytes: 22568
#include<iostream>
#include<cstdio>
#include<functional>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<map>
#include<ctime>
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn = 7e4+7;
const int inf = 1e5;
const int modn = 1e9+7;
const ld eps = 1e-8;
const long double PI = acos(-1.0);
void qRead(ll &x){x = 0;char a;for(a = getchar();a <'0' || a > '9';a = getchar());for(;a >= '0' && a <= '9';a = getchar())x = x*10 + a-'0';}
void qRead(int &x){x = 0;char a;for(a = getchar();a <'0' || a > '9';a = getchar());for(;a >= '0' && a <= '9';a = getchar())x = x*10 + a-'0';}
ll qpow(ll a,ll b,ll mo = modn){
//    printf("%lld\n",mo);
    ll res = 1;
    while(b){
        if(b & 1)res = (res*a) % mo;
        a = (a*a) % mo;
        b >>= 1;
    }
    return res;
}
ld qpow(ld a,ll b){
    ld res = 1;
    while(b){
        if(b & 1)res *= a;
        a = a*a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b){
    if(!b)return a;
    return gcd(b,a%b);
}
//ll vis[maxn],prime[maxn],cnt,smallP[maxn];
//void getPrime(int n){
//    cnt = 0;
//    for(int i = 1;i <= n;i++)vis[i] = 0;
//    for(ll i = 2;i <= n;i++){
//        if(!vis[i]){
//            prime[++cnt] = i;
//            smallP[i] = i;
//        }
//        for(int j = 1;j <= cnt && i*prime[j] <= n;j++){
//            vis[prime[j]*i] = 1;
//            smallP[prime[j]*i] = prime[j];
//            if((i % prime[j]) == 0)break;
//        }
//    }
//}
//ll cnm[maxn][maxn];
//void getCnm(){
//    cnm[0][0] = 1;
//    for(int i = 1;i < maxn;i++){
//        for(int j = 0;j <= i;j++){
//            cnm[i][j] = cnm[i-1][j];
//            if(j)cnm[i][j] += cnm[i-1][j-1];
//            cnm[i][j] %= (modn-1);
//        }
//    }
//}
//ll f[maxn],invF[maxn];
//void getF(){
//    f[0] = invF[0] = 1;
//    for(int i = 1;i < maxn;i++)f[i] = f[i-1]*i % modn;
//    invF[maxn-1] = qpow(f[maxn-1],modn-2);
//    for(int i = maxn-2;i >= 1;i--)invF[i] = invF[i+1]*(i+1) % modn;
//}
int main(){
    int x1,y1,x2,y2;
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    printf("%d %d %d %d\n",x2+y1-y2,y2+x2-x1,y1-y2+x1,x2+y1-x1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#ifdef LOCAL
#define debug(x) cerr << '[' << #x << " = " << (x) << "]\n"
#else
#define debug(x)
#endif
const int maxn=3000;
ll dp[maxn][maxn],v[maxn];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;cin>>n;
	rep(i,0,n)cin>>v[i];
	per(i,0,n){
		rep(j,i,n){
			if(i==j){
				dp[i][j]=v[i];
			}else{
				dp[i][j]=max(v[i]-dp[i+1][j],v[j]-dp[i][j-1]);
			}
		}
	}
	cout<<dp[0][n-1]<<'\n';
}

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

#define IOS std::cin.tie(0);std::ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>;

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())
#define END cout<<"\n"

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)    for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
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 int NMAX = 55;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    CIN(x);
    int A,B;
    for(ll a=-200;a<=200;a++){
        for(ll b=-200;b<=200;b++)
        if(pow(a,5)==x+pow(b,5)){A=a;B=b;}
    }
    COUT(A,B);

    return 0;
}

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

long long MOD = 1000000007;

int main() {
    
    vector<int> A(3);
    for ( int i = 0; i < 3; i++ ) {
        cin >> A[i];
    }
    sort( A.begin(), A.end() );

    cout << A[2]-A[0] << endl;


    return 0;
}

Measured memory_bytes: 256
fun main (args : Array<String>) {
    val (n, r) = readLine()!!.split(" ")
    if (n.toInt() >= 10) {
        println("${r.toInt()}")
    } else {
        val res : Int = 100 * (10 - n.toInt())
        println("${r.toInt() + res}")
    }

}

Measured memory_bytes: 36064