akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main()
{
  typedef long long ll;
  ll r, D, x_2000;
  cin >> r >> D >> x_2000;
  ll x = x_2000; 
  for (int i = 0; i < 10; ++i)
  {
    x = r*x - D;
    cout << x << endl;
  }
  return 0;
}


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

const int INF = (int)2.01e9;

int slow(vector<pair<int, int> > a) {
    sort(a.begin(), a.end());
    int ans = 0;
    do {
        int curAns = 0, curX = 0;
        for (auto o : a) {
            if (curX <= o.first) {
                curAns++;
                curX += o.second;
            }
        }
        ans = max(ans, curAns);
    } while (next_permutation(a.begin(), a.end()));
    return ans;
}

int fast(vector<pair<int, int> > a) {
    sort(a.begin(), a.end(), [&](pair<int, int> x, pair<int, int> y) {
        //return x.second < y.second;
        return x.first + x.second < y.first + y.second;
        if (x.second != y.second) return x.second < y.second;
        return x.first < y.first;
    });
    int n = a.size();
    vector<int> dp(n + 1, INF);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        vector<int> ndp = dp;
        for (int j = n; j >= 0; j--) {
            if (dp[j] <= a[i].first) {
                ndp[j + 1] = min(ndp[j + 1], dp[j] + a[i].second);
            }
        }
        dp = ndp;
    }
    for (int i = n; i >= 0; i--) if (dp[i] != INF) return i;
    assert(0);
}

void stress() {
    for (int it = 0;; it++) {
        cout << it << endl;
        srand(it);

        int n = rand() % 6 + 1;
        vector<pair<int, int> > a(n);
        for (int i = 0; i < n; i++) {
            a[i].first = rand() % 10 + 1;
            a[i].second = rand() % 10 + 1;
        }
        int ans1 = fast(a);
        int ans2 = slow(a);
        if (ans1 != ans2) {
            cout << ans1 << " instead of " << ans2 << endl;
            cout << n << endl;
            for (auto o : a) cout << o.first << " " << o.second << endl;
            exit(0);
        }
    }
}
int main() {
#ifdef HOME
    freopen("in", "r", stdin);
#endif
    //stress();

    int n;
    while (cin >> n) {
        vector<pair<int, int> > a(n);
        for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;

        cout << fast(a) << endl;
    }


#ifdef HOME
    cerr << clock() / (double)CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define dl double
#define mp make_pair
#define pb push_back
using namespace std;

//***********************************************************************

// hash struct for unordered_map
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************


struct line{
    ll m,c;
};

dl findintersect(line A,line B)
{
    if(A.m==B.m)
    return LLONG_MAX;
    else
    {
        return (B.c-A.c)/(A.m-B.m);
    }
    
}

ll evaluate(ll x,line A)
{
    return A.m*x+A.c;
}
deque<line> lines;
deque<dl> points;
void addline(line A)
{
    if(lines.empty())
    lines.pb(A);
    else
    {
        if(points.empty())
        {
            points.pb(findintersect(lines.back(),A));
            lines.pb(A);
        }
        else
        {
            while(!points.empty())
            {
                line l1=lines.back();
                lines.pop_back();
                line l2=lines.back();
                if(findintersect(A,l1)>points.back())
                {
                    lines.pb(l1);
                    break;
                }
                else
                {
                    points.pop_back();
                }
            }
            points.pb(findintersect(A,lines.back()));
            lines.pb(A);
        }
    }
}

void solve(){
    ll n,C;
    cin >> n >> C;
    vector<ll> h(n+1);
    vector<ll> dp(n+1);
    for(int i=1;i<=n;i++)
    {
        cin >> h[i];
    }
    dp[1]=0;
    line A;
    A.m=-2*h[1];
    A.c=dp[1]+h[1]*h[1]+C;
    addline(A);
    for(int i=2;i<=n;i++)
    {
        ll X=h[i];
        ll pos=lower_bound(points.begin(),points.end(),(dl)X)-points.begin();
        // cout <<" pos : " << pos << endl;
        // cout << "m : " << lines[pos].m << " c : " << lines[pos].c << endl;
        dp[i]=evaluate(X,lines[pos])+h[i]*h[i];
        line B;
        B.m=-2*h[i];
        B.c=dp[i]+h[i]*h[i]+C;
        addline(B);
    }
    // cout << "dp .... " << endl;
    // for(int i=1;i<=n;i++) 
    // cout << dp[i]<<" ";
    // cout << endl;
    cout << dp[n] << endl;

}

int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 8320
<?php
 
list($n, $m) = preg_split('/ /', trim(fgets(STDIN)));
$a = preg_split('/ /', trim(fgets(STDIN)));
rsort($a, SORT_NUMERIC);
$sum = 0;
for ($i=0; $i < $n; $i++) {
    $sum += $a[$i];
}
for ($i=0; $i < $m; $i++) { 
    if ($a[$i] < $sum / (4*$m)) {
        print "No";
        return;
    }
}
print "Yes";
return;


Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;


#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1<<29;
using Graph = vector<vector<int>>;


int main()
{
  ll n,m;
  cin >> n >> m;
  vector<ll> h(n);
  REP(i,n) cin >> h.at(i);
  vector<ll> a(m);
  vector<ll> b(m);
  REP(i,m){
    cin >> a.at(i) >> b.at(i);
    a.at(i)--;
    b.at(i)--;
  }
  vector<bool> ans(n,true);
  REP(i,m){
    if(h[a.at(i)]>h[b.at(i)]){
      ans.at(b.at(i))= false;
    }else if(h[a.at(i)]<h[b.at(i)]){
      ans.at(a.at(i))= false;
    }else{
      ans.at(a.at(i))= false;
      ans.at(b.at(i))= false;
    }
  }
  ll count =0 ;
  REP(i,n){
    if(ans.at(i)){
      count++;
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 5584
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element? {
        return self.maxElement()
    }
    func min() -> Element? {
        return self.minElement()
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
//    func enumerated() -> [(Int, Element)] {
//        return self.enumerate()
//    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let input = readIntSplit(by: " ")
let (N, K) = (input[0], input[1])
let h = (0..<N).map{_ in readInt()!}.sorted()
var ans = 1_000_000_000
for i in 0...N-K {
    ans = min(h[i+K-1] - h[i], ans)
}
print(ans)


Measured memory_bytes: 2816
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(llint i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
const ll mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const ll INF = 1000000000;


int main() {
	deque<Pint> a;
	int h, w;
	cin >> h >> w;
	hei(string) c(h);
	whei(int) visit(h, hei(int)(w, 0)),dist(h,hei(int)(w,0));
	int x, y;
	cin >> x >> y;
	visit[x - 1][y - 1] = 2;
	a.push_front(Pint(x-1, y-1));
	cin >> x >> y;
	rep(i, 0, h)cin >> c[i];
	while (!a.empty()) {
		Pint v = a.front();
		a.pop_front();
		int dx[] = { 1,0,-1,0 };
		int dy[] = { 0,1,0,-1 };
		rep(i, 0, 4) {
			int Nx = dx[i] + v.first;
			int Ny = dy[i] + v.second;
			if (Nx < 0 || Ny < 0 || Nx >= h || Ny >= w)continue;
			if (visit[Nx][Ny] == 2 || c[Nx][Ny] == '#')continue;
			dist[Nx][Ny] = dist[v.first][v.second];
			visit[Nx][Ny] = 2;
			a.push_front(Pint(Nx, Ny));
		}
		rep(i, -2, 3) {
			rep(j, -2, 3) {
				int Nx = i + v.first;
				int Ny = j + v.second;
				if (Nx < 0 || Ny < 0 || Nx >= h || Ny >= w)continue;
				if (visit[Nx][Ny]|| c[Nx][Ny] == '#')continue;
				dist[Nx][Ny] = dist[v.first][v.second] + 1;
				visit[Nx][Ny] = 1;
				a.push_back(Pint(Nx, Ny));
			}
		}
	}
	if (visit[x - 1][y - 1] == 0)cout << -1 << endl;
	else cout << dist[x - 1][y - 1] << endl;


	return 0;
}

Measured memory_bytes: 13460
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int x,y,x2,y2;
int main()
{
	cin>>x>>y>>x2>>y2;
	cout<<x2+y-y2<<' '<<y2+x2-x<<' '<<x+y-y2<<' '<<y+x2-x;
	return 0;
}

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

int a, b, c;

int main(){
	scanf("%d%d%d", &a, &b, &c);
	int t = 0, f, l;
	for (int i = 0; i < 5000; i++) {
		f = t % 60;
		l = (f + a) % 60;
		if ((f < l && c >= f && c <= l) || (f > l && (c <= l || c >= f))) {
			printf("%d\n", t - f + c);
			return 0;
		}
		t += a + b;
	}
	printf("-1\n");

	return 0;
}

Measured memory_bytes: 2724
N, K = map(int, input().split())
d = []
A = []
for i in range(K):
    d.append(int(input()))
    A.append(input().split())
    
child = list(range(1, N+1))
non_child = list(range(1, N+1))

for i in child:
    for j in range(K):
        for k in range(d[j]):
            if i == int(A[j][k]):
                non_child.remove(i)
                break
        else:
            continue
        break

print(len(non_child))

Measured memory_bytes: 9536
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(string.Join(" ", A));

            for (var i = 1; i < N; i++)
            {
                var v = A[i];
                var j = i - 1;

                while (j >= 0 && A[j] > v)
                {
                    A[j + 1] = A[j];
                    j--;
                }

                A[j + 1] = v;
                Console.WriteLine(string.Join(" ", A));
            }
        }
    }
}



Measured memory_bytes: 18264
s = gets.chomp.chars
s.pop

ans = s.length

while ans > 0
  if ans.odd?
    s.pop
    ans -= 1
    next
  end

  l = s[0..(ans / 2) - 1]
  r = s[(ans / 2)..ans - 1]
  break if l == r

  s.pop
  ans -= 1
end

puts ans


Measured memory_bytes: 1788
n, m = (int(x) for x in input().split())
A = sorted([[int(_) for _ in input().split()] for i in range(n)], key=lambda x:x[0])
res = 0
for l in A:
  if m == 0:
    break
  a, b = l
  res += a * min(b, m)
  m = max(0, m - b)
print(res)

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

void trace(int A[] , int N){
    for(int i = 0 ; i < N ; i++){
        if(i > 0){
            cout << " ";
        }
        cout << A[i];
    }
    cout << endl;
}

void insertionSort(int A[] , int N){
    for(int i = 1 ; i < N ; i++){
        int v,j;
        v = A[i];
        j = i - 1;
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace(A,N);
    }
}

int main(){
    int N;
    int A[100];

    cin >> N;
    for(int i = 0 ; i < N ; i++){
        cin >> A[i];
    }
    trace(A,N);
    insertionSort(A,N);
    
    return 0;
}


Measured memory_bytes: 3080
import java.util.*;

public class Main {
    static int count = 0;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		mergeSort(arr, 0, n);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    if (i > 0) {
		        sb.append(" ");
		    }
		    sb.append(arr[i]);
		}
		System.out.println(sb);
		System.out.println(count);
	}
	
	static void mergeSort(int[] arr, int left, int right) {
	    if (left + 1 < right) {
	        int mid = (left + right) / 2;
	        mergeSort(arr, left, mid);
	        mergeSort(arr, mid, right);
	        merge(arr, left, mid, right);
	    }
	}
	
	static void merge(int[] arr, int left, int mid, int right) {
	    int n1 = mid - left;
	    int n2 = right - mid;
	    int[] lArr = new int[n1 + 1];
	    int[] rArr = new int[n2 + 1];
	    for (int i = 0; i < n1; i++) {
	        lArr[i] = arr[left + i];
	    }
	    for (int i = 0; i < n2; i++) {
	        rArr[i] = arr[mid + i];
	    }
	    lArr[n1] = Integer.MAX_VALUE;
	    rArr[n2] = Integer.MAX_VALUE;
	    int lIdx = 0;
	    int rIdx = 0;
	    for (int i = left; i < right; i++) {
	        if (lArr[lIdx] <= rArr[rIdx]) {
	            arr[i] = lArr[lIdx];
	            lIdx++;
	        } else {
	            arr[i] = rArr[rIdx];
	            rIdx++;
	        }
	        count++;
	    }
	}
}



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

// #define ONLINE_JUDGE

#define V vector
#define P pair

using LL = long long;
#define FOR(i, x, y) \
    for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) \
    for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
    do {                                      \
        cerr << "\033[32;1m" << #x << " -> "; \
        err(x);                               \
    } while (0)
void err() { cerr << "\033[39;0m" << endl; }
template <template <typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) {
    for (auto v : a) cerr << v << ' ';
    err(x...);
}
template <typename T, typename... A>
void err(T a, A... x) {
    cerr << a << ' ';
    err(x...);
}
#else
#define dbg(...)
#endif
#define sz(x) (int)x.size()

LL bin(LL a, LL b, LL p) {
    LL res = 1;
    a = (a % p + p) % p;
    for (; b; b >>= 1, a = a * a % p)
        if (b & 1) res = res * a % p;

    return res;
}
const int N = 1e2+50;

int a[N];

int n;
void solve() {
    scanf("%d", &n);
    for (int i=0; i<n; ++i) {
        scanf("%d", &a[i]);
    }
    int ans = 0;
    for (int i=0; i<n; ++i) {
        for (int j=i+1; j<n; ++j) {
            for (int k=j+1; k<n; ++k) {
                if (a[i] == a[j] || a[i] == a[k] || a[j] == a[k])
                    continue;
                
                vector<int> v = {a[i], a[j], a[k]};
                sort(v.begin(), v.end());
                if (v[0] + v[1] > v[2]) {
                    ++ans;
                }
            }
        }
    }
    printf("%d\n", ans);
}

int main() {

    // int t;
    // cin >> t;
    // while (t--) solve();

    solve();

    return 0;
}

Measured memory_bytes: 3824
#include<stdio.h>
#include<map>
#include<queue>
#include<algorithm>
#include<iostream>
 
#define FI first
#define SE second
 
using namespace std;
 
int ans,ac[100005],pre[100005];
string x;
int n,k,l,r,q;
 
int main(){
    scanf("%d%d",&n,&q);
    cin>>x;
    int pan = x.length();
    for(int i =0;i<pan-1;i++){
        if(x[i]=='A'&&x[i+1]=='C'){
            ac[i+2 ] = 1;
        }
    }
    for(int i =1;i<=pan;i++){
        pre[i] = pre[i-1]+ac[i];
    }
    while(q--){
        scanf("%d%d",&l,&r);
        ans = pre[r] - pre[l-1];
        if(ac[l]==1) ans--;
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String str =  scan.next();
		String[] strArray = str.split("");
		int flag = 0;
		String bs = strArray[0];
		for(int i =0 ; i < 3; i++) {
			if ( ! bs.equals(strArray[i])){
				flag = 1;
			}
			bs = strArray[i];
		}

		if (flag == 1){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		} 


	}
}

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

int main(){

    int N, X;
    int x[100000];
    cin >> N >> X;
    for( int i = 0; i < N; i++ ) cin >> x[i];


    int min_dist = abs( X - x[0] );
    int num_min_dist = 0;

    for( int i = 1; i < N; i++ ){
        int dist = abs( X - x[i] );
        if( min_dist > dist ){
            min_dist = dist;
            num_min_dist = i;
        }
    }

    bool check = false;

    for( int D = min_dist; D >= 1; D-- ){
        for( int i = 0; i < N; i++ ){
            if( ( x[i] - X ) % D != 0 ) break;
            if( i == N-1 ){
                check = true;
                break;
            }
        }
        if( check ){
            cout << D << endl;
            break;
        }
    }

    return 0;

}

Measured memory_bytes: 640
# https://atcoder.jp/contests/abc128/tasks/abc128_c
# C - Switches
from itertools import product

n, m = list(map(int, input().split()))
k_list = []
s_list_list = []

for _ in range(m):
    k, *s = list(map(int, input().split()))
    k_list.append(k)
    s_list_list.append(s)

p_list = list(map(int, input().split()))

# スイッチの点灯の組み合わせは最大で100
s_p_list = product([0, 1], repeat=n)
c = 0
match_list = []
for s_p in s_p_list:

    is_match = True
    for i, s_list in enumerate(s_list_list):
        w = sum([s_p[s-1] for s in s_list])
        if w % 2 != p_list[i]:
            is_match = False
            break
    if is_match:
        c += 1
        match_list.append(s_p)

print(c)


Measured memory_bytes: 3064
def count(x):
    c = 0
    while True:
        if x == 1 or x == 0:
            return c
        x, v = divmod(x, 2)
        if v == 0:
            c += 1
        else:
            return c

def main():
    n = [int(x.strip()) for x in input().split()]
    a = [int(x.strip()) for x in input().split()]

    m = 10 ** 9
    for x in a:
        c = count(x)
        m = min(m, c)

    print(m)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int N, T;
    cin >> N >> T;
    vector<int> cost(N, 0);
    vector<int> time(N, 0);
    for (int i = 0; i < N; i++)
        cin >> cost[i] >> time[i];

    int ans = 1001;
    int temp;
    for (int i = 0; i < N; i++) {
        if (time[i] <= T) {
            temp = cost[i];
            if (temp < ans) {
                ans = temp;
            }
        }
    }

    if (ans <= 1000) cout << ans << endl;
    else cout << "TLE" << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int i;
    if(s.size()==2){
        cout << s <<endl;
    }
    else if(s.size()==3){
        for(i=0;i<3;i++){
            cout << s.at(2-i);
        }
        cout << endl;
    }
return 0;
}

Measured memory_bytes: 256
#include <iostream>


using namespace std;

int main()
{
	int n;
	cin >>n;
	int m=n;

	int ans=0;
	for (int i=0; i<10; i++){
		ans+=n%10;
		n=n/10;
	}

	if (m%ans==0)	cout << "Yes" << endl;
	else			cout << "No" << endl;

}


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

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int N,M;
    cin >> N >> M;
    dsu d(N);
    rep (i, M) {
        int u,v;
        cin >> u >> v;
        u--;
        v--;
        d.merge(u, v);
    }
    cout << d.groups().size()-1 << endl;
    return 0;
}

Measured memory_bytes: 8804
hash = { 'A' => 0, 'B' => 0, 'O' => 0, 'AB' => 0 }
while line = gets do
	a, b = line.chomp.split(',')
	hash[b] += 1
end

puts hash['A']
puts hash['B']
puts hash['AB']
puts hash['O']

Measured memory_bytes: 6088
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int m,k; cin>>m>>k;
    if(k>=(1<<m)) cout<<-1<<endl;
    else if(m==0){
        cout<<"0 0"<<endl;
    }
    else if(m==1){
        if(k==0) cout<<"0 0 1 1"<<endl;
        else cout<<-1<<endl;
    }
    else{
        for(int i=0;i<(1<<m);i++) if(i!=k) cout<<i<<" ";
        cout<<k<<" ";
        for(int i=(1<<m)-1;i>=0;i--) if(i!=k) cout<<i<<" ";
        cout<<k<<endl;
    }
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
// BEGIN CUT HERE
#define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
// END CUT HERE

int main(){
  int i;
  string str;

  getline(cin,str);
  rep(i,str.size()) if('a' <= str[i] && str[i] <= 'z') str[i] += 'A' - 'a';
  cout << str << endl;

  return 0;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    int a[200001];
    for(int i=0;i<n;i++)cin >> a[i];
    for(int i=n;i<200001;i++)a[i]=0;
    sort(a,a+200001,greater<int>());
    long long int sum=0;
    for(int i=0;i+k<n;i++){
        sum += a[k+i];
    }
cout << sum <<endl;
}

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

int main(){
    char num[1000];
    int i;
    while(1){
      	int sum = 0;
        scanf("%s", num);
        if(num[0] == '0') break;
        for(i = 0; num[i]!='\0'; i++){
            sum += num[i] - '0';
        }
      	printf("%d\n", sum);
    }
}


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

#define endl '\n'

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

    int n,r; cin >> n >> r;
    if (n >= 10) cout << r << endl;
    else cout << r + 100*(10 - n) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    int n;
    cin >> n;
    int front = n/100;
    int rear = n%100;

    if(1<=front && front<=12 && 1<=rear && rear<=12){
        cout << "AMBIGUOUS" << endl;
    }else if(0<=front && front<=99 && 1<=rear && rear<=12){
        cout << "YYMM" << endl;
    }else if(1<=front && front<=12 && 0<=rear && rear<=99){
        cout << "MMYY" << endl;
    }else{
        cout << "NA" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int count = 0;
  int a, b[100];
  scanf("%d", &a);
  for(int i = 0; i < a; i++)
	scanf("%d", &b[i]);
  
  for(int i = 0; i < a; i++){
   	if((i+1)%2 == 1 && (b[i]%2) == 1)
      count++;
  }
  printf("%d", count);
  return 0;
}

Measured memory_bytes: 2100
i = list(map(int, input().split()))
a = i[0]
b = i[1]
h = i[2]
m = i[3]

minute = 60*h + m

thetaa = 0.5 * minute
thetab = 6 * m

import math
ax = a*math.cos(math.radians(thetaa))
ay = a*math.sin(math.radians(thetaa))
bx = b*math.cos(math.radians(thetab))
by = b*math.sin(math.radians(thetab))

long = (ax-bx)**2 + (ay-by)**2

l = math.sqrt(long)

print(l)

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

int main() {
  ll n, m;cin>>n>>m;
  ll ans=min(n, m/2);
  m = max(0LL, m - n*2);
  ans += m / 4;
  cout << ans;
}


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

#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;

int A, B, C, D, E, F;

int main() {
   cin >> A >> B >> C >> D >> E >> F;

   set<int> sugar, water;
   for (int i = 0; i < 3333; i++) {
      for (int j = 0; j < 3333; j++) {
         int s = C*i + D*j;
         if (s <= F) sugar.insert(s);
      }
   }

   for (int i = 0; i < 33; i++) {
      for (int j = 0; j < 33; j++) {
         int w = A*100*i + B*100*j;
         if (w <= F) water.insert(w);
      }
   }

   const double lim = (double)E / (100+E);
   double noudo = -1;
   int ans1 = 0, ans2 = 0;
   for (int s : sugar) {
      for (int w : water) {
         int sum = s + w;
         if (sum == 0) continue;
         double x = (double)s / sum;

         if (sum == s*2) {
            // printf("sum: %d, s: %d, x: %.15f\n", sum, s, x);
         }
         if (sum > F || x > lim) continue;
         if (x > noudo) {
            noudo = x;
            ans1 = sum, ans2 = s;
            // printf("ans1: %d, ans2: %d, noudo: %.15f\n", ans1, ans2, noudo);
         }

         // if (sum <= F && x <= lim && x > noudo) {
         //    noudo = x;
         //    ans1 = sum, ans2 = s;
         // }
      }
   }
   cout << ans1 << " " << ans2 << endl;

   return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        String[] S = s.split("");
        String[] T = t.split("");
        
        int slen = S.length;
        int tlen = T.length;
        int[][] dp = new int[slen+1][tlen+1];

        String les = "";
        
        int N;
        if(S.length >= T.length) {
            N = T.length;
        }else {
            N = S.length;
        }
        
        for(int i = 1; i <= slen; i++) {
            for(int j = 1; j <=tlen; j++) {
                dp[i][j] = max(dp[i][j], dp[i-1][j]);
                dp[i][j] = max(dp[i][j], dp[i][j-1]);
                if(S[i-1].equals(T[j-1])) {
                    dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
                }
            }
            
        }
    
        int i = slen;
        int j = tlen;
        while(i > 0 && j > 0) {
            if(dp[i][j] == dp[i-1][j]) {
                i--;
            }else if(dp[i][j] == dp[i][j-1]) {
                j--;
            }else {
                i--;
                j--;
                les = S[i] + les;
            }
        }
        
        System.out.println(les);
    }
    
    public static long max(long a, long b) {
        if(a >= b) {
            return a;
        }else {
            return b;
        }
    }
    
    public static int max(int a, int b) {
        if(a >= b) {
            return a;
        }else {
            return b;
        }
    }
    
    public static long min(long a, long b) {
        if(a >= b) {
            return b;
        }else {
            return a;
        }
    }
    
    public static int min(int a, int b) {
        if(a >= b) {
            return b;
        }else {
            return a;
        }
    }
}

Measured memory_bytes: 86584
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {
    let v = read_t_in_line::<i32>();
    let (x, y, z) = (v[0], v[1], v[2]);
    let space = x - z;
    println!("{}", space / (y + z));
}


Measured memory_bytes: 4352
// @author: arch_

#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int a, b, c, count = 0;
    cin >> a >> b >> c;
    for (int i = a; i <= b; i++)
        count += static_cast<int>(c % i == 0);
    cout << count << "\n";
    return 0;
}

Measured memory_bytes: 3084
package main

import (
	"fmt"
	"sort"
)

type ByC []struct{ b, c int }

func (a ByC) Len() int           { return len(a) }
func (a ByC) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByC) Less(i, j int) bool { return a[i].c > a[j].c }

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	opelist := make([]struct {
		b, c int
	}, m+n)

	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		opelist[i].b = 1
		opelist[i].c = a
	}
	for i := n; i < m+n; i++ {
		fmt.Scan(&opelist[i].b, &opelist[i].c)
	}
	sort.Sort(ByC(opelist))
	cardCount := 0
	sum := 0
	for i := 0; i < n+m; i++ {
		cardCount += opelist[i].b
		if cardCount >= n {
			sum += opelist[i].c * (opelist[i].b - (cardCount - n))
			break
		}
		sum += opelist[i].c * opelist[i].b
	}
	fmt.Println(sum)
}


Measured memory_bytes: 9728
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n);
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); ++i)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)          (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)          (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define mp                  make_pair

typedef long long ll;
typedef unsigned long long ull;

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)

#ifdef _DEBUG
#define pf printf
#define pr(n) do { cout << #n " = " << (n) << endl; } while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#endif

int dir[][2] = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};

void doit(vector<string> v){
    int width = v[0].size();
    int height = v.size();
    if(width != 12 || height != 12) throw;
    int count = 0;
    REP(y, height) REP(x, width){
        deque<pair<int,int> > q;
        if(v[y][x] != '1') continue;
        v[y][x] = ' ';
        count++;

        q.push_back(mp(x,y));
        while(!q.empty()){
            int x1 = q.front().first;
            int y1 = q.front().second;
            q.pop_front();
            REP(i,4){
                int nx = x1 + dir[i][0];
                int ny = y1 + dir[i][1];
                if(nx < 0 || nx >= width || ny < 0 || ny >= height) continue;
                if(v[ny][nx] == '1'){
                    v[ny][nx] = ' ';
                    q.push_back(mp(nx,ny));
                }
            }
        }
    }
    cout << count << endl;
}

int main(){
    string s;
    vector<string> v;
    while(getline(cin, s)){
        if(s == ""){
            doit(v);
            v.clear();
            continue;
        }
        v.push_back(s);
    }
    doit(v);
    return 0;
}

Measured memory_bytes: 1196
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*-----------------------------------------------------------------------------------------------------*/
#define int ll
set<int> s;
int solve(int now, int n) {
	//cerr << now << '\n';
	if(now > n)
		return 0;
	if(now <= n) {
		int w = now;
		bool x[10] = {0};
		for(; w; w/=10)
			x[w%10] = 1;
		if(x[3]&&x[5]&&x[7])
			s.insert(now);
	}
	int res = 0;
	now*=10;
	res += solve(now+3, n)+solve(now+5, n)+solve(now+7, n);
	return res;
}

signed main() {
	EmiliaMyWife

	int n;
	cin >> n;
	solve(0, n);
	cout << s.size() << '\n';
	//for(int a : s)
		//cout << a << ' ';

	return 0;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int a, b;
  cin >> a >> b;
  string s; cin >> s;
  if (s[a] != '-') {
    cout << "No" << '\n';
    return 0;
  }
  s.erase(a, 1);
  for (auto &i : s) {
    if (i < '0' || i > '9') {
      cout << "No" << '\n';
      return 0;
    }
  }
  cout << "Yes" << '\n';
}


Measured memory_bytes: 3656
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second



int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> H;
    rep (i, N) {
        ll h;
        cin >> h;
        H.pb(h);
    }
    ll ans = 0;
    rep (i, N) {
        bool f = true;
        for (ll j = 0; j <= i; ++j) {
            f = f && (H[i] >= H[j]);
        }
        if (f) ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll a, b, c;
    cin >> a >> b >> c;
    vector<ll> k;
    // Aの倍数でBで割った余りがC
    for (ll i = a;; i += a)
    {
        if (i % b == c)
        {
            cout << "YES" << endl;
            break;
        }
        else if (find(k.begin(), k.end(), i % b) != k.end())
        {
            cout << "NO" << endl;
            break;
        }
        else
        {
            k.push_back(i % b);
        }
    }
    
}


Measured memory_bytes: 256
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
using namespace std;

typedef complex<int> P;

int b[19][19];


int main(){
	
	int n;
	double m=0;
	double h=0.5;
	
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		m+=a[i];
	}
	if(m<0)
		h=-0.5;
	m=int((m/n)+h);
	long long ans=0;
	
	for(int i=0;i<n;i++){
		ans+=pow((a[i]-m),2);
	}
	cout<<ans<<endl;
	

	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n;
ll a[100010],b[100010];
ll res;
int main()
{
	cin >>n;
	for (int i=0;i<=n;i++) cin >>a[i];
	for (int i=0;i<n;i++) cin >>b[i];
	for (int i=0;i<n;i++)
	{
		if (b[i]<=a[i]+a[i+1])
		{
			ll t=min(a[i],b[i]);
			a[i]-=t,b[i]-=t;
			res+=t;
			t=min(b[i],a[i+1]);
			a[i+1]-=t,b[i]-=t;
			res+=t; 
		}
		else
		{
			res+=a[i]+a[i+1];
			a[i]=a[i+1]=0;
		}
	}
	cout <<res;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
using namespace std;
 
int main(){
        double a,b,c,d,e,f;
        double x,y;
 
        while(cin >> a >> b >> c >> d >> e >> f){
                x = ((e*c-b*f) / (a*e - b*d));
                y = ((-(d*c) + a*f) / (a*e - b*d));
 
        if(x == 0)
                x = 0;
        if(y == 0)
                y = 0;
 
        printf("%.3f %.3f\n", x, y);
 
        }
 
        return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define ll long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

int a[maxn],n,k;

int main()
{
    fastio();
    cin>>n>>k;
    rep(i,1,n) cin>>a[i];
    rep(i,1,n-k){
        if(a[i]>=a[i+k]) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 4432
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
const ll MOD=1e9+7;
using namespace std;

int main(){
  ll N;
  cin >> N;
  vector<ll> a(N),b(N);
  rep(i,N){
    cin >> a[i] >> b[i];
  }
  ll plus = 0;
  for(ll i=N-1;i>=1;i--){
    if(a[i]%b[i] != 0){
      plus += (b[i]-a[i]%b[i]);
    }
    a[i-1] += plus;
  }
  if(a[0]%b[0] != 0){
    plus += (b[0]-a[0]%b[0]);
  }

  cout << plus << endl;
}


Measured memory_bytes: 1792
// forked from https://beta.atcoder.jp/contests/arc087/submissions/2069621
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
#include <memory>
using namespace std;

struct node_t {
        shared_ptr<node_t> left, right;
        node_t(shared_ptr<node_t> l, shared_ptr<node_t> r) : left(l), right(r) {}
};

using node = shared_ptr<node_t>;

node new_node() {
        return node(new node_t(NULL, NULL));
}

int main() {
        int n;
        long long l;
        scanf("%d %lld", &n, &l);
        vector<string> s(n);
        for (int i = 0; i < n; i ++) {
                cin >> s[i];
        }
        node root = new_node();
        function<void (node, const string&, int)> dfs = [&](node u, const string& str, int depth) {
                if (depth >= (int) str.size()) {
                        return;
                }
                if (str[depth] == '0') {
                        if (u->left == NULL) {
                                u->left = new_node();
                        }
                        dfs(u->left, str, depth + 1);
                } else {
                        if (u->right == NULL) {
                                u->right = new_node();
                        }
                        dfs(u->right, str, depth + 1);
                }
        };
        for (int i = 0; i < n; i ++) {
                dfs(root, s[i], 0);
        }
        function<long long (long long)> get_grundy = [&](long long x) {
                int ctz = __builtin_ctzll(x);
                return 1LL << ctz;
        };
        long long ans = 0;
        function<void (node, int)> dfs2 = [&](node u, int depth) {
                if ((u->left == NULL && u->right != NULL) || (u->left != NULL && u->right == NULL)) {
                        ans ^= get_grundy(l - depth);
                }
                if (u->left != NULL) {
                        dfs2(u->left, depth + 1);
                }
                if (u->right != NULL) {
                        dfs2(u->right, depth + 1);
                }
        };
        dfs2(root, 0);
        puts(ans ? "Alice" : "Bob");
        return 0;
}


Measured memory_bytes: 20608
from collections import defaultdict

def find(x, parent):
    if parent[x] == x:
        return x
    else:
        # keyとvalueが同じ位置に当たるまで親をたどる
        parent[x] = find(parent[x], parent)
        return parent[x]

# 併合
def unite(x, y, parent):
    x = find(x, parent)
    y = find(y, parent)
    if x == y: return

    parent[y] = x

def solve():
    N, K, L = map(int, input().split())
    
    street = [i for i in range(N)]
    train = [i for i in range(N)]

    for _ in range(K):
        a, b = map(int, input().split())
        unite(a-1, b-1, street)

    for _ in range(L):
        a, b = map(int, input().split())
        unite(a-1, b-1, train)

    d = defaultdict(int)
    for i in range(N):
        a = find(street[i], street)
        b = find(train[i], train)
        d[(a, b)] += 1

    ans = []
    for i in range(N):
        a = find(street[i], street)
        b = find(train[i], train)
        ans.append(str(d[a, b]))

    print(' '.join(ans))

solve()

Measured memory_bytes: 55900
def read():
    N = int(input().strip())
    D = list(map(int, input().strip().split()))
    return N, D

def solve(N, D):
    s = 0
    for i in range(N):
        for j in range(i+1, N):
            s += (D[i] * D[j])
    return s

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


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

int main(void) {
    int n, c, k, cnt = 1;
    vector<int> t, ans;
    cin >> n >> c >> k;
    t.resize(n);
    for (int i = 0; i < n; i++)
        cin >> t[i];
    sort(t.begin(), t.end());
    for (int i = 0; i < n; i++) {
        if (ans.empty() || t[i] > ans.back() || t[i] + k < ans.back() || cnt == c) {
            cnt = 1;
            ans.push_back(t[i] + k);
        }
        else cnt++;
    }
    cout << ans.size() << endl;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>inline bool read(T &x)
{
    x=0;register char c=getchar();register bool f=0;
    while(!isdigit(c)){if(c==EOF)return false;f^=c=='-',c=getchar();}
    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
    if(f)x=-x;
    return true;
}
template<class T>inline void print(T x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10^48);
}
template<class T>inline void print(T x,char c){print(x),putchar(c);}
template<class T,class ...S>inline bool read(T &x,S &...y){return read(x)&&read(y...);}
int ans,a[10005],n;
int main(){
	read(n);
	for (int i=1;i<=n;i++)
	read(a[i]);
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++)
	for (int j=i+1;j<=n;j++)
	for (int k=j+1;k<=n;k++)
	if (a[i]!=a[j]&&a[j]!=a[k]&&a[i]+a[j]>a[k]) ans++;
	print(ans);
	return 0;
}

Measured memory_bytes: 3636