akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
inline int scan(){ return getchar(); }
inline void scan(int &a){ scanf("%d", &a); }
inline void scan(unsigned &a){ scanf("%u", &a); }
inline void scan(long &a){ scanf("%ld", &a); }
inline void scan(long long &a){ scanf("%lld", &a); }
inline void scan(unsigned long long &a){ scanf("%llu", &a); }
inline void scan(char &a){ cin >> a; }
inline void scan(float &a){ scanf("%f", &a); }
inline void scan(double &a){ scanf("%lf", &a); }
inline void scan(long double &a){ scanf("%Lf", &a); }
inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } }
inline void scan(string &a){ cin >> a; }
template<class T> inline void scan(vector<T> &vec);
template<class T, size_t size> inline void scan(array<T, size> &vec);
template<class T, class L> inline void scan(pair<T, L> &p);
template<class T, size_t size> inline void scan(T (&vec)[size]);
template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); }
template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); }
template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(T &a){ cin>>a; }
inline void in(){}
template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); }
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;
int main(){
   INT(A);
   INT(B);
   if(A-2*B > 0){
       cout << A-2*B << endl;
   } else {
       cout << 0 << endl;
   }
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
X = []
Y = []
H = []
ans = ()
for i in range(n):
    x, y, h = LI()
    if h:
        r = i
    X += [x]
    Y += [y]
    H += [h]




for cx in range(101):
    for cy in range(101):
        x0, y0, h0 = X[r], Y[r], H[r]
        h = h0 + abs(cx - x0) + abs(cy - y0)
        for i in range(n):
            if H[i] != max(h - abs(cx - X[i]) - abs(cy - Y[i]), 0):
                break
        else:
            print(cx, cy, h)
            exit()




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

long long X, M;

void next(long long &a) { a = (a == -1) ? X : (a * a) % M; }

int main() {
    long long N; cin >> N >> X >> M;
    vector<bool> seen(M, false);
    long long cycle_detect_i = -1;
    long long cycle_detect_A = -1;
    long long A = -1;
    for (int i = 1; i <= N; ++i) {
        next(A);
        if (seen[A]) {
            cycle_detect_i = i;
            cycle_detect_A = A;
            break;
        }
        seen[A] = true;
    }
    A = -1;
    vector<long long> cycle_csum(M + 1, 0);
    long long ans = -1;
    long long path_sum = 0;
    int path_len = 0;
    for (int i = 1; i <= N; ++i) {
        next(A);
        path_sum += A;
        path_len++;
        if (A == cycle_detect_A) {
            int cycle_len = cycle_detect_i - i;
            for (int j = 1; j <= cycle_len; ++j) {
                next(A);
                cycle_csum[j] = cycle_csum[j - 1] + A;
            }
            N -= path_len;
            ans = path_sum 
                   + cycle_csum[cycle_len] * (N / cycle_len) 
                    + cycle_csum[N % cycle_len];
            break;
        }
    }
    if (ans == -1) ans = path_sum;
    cout << ans << endl;
}

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

using I = long long;

int main() {
  I A, B, C, K;
  cin >> A >> B >> C >> K;
  I d = A - B;
  if(K&1) d = -d;
  if(1e18 < abs(d)) cout << "Unfair" << endl;
  else cout << d << endl;
}


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

int main(){

    int n,k;
    string s;
    cin >> n >> k >> s;
    if(s[k-1]=='A'){
        s[k-1] = 'a';
    } 
    if(s[k-1]=='B'){
        s[k-1] = 'b';
    }
    if(s[k-1]=='C'){
        s[k-1] = 'c';
    } 
    cout << s << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int ans,n,s;
void solve(int,int,int);
int main(){
  while(1){
    ans = 0;
    cin >> n >> s;
    if(n==0&&s==0)break;
    solve(n,s,0);
    cout << ans << endl;
  }
}
void solve(int n,int sum,int min){ //回,計,min値
  if(n==0&&sum==0){
    ans++;
    return;
  }
  for(int i=min;i<10&&n>0;i++){
    if(sum-i>=0) solve(n-1,sum-i,i+1);
  }
}

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

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
#define mem(x,n) memset(x,n,sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

int main()
{
	faster;
	
	ll n,x,t;
	cin >> n >> x >> t;
	ll div = ceil(n*1.0/x);
	cout << div * t << endl;
	
	return 0;
}

Measured memory_bytes: 3756
using System;
using System.Collections.Generic;
using System.Text;

namespace ABC160 {
    class B {
        static void Main(string[] args) {
            var s = long.Parse(Console.ReadLine());
            var amount500 = s / 500;
            var amount5 = (s - amount500 * 500) / 5;

            Console.WriteLine(amount500 * 1000 + amount5 * 5);
        }
    }
}


Measured memory_bytes: 11092
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { cin.sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	double l; cin >> l;
	cout << fixed << setprecision(15) ;
	cout << pow(l / 3, 3);

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
 #include<stdio.h>
	   using namespace std;  
	    int main()
		 { int sx, sy, tx, ty;
		  scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
		   for(int i = sy + 1; i <= ty; i++)
		    printf("U"); 
			for(int i = sx + 1; i <= tx; i++)
			 printf("R");
			  for(int i = ty - 1; i >= sy; i--) 
			  printf("D"); 
			  for(int i = tx - 1; i >= sx; i--) 
			  printf("L"); printf("L");
			   for(int i = sy; i <= ty; i++)
			    printf("U");
				 for(int i = sx; i <= tx; i++)
				  printf("R");
				   printf("DR");
				    for(int i = ty; i >= sy; i--) 
				   printf("D");
				    for(int i = tx; i >= sx; i--)
					 printf("L");
					  printf("U\n"); 
					 return 0; }

Measured memory_bytes: 256
from sys import stdin as s
init=s.readline().rstrip()
state=1
s1=""
s2=""
q=int(s.readline())
for i in range(q):
  t=s.readline().rstrip()
  if t=="1":
    state=(state+1)%2
  else:
    a,b,c=t.split()
    if int(b)+state==2:
      s1=c+s1
    else:
      s2+=c
ans=s1+init+s2
if state:
  print(ans)
else:
  print(ans[::-1])

Measured memory_bytes: 4604
d={}
for _ in range(int(input())):
  s=input()
  s=list(s)
  s.sort()
  t=''.join(s)
  if t in d:
    d[t]+=1
  else:
    d[t]=1
c=0
# print(d)
for i in d:
  c+=(d[i]*(d[i]-1))//2
print(c)

Measured memory_bytes: 17852
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;

	for (int i=1; i<=b; ++i){
		if ((a*i)%b == c){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	ll A=gi(),B=gi(),K=gi();
	if(A>=K)A-=K;
	else B-=K-A,A=0;
	if(B<0)B=0;
	printf("%lld %lld\n",A,B);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for(int i=m; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <typename T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0; }
template <typename T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1;} return 0; }
const int INF = 1000000000;

int wall[10][10];
int ans[10];

int main(){
    int H,W; cin>>H>>W;
    rep(i,0,10) rep(j,0,10) cin>>wall[i][j];
    rep(i,0,H) rep(j,0,W){
        int a; cin>>a;
        if(a!=-1) ans[a]++;
    } 

    rep(k,0,10) rep(i,0,10) rep(j,0,10){
        wall[i][j] = min(wall[i][j],wall[i][k]+wall[k][j]);
    }

    ll res=0;
    rep(i,0,10) res+=ans[i]*wall[i][1];

    cout << res << endl;

}

Measured memory_bytes: 256
N,K,Q = map(int,input().split())
A = [int(input()) for _ in range(Q)]
score_board = [K-Q for _ in range(N)]

for a in A:
  score_board[a-1] += 1
  
for res in score_board:
  if res > 0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 16864
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a+b){
       if(k>=a) cout<<a<<endl;
       else cout<<k<<endl;
    }
    else{
        int temp = k- (a+b);
        cout<< a- temp<<endl;
    }
}


Measured memory_bytes: 3624
import numpy as np

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

list1=[0]*(1+10**5)
list2=[0]*(1+10**5)

for i in range(0, n, 2):
  list1[v[i]]+=1
  
for i in range(1, n, 2):
  list2[v[i]]+=1
  
n1=np.max(list1)
m1=np.argmax(list1)
n2=np.max(list2)
m2=np.argmax(list2)

if m1!=m2:
  print(n-(n1+n2))
else:
  list1[m1]=0
  list2[m2]=0
  n12=np.max(list1)
  n22=np.max(list2)
  print(n-max(n1+n22, n2+n12))

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

int main(int argc,char* argv[]){
  int n;
  std::cin >> n;

  std::vector<int> array(n);

  for(int i = 0; i < n; i++){
    std::cin >> array[i];
  }
  
  int count = 0;
  for(int i = 0; i < n; i++){
    for(int j = n - 1; j >= i + 1; j--){
      if(array[j] < array[j - 1]){
	std::swap(array[j], array[j-1]);
	count++;
      }
    }
  }
  
  bool first = true;
  for(int i = 0; i < n; i++){
    if(!first){
      std::cout << " ";
    }else{
      first = false;
    }
    
    std::cout << array[i];
  }
  std::cout << std::endl;
  std::cout << count << std::endl;

  return 0;
  
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector <int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    vector <int> dp(a.back()+1,0);
    for(int i = 0; i < a.size(); i++){
        if(dp[a[i]]>0){
            dp[a[i]]++;
            continue;
        }
        int tmp = a[i];
        while(tmp<dp.size()){
            //cout << tmp << endl;
            dp[tmp]++;
            tmp+=a[i];
        }
    }
    int ans = 0;
    if(n==1){
        cout << 1 << endl;
        return 0;
    }
    for(int i = 0; i < a.size(); i++){
        if(dp[a[i]]<=1){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7964
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    ArrayList<Integer> ar = new ArrayList<Integer>(3);
    for(int i=0;i<3;i++){
      int abc = sc.nextInt();
      ar.add(abc);
    }
    Collections.sort(ar);
    System.out.println((int)ar.get(0)+(10 * (int)ar.get(2)+(int)ar.get(1)));
  }
}

Measured memory_bytes: 22740
import math
def nCr(n,r):
    return (math.factorial(n)//(math.factorial(r)*math.factorial(n-r)))
N, A, B = map(int,input().split())
v = sorted(list(map(int,input().split())), reverse = True)
print(sum(v[:A])/A)

t = v[A-1]
m, u = 0, 0
for k in range(A):
    if v[k] == t:
        m += 1
for k in range(A,N):
    if v[k] == t:
        u += 1
if m == A:
    ans = 0
    for k in range(A,min(A+u+1,B+1)):
        ans += nCr(m+u,k)
    print(ans)
else:
    print(nCr(m+u,m))


Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main() {

	int N, M;
	cin >> N >> M;

	if (N == 0 && M == 0)
	{
		cout << "0";
		return 0;
	}
	else if (N == 0 || M == 0)
	{
		cout << (N + M) * (N + M - 1) / 2;
		return 0;
	}

	int* A = new int[N];
	int* B = new int[M];

	for (int i = 0; i < N; ++i)
	{
		A[i] = 0;
	}
	for (int i = 0; i < M; ++i)
	{
		B[i] = 1;
	}

	int* X = new int[N + M];
	for (int i = 0; i < N + M; ++i)
	{
		if (i < N) {
			X[i] = A[i];
		}
		else {
			X[i] = B[i - N];
		}
	}

	int x = 0;

	for (int i = 0; i < N + M; ++i)
	{
		for (int j = i; j < N+M; ++j)
		{
			if (((X[i]+X[j]) % 2 == 0) && i!=j) x++;
		}
	}

	cout << x;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a=0,b=0,c=0;
  cin >> a>>b>>c;
  int frag=0;
  if (a==b) {
    frag++;
  }
  if(a==c){
      frag++;
  }
  if(b==c){
      frag++;
  }
 
 if(frag==1){
  cout << "Yes" << endl;
 }
 else{
     cout << "No" << endl;
 }
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
  int a, b, c, d, e, k;
  scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &k);
 
  if ( e - a <= k )
    printf("Yay!");
  else {
    printf(":(");  
  }
}

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

struct StList
{
  int  m_nKey;
  StList *m_poPrev;
  StList *m_poNext;
  
  StList() :
    m_nKey(0), m_poPrev(nullptr), m_poNext(nullptr)
  { }

  StList(int nNum, StList &roHead) :
    m_nKey(nNum), m_poPrev(&roHead), m_poNext(roHead.m_poNext)
  { }

  ~StList() { }
};

void fnLinkedListSet(StList &roHead, StList &roTrail)
{
  char acCmd[80];
  int nMaxCmd, nNum;

  cin >> nMaxCmd;
  for (int i = 0; i < nMaxCmd; i++)
  {
    cin >> acCmd;
    if (acCmd[0] == 'i')
    {
      cin >> nNum;
      StList *poList = new StList(nNum, roHead);
      roHead.m_poNext->m_poPrev = poList;
      roHead.m_poNext = poList;
    }
    else if (acCmd[6] == 'F')
    {
      StList *poList = roHead.m_poNext;
      if (poList != &roTrail)
      {
        poList->m_poNext->m_poPrev = poList->m_poPrev;
        roHead.m_poNext = poList->m_poNext;
        delete poList;
      }
    }
    else if (acCmd[6] == 'L')
    {
      StList *poList = roTrail.m_poPrev;
      if (poList != &roHead)
      {
        roTrail.m_poPrev = poList->m_poPrev;
        poList->m_poPrev->m_poNext = poList->m_poNext;
        delete poList;
      }
    }
    else if (acCmd[0] == 'd')
    {
      cin >> nNum;
      StList *poList = roHead.m_poNext;
      while (poList != &roTrail)
      {
        if (poList->m_nKey == nNum)
        {
          poList->m_poNext->m_poPrev = poList->m_poPrev;     
          poList->m_poPrev->m_poNext = poList->m_poNext;
          delete poList;
          break;
        }
        poList = poList->m_poNext;
      }
    }
  }
}

void fnLinkedListGet(StList &roHead, StList &roTrail)
{
  StList *poList = roHead.m_poNext;
  while (poList != &roTrail)
  {
    if (poList != roHead.m_poNext) cout << " ";
    cout << poList->m_nKey;
    poList = poList->m_poNext;
    delete poList->m_poPrev;
  }
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  StList oHead, oTrail;
  oHead.m_poNext  = &oTrail;
  oTrail.m_poPrev = &oHead;
 
  fnLinkedListSet(oHead, oTrail);
  fnLinkedListGet(oHead, oTrail);

  return 0;
}

Measured memory_bytes: 34368
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if (s.equals("ABC")) {
			System.out.println("ARC");
		}
		if (s.equals("ARC")) {
			System.out.println("ABC");
		}

		sc.close();
	}

}

Measured memory_bytes: 26876
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        int K = ni();
        if(K==1){
            out.println(0);
            return;
        }
        long ans = N-K;
        out.println(ans);
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);
    int upperBound(ArrayList<Long> list, Long target){
        int i = Collections.binarySearch(list, target, new UpperBoundComparator<Long>());
        return ~i;
    }
    class UpperBoundComparator<T extends Comparable<? super T>> implements Comparator<T>{
        public int compare(T x, T y){
            return (x.compareTo(y) > 0) ? 1 : -1;
        }
    }
    int lowerBound(ArrayList<Long> list, Long target){
        int i = Collections.binarySearch(list, target, new LowerBoundComparator<Long>());
        return ~i;
    }
    class LowerBoundComparator<T extends Comparable<? super T>> implements Comparator<T>{
        public int compare(T x, T y){
            return (x.compareTo(y) >= 0) ? 1 : -1;
        }
    }
    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 33244
#include<stdio.h>
int a[100],b[100];
int main()
{
    int n,i,j,s=0,m=0,t;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(j=0;j<n;j++)
       scanf("%d",&b[j]);
    for(i=0;i<n;i++)
    {
       s+=a[i];
       t=s;
         for(j=i;j<n;j++)
             s+=b[j];
             if(s>m)
             m=s;
             s=t;


    }
    printf("%d\n",m);
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;

const int N = 101, W = 1e5 + 1;
const ll inf = 1e18;
ll dp[2][W];
int n, w;

int main(){
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.precision(10);
   cout << fixed;
   cin >> n >> w;
   bool at = 0;
   for (int i = 1; i <= w; ++i)
      dp[at][w] = -inf;
   for (int i = 0; i < n; ++i){
      at ^= 1;
      int weight, value;
      cin >> weight >> value;
      for (int j = 1; j <= w; ++j){
         dp[at][j] = max(dp[at ^ 1][j], dp[at][j - 1]);
         if (j - weight >= 0)
            dp[at][j] = max(dp[at][j], dp[at ^ 1][j - weight] + value);
      }
   }
   cout << dp[at][w] << '\n';
   return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<climits>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>
#include<sstream>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<cmath>
#include<typeinfo>
using namespace std;
#define inf 0x3f3f3f3f
#define fast ios::sync_with_stdio(false); cin.tie(0)
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define clr(a,b) memset((a),b,sizeof(a))
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define sz(a) int((a).size())
#define pb push_back
#define fr first
#define sc second
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pll;
//const ld PI = 3.1415926535897932384626433832795L;

template<typename T>
inline void input(T &a) {
    static int ed;
    a = 0;
    while (!isdigit(ed = getchar()) && ed != '-') { }
    char neg = 0;
    if (ed == '-') {
        neg = 1;
        ed = getchar();
    }
    while (isdigit(ed)) {
        a = 10 * a + ed - '0';
        ed = getchar();
    }
    if (neg) a = -a;
}

template<typename T = int>
inline T nxt() {
    T res;
    input(res);
    return res;
}

int gcd(int a, int b){return b==0? a : gcd(b,a%b);}

#define mod 1000000007
ll a[100100];
int main(){
    int t=1;
    //cin>>t;
    while(t--){
        int a,b; cin>>a>>b;
        if(a>0&&b>0) cout<<"Positive";
        else if(a<0&&b<0) {
            if(abs(abs(a)-abs(b))%2==0){
                cout<<"Negative";
            }else{
                cout<<"Positive";
            }
        }else if(a<0&&b>0){
            cout<<"Zero";
        }else if(a==0||b==0){
            cout<<"Zero";
        }
        
    }
    return 0;
}

Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
ll dp[2][4];
int now = 0;
int t[3];
ll p2[32];
bool use[100010];

int main() {
	int n;
	cin >> n;
	int a[100010];
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}

	use[1] = true;
	int now = 1;
	int count = 0;
	while (true)
	{
		int nex = a[now];
		if (use[nex]) {
			cout << -1 << endl;
			return 0;
		}
		use[nex] = true;
		count++;

		if (nex == 2) {
			break;
		}
		now = nex;
	}
	cout << count << endl;
	return 0;
}



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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
string S[500];

vint G[26];
void solve(){
    rep(i,26)G[i].clear();
    rep(i,N)reps(j,i+1,N){
        int k=0;
        while(k<S[i].size()&&k<S[j].size()&&S[i][k]==S[j][k])k++;
        if(k==S[i].size()||k==S[j].size()){
            if(S[i].size()>S[j].size()){
                cout<<"no"<<endl;
                return;
            }
            continue;
        }
        G[S[i][k]-'a'].pb(S[j][k]-'a');
    }
    rep(i,26){
        sort(all(G[i]));
        G[i].erase(unique(all(G[i])),G[i].end());
    }

    vint deg(26);
    rep(i,26)rep(j,G[i].size())deg[G[i][j]]++;
    queue<int>que;
    rep(i,26)if(deg[i]==0)que.push(i);
    while(que.size()){
        int v=que.front();
        que.pop();
        for(auto u:G[v]){
            if(--deg[u]==0)que.push(u);
        }
    }
    rep(i,26)if(deg[i]){
    cout<<"no"<<endl;return;}
    cout<<"yes"<<endl;
}

signed main(){
    while(cin>>N,N){
        rep(i,N)cin>>S[i];
        solve();
    }
    return 0;
}

Measured memory_bytes: 13696
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main(){
    ll n;
    cin>>n;
    vll a(n+1);
    vll b(n+1);
    std::queue<ll> q;
    rep(i,n){
        cin>>a.at(i+1);
        b.at(i+1)=0;
    }
    for(int i=n;i>0;i--){
        for(int j=1;j*i<=n;j++){
            b.at(i)+=b.at(i*j);
        }
        if(b.at(i)%2!=a.at(i))b.at(i)=1;
        else b.at(i)=0;
    }
    rep(i,n){
        if(b.at(i+1)==1)q.push(i+1);
    }
    if(q.empty())cout<<0<<endl;
    else{
        cout<<q.size()<<endl;
        while(!q.empty()){
            ll k=q.front();
            q.pop();
            cout<<k;
            if(q.empty())cout<<endl;
            else cout<<" ";
        }
    }
}
   



Measured memory_bytes: 4992
#include<bits/stdc++.h>                                                      
using namespace std;
int main()
{
  int N,T;
  cin >> N >> T;
  vector<int> c(N);
  vector<int> t(N);
  for(int i=0; i<N; i++){
    cin >> c.at(i) >> t.at(i);
  }
  int min=1001;
  int ans=0;
  for(int i=0; i<N; i++){
    if(t.at(i)<=T){
      if(c.at(i)<min){
        min=c.at(i);
      }
    }
  }
  if(min==1001){
    cout << "TLE" << endl;
  }
  else
    cout << min << endl;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/dp/tasks/dp_k
/*
* Author : MaxSally
*/
/********   All Required Header Files ********/
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i <= k ; ++i)
#define rrep(i, j, k) for (int i = j; i >= k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define inf (int) (1e9 + 7)
#define epsi 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define read(type) readInt<type>()
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define left tuyiuoi
#define right fgjhk
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) rep(i, l, r) cout << a[i] << " "; cout << endl
#define Flag(n) cout << "here " << n << endl
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

const int N = 100005;
const int M = 105;

int a[M];
bool win[N];

int main(){
    io;
    //freopen("input.txt", "r", stdin);
    int n, k;
    cin >> n >> k;
    mem(win, 0);
    rep(i, 0, n - 1){
        cin >> a[i];
    }
    rep(i, 0, N - 1){
        if(win[i]) continue;
        rep(j, 0, n - 1){
            if(i + a[j] >= N) break;
            win[i + a[j]] = 1;
        }
    }
    cout << (win[k]? "First": "Second");
    return 0;
}



Measured memory_bytes: 384
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    deque<ll> dq;
    ll a;
    rep(0, i, N)
    {
        cin >> a;
        if (i % 2 == 0)
        {
            dq.push_back(a);
        }
        else
        {
            dq.push_front(a);
        }
    }
    if (N % 2 == 0)
    {
        while (!dq.empty())
        {
            cout << dq.front() << ' ';
            dq.pop_front();
        }
        cout << endl;
    }
    else
    {
        while (!dq.empty())
        {
            cout << dq.back() << ' ';
            dq.pop_back();
        }
        cout << endl;
    }
}

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

int main()
{
  int N;

  cin >> N;

  vector<int> d(N);

  for (int i = 0; i < N; i++)
  {
    cin >> d.at(i);
  }

  int result = 0;

  for (int i = 0; i < N; i++)
  {
    for (int j = i + 1; j < N; j++)
    {
      result += d.at(i) * d.at(j);
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApp39
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            if (a >= b)
            {
                for (int i = 0; i < a; i++)
                {
                    Console.Write(b);
                }
            }
            else
            {
                for(int i = 0; i < b; i++)
                {
                    Console.Write(a);
                }
            }
        }
    }
}


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

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

ll prime_factor(ll n){
  ll rtn=1;
  for(ll i=2;i*i<=n;i++){
    if(!(n%i)) rtn++;
    while(!(n%i)) n/=i;
  }
  if(n!=1) rtn++;
  return rtn;
}

int main(){
  ll x,y;cin>>x>>y;
  cout<<prime_factor(gcd(x,y));
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;

int main(){
    ll n;
    cin >> n;
    vector<ll>dp(n+1);
    REP(i,n+1)dp[i]=n;

    dp[0]=0;

    FOR(i,0,n+1){
        for(int j = 1;i+j <= n;j *= 6){
            dp[i+j] = min(dp[i+j],dp[i]+1);
        }
        for(int j = 1;i+j <= n;j *= 9){
            dp[i+j] = min(dp[i+j],dp[i]+1);
        }
    }
    cout << dp[n] << endl;;
    return 0;
}
/*int main(){
    int n;
    vector<int>a;
    int tmp = 6;
    FOR(i,1,7){
        a.push_back(tmp);
        tmp *= 6;
    }
    tmp = 9;
    FOR(i,1,6){
        a.push_back(tmp);
        tmp *= 9;
    }
    sort(ALL(a));
    reverse(ALL(a));
    int answer = 100000;
    int count = 0;
    
    return 0;
}*/

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

using namespace std;

int main(){
     string S;
     cin >> S;
     if (S[0]=='S' and S[1]=='S' and S[2]=='S')cout << "0" <<endl;
     if (S[1] == 'R'){
          if (S[0]=='R' or S[2]=='R'){
               if(S[0]=='R' and S[2]=='R'){
                    cout <<"3"<<endl;
               }else{
                    cout << "2" <<endl;
               }
          }else{
               cout << "1" <<endl;
          }
     }else{
          if(S[0]=='R' or S[2]=='R')cout << "1" <<endl;
     }
}


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

int main(){
	int A,B,C;
	cin >> A >> B >> C;
	if(A==B && B==C) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
queue <int> qua;
map <int, int> mp;
int a, b;

int main() {
	cin >> a >> b;
	int t1 = max(a + b, a - b);
	int ans = max(t1, a * b);
	cout << ans << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i, n) for(int i=((int)(n));i>0;i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)	
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define REVSORT(c) SORT(c);REVERSE(c)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
const long long MOD = 1000000007;
typedef long long ll;

int SumDigit(long long N){
	int res = 0;
	while(N > 0){
		res += (N % 10);
		N /= 10;
	}
	return res;
}

int main(){
	ll N;
	cin >> N;
	cout << ((N % SumDigit(N) == 0) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <complex>
#include <vector>
#include <cfloat>
#include <algorithm>
using namespace std;

#define EPS 1e-12

typedef complex<double> point;
typedef vector<point> polygon;

double dot(point va, point vb){
	return real(va) * real(vb) + imag(va) * imag(vb);
}

double cross(point va, point vb){
	return real(va) * imag(vb) - imag(va) * real(vb);
}

double solve(polygon pts)
{
	double len = 0.0;
	point p = point(0.0, 0.0), dvec= point(0.0, 1.0);
	
	while( !pts.empty() )
	{
		int nexidx;
		double minarg = 4*3.1415;
		double mindist = 1.0e10;
		
		for(int i = 0; i < pts.size(); i++)
		{
			point vec = pts[i] - p;
			double nexarg = atan2(cross(vec, dvec), dot(vec, dvec));
			double nexdist = abs(vec);
			
			if( nexarg < minarg )
			{
				minarg = nexarg;
				mindist = nexdist;
				nexidx = i;
			}
			else if( abs(minarg - nexarg) < EPS && nexdist < mindist )
			{
				mindist = nexdist;
				nexidx = i;
			}
			
		}
		
		len += abs(pts[nexidx] - p);
		
		dvec = pts[nexidx] - p;
		p = pts[nexidx];
		pts.erase(pts.begin()+nexidx);
	}
	
	return len;
}

int main()
{
	int n;
	polygon pts;
	
	while( cin >> n, n)
	{
		polygon pts;
		
		for(int i = 0; i < n; i++)
		{
			double x, y;
			cin >> x >> y;
			pts.push_back(point(x, y));
		}
		
		printf("%.1lf\n", solve(pts));
	}
	
	return 0;
}

Measured memory_bytes: 1360
# from sys import exit
X, A = [int(n) for n in input().split()]
# N = int(input())
# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())
# exit()
if X < A:
    print(0)
else:
    print(10)


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

typedef long long ll;
#define fore(i,ii,iii) for(int i=ii;i<iii;i++)
#define OUT(a) cout<<a<<endl
#define FIN ios::sync_with_stdio(false)
#define mset(a,b) memset(a,b,sizeof(a))
const int N=128,K=1e5+15,MOD=1e9+7;

int n,k,a[N],sp[N][K];

int main() {FIN;
  cin>>n>>k;
  if(!k)return!(OUT(1));
  fore(i,0,n)cin>>a[i];
  fore(i,0,k+1)sp[n][i]=1;
  for(int i=n-1;i>=0;i--) {
    fore(j,0,k+1) {
      sp[i][j]=sp[i+1][j];
      if(j-a[i]-1>=0) {
        //cout<<"correct "<<i<<" "<<j<<" "<<sp[i+1][j]<<" "<<sp[i+1][j-a[i]-1]<<endl;
        sp[i][j]=(sp[i][j]-sp[i+1][j-a[i]-1]+MOD)%MOD;
      }
    }
    fore(j,1,k+1)sp[i][j]=(sp[i][j]+sp[i][j-1])%MOD;
  }
  //fore(i,0,n+1){fore(j,0,k+1)cout<<sp[i][j]<<" ";cout<<endl;}
  cout<<(sp[0][k]-sp[0][k-1]+MOD)%MOD<<endl;
}

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

int main() {
  string s, t;
  cin >> s >> t;

  int maxMatchCnt = 0;
  for(int i = 0; i < s.length() - t.length() + 1; i++){
    int matchCnt = 0;
    for(int j = 0; j < t.length(); j++){
       if(t[j] == s[i+j]) matchCnt++;
    }
    maxMatchCnt = max(matchCnt, maxMatchCnt);
  }
  cout << t.length() - maxMatchCnt << endl;
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int N;

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

  cin >> N;
  vector< ll > a(N);
  vector< ll > b(N);
  REP(i, N) {
    cin >> a[i] >> b[i];
  }

  ll ans = 0ll;
  RREP(i, N) {
    ll tmp = (a[i] + ans) % b[i];
    if (tmp == 0) {
      continue;
    }
    ans += b[i] - tmp;
    // debug(tmp);
    // debug(ans);
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
typedef long long LL;
const LL N = 400005;
const LL INF = 0x3f3f3f3f3f3f3f3f;

LL ec = 1,to[N << 1],nxt[N << 1],hed[N],cur[N],cap[N << 1];
void add_edge(LL f,LL t,LL c1,LL c2){
	++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec; cap[ec] = c1;
	++ ec; to[ec] = f; nxt[ec] = hed[t]; hed[t] = ec; cap[ec] = c2;
}

LL lev[N];
queue <LL> q;
void bfs(LL s){
	memset(lev,0,sizeof(lev));
	while(!q.empty()) q.pop();
	q.push(s); lev[s] = 1; 
	while(!q.empty()){
		LL u = q.front(); q.pop();
		for(LL i = hed[u];i;i = nxt[i]){
			LL v = to[i];
			if(lev[v] || !cap[i]) continue;
			lev[v] = lev[u] + 1;
			q.push(v);
		}
	}
}

LL dfs(LL u,LL t,LL f){
	if(u == t) return f;
	for(LL i = cur[u];i;i = nxt[i]){
		cur[u] = i;
		LL v = to[i];
		if(lev[v] == lev[u] + 1 && cap[i]){
			LL tmp = dfs(v,t,min(cap[i],f));
			if(tmp){
				cap[i] -= tmp;
				cap[i ^ 1] += tmp;
				return tmp;
			}
		}
	}
	return 0;
}

LL mxf = 0;
void dinic(LL s,LL t){
	LL f = 0;
	while(1){
		bfs(s);
		if(!lev[t]) return;
		for(LL i = 1;i < N;i ++) cur[i] = hed[i];
		while(1){
			f = dfs(s,t,INF);
			mxf += f;
			if(!f) break;
		}
	}
}

LL a[N],b[N],l[N],r[N];
int main(){
	LL n,sum,S,T;
	cin >> n; sum = n; S = (n << 1) + 1; T = S + 1;
	for(LL i = 1;i <= n;i ++){ cin >> a[i]; a[i] ++; l[i] = i; }
	for(LL i = 1;i <= n;i ++){ cin >> b[i]; b[i] ++; r[i] = i; }
	for(LL i = 1;i <= n;i ++){
		if(l[i] == i) for(LL j = a[i];j != i;j = a[j]) l[j] = i;
		if(r[i] == i) for(LL j = b[i];j != i;j = b[j]) r[j] = i;
	}
	for(LL i = 1;i <= n;i ++){
		if(a[i] == i && b[i] == i) sum --;
		if(a[i] != i && b[i] == i) add_edge(S,l[i],1,0);
		if(a[i] == i && b[i] != i) add_edge(r[i] + n,T,1,0);
		if(a[i] != i && b[i] != i){
			if(a[i] != b[i]) add_edge(r[i] + n,l[i],1,0);
			if(a[i] == b[i]) add_edge(l[i],r[i] + n,1,1);
		}
	}
	dinic(S,T);
	cout << sum - mxf << '\n';
	return 0;
}

Measured memory_bytes: 30720
#include<stdio.h>
        int main(void)
{
        long long int A,B,K;
        scanf("%ld",&A);
        scanf("%ld",&B);
 
        K = (A*A - B*B) / (2*A - 2*B);
        if((A*A - B*B) % (2*A - 2*B) != 0)
                printf("IMPOSSIBLE\n");
        else printf("%ld\n",K);
        return 0;
        }

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>

using namespace std;

int main()
{
long double L,l,r,ans;
  cin >> L;
  l = L/3.0;
  r = L - l*2.0;
  ans = l*l*r;

  cout << fixed << setprecision(6) << ans;
  return 0;

}


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

using namespace std;

typedef long long ll;

struct seg
{
	ll l, r, s;
	inline int operator<(const seg &a) const {return s > a.s;}
} s[5010];

const ll inf = (1ll<<62) - 1;
int n, m;
ll f[5010][2], g[5010][2];

int main()
{
	ios::sync_with_stdio(0);
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> s[i].l >> s[i].r;
		s[i].s = s[i].l + s[i].r;
	}
	sort(s+1, s+n+1);
	
	for (int i = 1; i <= n; ++i)
		f[i][0] = f[i][1] = g[i][0] = g[i][1] = inf;
	f[0][0] = 0;
	
	int x = 1, y = 0;
	m = n / 2;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j <= n; ++j)
			f[j][x] = g[j][x] = inf;
		for (int j = 0; j < i; ++j)
		{
			int k = i-j-1;
			if (j < m)
			{
				f[j+1][x] = min(f[j+1][x], f[j][y] + s[i].r + s[i].s * j);
				g[j+1][x] = min(g[j+1][x], g[j][y] + s[i].r + s[i].s * j);
			}
			if (k < m)
			{
				f[j][x] = min(f[j][x], f[j][y] + s[i].l + s[i].s * k);
				g[j][x] = min(g[j][x], g[j][y] + s[i].l + s[i].s * k);
			}
			g[j][x] = min(g[j][x], f[j][y] + (n-1)/2 * s[i].s);
		}
		swap(x, y);
	}
	
	cout << (n&1 ? g[m][y] : f[m][y]) << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

vector<vector<int>> g(100005, vector<int>());
map<ii, int> mp;
vector<int> ans(100005, 0);
int k=1;

void dfs(int n, int p)
{
  int t = 1;
  for (auto v: g[n]) {
    if (p==v) continue;
    if (t == ans[mp[make_pair(p,n)]]) t++;
    ans[mp[make_pair(n,v)]] = t;
    k = max(k, t);
    t++;
    dfs(v, n);
  }
}

int main()
{
  ll N;
  cin >> N;
  vector<ll> a(N-1);
  vector<ll> b(N-1);
  for (int i=0; i<N-1; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
    mp.insert(make_pair(make_pair(a,b), i));
    mp.insert(make_pair(make_pair(b,a), i));
  }
  dfs(0, 0);
  cout << k << endl;
  for (int i=0; i<N-1; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 20480
using System;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);

        int ans = 0;

        if (A >= 13) { ans = B; }
        else if (6 <= A && A <= 12) { ans = B / 2; }
        else { ans = 0; }

        Console.WriteLine(ans);
    }
} 


Measured memory_bytes: 11092
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        r: usize
    }
    println!("{}", if n < 10 {r + 100 * (10 - n)} else {r});
}


Measured memory_bytes: 4352