peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
ans = True
for i in l:
    t, x, y = i[0], i[1], i[2]
    if x+y > t or (x+y)%2 != t%2:
        ans = False
 
print("Yes") if ans else print("No")
# Judge status: Wrong Answer
def main():
    n = int(input())
    test = [int(input()) for i in range(n)]
    score = sum(test)
    test.sort()
    if len(list(filter(lambda x:x % 10 == 0, test))) == n:
        print(0)
        exit()

    ind = 0
    while score % 10 == 0:
        tmp = []
        for i in range(len(test)):
            tmp.append(score - test[i])
        score = max(tmp)
        test.pop(tmp.index(max(tmp)))
        if score < 10:
            break
    print(score)

if __name__ == '__main__':
    main()
# Judge status: Accepted
W, H, N = map(int, input().split())
left = 0
right = W
down = 0
up = H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 2:
        right = min(right, x)
    if a == 1:
        left = max(left, x)
    if a == 3:
        down = max(down, y)
    if a == 4:
        up = min(up, y)
# print(left, right, down, up)
if right >= left and up >= down:
    print((right-left)*(up-down))
else:
    print(0)
# Judge status: Wrong Answer
N=int(input())
L=list(map(int,input().split()))
count=0
sum=0
A=float("inf")
for i in L:
	sum+=abs(i)
	A=min(A,abs(i))
	if i<0:
		count+=1
if count%2==0:
	print(sum)
else:
	for i in L:
		if abs(i)==A:
			B=i
	print(sum-(B*2))
# Judge status: Wrong Answer
n=int(input())
s=[str(input()) for i in range (n)]
l=[0]*n
t=0
for j in range (n):
    d=1
    for k in range (t):
        if s[j]==l[k]:
            d=0
    if d==1:
        l[j]=s[j]
        t+=1
print(t)
# Judge status: Accepted
import sys

N,A,B = map(int,input().split(' '))

Count_Blue = 0
if 1<=N<=10**18 and A > 0 and B >= 0 and \
   0< A + B <= 10**18:
    Add_Blue = 1 * A
    Add_Both = Add_Blue + 1 * B

    q = N // Add_Both
    mod = N % Add_Both
    if mod < Add_Blue:
        Count_Blue = (q *Add_Blue) + mod
    else:
        Count_Blue = (q * Add_Blue) + Add_Blue
    print(Count_Blue)
elif A == 0:
    print(Count_Blue)
# Judge status: Accepted
import bisect
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))


a.sort()
c.sort()
sum_count = 0
for i in b:
    sum_count += bisect.bisect_left(a, i) * (N - bisect.bisect_right(c, i))
print(sum_count)
# Judge status: Accepted
# 整数aとbを入力
a,b = map(int,input().split())
# ２で割れたら偶数と出力、それ以外なら奇数と出力
if (a * b) % 2 == 0:
    print("Even")
else:
    print("Odd")
# Judge status: Accepted
h1, m1, h2, m2, k = list(map(int, input().split()))
 
s = (h1*60)+m1
e = (h2*60)+m2
 
print(e-s-k)
# Judge status: Wrong Answer
n = int(input())

ls = []
rs = []
for _ in range(n):
    x, y = map(int, input().split())
    ls.append(x)
    rs.append(y)

if n % 2 == 1:
    print(rs[len(rs)//2] - ls[len(ls)//2] + 1)
else:
    a = (rs[len(rs)//2-1] * 10 + rs[len(rs)//2] * 10) / 2
    b = (ls[len(ls)//2-1] * 10 + ls[len(ls)//2] * 10) / 2
    print((a - b) // 5 + 1)
# Judge status: Wrong Answer
s = input()

result = ''
for i in s:
  if (i == 'B'):
    if len(result) == 0:
      continue
    else:
      result = result[:-1]
      print(result)
  else:
    result = result + i

print(result)
# Judge status: Wrong Answer
N,H = map(int,input().split())
ls = []
for i in range(N):
    a,b = map(int,input().split())
    ls.append([a,b])
ls.sort()
ls.sort(key=lambda x:-x[0])
mainkatana = ls.pop(0)
ls.sort(key=lambda x:-x[1])
ls.append([0,0])
ii = 1
while ls[0][1] >= mainkatana[0] and H > mainkatana[1]:
    ii += 1
    nage = ls.pop(0)
    H -= nage[1]
cut = max(0,-(-(H-mainkatana[1])//mainkatana[0]))
ii += cut
H -= cut*mainkatana[0]       
print(ii)
# Judge status: Accepted
from collections import defaultdict
K = int(input())
if K % 2 == 0:
    print(-1)
    exit()
c = 1
d = 7 % K
D = defaultdict(int)
while True:
    if d == 0:
        print(c)
        exit()
    if D[d] == 1:
        print(-1)
        exit()
    D[d] += 1
    c += 1
    d = (d * 10 + 7)%K
# Judge status: Accepted


def c(n):
    return n*(n-1)//2

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

ans = c(n) + c(m)

print(ans)
# Judge status: Accepted
x = int(input())
t = p = 0
while p < x:
    t += 1
    p += t
print(t)
# Judge status: Accepted
x,y,a,b,c, = map(int, input().split())
xx = list(map(int, input().split()))
yy = list(map(int, input().split()))
rr = list(map(int, input().split()))
 
xx = sorted(xx, reverse=True)[:x]
yy = sorted(yy, reverse=True)[:y]
rr = rr + xx + yy
print(sum(sorted(rr, reverse=True)[:x+y]))
# Judge status: Wrong Answer
S = input()
T = input()
s = list(S)
t = list(T)
K = len(s)
n=0
for i in range(0, K):
  if s[i] == t[i]:
    n+=1
  else:
    pass
print(n)
# Judge status: Wrong Answer
def main():
    S = input()
    buf = S[0]
    num = 1
    N = len(S)
    for i in range(1, N):
        if buf != S[i]:
            num += 1
            buf = S[i]
        else:
            if i == N-1:
                num += 1
            buf = buf + S[i]
    print(num)
main()
# Judge status: Wrong Answer
N=int(input())
A = []

for i in range(N):
    new = int(input())
    A.append(new)

A.sort()
A.append(0)

start=A[0]
cnt=1
anscnt=0

for i in range(1,len(A)):

    if A[i]==start:
        cnt+=1
    elif A[i]!=start:
        if cnt%2==0:
            anscnt+=cnt
        cnt=1
        start=A[i]
    

print(N-anscnt)
# Judge status: Accepted
N,K=map(int, input().split())
A = list(map(int, input().split()))

A0=list(range(N))

def calc_zero(n):
    return n * 0

A0 = list(map(calc_zero, A0))

temp=0
tempv=[]

for i in range(K):
  if A0[temp]>=1:
    loop=i-A0[temp]
    t=(K-A0[temp])%loop
    temp=tempv[A0[temp]+t-1]
    break
  else:
    A0[temp]=i
    temp=A[temp]-1
    tempv.append(temp)

print(temp+1)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))

border_4 = n//2
border_2 = n

cnt_4=0
cnt_2=0

for i in range(n):
    if a[i]%4==0:
        cnt_4+=1
    elif a[i]%4!=0 and a[i]%2==0:
        cnt_2+=1
    else:
        continue


if cnt_4>=border_4:
    print('Yes')
elif n-cnt_4*2<=cnt_2:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
n,k=map(int,input().split())
a=[]
for i in range(n):
  a.append(int(input()))
b=sorted(a)
print(b[n-1]-b[n-k+1])
# Judge status: Accepted
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
N = int(input())
S = list(str(input()))

b = 0
w = 0
for i in range(N) :
  if S[i] == "." :
    w += 1

minN = w
for j in range(N) :
  if S[j] == "#" :
    b += 1
  else :
    w -= 1
  minN = min(minN, b+w)
print (minN)
# Judge status: Wrong Answer
S = input()
N = len(S)

cursol = -1
lst = []
for i in range(N - 1):
    if S[i] != S[i + 1]:
        lst.append(i - cursol)
        cursol = i
lst.append(i+1 - cursol)
#print(lst)

cnt = 0
for val in lst:
    if val <= 2:
        cnt += 1
    elif val % 3 == 0:
        cnt += (val // 3) * 2
    else:
        cnt += (val // 3) * 2 + 1
print(cnt)
# Judge status: Wrong Answer
from itertools import accumulate

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

    wests = list(accumulate([0]+people, lambda total, x: total + (1 if x == "W" else 0)))
    easts = list(accumulate([0]+people, lambda total, x: total + (1 if x == "E" else 0)))

    def fullsearch():
        easts_total = easts[-1]
        for i in range(1, N):
            yield wests[i-1] + easts_total - easts[i]

    print(min(fullsearch()))

main()
# Judge status: Accepted
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))

L = [0] * (N+1)
R = [0] * (N+1)

for i in range(N):
  L[i+1] = gcd(L[i], A[i])
  
for i in range(N,0,-1):
  R[i-1] = gcd(R[i], A[i-1])
  
ans = 1
for i in range(N):
  ans = max(ans, gcd(L[i], R[i+1]))

print(ans)
# Judge status: Wrong Answer
S = input()
print(S[0:2:1])
# Judge status: Wrong Answer
n, m, k = map(int, input().split())
ok = False
for i in range(n+1):
    for j in range(m+1):
        if k == (n*i + m*j) - 2*i*j:
            ok = True

if ok:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
input = input()
output = ""

for i in range(len(input)):
    if input[i] == "0":
        output += "0"
    elif input[i] == "1":
        output += "1"
    elif input[i] == "B":
        if output != "":
            output.rstrip()
        else:
            pass
    else:
        pass

print(output)
# Judge status: Wrong Answer
n = int(input())
a = input()
print(" ".join(["0"]*n))
# Judge status: Accepted
import sys
n,m,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))

d=min(y)-max(x)
warFlag = False
if d<=0:
    print("War")
    sys.exit()
else:
    for i in range(1, Y - X + 1):
        Z=X+i
        if (max(x)>=Z or min(y)<Z):
          warFlag = True
        else: #max(x) < Z, max(y) >= Z
          warFlag = False
          break
if warFlag:
  print("War")
else:
  print("No War")
# Judge status: Wrong Answer
x, y = map(int, input().split())
A = ['1', '3', '5', '7', '8', '10', '12']
B = ['4', '6', '9', '11']
if x == y == 2:
    print('Yes')
elif (x in A) and (y in A):
    print('Yes')
elif (x in B) and (y in B):
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
y1_list = list(map(int,input().split()))
y2_list = list(map(int,input().split()))
y3_list = list(map(int,input().split()))

a1 = list()
a2 = list()

for i in range(3):
    a1.append(y1_list[i] - y2_list[i])
    a2.append(y2_list[i] - y3_list[i])


if a1[0] == a1[1] and a1[2] == a1[0]:
    if a2[0] == a1[1] and a2[2] == a1[0]:
        print("yes")
        
    else:
        print("no")
else:
    print("no")
# Judge status: Accepted
word=[]
blue=[]
red=[]
n=int(input())
for i in range(n):
  s=input()
  blue.append(s)
  if not s in word:
    word.append(s)
    
m=int(input())
for i in range(m):
  s=input()
  red.append(s)
  if not s in word:
    word.append(s)
ans=0
for wd in word:
  x=blue.count(wd)-red.count(wd)
  if ans<x:
    ans=x
print(ans)
# Judge status: Accepted
x,a,b = map(int,input().split())
if abs(a-x)<abs(b-x):
    print("A")
else:
    print("B")
# Judge status: Accepted
N, R = map(int, input().split())

if N >= 10:
  print(R)
else:
  print(R + 100*(10-N))
# Judge status: Accepted
#!/usr/bin/env python3

n, k = map(int, input().split())
have = []
for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for j in a:
        if j not in have:
            have.append(j)
print(n - len(have))
# Judge status: Wrong Answer
d = int(input())

if d == 25:
  print('Christmas')
elif d == 24:
  print('Christmas Eve')
elif d == 24:
  print('Christmas Eve Eve')
else:
  print('Christmas Eve Eve Eve')
# Judge status: Wrong Answer
n, y = map(int,input().split())

for i in range(n+1):
  for j in range(n+1-i):
    for k in range(n+1-i-j):
      if y == i*1000+j*5000+k*10000 :
        print("{} {} {}".format(k,j,i))
        exit(0) 

print("-1 -1 -1")
# Judge status: Wrong Answer
x = list(map(int,input().split()))
for i in range(len(x)):
    if x[i] != i:
        print(i)
# Judge status: Accepted
n=int(input())
a=[0]*n
a=list(map(int,input().split()))
flag=0
num=0
for i in range(100):
  for j in range(n):
    if (a[j]%2==0):
      a[j]=a[j]//2
    else:
      flag=1
      break
  if (flag==1):
    break
  num+=1
print(num)
# Judge status: Accepted
from heapq import *
from collections import defaultdict
N, M = map(int, input().split())
data = defaultdict(list)
for _ in range(N):
    A, B = map(int, input().split())
    data[A].append(-B)

res = 0
temp = []
for i in range(1,M+1):
    for a in data[i]:
        heappush(temp,a)
    if temp:
        res -= heappop(temp)
print(res)
# Judge status: Wrong Answer
input()
*p,=input().split()
q=sorted(p)
print('YNEOS'[2<sum(1 for i,j in zip(p,q) if int(i)!=int(j))::2])
# Judge status: Accepted
n = int(input())
cnt_l = {}
for _ in range(n):
    a = int(input())
    if a in cnt_l:
        cnt_l[a] ^= 1
    else:
        cnt_l[a] = 1
print(sum(cnt_l.values()))
# Judge status: Wrong Answer
N = int(input())

for i in range(1,10):
  if N%i == 0 and 1<=N//i<= 9:
    print("Yes")
  else:
    print("No")
# Judge status: Accepted
x = int(input())
y = x // 11
z = x % 11
if z == 0:
  print(2*y)
elif z <= 6:
  print(2*y + 1)
else:
  print(2*y + 2)
# Judge status: Wrong Answer
a=int(input())
print(int(a^2))
# Judge status: Accepted
N = int(input())

l = [int(input()) for i in range(N)]

new_l = sorted(l)

fmax = new_l[N-1]
fmax2 = new_l[N-2]
smax = fmax

for j in reversed(range(N)):
    if not new_l[j] == fmax:
        smax = new_l[j]
        break

if fmax == fmax2:
    for k in range(N):
        print(fmax)
else:
    for m in range(N):
        if l[m] == fmax:
            print(smax)
        else:
            print(fmax)
# Judge status: Accepted
def gcd(a,b):
  return a if b == 0 else gcd(b,a%b)

N = int(input())
A = [int(x) for x in input().split()]

gcd_from_left = [0]*N # 自分のindexは含まないようなもの
gcd_from_right = [0]*N

for i in range(1,N):
  gcd_from_left[i] = gcd(A[i-1],gcd_from_left[i-1])
  gcd_from_right[N-1-i] = gcd(A[N-i],gcd_from_right[N-i])

ans = 0

for a,b in zip(gcd_from_left, gcd_from_right):
  x = gcd(a,b)
  if ans < x:
    ans = x
    
print(ans)
# Judge status: Accepted
n = int(input())
slist = [input()for i in range(n)]

alp = {chr(i):float('inf') for i in range(97,97+26)}

for i in range(len(slist)):
    sdic = {chr(i):0 for i in range(97,97+26)}
    for j in range(len(slist[i])):
        sdic[slist[i][j]] += 1
    
    for k in alp:
        alp[k] = min(alp[k],sdic[k])

alplist = sorted(list(alp.items()))
ans = ''
for i in range(26):
    ans += alplist[i][0]*alplist[i][1]
print(ans)
# Judge status: Accepted
import itertools
n=int(input())
a=list(map(int,input().split()))
li=list(itertools.accumulate(a))
ans=float("inf")
#print(li)

for i in range(n-1):
    l=li[i]
    r=li[-1]-li[i]
    #print(l,r)
    ans=min(ans,abs(l-r))

print(ans)
# Judge status: Wrong Answer
x,y = map(int, input().split())
if x!= y and min(x,y) == x: print(x)
elif x%y == 0: print(-1)
else:
  for i in range(1, 10**9//x):
    if (x ** i) % y != 0: 
      print(x**i)
      exit()
# Judge status: Wrong Answer
N=int(input())

p=0
for i in range(1,N):
    if i%2==1:
        p +=1
print(p/N)
# Judge status: Accepted
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
    s=i
    m=1
    while 1<=s and s<=k-1:
        m*=0.5
        s*=2
    ans+=m
print(ans/n)
# Judge status: Accepted
import math
H, A = map(int, input().split())
print(math.ceil(H/A))
# Judge status: Accepted
n = input()
if n[0] == n[1] == n[2] or n[1] == n[2] == n[3]:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
N, K = map(int, input().split())
A = list(map(int, input().split()))
was = []
tf = [False] * N
place = 1
cnt = 0

while tf[place-1] == False:
  if cnt < K:
    tf[place-1] = True
    was.append(place)
    place = A[place-1]
    cnt += 1
  else:
    print(place)
    break;
else:
  loop = cnt - was.index(place)
  num = (K-cnt) % loop + was.index(place)
  print(was[num])
# Judge status: Wrong Answer
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

a,b,c=mp()
print(c-a+b)
# Judge status: Accepted
n,m = map(int, input().split())

sc = set([tuple(map(int, input().split())) for _ in range(m)])
ans = 0
h = []

for x,y in sc:
  if n != 1 and x == 1 and y == 0:
    print(-1)
    exit()
  if x in h:
    print(-1)
    exit()
  ans += y * (10 ** (n-x))
  h.append(x)
  
if ans < 10**(n-1) and n != 1:
  ans += 10**(n-1)
print(ans)
# Judge status: Accepted
a,b,x = map(int, input().split())
if (x >= a)&(a+b>=x):
    print("YES")
else:
    print("NO")
# Judge status: Accepted
import itertools
import fractions
def main():
  n,k = map(int, input().split())
  print(0 if n%k == 0 else 1)
if __name__ == '__main__':
  main()
# Judge status: Accepted
S=input()
X=[]
for i in S:
  i="x"
  X.append(i)
X="".join(X)
print(X)
# Judge status: Accepted
n = int(input())
C = [[0]*10 for _ in range(10)]
for i in range(1,n+1):
    C[int(str(i)[0])][int(str(i)[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += C[i][j]*C[j][i]
print(ans)
# Judge status: Wrong Answer
n = int(input())

if n < 1000:
    print('abc')
else:
    print('abd')
# Judge status: Accepted
S = input()
N = len(S)

def isOk(s):
    for s, t in zip(s, s[:: -1]):
        if s != t:
            return False
    return True

for s in [S, S[:(N - 1) // 2], S[(N + 3) // 2 - 1:]]:
    if not isOk(s):
        print('No')
        exit()

print('Yes')
# Judge status: Wrong Answer
n = int(input())
arr = [int(x) for x in input().split()] 

mult = 1;

for x in arr:
	mult *= x;

if(mult < 1000000000000000001):
	print(x)
else:
	print("-1")
# Judge status: Accepted
N = int(input())
count =[[0 for x in range(10)] for z in range(10)]
for x in range(1,N+1):
    F = str(x)[0]
    E = str(x)[-1] 
    count[int(F)][int(E)] +=1
ans = 0
for x in range(10):
    for y in range(10):
        ans += count[x][y] *count[y][x]
print(ans)
# Judge status: Accepted
sx,sy,tx,ty = map(int,input().split())
ans1 =tx - sx
ans2 = ty - sy
Answer1 = 'R'*ans1 + 'U'*ans2 +'L'*ans1+'D'*(ans2+1)
Answer2 = 'R'*(ans1+1) +'U'*(ans2+1)+'L' +'U'+'L'*(ans1+1)+'D'*(ans2+1)+'R'
Answer = Answer1 + Answer2
print(Answer)
# Judge status: Accepted
from math import atan, pi
a, b, x = map(int, input().split())
if 2*x <= a**2*b:
    print(180 * atan(a * b ** 2 / (2 * x)) / pi)
else:
    print(180 * atan(2*(a**2*b-x)/a**3)/pi)
# Judge status: Accepted
n = int(input())
ans = 9*10
def f(x):
    kurainowa = 0
    while x>0:
        kurainowa += x%10
        x = x // 10
    return kurainowa
for a in range(1,n):
    b = n-a
    if ans > f(a) + f(b):
        ans = f(a) + f(b)
print(ans)
# Judge status: Accepted
from collections import Counter

s = list(input())
c = Counter(s)
print(min(c["0"], c["1"]) * 2)
# Judge status: Accepted
x = int(input())
a = int((x//500)*1000)
b = int(((x-(x//500)*500)//5)*5)
print(int(a+b))
# Judge status: Wrong Answer
import heapq as hp

n,m=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]

hp.heapify(a)

bc=[]
for i in range(m):
  b,c=[int(x) for x in input().rstrip().split()]
  bc.extend([-c]*b)


for i in range(len(bc)):
  now_bc=hp.heappop(bc)
  now_a=hp.heappop(a)
  if -now_bc<=now_a:
    hp.heappush(a,now_a)
    break
  else:
    hp.heappush(a,-now_bc)

print(sum(a))
# Judge status: Wrong Answer
a,b=input().split()
a=int(a)
c=a
b=int(b)
i=0
k=0
while c<b:
  c=c+a-1
  k=k+1
print(k)
# Judge status: Wrong Answer
N = int(input())
for i in range(1,10):
    for j in range(1,10):
        ij = i * j
    if(N == i*j):
        print("Yes")
        exit(0)
print("No")
# Judge status: Wrong Answer
x = int(input())

'''
if x <= 6:
    print(1)
'''
judge = x%11
#print(judge)
if judge >= 6:
    print(2*(x//11)+2)
else:
    print(2*(x//11)+1)
# Judge status: Wrong Answer
import string
N=int(input())
S=list(str(input()))

Alphabet_List=list(string.ascii_uppercase)
Alphabet_List.extend(2*Alphabet_List)

for i in range(len(S)):
    for j in range(len(Alphabet_List)):
        if S[i]==Alphabet_List[j]:
            S[i]=Alphabet_List[j+13]
            break
            
print(("").join(S))
# Judge status: Accepted
n = int(input())
a = [int(x) for x in input().split()]

full_arr = 0
for x in a:
    full_arr ^= x

for x in a:
    print(full_arr ^ x, end=' ')

print()
# Judge status: Wrong Answer
a, b = (int(x) for x in input().split(' '))
s = (a + b) % 2
t = (a + b) / 2
if s == 0:
	print(t)
else:
    print(t+0.5)
# Judge status: Accepted
from collections import Counter

in_s = input()

def judge(s):
    cnt = Counter(list(s))
    for _, v in cnt.items():
        if v % 2 != 0:
            return False
    return True

if judge(in_s):
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
x, y, z =map(int, input().split())
A=[z, x, y]
print(' '.join(i) for i in A)
# Judge status: Wrong Answer
N = int(input())
b = [10**9] + list(map(int,input().split())) + [10**9]
a = []
a.append(b[1])
for i in range(1,N-1):
  a.append(min(b[i-1],b[i]))
  
a.append(b[-2])
print(sum(a))
# Judge status: Accepted
import sys
x,y=map(int,input().split())
tmp=x
ans=0
while tmp<=y:
    ans+=1
    tmp*=2
    if tmp>y:
        print(ans)
        sys.exit()
# Judge status: Accepted
n = int(input())
ma = []
for _ in range(n):
    tmp = list(map(int,input().split()))
    ma.append(tmp)
ma.reverse()

count = 0
for m in ma:
    a = m[0]+count
    b = m[1]
    if a == 0:
        #count += b
        continue
    if a%b != 0:
        amari = a%b
        addition = b - amari
        count += addition
print(count)
# Judge status: Accepted
N=int(input())
S=str(input())
ls = []
for i in range(len(S)):
    ls.append(S[i])
for i in range(len(S)):
    x = S[i]
    #print(ord(x)+N,ord("Z"))
    if ord(x)+N > ord("Z"):
        #print("if")
        #print(ord("A")-ord("Z")+(ord(x)+N))
        ls[i]=chr(ord("A")-ord("Z")+(ord(x)+N)-1)
    else:
        #print("else")
        ls[i]=chr((ord(x)+N))
print("".join(ls))
# Judge status: Accepted
a=list(map(int,input().split()))
a.sort()
x=(a[2]-a[1])+(a[1]-a[0])//2+((a[1]-a[0])%2)*2
print(x)
# Judge status: Accepted
s=input()
i1 = s.find('A')
i2 = s.rfind('Z')
print(i2-i1+1)
# Judge status: Accepted
n = input()
a = list(map(int,input().split()))
count = 0
flag = True
while flag:
    for i in range(len(a)):
        if a[i] % 2 != 0:
            print(count)
            flag = False
            break
    else:
        count += 1
        a = [ i / 2 for i in a]
# Judge status: Accepted
X=list(map(int,input().split()))
if (max(X)*3)%2==sum(X)%2:
    print(int((max(X)*3-sum(X))/2))
else:
    print(int(((max(X)+1)*3-sum(X))/2))
# Judge status: Accepted
w, h, *xy = map(int, input().split())
print(w*h/2, ([w/2, h/2] == xy)+0)
# Judge status: Accepted
Y, M, D = input().split("/")

S = int(Y+M+D)

if S <= 20190430:
    print("Heisei")
else:
    print("TBD")
# Judge status: Wrong Answer
s = input()
y, m, d = map(int, s.split('/'))
if y >= 2019 and m >= 4:
    print('Heisei')
elif y >= 2019 and m >= 4 and d >= 30:
    print('Heisei')
else:
    print('TBD')
# Judge status: Wrong Answer
from fractions import gcd
n = int(input())
lcm = 1
for _ in range(n):
    t = int(input())
    lcm = lcm * t / gcd(lcm, t)
print(int(lcm))
# Judge status: Accepted
n = input()

if n[-1] == 's':
  print(n + 'es')
else:
  print(n + 's')
# Judge status: Accepted
A,B,T=map(int,input().split())
print(int((T+0.5)//A*B))
# Judge status: Accepted
N = int(input())
A = [0] + list(map(int, input().split()))
Ans = [0] * (N+1)
for i, a in zip(range(N, 0, -1), A[:0:-1]):
    n = 0
    for aj in Ans[i*2::i]:
        n ^= aj
    Ans[i] = n ^ a
Ans = [i for i, a in enumerate(Ans[1:], 1) if a]
print(len(Ans))
print(" ".join(map(str, Ans)))
# Judge status: Wrong Answer
N = int(input())
if int(N/1.08)*1.08 == N*1.08:
  print(N//1.08)
else:
  print(':(')
# Judge status: Accepted
C = [list(map(int, input().split())) for _ in range(3)]
x = [0, 0, 0]
y = [0, 0, 0]

for i in range(3):
    y[i] = C[0][i]
for i in range(3):
    x[i] = C[i][0] - y[0]
for i in range(3):
    for j in range(3):
        if C[i][j] != x[i] + y[j]:
            print('No')
            exit()
print('Yes')
# Judge status: Wrong Answer
import numpy as np
n = int(input())
d = np.array([list(map(int,input().split())) for i in range(n)])
D = np.abs(d[:,0]-d[:,1])
f = False
for i in range(n-3):
    if D[i:i+3].sum() == 0:
        f = True
        break
print('Yes' if f else 'No')
# Judge status: Accepted
n = int(input())
x = list(map(int, input().split()))
x_ans = round(sum(x)/len(x))
ans = 0
for i in x:
    ans += (i-x_ans)**2
print(ans)