akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

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

int main()
{
    ll a, b;
    cin >> a >> b;
    cout << a*b/gcd(a,b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include<math.h>
using namespace std;

int main() {
	int x, y; cin >> x >> y;
	if (x < y)swap(x, y);
	while (y>0) {
		int r = x % y;
		x = y;
		y = r;
	}
	cout << x << endl;
}


Measured memory_bytes: 3084
#include <cstdio>

int main(){
	int a, b, n, t1, t2, way[17][17];
	while(scanf("%d %d", &a, &b), a || b){
		scanf("%d", &n);
		for(int i = 1;i <= b;i++){
			for(int j = 1;j <= a;j++)way[i][j] = 0;
		}
		for(int i = 0 ;i < n;i++)scanf("%d %d", &t1, &t2), way[t2][t1] = -1;
		for(int i = 1;i <= a;i++){if(way[1][i] == -1)break;way[1][i] = 1;}
		for(int i = 1;i <= b;i++){if(way[i][1] == -1)break;way[i][1] = 1;}
		for(int i = 2;i <= b;i++){
			for(int j = 2;j <= a;j++){
				if(way[i][j] != -1){
					int w = 0, h = 0;
					if(way[i][j-1] != -1)w = way[i][j-1];
					if(way[i-1][j] != -1)h = way[i-1][j];
					way[i][j] = w + h;
				}
			}
		}
		printf("%d\n", way[b][a]);
	}
	return 0;
}

Measured memory_bytes: 2692
#include <bits/stdc++.h>
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; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    int ans = a + b;
    chmax(ans, a - b);
    chmax(ans, a * b);
    cout << ans << endl;
}

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

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;

int n, a[N];
bool was[N];
vector< int > ans;
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for(int i = 1; i <= n; i++){
		int p = -1, pp;
		for(int j = 1, q = 1; j <= n; j++){
			if(was[j])
				continue;
			if(a[j] == q)
				p = j, pp = q;
			q++;
		}
		if(p == -1){
			printf("-1");
			return 0;
		}
		ans.pb(pp);
		was[p] = 1;                    
	}
	reverse(ans.begin(), ans.end());
	for(auto it : ans)
		printf("%d\n", it);
	return 0;
}


Measured memory_bytes: 256
n=int(input())
a,b=map(int,input().split())
p=list(sorted(map(int,input().split())))
c=d=e=0
for i in range(n):
    if p[i]<=a:c+=1
    elif p[i]<=b:d+=1
    else: e+=1
print(min(c,d,e))

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

int main(){
  string s;
  cin>>s;
  bool a = false;
  bool b = false;
  for(int i=0; s[i]; i++){
    if(s[i]=='A') a = true;
    else b=true;
  }
  if(a && b) cout<<"Yes";
  else cout<<"No";
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<long long> vl;
typedef pair<long long, long long> pl;
typedef vector<vector<long long>> matrix;

#define F 						first
#define S 						second
#define PB 						push_back
#define MP 						make_pair
#define all(c) 					c.begin(), c.end()
#define f(i,a,b) 				for(ll i=a; i<b; i++)
#define rep(i,n) 				f(i,0,n)
#define tr(c,i) 				for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) 			(c.find(x) != c.end())	//for set and map
#define cpresent(c,x) 			(find(all(c),x) != c.end())	//for vectors
#define w(t)					ll t; cin>>t; while(t--)
#define epsilon 				1e-9
// #define MOD						(ll)(1e9+7)

void doublade() {
	ios::sync_with_stdio(false); cin.tie(0); cout.precision(10);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

const ll MOD = 1e9+7;

ll  binpow(ll a, ll b) {
	ll res = 1;
	while(b>0) {
		if(b&1) res *= a%MOD;
		a = (a*a)%MOD;
		b >>= 1;
		res %= MOD;
		a %= MOD;
	}
	return res;
}

int main() {
	doublade();
	// w(t) {
		ll n;
		cin >> n;
		if(n==1) cout<<"0\n";
		else {
			ll ans = 0;
			ans = (binpow(10, n)%MOD-2*binpow(9, n)%MOD+binpow(8, n)%MOD)%MOD;
			if(ans<0) {
				ans += MOD;
			}
			cout<<ans<<"\n";
		}
	// }
	return 0;
}

Measured memory_bytes: 3656
LEN, QES = gets.chomp.split(" ").map(&:to_i)
STRING = gets.chomp

RES = [0, 0]
(2..LEN).each do |i|
  if STRING[i-2] == "A" && STRING[i-1] == "C"
    RES[i] = RES[i-1] + 1
  else
    RES[i] = RES[i-1]
  end
end

(0...QES).each do |i|
  l, r = gets.chomp.split(" ").map(&:to_i)
  puts (RES[r] - RES[l])
end

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

using namespace std;

int main(){
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> As(A), Bs(B);
    int minA=1e9, minB=1e9;
    for(int i = 0; i < A; ++i){
        cin >> As[i];
        minA = min(minA, As[i]);
    }
    for(int i = 0; i < B; ++i){
        cin >> Bs[i];
        minB = min(minB, Bs[i]);
    }

    int minV = minA + minB;
    for(int i = 0; i < M; ++i){
        int x, y, c;
        cin >> x >> y >> c;
        int tmp = As[x-1] + Bs[y-1] - c;
        minV = min(minV, tmp);
    }
    cout << minV << endl;

    return 0;
}

Measured memory_bytes: 1024
A,B,C = list(map(int,input().split()))

def get_num(n,x):
    if n>=x:
        return n-x
    else:
        return (x-n+1)//2 + (x-n)%2
ans = 10**9
for x in range(min(A,B,C),max(A,B,C)+2):
    ans = min(ans,get_num(A,x)+get_num(B,x)+get_num(C,x))
print(ans)

Measured memory_bytes: 3060
N = int(input())
A = [0] * (N + 1)
B = [0] * (N + 1)

count = 0

for i in range(1, N + 1):
  A[i], B[i] = map(int, input().split())

A.sort()
B.sort()
if N % 2 == 1:
  centerA = A[(N + 1) // 2]
  centerB = B[(N + 1) // 2]
else:
  centerA = (A[N // 2] + A[N // 2 + 1]) / 2
  centerB = (B[N // 2] + B[N // 2 + 1]) / 2

#print(centerA, centerB)  

if N % 2 == 1:
  count = centerB - centerA + 1
else:
  count = (centerB - centerA) * 2 + 1

print(int(count))

Measured memory_bytes: 25496
#include "bits/stdc++.h"

using namespace std;

#define cerr if(false)cerr
#define what(x) cerr<<#x<<" = "<<x<<endl
 
typedef long long ll;
typedef pair<ll, ll> ii;

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;

int main(){

	ios_base::sync_with_stdio(false); 
	cin.tie(0);
	cout.tie(0);

	int t, a, b;
	cin >> t >> a >> b;

	if(a % t == 0){
		cout << "OK" << endl;
	}else{
		int mul = (a / t + 1) * t;
		cout << (mul <= b ? "OK" : "NG") << endl;
	}

	return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;
ll INF = 1e10;

int main()
{
	int a,b;
	cin >> a >> b;
	if (a<b)
	{
		co("a < b");
	}
	else if (a>b)
	{
		co("a > b");
	}
	else
	{
		co("a == b");
	}
	return 0;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

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

int main(void){
    int N;
    cin>>N;
    VI a(N),gr(N),gl(N);
    REP(i,N)cin>>a[i];
    gr[0]=a[0];gl[0]=a[N-1];
    FOR(i,1,N){
        gr[i]=gcd(gr[i-1],a[i]);
        gl[i]=gcd(gl[i-1],a[N-1-i]);
    }
    int g_max=max(gr[N-2],gl[N-2]);
    FOR(i,1,N-1){
        g_max=max(g_max,gcd(gr[i-1],gl[N-2-i]));
    }
    cout<<g_max<<endl;
}




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

int main()
{
	while (true){
		int n;
		cin >> n;
		if (!n) break;
		char order[128];
		for (int i = 0; i < 128; i++) order[i] = i;
		for (int i = 0; i < n; i++){
			char in1, in2;
			cin >> in1 >> in2;
			order[in1] = in2;
		}
		int m;
		cin >> m;
		for (int i = 0; i < m; i++){
			char in;
			cin >> in;
			cout << order[in];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    println!("{}", read::<String>().chars().map(|c| if c == '?' { 'D' } else { c }).collect::<String>());
}


Measured memory_bytes: 2368
import java.util.*;

class Main{

    void solve(){
	Scanner sc = new Scanner(System.in);

	while(true){
	    int n1 = sc.nextInt();
	    int n2 = sc.nextInt();
	    if(n1==0 && n2==0) break;
	    if(n1<n2){
		int tmp = n1;
		n1 = n2;
		n2 = tmp;
	    }

	    cnt = 0;
	    gcd(n2, n1);
	}
    }

    int cnt;

    void gcd(int x, int y){
	if(x==0){
	    System.out.println(y+" "+cnt);
	    return;
	}
	cnt++;
	gcd(y%x, x);
    }

    public static void main(String[] args){
	new Main().solve();
    }
}

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

int main() {
    int X, Y;
    cin >> X >> Y;
    for (int x4 = 0; x4 <= X; ++x4) {
        if (x4 * 4 + (X - x4) * 2 == Y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int main() {
  string s;cin>>s;
  vector<int> a(26);
  rep(i,s.size()){
    a[s[i]-'a']++;
  }
  rep(i,26){
    if(a[i]==0){
      cout<<(char)(i+'a')<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
}

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

#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    cin.tie(0); //cinとcoutの同期切り
    ios::sync_with_stdio(false); //iostreamとstdioの同期切り

    int A, B, C, K;
    cin >> A >> B >> C >> K;

    int m = max(A, max(B, C));
    int ans = A + B + C - m;

    REP(i, K) m = m * 2;
    ans += m;
    cout << ans << endl;

    return 0;
}

/*****************************************************************************/
/*****   1秒間で処理できるfor文ループの回数                                 *****/
/*****   → 10^8 = 100,000,000 回程度                                      *****/
/*****                                                                   *****/
/*****   sort(a, a+N, greater<int>()); // a[0:N) を大きい順にソート        *****/
/*****                                                                   *****/
/*****                                                                   *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3"                *****/
/*****   std::cout << std::fixed;                                        *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3.00"             *****/
/*****                                                                   *****/
/*****************************************************************************/

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

int main(void) {
  int N;
  cin >> N;
  set<string> se;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    se.insert(S);
  }
  cout << se.size() << endl;
  return 0;
}

Measured memory_bytes: 19260
N = int(input())
Bs = list(map(int, input().split()))

# B_i >= max(A_i, A_i+1)

# sumA = A_1 + A_2 + ... + A_N
# 求めたいのは sumA の max

# B_i >= max(A_i, A_i+1)
# B_i+1 >= max(A_i+1, A_i+2)
# A_i+1 <= min(B_i, B_i+1)

As = [0] * N
As[0] = Bs[0]
As[N-1] = Bs[N-2] 

for i in range(N-2):
  As[i+1] = min(Bs[i], Bs[i+1])
  
#print(As)
print(sum(As))


Measured memory_bytes: 3060
N = int(input())
list_num = list(map(int,input().split()))

C= 0
flag = True
while flag == True:
  for i in range(N):
    if list_num[i] % 2 == 1:
      flag = False
  if flag == False:
    break
  for i in range(N):
    list_num[i] = int(list_num[i] / 2)
  C += 1
print(C)

Measured memory_bytes: 9076
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m = map(int, input().split())
p = list(map(int, input().split()))
x = [list(map(int, input().split())) for _ in range(m)]

uf = UnionFind(n)
for i in range(m):
    uf.union(x[i][0]-1,x[i][1]-1)
ans = 0
for i in range(0,n):
    if uf.same(p[i]-1,i):
        ans += 1
print(ans)


Measured memory_bytes: 33524
#include<stdio.h>
int main(){
  int a[100][100];
  int b[100];
  int c[100];
  int n,m;
  int i,j;

  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      scanf("%d",&a[i][j]);
    }
  }
  for(i=0;i<m;i++){
    scanf("%d",&b[i]);
  }

  for(i=0;i<n;i++){
    c[i] = 0;
    for(j=0;j<m;j++){
      c[i] += a[i][j]*b[j];
    }
  }

  for(i=0;i<n;i++){
    printf("%d\n",c[i]);
  }

  return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int d = sc.nextInt();
			if(a==0) {
				break;
			}
			int[] m = new int[2];
			Ans[] ans = new Ans[4];
			for(int i=0;i<4;i++) {
				ans[i] = new Ans();
			}
			for(int i=2;i<=3;i++) {
				ans[i].m = 1000000;
			}
			for(int i=0;i<2;i++) {
				if(i==0) {
					m[0] = d;
					m[1] = 0;
				}else{
					m[0] = 0;
					m[1] = d;
				}
				while(m[0]!=m[1]) {
					ans[i].m++;
					if(m[0]<m[1]) {
						m[0]+=a;
						ans[i].x++;
						ans[i].w+=a;
					}else{
						m[1]+=b;
						ans[i].y++;
						ans[i].w+=b;
					}
				}
			}
			for(int i=1;i*a<d;i++) {
				if((d-i*a)%b==0) {
					ans[2].m = i+(d-i*a)/b;
					ans[2].w = d;
					ans[2].x = i;
					ans[2].y = (d-i*a)/b;
					break;
				}
			}
			for(int i=1;i*b<d;i++) {
				if((d-i*b)%a==0) {
					ans[3].m = i+(d-i*b)/a;
					ans[3].w = d;
					ans[3].x = (d-i*b)/a;
					ans[3].y = i;
					break;
				}
			}
			Arrays.sort(ans);
			System.out.println(ans[0].x +" "+ans[0].y);
		}
	}
}
class Ans implements Comparable<Ans>{
	int m = 0;
	int w = 0;
	int x = 0;
	int y = 0;
	@Override
	public int compareTo(Ans o) {
		if (this.m!=o.m) {
			if(this.m>o.m) {
				return 1;
			}else{
				return -1;
			}
		}else{
			if(this.w>o.w){
				return 1;
			}else if(this.w==o.w){
				return 0;
			}else{
				return -1;
			}
		}
	}

}

Measured memory_bytes: 22680
n=int(input())
al=[int(input()) for _ in range(n)]
b=al[:]
b=sorted(b,reverse=True)
m=max(al)
if al.count(m)>1:
    for _ in range(n):
        print(m)
else:
    for a in al:
        if a==m:
            print(b[1])
        else:
            print(m)

Measured memory_bytes: 14876
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
int gcd(int a, int b) { return a ? gcd(b%a, a) : b; }
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/









int H, W, A[505][505];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> H >> W;
    rep(y, 0, H) rep(x, 0, W) cin >> A[y][x];

    vector<tuple<int, int, int, int>> ans;
    rep(y, 0, H) rep(x, 0, W - 1) {
        if (A[y][x] % 2 == 1) {
            A[y][x]--;
            A[y][x + 1]++;
            ans.push_back(make_tuple(y, x, y, x + 1));
        }
    }
    rep(y, 0, H - 1) {
        if (A[y][W-1] % 2 == 1) {
            A[y][W - 1]--;
            A[y + 1][W - 1]++;
            ans.push_back(make_tuple(y, W - 1, y + 1, W - 1));
        }
    }

    int n = ans.size();
    printf("%d\n", n);
    fore(t, ans) {
        int a, b, c, d;
        tie(a, b, c, d) = t;
        printf("%d %d %d %d\n", a + 1, b + 1, c + 1, d + 1);
    }
}

Measured memory_bytes: 5232
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;


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

  ll A,B,C;
  cin >> A >>B>>C;

  if(A==B||B==C||C==A){
    if(A==B&&B==C){
      cout << "No" << endl;
    }
    else{
      cout << "Yes" << endl;
    }
  }
  else{
    cout << "No" << endl;
  }
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long arr[n];
    for(int i = 0; i < n; i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    for(int i = 0; i < n-1; i++)
    {
        if(arr[i] == arr[i+1])
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 5164
class UnionFind:
    def __init__(self, n):
        # parent[x] < 0 means x is root and abs(parent[x]) == size[x]
        self.par = [i for i in range(n+1)]
        self.size = [1] * (n + 1)
        self.rank = [0]*(n+1)
    def root (self,x):
        if self.par[x]==x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
        return self.par[x]
    def union(self,x,y):
        x = self.root(x)
        y = self.root(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def same (self,x,y):
        return self.root(x)==self.root(y)
    def get_size(self,x):
        return self.size[self.root(x)]
N,M = list(map(int,input().split())) 
group = UnionFind(N)
ab = [[int(item) for item in input().split()] for _ in range(M)]
ab.reverse()
ans =[(N*(N-1))/2]
for a,b in ab:
    if not group.same(a,b):
        ans.append(ans[-1]-group.get_size(a) * group.get_size(b))
        group.union(a,b)
    else:
        ans.append(ans[-1])
for i in range(M):
    print(int(ans[M-1-i]))

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

// 入力
int n, W;
int weight[110], value[110];

// DPテーブル
int dp[110][10010];

int main() {
  cin >> n >> W;
  for (int i = 0; i < n; i++) cin >> value[i] >> weight[i];

  // DP初期条件: dp[0][w] = 0
  for (int w = 0; w <= W; w++) dp[0][w] = 0;

  // DPループ
  for (int i = 0; i < n; i++) {
    for (int w = 0; w <= W; w++) {
      if (w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
      else dp[i+1][w] = dp[i][w];
    }
  }

  cout << dp[n][W] << endl;
}


Measured memory_bytes: 7044
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_C
{
    class C064
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] s1 = Console.ReadLine().Split(' ');

            int[] color = new int[8];
            int freeCount = 0;
            foreach (string s in s1)
            {
                int c = int.Parse(s) / 400;
                if (c >= 8) freeCount++;
                else color[c]++;
            }

            int min = color.Count(x => x > 0);
            if (min == 0)
            {
                min = 1; freeCount--;
            }

            int max = min + freeCount;
            Console.WriteLine(min.ToString() + " " + max.ToString());
        }

    }
}


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


n, x = Is()
L = LI()
A = [0]
for i in range(1, n+1):
    A.append(A[i-1]+L[i-1])
index = bisect_right(A, x)
print(index)

Measured memory_bytes: 67564
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
typedef long long ll;
const int N=3005;
int n,s;
ll dp[N];
int main()
{
    ll inv2=mod-mod/2;
    dp[0]=1;
    scanf("%d%d",&n,&s);
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d",&x);
        for(int j=s;j>=x;j--)
            dp[j]=(dp[j]+dp[j-x]*inv2)%mod;
    }
    for(int i=1;i<=n;i++) dp[s]=dp[s]*2%mod;
    printf("%lld\n",dp[s]);
}


Measured memory_bytes: 3836
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;


int main(void) {
   int N,K;
   cin>>N>>K;
   vector<ll> As(N+1);
   As[0] = 0;
   rep(i,0,N) {
      ll a;
      cin>>a;
      a--;
      As[i+1] = As[i]+a;
   }
   map<ll,vector<ll>> Amod;
   rep(i,0,N+1) {
      Amod[As[i]%K].push_back(i);
   }
   ll ans = 0;
   for (auto el: Amod) {
      ll n = el.second.size();
      int i = 0;
      int j = 0;
      while(1) {
         if (i>=n) break;
         if (j==i) j++;
         while(1) {
            if (j>=n) break;
            if(el.second[i] + K <= el.second[j]) break;
            j++;
         }
         j--;
         ans += j-i;
         i++;
      }
   }
   cout<<ans<<endl;



   return 0;
}

Measured memory_bytes: 23680
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [k, x] <- getIntList
    putStrLn . unwords $ map show [(x-k+1)..(x+k-1)]

Measured memory_bytes: 508
/* ALDS1_1_C: Prime Numbers - http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_C

Prime Numbers
A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.

Write a program which reads a list of N integers and prints the number of prime numbers in the list.

Input
The first line contains an integer N, the number of elements in the list.

N numbers are given in the following lines.

Output
Print the number of prime numbers in the given list.

Constraints
1 ≤ N ≤ 10000

2 ≤ an element of the list ≤ 108

Sample Input 1
5
2
3
4
5
6
Sample Output 1
3
Sample Input 2
11
7
8
9
10
11
12
13
14
15
16
17
Sample Output 2
4
*/

use std::io::*;

fn is_prime(n: u32) -> bool {
    if n == 0 { return false }
    if n == 1 { return false }
    if n == 2 { return true } 
    if n == 3 { return true } 
    if n%2 == 0 { return false }
    let mut i = 3;
    loop {
        if n%i == 0 { return false }
        i += 2;
        if i * i > n { break; }
    }
    return true;
}
 
fn main() {
    let stdin = stdin();
    let mut lines = stdin.lock().lines().map(|l| l.unwrap());
    let N = lines.next().unwrap().parse().unwrap();
    let nums = lines.take(N).map(|s| s.parse::<u32>().unwrap());

    let mut ans = 0;
    for i in nums {
        if is_prime(i) {
            ans += 1;
        }
    }

    println!("{}", ans);
}

// ------------------------------------------------------------------
// Auxiliary methods.
fn array_to_str(arr: &Vec<i32>) -> String {
    // Converts a numerical array to a string for output purposes.
    let mut ans = String::new();
    for a in arr {
        ans.push_str(&format!("{} ", *a));
    }
    return ans.trim().to_string();
}

fn read_line() -> String {
    let mut return_ = format!("");
    std::io::stdin().read_line(&mut return_).ok();
    return_
}



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

int main(){
	long long t[2], a[2], b[2];
	long long cnt = 0;
	bool flag = false;
	long long dif_total, dif_mid;
	long long ans = 0;

	// input
	for(int i=0; i<2; i++){
		cin >> t[i];
	}
	for(int i=0; i<2; i++){
		cin >> a[i];
		a[i] = a[i]*t[i];
	}
	for(int i=0; i<2; i++){
		cin >> b[i];
		b[i] = b[i]*t[i];
	}

	// infinity pattern
	if(a[0]+a[1] == b[0]+b[1]){
		cout << "infinity" << endl;
		return 0;
	}

	dif_total = a[0]+a[1]-b[0]-b[1];
	dif_mid = a[0]-b[0];
	// zero pattern
	if((dif_total>0&&dif_mid>0) || (dif_total<0&&dif_mid<0)){
		cout << 0 << endl;
		return 0;
	}

	dif_total = labs(a[0]+a[1]-b[0]-b[1]);
	dif_mid = labs(a[0]-b[0]);
	if(dif_mid%dif_total == 0){
	cout << 1 + (dif_mid/dif_total)*2 -1 << endl;

	}else{
	cout << 1 + (dif_mid/dif_total)*2 << endl;

	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int MOD=1e9+7;
const int DIM = 4;

struct Matrix {
  int a[DIM][DIM];
  int *operator [] (int r) { return a[r]; };

  Matrix(int x = 0) {
    memset(a, 0, sizeof a);
    if (x)
    {
		for(int i = 0; i < DIM; i++) a[i][i] = x;
	}
  }
} const I(1);

Matrix operator * (Matrix A, Matrix B) {
  const ll mod2 = ll(MOD) * MOD;
  Matrix C;
 for(int i = 0; i < DIM; i++)
 {
	 for(int j = 0; j < DIM; j++)
	 {
		ll w = 0;
		for(int k = 0; k < DIM; k++)
		{
			w += ll(A[i][k]) * B[k][j];
			if (w >= mod2) w -= mod2;
		}
	C[i][j] = w % MOD;
	}
  }
  return C;
}

Matrix operator ^ (Matrix A, ll b) {
  Matrix R = I;
  for (; b > 0; b /= 2) {
    if (b % 2) R = R*A;
    A = A*A;
  }
  return R;
}

void add(ll &a, ll b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
}

ll mult(ll a, ll b)
{
	return (a*b)%MOD;
}

Matrix M1,M2;

vector<ll> mult(Matrix &a, vector<ll> cur)
{
	vector<ll> V(4,0);
	for(int i = 0; i < 4; i++)
	{
		for(int j = 0; j < 4; j++)
		{
			add(V[i], mult(a[i][j],cur[j]));
		}
	}
	return V;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n,k;
	cin>>n>>k;
	vi vec;
	for(int i=0;i<k;i++)
	{
		ll x; cin>>x; vec.pb(x);
	}
	vec.pb(n);
	for(int i=0;i<4;i++)
	{
		for(int j=0;j<4;j++)
		{
			if((j&i)==j)
			{
				M1[i][j]=M2[i][j]=1;
			}
		}
		M1[i][3]++;
	}
	vector<ll> V = {1,1,1,1};
	int cur = 1;
	for(int i = 0; i < vec.size(); i++)
	{
		int ext = vec[i] - cur;
		Matrix M = M1^ext;
		V = mult(M, V);
		cur = vec[i];
		if(cur==n) break;
		cur++;
		V = mult(M2,V);
	}
	cout<<V[3]<<'\n';
}


Measured memory_bytes: 892
#include<stdio.h>

int main(void){
  int x, y, z, n, i;
  scanf("%d", &n);
  for(i = 0;i < n; i++){
    scanf("%d %d %d", &x, &y, &z);
    if(x*x+y*y==z*z||x*x+z*z==y*y||y*y+z*z==x*x){
      printf("YES\n");
    }else{
      printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	ll n,k; cin >> n >> k;
	vl a(n); rep(i,n) cin >> a[i];
	ll left = -1e18, right = 1e18 + 1;
	sort(all(a));
	while(right-left>1){
		ll mid = (left+right)/2;
		ll cnt = 0;
		rep(i,n){
			if(a[i] < 0){
				ll t = mid / a[i];
				if((mid<0 && a[i]<0) || (mid>0 && a[i]>0)){
					if(a[i]*t > mid) t++;
				}
				auto itr = lower_bound(all(a),t);
				ll d = a.end() - itr;
				cnt += min(d,n-i-1);
			}else if(a[i] == 0){
				if(mid < 0) continue;
				else cnt += n - i - 1;
			}else{
				ll t = mid / a[i];
				auto itr = upper_bound(all(a),t);
				itr--;
				ll d = itr - a.begin();
				cnt += max(0LL,d-i);
			}
		}
		if(cnt >= k) right = mid;
		else left = mid;
	}
	cout << right << endl;
}

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

int main(int argc, char const* argv[])
{
	std::vector<int> d;
	int a,b,c;
	std::cin >> a >> b >> c;
	d.push_back(a);
	d.push_back(b);
	d.push_back(c);
	std::sort(d.begin(), d.end());
	for (size_t i = 0; i < d.size(); i++) {
		if (i!=0) {
			std::cout << " ";
		}
		std::cout << d[i];
	}
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
using ull =unsigned long long;
const ll INF =1001001001;
const double PI = 3.14159265358979323846;
//10億7。　　　100000007

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}


int main(){
cout<<fixed<<setprecision(10);
//cin.tie(0); ios::sync_with_stdio(false);

int a;
  cin>>a;
  cout<<a+a*a+a*a*a<<endl;
}



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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  long long n;
  scanf("%lld", &n);
  std::vector<i_i> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }

  sort(all(a));

  string s = "";
  for (auto p : a) {
    s += to_string(p.second) + " ";
  }
  s.pop_back();
  put(s);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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;
}

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 2304
extern crate core;

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input);
    println!("{}", output);
}

fn run(input: String) -> String {
    let list: Vec<i32> = input
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    let n = list[0];
    let a = list[1];
    let b = list[2];

    (1..(n+1))
        .map(|x| {
            (
                x,
                x.to_string()
                    .chars()
                    .map(|y| y.to_string().parse::<i32>().unwrap())
                    .fold(0, |sum, i| sum + &i),
            )
        })
        .filter(|&(_, x)| a <= x && x <= b)
        .map(|(i, _)| i)
        .fold(0, |sum, i| sum + &i)
        .to_string()
}

Measured memory_bytes: 4352
#include <cstdio>

int main(void)
{
	int a1count=0,a2count=0,a4count=0;
	int i,N,x;
	scanf("%d",&N);
	while(N--)
	{
		scanf("%d",&x);
		if(x%4==0)
			a4count++;
		else if(x%2==0)
			a2count++;
		else
			a1count++;
	}
	if(a2count>0 && a1count<=a4count)
		printf("Yes\n");
	else if(a2count==0 && a1count<=a4count+1)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll


signed main(){
  int w,d;

  while(1){
    cin>>w>>d;
    if(w==0) break;
    vector<int> a,b;
    rep(i,w){
      int c;
      cin>>c;
      a.PB(c);
    }
    rep(i,d){
      int c;
      cin>>c;
      b.PB(c);
    }
    
    bool c[10]={};
    bool d[10]={};
    rep(i,a.size()){
      rep(j,b.size()){
        if(a[i]==b[j]&&!c[i]&&!d[j]){
          c[i]=true;
          d[j]=true;
        }
      }
    }

    int sum=0;
    rep(i,a.size()){
      if(!c[i]) sum+=a[i];
    }
    rep(i,b.size()){
      sum+=b[i];
    }

    cout<<sum<<endl;
  }
}


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

int main(){
  int x;
  vector<int> a(4);
  cin >> x;
  for(int i = 3;i >= 0;i--){
    a.at(i) = x%10;
    x /= 10;
  }
 for (int tmp = 0; tmp < (1 << 3); tmp++) {
   bitset<4> s(tmp);
   int sum = a.at(0);
   string ans = to_string(a.at(0));
   for (int i = 0; i < 3; i++) {
     if (s.test(i) == 1) {
       sum += a.at(i+1);
       ans += "+" + to_string(a.at(i+1));
     }
     else{
       sum -= a.at(i+1);
       ans += "-" + to_string(a.at(i+1));
     }
   }
   if (sum == 7) {
     ans += "=7";
     cout << ans <<endl;
     break;
   }
 }
}

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

ll N, M, K, H, W, L, R;
string S, T;

int main(){
  cin >> N;
  vll A(N), B(N);
  rep(i,N) cin >> A[i] >> B[i];
  ll ans = 0;
  for(int i=N-1; i>=0; --i){
    if( (A[i]+ans)%B[i] == 0) continue;
    ans += B[i] - (A[i]+ans)%B[i];
  } 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4772
#include <iostream>
#define MAX 1000000000


typedef long long int ll;

using namespace std;


ll min(ll a, ll b){
	return (a<b?a:b);
}

ll abs(ll a, ll b){
	return (a<b?b-a:a-b);
}


ll frog2(ll* ht, ll n, ll K){
	ll dp[n+1]={0};
	
	ll min_;
	
	
	dp[2] = abs(ht[1]-ht[0]);
	
	//dp[3] = min(abs(ht[2]-ht[0]), abs(ht[1]-ht[0])+ abs(ht[2]-ht[1]));
	
	for(int i=3;i<=n;i++){
	
		min_ = MAX;
		
		for(int jump = 1; jump<=K && i-jump<=n && i-1<n && i-1-jump>=0; jump++){
			ll temp = dp[i-jump] + abs(ht[i-1]-ht[i-1-jump]);
			if(temp<min_) min_=temp;	
		}
		
		dp[i] = min_;
		
	}
	
	return dp[n]; 

}

int main(){
	
	ll n;
	ll k;
	
	cin>>n>>k;
	ll arr[n];
	for(int i=0;i<n;i++)cin>>arr[i];
	
	cout<<frog2(arr, n,k)<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a, a+n, greater<int>());
	long long sum = 0;
	int k = 0;
	for(int i=0;i<n-1;i++){
		sum += a[k];
		if(i%2==0) k++;
	}
	cout << sum << endl;
	return 0;
}


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

typedef long long ll;

#define v(T) vector<T>
#define ttt(T) tuple<T, T, T>
#define pb push_back
#define mp make_pair
#define rep(i, s, n) for(int i=s;i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define poiu(n) for(int i=0; i < n; i++)
#define MOD 1000000007
#define endl '\n'

template<typename T>
void max_self(T& a, T b) { a=a>b?a:b; }
template<typename T>
void min_self(T& a, T b) { a=a<b?a:b; }

using namespace std;

int n;
int temps[3];
int dp[3][2];


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

    cin >> n;
    
    while(n--) {
        for(int i=0; i<3; ++i)
            cin >> temps[i];
        for(int i=0;i<3; ++i){
            for(int j=1; j<3; j++)
                max_self(dp[i][1], dp[(i+j)%3][0]+temps[i]);
        }
        for(int i=0; i<3; ++i)
            dp[i][0]^=dp[i][1], dp[i][1]^=dp[i][0], dp[i][0]^=dp[i][1];
    }

    int temp_max = 0;
    for(int i=0; i<3; ++i)
        max_self(temp_max, dp[i][0]);

    cout << temp_max << endl;
    return 0;

}



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,x; cin >> N >> x;
  int ans = 1;
  int dist = 0;
  vector<int>A(N);
  rep(i,N){
    cin >> A[i];
  }
  rep(i,N){
    dist += A[i];
    if(dist <= x){
      ans++;
    }
  }
  cout << ans;
}
    

Measured memory_bytes: 3592
s=input()
#l=[]
#for ss in s:
#    l.append(ss)
q=0
if s[0]=="A":
    w=0
    for ss in s[2:-1]:
        if ss=="C":
            w+=1
#            l.remove(ss)

    if w==1:
        for ss in s[1:]:
            if ss=="C":
                continue
            elif ss==ss.lower() :
                continue
            else:
                q=1
                break
    else:
        q=1
else:
    q=1

if q==0:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long int 
#define pb push_back 
#define mod 1e9+7

int main(){
      ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);   
       
      ll n;
        cin>>n;
          map<string,ll>m;
          for(int i=0; i<n; i++){
		   string s;
		      cin>>s;
		       m[s]++;
		  }
		  ll mx=0;
		  for(auto it=m.begin(); it!=m.end(); it++){
		       
		  mx=max(it->second,mx);
		  }
		  for(auto it=m.begin(); it!=m.end(); it++){
		     if(it->second==mx)
		       cout<<it->first<<endl;
		   
		  } 
    }




Measured memory_bytes: 23936
#include<cstdio>
#include<iostream>
#include<list>
#include<cstring>
#include<stack>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
const int maxn = 510000;
int cnt = 0, id[maxn], lson[maxn], rson[maxn];
long long val[maxn];

int insert(int root,long long in)
{
	if (root == -1)
	{
		root = cnt++;
		val[root] = in;
		return root;
	}
	if (in > val[root])
		rson[root] = insert(rson[root], in);
	else
		lson[root] = insert(lson[root], in);
	return root;
}
vector<long long> preorder, inorder;
void ps(int root)
{
	if (root == -1)
		return;
	preorder.push_back(val[root]);
	ps(lson[root]);
	ps(rson[root]);
}
void ino(int root)
{
	if (root == -1)
		return;
	ino(lson[root]);
	inorder.push_back(val[root]);
	ino(rson[root]);
}
int main()
{
	char inp[100];
	//freopen("out.txt", "w", stdout);
	memset(lson, -1, sizeof lson);
	memset(rson, -1, sizeof rson);
	int n, root=-1;
	long long pp;
	scanf("%d", &n);
	set<long long> si;
	for (int i = 1; i <= n; i++)
	{
		scanf("%s",inp);
		if (inp[0] == 'i')
		{
			scanf("%lld", &pp);
			root = insert(root, pp);

			si.insert(pp);
		}
		else if (inp[0] == 'p')
		{
			preorder.clear();
			inorder.clear();
			ps(root);
			ino(root);
			printf(" ");
			for (int i = 0; i < inorder.size(); i++)
				printf(i == inorder.size() - 1 ? "%lld\n" : "%lld ", inorder[i]);
			printf(" ");
			for (int i = 0; i < preorder.size(); i++)
				printf(i == preorder.size() - 1 ? "%lld\n" : "%lld ", preorder[i]);
			
			
		}
		else if (inp[0] == 'f')
		{
			scanf("%lld", &pp);
			if (si.find(pp) != si.end())
				puts("yes");
			else
				puts("no");
		}
		
	}
	return 0;
}


Measured memory_bytes: 37852
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000001



int main(){
	
	int N;
	cin>>N;
	
	int sum = 0;
	
	vector<int> a(N);
	for(int i=0;i<N;i++){
		cin>>a[i];
		sum += a[i];
	}
	
	vector<vector<int>> dp(N+1,vector<int>(sum+1,0));
	dp[0][0] = 1;
	
	for(int i=0;i<N;i++){
		for(int j=0;j<=sum;j++){
			dp[i+1][j] = mod(dp[i+1][j] + mod(dp[i][j]*2));
			int x = j+a[i];
			if(x>sum)continue;
			dp[i+1][x] = mod(dp[i+1][x]+dp[i][j]);
		}
	}
	
	int ans = 0;
	
	for(int i=(sum+1)/2;i<=sum;i++){
		ans = mod(ans + dp.back()[i]);
		//cout<<i<<':'<<dp.back()[i]<<endl;
	}
	
	ans = mod(ans * 3);
	
	vector<vector<int>> dp2(N+1,vector<int>(sum+1,0));
	dp2[0][0] = 1;
	
	for(int i=0;i<N;i++){
		for(int j=0;j<=sum;j++){
			dp2[i+1][j] = mod(dp2[i+1][j] + dp2[i][j]);
			int x = j+a[i];
			if(x>sum)continue;
			dp2[i+1][x] = mod(dp2[i+1][x]+dp2[i][j]);
		}
	}
	
	if(sum%2==0){
		int d = dp2.back()[sum/2];
		d = mod(d*3);
		ans = mod(ans-d);
	}
	
	int x = 1;
	for(int i=0;i<N;i++){
		x = mod(x*3);
	}
	
	ans = mod(x-ans);
	
	cout<<ans<<endl;
	
    return 0;
}


Measured memory_bytes: 212000
//By Tushar Gautam
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;
int dp[LIM];
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin>>n;
    dp[1]=1;dp[0]=0;
    forsn(i,1,n+1){
        dp[i]=1+dp[i-1];
        t=1;
        while(t<i){
            t*=6;
            if(t<=i) dp[i]=min(dp[i],1+dp[i-t]);
            else break;
        }
        t=1;
        while(t<i){
            t*=9;
            if(t<=i) dp[i]=min(dp[i],1+dp[i-t]);
            else break;
        }
    }
    cout<<dp[n];
    return 0;
}

Measured memory_bytes: 640