peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N,M=map(int,input().split())
l=[N,M]
l.sort()
buf=0
f=0
c=0
if l[0]==1:
    if l[1]==1:
        print("1")
    else:
        print(l[1]-2)
else:   #l[0]>1
    print((l[0]-2)*(l[1]-2))
# Judge status: Accepted
n, m = list(map(int, input().split()))
cnt = [1] * n
has_red = [False] * n
has_red[0] = True
for i in range(m):
    a, b = list(map(int, input().split()))
    has_red[b - 1] = has_red[b - 1] or has_red[a - 1]
    if cnt[a - 1] == 1:
        has_red[a - 1] = False
    cnt[a - 1] -= 1
    cnt[b - 1] += 1
print(has_red.count(True))
# Judge status: Accepted
import numpy as np
n, k = map(int,input().split())
p = list(map(int,input().split()))

e = [(i+1)/2 for i in p]
e = np.cumsum(e)
e = np.append(0,e)
ans = 0
for i in range(n-k+1):
    ans = max(e[i+k]-e[i],ans)
print(ans)
# Judge status: Accepted
N,M=map(int,input().split())

ans=[0]*N
pen=[0]*N
AC=[0]*N

for i in range(M):
    p,s=input().split()
    p=int(p)
    if s=="WA":
        pen[p-1]+=1
    else:
        if AC[p-1]==0:
            ans[p-1]+=pen[p-1]
        AC[p-1]=1

print(AC.count(1),sum(ans))
# Judge status: Accepted
n = int(input())


def num2alpha(n):
    if n <= 26:
        return chr(96+n)
    elif n % 26 == 0:
        return num2alpha(n//26-1)+chr(122)
    else:
        return num2alpha(n//26)+chr(96+n % 26)


print(num2alpha(n))
# Judge status: Wrong Answer
s = input()
week = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"]
for i in range(7):
    if s == "SUN":
        print(7)
    else:
        print(6 - i)
# Judge status: Accepted
a,b,c=map(int,input().split())
if c<=b:
  print("delicious")
elif c<=a+b:
  print("safe")
else:
  print("dangerous")
# Judge status: Accepted
import math

n = int(input())


def prime_checker(n):
    dest = int(math.sqrt(n))
    for i in range(2, dest):
        if n % i == 0:
            return False
    return True


while True:
    if prime_checker(n):
        print(n)
        break
    n += 1
# Judge status: Accepted
s = input()
t = input()
n = len(t)

for i in reversed(range(len(s)-n+1)): #後ろから一致する部分が無いか見ていく
    x = s[i:i+n]
    y = 0
    for j in range(n):
        if x[j] == "?" or x[j] == t[j]:
            continue
        else:
            y = 1
            break
    if y == 0:
        print(s[:i].replace("?", "a") +t + s[i+n:].replace("?", "a"))
        exit()

print("UNRESTORABLE")
# Judge status: Accepted
n = int(input())
if n%10==9 or n//10==9:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    O = readline().strip()
    E = readline().strip()

    ans = ''.join(O[i // 2] if i % 2 == 0 else E[i // 2] for i in range(len(O) + len(E)))
    print(ans)
    return


if __name__ == '__main__':
    main()
# Judge status: Accepted
import sys

n = int(input())
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]

button = 1

for i in range(n):
    if button == 2:
        print(i)
        break
    button = a[button]
else:
    print(-1)
# Judge status: Accepted
n = int(input())

pos = [[int(w) for w in input().split()] for _ in range(n)]

dist = [[0] * n for i in range(n)]

for i in range(n):
    for j in range(i+1, n):
        d = ((pos[i][0]-pos[j][0])**2 + (pos[i][1]-pos[j][1])**2)**0.5
        dist[i][j] = d

ave = sum(map(sum, dist))/((n**2-n)//2)

print(ave*(n-1))
# Judge status: Accepted
n = str(input())

ans = 0
for s in n:
    ans += int(s)
if ans % 9 == 0:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
total = 1000
for i in range(1, N):
    if A[i] > A[i-1]:
        total += (total // A[i-1]) * (A[i]-A[i-1])
print(total)
# Judge status: Accepted
def main():
    N = int(input())
    S = input()
    if len(set(S)) == 1:
        return print(0)
    w = S.count(".")
    b = 0
    ans = w
    for s in S:
        if s == "#":
            b += 1
        else:
            w -= 1
        ans = min(ans, b+w)
    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = 0

List = [0]*100000
for i in A:
  List[i-1] += 1
  ans += i

tmp = 0
for i in range(Q):
  B,C= map(int, input().split())
  tmp = List[B-1]
  ans = ans + tmp*(C-B) 
  print(ans)
  List[C-1] += tmp
# Judge status: Wrong Answer
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    s = readline().strip()

    if s == "BBB":
        print("No")
    else:
        print("Yes")



if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))

A = A[::-1]
a = A.copy()

ans_list = list()
A_len =len(A)

while A_len != 0:
    for i in range(A_len-1):
        if A[i+1] % A[0]==0:
            a.remove(A[i+1])
    ans_list.append(A[0])
    a.remove(A[0])
    A = a.copy()
    A_len = len(A)
ans = len(ans_list)
print(ans-1)
# Judge status: Accepted
'''input
3 5
1 2 1
2 3 0
'''
# connected components
from sys import stdin, setrecursionlimit
from bisect import bisect_left
import sys, threading


# main start
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
k = 0
for i in range(n):
    if arr[i] == k + 1:
        k += 1

if k == 0:
    print(-1)
else:
    print(n - k)
# Judge status: Accepted
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,X=map(int,readline().split())
    L=list(map(int,readline().split()))

    S=[0]*(N+1)
    for i in range(1,N+1):
        S[i]+=S[i-1]+L[i-1]
    res=0
    for i in range(N+1):
        if S[i]<=X:
            res+=1
        else:
            break
    print(res)
if __name__=="__main__":
    main()
# Judge status: Wrong Answer
a = list(map(int,input().split()))

i = 0

if(a[i] == a[i+1] and a[i] == a[i+2]):
  print("No")
else:
  print("Yes")
# Judge status: Wrong Answer
s = list(input())
s.sort()
alp = list('abcdefghijklmnopqrstuvwxyz')

for s_,alp_ in zip(s,alp):
    if s_ != alp_ :
        print(alp_)
        exit()

print('None')
# Judge status: Accepted
S = int(input())
x = [1, 0, 0]

for i in range(3, S+1):
    x.append(x[i-1] + x[i-3])
print(x[S]%1000000007)
# Judge status: Accepted
N = int(input())
ans = ''
if N > 81 or N < 1:
    ans = 'No'
else:
    a = [i for i in range(1,10)]
    for i in a:
        q, mod = divmod(N, i)
        if q < 10 and mod == 0:
            ans = 'Yes'
            break
if ans == 'No' or ans == '':
    print('No')
else:
    print('Yes')
# Judge status: Accepted
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


n = I()
A = LI()
ans = 0
isEven = True
while 1:
    for a in A:
        if a % 2 == 1:
            isEven = False
    if isEven == False:
        break
    for a in range(len(A)):
        A[a] = A[a] // 2
    ans += 1
print(ans)
# Judge status: Wrong Answer
def getter(i):
  res=0
  while True:
    res+=i%10
    i//=10
    if i==0:
      break
  return res
n=int(input())
digit=n//10
a=10**digit
if n-a>0:
  res=1+getter(n-a)
  print(res)
  exit()
else:
  print("10")
# Judge status: Accepted
import numpy as np
import fractions
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
d = np.diff(a)
if n>1:
    gcd = fractions.gcd(d[0],d[1])
    if n>3:
        for i in range(2,n-1):
            gcd = fractions.gcd(gcd,d[i])
    print(gcd)
else:
    print(d[0])
# Judge status: Accepted

def main():
    a, b = map(int, input().split())
    if (a + b) % 2 == 0:
        print(int((a + b) / 2))
    else:
        print('IMPOSSIBLE')


if __name__ == "__main__":
    main()
# Judge status: Accepted
sx, sy, tx, ty = map(int,input().split())
width = tx - sx
depth = ty - sy
st1 = width * 'R' + depth * 'U'
st2 = 'D' + (width + 1) * 'R' + (depth + 1) * 'U' + 'L'
back1 = width * 'L' + depth * 'D'
back2 = 'U' + (width + 1) * 'L' + (depth + 1) * 'D' + 'R'
ans = st1 + back1 + st2 + back2
print(ans)
# Judge status: Accepted
N,K = map(int,input().split())
S = input()
s = list(S)
T = s[K-1]
T = T.lower()
s[K-1] = T
s = ''.join(s)
print(s)
# Judge status: Wrong Answer
import math
x,y = map(int,input().split())
print(math.floor(math.log2(y/x)))
# Judge status: Wrong Answer
w=input()
list_w=list(w)
count1=0
if(len(list_w)==1):
	print("No")
elif(len(list_w)!=1):		
	for i in range(0,len(w)):
		a=w.count(w[i])
		if(a%2==0):
			count1+=1
		elif(a%2 != 0):
			count1-=1
if(count1>0):
	print("Yes")
elif(count1<0):
	print("No")
# Judge status: Accepted
D, T, S = map(int, input().split())

if T*S >= D:
    print("Yes")
else:
    print ("No")
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))
l = [0] * 10000001
for i in A:
    l[i] += 1
s = 0
for i in range(N):
    s += l[i] * (l[i] - 1) / 2
for a in A:
    print(int(s - (l[a] * (l[a] - 1)) / 2 + (l[a] - 1) * (l[a] - 2) / 2))
# Judge status: Accepted
#スペース区切りの整数の入力
N,M = map(int, input().split())

#スペース区切りの整数の入力リスト
A_list = list(map(int, input().split()))
A_list_sum = sum(A_list)


count = 0
aa = A_list_sum/(4*M)
#print(aa)
for  i in range(len(A_list)):
  #print(i)
  if(A_list[i]>=aa):
    count = count + 1
    #print(count)
    
if(count >= M):
  print("Yes")
else:
  print("No")
#print(A_list_sum)
# Judge status: Wrong Answer
import math
from itertools import groupby
N = int(input())
A = list(map(int, (input().split())))
cash = 1000
stock = 0
A = [i[0] for i in groupby(A)]
if (A[0] == max(A)):
    print(cash)
else:
    for i in range(len(A)-1):
        if (A[i] > A[i+1]):
            cash = cash + stock*A[i]
            stock = 0
        else:
            stock = stock + math.floor(cash/A[i])
            cash = cash - math.floor(cash/A[i])*A[i]
    cash = cash + stock*A[i+1]
    print(cash)
# Judge status: Accepted
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")


count = 0

for i in range(n):
	for j in range(i+1,n):
		k = j*2-i
		if 0 <= k < n:
			if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
				count += 1
print(r*g*b - count)
# Judge status: Wrong Answer
n=input()
x=list(map(int,input().split()))
ans=0
for i in x[1::2]:
    if i%2==1:
        ans+=1
print(ans)
# Judge status: Accepted
import heapq
N = int(input())
h = list(map(int, input().split()))
heapq.heapify(h)

while len(h) > 1:
  monster = heapq.heappop(h)
  tmp = [monster]
  heapq.heapify(tmp)
  while len(h) > 0:
    num = heapq.heappop(h) % monster
    if num != 0:
      heapq.heappush(tmp, num) 
  h = tmp
print(heapq.heappop(h))
# Judge status: Accepted
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-11 14:10:37 +0900
# LastModified: 2020-09-11 14:16:43 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    S = input()
    if S.count('0') < S.count('1'):
        print(S.count('0')*2)
    else:
        print(S.count('1')*2)


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
N, M = map(int, input().split())

st = []
for n in range(N):
  st.append(list(map(int, input().split())))

cs = []
for m in range(M):
  cs.append(list(map(int, input().split())))
  
for n in range(N):
  min_d = 100000
  min_i = -1
  for m in range(M):
    d = abs(st[n][0]-cs[m][0]) + abs(st[n][1]-cs[m][1])
    if d < min_d:
      min_d = d
      min_i = m
  print(min_i+1)
# Judge status: Wrong Answer
N = int(input())
X = list(map(int,input().split()))
ans = max(X) **2
for i in range(1,100):
    sum = 0
    for j in range(N):
        sum += (X[j]-i)**2
    ans = min(ans,sum)
print(ans)
# Judge status: Accepted
import sys


X = int(input())

year = 1
ans  = 100
while 1:

    ans = int(ans*(1.01))
    if ans>=X:
        break
    year = year + 1

print(year)
# Judge status: Wrong Answer
n,k=map(int,input().split())
#hp=list(map(int,input().split()))
hp=[int(x) for x in input().split()]
hp.sort()
if n>=k:
	re=sum(hp[:n-k])
else:
	re=len(hp)
print(re)
# Judge status: Wrong Answer
#整数の入力
A = int(input())
#文字列の入力
S = input()
#listを一文字ずつのlistに
S_list = list(S)
for i in range(A-1):
  S_list.remove(" ")

A_list = []
for i in range(A):
  A_list.append(i+1)


counter = 0
for i in range(A):
  if(A_list[i] != S_list[i]):
    counter = counter + 1

if((counter == 0)or(counter == 2)):
  print("YES")
else:
  print("NO")
# Judge status: Accepted
def main():
    A = [int(i) for i in input().split()]
    A.sort()
    B = [A[2]-A[0], A[2]-A[1]]
    ans = 0
    if all(b % 2 == 0 for b in B):
        ans += sum(b//2 for b in B)
    elif all(b % 2 == 1 for b in B):
        ans += sum((b-1)//2 for b in B) + 1
    else:
        ans += sum(b//2 for b in B) + 2
    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Accepted
def main():
  n=list(input())
  n=[int(i) for i in reversed(n)]
  l=len(n)
  n.append(0)
  
  ans=0
  for i in range(l):
    if n[i]<=4:
      a=n[i]
    elif n[i]==5:
      if n[i+1]<=4:
        a=n[i]
      else:
        a=10-n[i]
        n[i+1]+=1
    else:
      n[i+1]+=1
      a=10-n[i]
    ans+=a
  ans+=n[l]
  print(ans)  
if __name__=='__main__':
    main()
# Judge status: Accepted
import math
a,b=input().split()
x=int(a+b)
rt=math.sqrt(x)
if rt%1>0:
    print('No')
else:
    print('Yes')
# Judge status: Wrong Answer
s = input()

OD = ["D", "R", "U"]
EV = ["D", "L", "U"]

if (sorted(set(s[::2])) == OD) and (sorted(set(s[1::2])) == EV):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
import _heapq as heapq
n, m = [int(i) for i in input().split()]
ab = []
for _ in range(n):
    a, b = [int(i) for i in input().split()]
    ab.append([a, -b])
ab.sort()
j = 0
ans=0
h = []
for i in range(1, m + 1):
    while j<n and ab[j][0] <= i:
        heapq.heappush(h, ab[j][1])
        j += 1
    if h:
        ans += heapq.heappop(h)
print(-ans)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N):
  ans = max(ans, sum(A[:i+1])+sum(B[i:]))
print(ans)
# Judge status: Accepted
s = input()
t = input()

s = sorted(s)
t = sorted(t, reverse=True)

if s < t:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
import sys

X, K, D = [int(x) for x in input().strip().split(" ")]

X = abs(X)
k, x = divmod(X, D)

if K <= k:
    print(abs(X - D * K))
    sys.exit(0)

X = x
K -= k

if k % 2 == 0:
    print(abs(X))
    sys.exit(0)

print(abs(X - D))
# Judge status: Accepted
a = input()

N = len(a)
t = int((N-1)/2) #真ん中まで
hantei = True

for i in range(t):
  if a[i] == a[t-1-i]:
    hantei = True
  else:
    hantei = False

if hantei == False:
  print("No")
else:
  b = a[:t+1] + a[:t]
  if a == b:
    print("Yes")
  else:
    print("No")
# Judge status: Wrong Answer
n,m,q = map(int,input().split())
l = [list(map(int,input().split())) for i in range(q)]
ans = 0

def count(a):
    score = 0
    for i in range(q):
        if a[l[i][1]-1] - a[l[i][0]-1] == l[i][2]:
            score += l[i][3]
    return score

def dfs(x,now,s):
    if x == n:
        return count(s)
    score = 0
    for i in range(now,m+1):
        s.append(i)
        score = max(score,dfs(x+1,i,s))
        s.pop()
    return score
print(dfs(0,0,[]))
# Judge status: Wrong Answer
x, a, b = map(int,input().split())
 
if 0 > (b - a):
  print("delicious")
elif x < (b - a):
  print("dangerous")
else:
  print("safe")
# Judge status: Accepted
import sys
import math
import collections

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin


def int_input():
    return list(map(int, input().split()))


def get(s):
    return str(s % 9) + '9' * (s // 9)

if __name__ == '__main__':
    # set_debug(True)

    # t = int(input())
    t = 1

    for ti in range(1, t + 1):
        n, k = int_input()
        A = int_input()

        A.sort()

        print(sum(A[:k]))
# Judge status: Accepted
a = int(input())
n = 1
while a > 1:
    a //= 2
    n += 1
ans = 0
for i in range(n):
    ans += 2 ** i
print(ans)
# Judge status: Accepted
a, b = map(int, input().split())

if (a*b) % 2:
    print('Odd')
else:
    print('Even')
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

m=0
for i in range(n-1):
  if a[i+1]==a[i]+1:
    m=m+c[i]

print(sum(b)+m)
# Judge status: Wrong Answer
sx, sy, tx, ty = list(map(int, input().split()))

ans = "L"

dx = tx - sx
dy = ty - sy

ans += "U" * (dy + 1) + "R" * (dx + 1) + "D"
ans += "L" * dx + "D" * dy
ans += "R" * dx + "U" * dy
ans += "R" + "D" * dy + "L" * dx
print(ans)
# Judge status: Wrong Answer
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
bc = [[0 for i in range(2)] for j in range(Q)]
for i in range(Q):
  bc[i] = list(map(int,input().split()))

count = [0 for i in range(110000)]
for i in range(N):
  count[A[i]] += 1

sum_ = sum(A)
for i in range(Q):
  b,c = bc[i]
  n = count[b]
  sum_ -= b*n
  sum_ += c*n
  count[c] += n
  print(sum_)
# Judge status: Wrong Answer
N,P = map(int,input().split())
A = list(map(int,input().split()))
C = [0,0]
for i in range(N):
    if A[i]%2==0:
        C[0] += 1
    else:
        C[1] += 1
if C[1]==0 and P==1:
    print(0)
else:
    print((2**C[0])*(2**(C[1]-1)))
# Judge status: Accepted
s = input()
t = input()
n = len(s)
for i in range(n):
    s = list(s)
    s_last = [s[n - 1]]
    u = s_last + s[0:n - 1]
    s = "".join(u)
    if s == t:
        print("Yes")
        exit()
print("No")
# Judge status: Accepted
s = list(str(input()))
answer = ""

for i in s:
    if i == "0":
        answer = answer + "0"

    elif i == "1":
        answer = answer + "1"

    elif i == "B":
        answer = answer[:-1]

print(answer)
# Judge status: Accepted
N = int(input())
B = list(map(int, input().split()))
A_max = list()
for i in range(len(B)+1):
    if i == 0:
        A_max.append(B[i])
    elif i == len(B):
        A_max.append(B[-1])
    else:
        A = min([B[i], B[i-1]])
        A_max.append(A)

print(sum(A_max))
# Judge status: Accepted
a, b, x = map(int, input().split())

print(b // x - (a - 1) // x)
# Judge status: Wrong Answer
n = int(input())
A = list(map(int,input().split()))
b = ""
inv = 1
for i in range(n):
    a = str(A[i])
    if inv ==1:
        b = b+a
    else:
        b = a+b
    inv *=-1
if inv ==1:
    print(*list(b))
else:
    print(*list(b[::-1]))
# Judge status: Accepted
f = lambda:map(int,input().split())
n,q = f()
s = input()
ln = [0]
for i in range(n):
  ln.append(ln[i]+(s[i-1:i+1]=='AC'))
for _ in range(q):
  l,r = f()
  print(ln[r]-ln[l])
# Judge status: Accepted
import sys

n, *a = map(int, sys.stdin.read().split())

def main():
  s = sum(a)
  if s % 10: ans = s
  else: 
    m = min([101] + [x for x in a if x % 10])
    if m == 101: ans = 0
    else: ans = s - m
  print(ans)

if __name__ == '__main__':
  main()
# Judge status: Wrong Answer
from sys import stdin
input = stdin.readline
S = input()
Q = int(input())
s = [S[0]]
A = []
count = 0
for i in range(Q):
  A += [input().split()]
for i in range(Q):
  if int(A[i][0]) == 2:
    if count % 2 == 1:
      s = s[::-1]
    count = 0
    if int(A[i][1]) == 1:
      s = [A[i][2]] + s
    else:
      s = s + [A[i][2]]
  else:
    count += 1
    if i == Q-1:
      if count % 2 == 1:
        s = s[::-1]
 
 
result = ''.join(s)
print(result)
# Judge status: Accepted
N=int(input())
cnt=N//11*2
if N%11>6:
    cnt+=2
elif N%11>0:
    cnt+=1
print(cnt)
# Judge status: Accepted
n=int(input())
s=[input()]
for i in range(n-1):
    w=input()
    if s[-1][-1]==w[0]:
        if not w in s:
            s.append(w)
            
if len(s)==n:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n, k = map(int, input().split())
scores = list(map(int, input().split()))

evals = []
cnt = 0

for i in range(k, n, 1):
    edge = scores[cnt]
    new_edge = scores[i]
    if edge < new_edge:
        print('Yes')
    else:
        print('No')
    cnt += 1
# Judge status: Accepted
a,b,n=map(int,input().split())

x=b-1
if x>n:
    x=n
p=a*x//b
q=x//b
print(p-q)
# Judge status: Accepted
A, B, T = map(int, input().split())

print( (T//A) * B)
# Judge status: Accepted
ans = {}
n = int(input())
for _ in range(n):
    s = input()
    ans.setdefault(s, 0)
    ans[s] += 1

m = int(input())
for _ in range(m):
    t = input()
    ans.setdefault(t, 0)
    ans[t] -= 1

ans = sorted(ans.items(), key=lambda x: x[1], reverse=True)
print(max(0, ans[0][1]))
# Judge status: Accepted
n = int(input())
l = [[int(i) for i in input().split()] for _ in range(n)]

ans = 0
p = 0
for i in l[::-1]:
    i[0] += p
    ans += i[1] - (i[0] % i[1]) if i[0] % i[1] else 0
    p += i[1] - (i[0] % i[1]) if i[0] % i[1] else 0
    
print(ans)
# Judge status: Accepted
N,K,S=map(int,input().split())
if S!=10**9:
  l=[S]*K+[S+1]*(N-K)
  print(" ".join(map(str,l)))
else:
  l=[S]*K+[1]*(N-K)
  print(" ".join(map(str,l)))
# Judge status: Accepted
n,T = map(int,input().split())
ct = [map(int, input().split()) for _ in range(n)]
c,t = [list(i) for i in zip(*ct)]
ans = 1000000
for i in range(n):
  if(T >= t[i]):
    ans = min(ans,c[i])
if(ans == 1000000):
  print('TLE')
else:
  print(ans)
# Judge status: Wrong Answer
import math
A,B = input().split()
a = int(A)
b = float(B)
print(int(a*b))
# Judge status: Accepted
import fractions
n = int(input())
a = list(map(int,input().split()))

ans = fractions.gcd(a[0],a[1])
for i in range(2,n):
    ans = fractions.gcd(ans,a[i])
print(ans)
# Judge status: Accepted
s = input()
alps = 'abcdefghijklmnopqrstuvwxyz'
for alp in alps:
    if alp not in s:
        print(alp)
        break
else:
    print('None')
# Judge status: Accepted
import fractions

a,b,c = map(int, input().split())

gab = fractions.gcd(a, b)
gbc = fractions.gcd(gab,c)

if gab ==1:
    print("YES")
    exit()
if c ==0:
    print("YES")
    exit()

if gbc == gab:
    print("YES")
    exit()
print("NO")
# Judge status: Accepted
n,k=map(int,input().split())
p=list(map(int,input().split()))
a=[]
b=[0]*n
q=0
for i in range(n):
  a.append((1/2)*(p[i]+1))
for j in range(k):
  q+=a[j]

b[0]=q

for l in range(1,n-k+1):
  b[l]=b[l-1]-a[l-1]+a[k+l-1]
print(max(b))
# Judge status: Wrong Answer
A = input()
B = input()
C = input()
i = "a"
player = {"a":A,"b":B,"c":C}

while True:
    l = player[i][0]
    player[i] = player[i][1:]
    if len(player[i])==0:
        print(i.upper())
        break
    i = l
# Judge status: Accepted
N, M = map(int, input().split())
X = list(map(int, input().split()))

X.sort()
diff_X = []
for i in range(M-1):
  tmp = X[i+1] - X[i]
  diff_X.append(tmp)

diff_X.sort(reverse=True)
ans = sum(diff_X[N-1:])
print(ans)
# Judge status: Accepted
c=str(input())
a='abcdefghijklmnopqrstuvwxyz'
b=a.find(c)
print(a[b+1])
# Judge status: Accepted
N=input()
i=0
for n in N:
  i+=int(n)

if i%9==0:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
s =  list(input())
if s[0] == s[1] or s[1] == s[2] or s[2] ==s[3]:
    print("Bad")
else:
    print("Good")
# Judge status: Accepted
S = input()
count = 0
passFlag = False
for x in range(len(S)):
    if x == 0:
        count = 1
        prev = S[0]
    else:
        if passFlag:
            passFlag = False
            count += 1
        else:
            if S[x] == prev:
                prev = S[x:x + 2]
                passFlag = True
            else:
                prev = S[x]
                count += 1
print(count)
# Judge status: Accepted
from math import sqrt
X=int(input())

def checkprime(x):
  for i in range(1,int(sqrt(x))+1,2):
    #print(i)
    if i == 1:
      continue
    if X%i==0:
      return False
  return True

if X<=2:
  print(X)
  exit()

if X%2==0:
  X+=1
while(1):
  if checkprime(X):
    print(X)
    break
  else:
    X+=2
# Judge status: Accepted
from math import gcd
n,x = map(int,input().split())
l = list(map(int,input().split()))
for i in range(n):
    l[i] = abs(l[i] - x)
d = l[0]
for i in range(1,n):
    d = gcd(d,l[i])
print(d)