peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
import sys
stdin = sys.stdin

mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

A, B, C, X, Y = na()
ans = 10**10
for ab in range((10**5+1)*2):
    cost = ab * C
    cost += max(0, X - ab//2) * A
    cost += max(0, Y - ab//2) * B
    ans = min(ans, cost)
print(ans)
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline

n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
from fractions import gcd

if n==1:
    print(1)
else:
    g=A[0]
    l=A[0]
    for i in range(n-1):
        g=gcd(l,A[i+1])
        l*=A[i+1]
        l//=g
    ans=n*l
    for i in range(n):
        ans//=A[i]
    print(ans%mod)
# Judge status: Accepted
s = input()

t = ""
for i in s:
    if i == "B":
        if t:
            t = t[:-1]
    else:
        t += i

print(t)
# Judge status: Accepted
## coding: UTF-8
s = input().split()
t = [int(p) for p in s]
#print(t)

#print(max(t))
count = 0
for i in range(1, max(t)+1):
    if(t[0] < i and i <= t[1] and t[2] < i and i <= t[3]):
        count += 1
print(count)
# Judge status: Accepted
import collections

TEISUU = 1000000007

S = input()
N = input()
c = collections.Counter(N)
lis = list(c.values())
ans = 1
for count in lis:
    ans *= int(count + 1)
    
ans -= 1
print(ans % TEISUU)
# Judge status: Accepted
# input
A, B = map(int, input().split())

# check
if abs(A - B) % 2 == 1:
    print("IMPOSSIBLE")
else:
    K = (A + B) // 2
    print(K)
# Judge status: Accepted
a, b, t = map(int, raw_input().split())

print t/a*b
# Judge status: Accepted
n = int(input())
card_list = list(map(int,input().split()))
alice_score = 0
bob_score = 0
card_list.sort(reverse = True)
for i in range(0,n):
    if i % 2 == 0:
        alice_score += card_list[i]
    else:
        bob_score += card_list[i]
        
print(alice_score - bob_score)
# Judge status: Accepted
S = list(input())

import numpy as np

S = np.array(S)

zeroichi = ["0","1"]*(len(S)//2)+["0"]*(len(S)%2)
ichizero = ["1","0"]*(len(S)//2)+["1"]*(len(S)%2)

zeroichi = np.array(zeroichi)
ichizero = np.array(ichizero)

print(min(list(S == ichizero).count(False),list(S == zeroichi).count(False)))
# Judge status: Accepted
x=int(input())
a=x%11
if a==0:
    res=0
elif a<7:
    res=1
else:
    res=2
print((x//11)*2 + res)
# Judge status: Wrong Answer
n,k,s = list(map(int, input().split()))

ret = [s for i in range(k)] + [s+1 for i in range(n-k)]
print(*ret)
# Judge status: Wrong Answer
N =int(input())
A =[int(_) for _ in input().split()]
a =0
for i in range(N):
  a += abs(A[i] - (i+1))
print(a)
# Judge status: Wrong Answer
import math #階乗を計算するために必要
def combinations_count(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r) #intを返すように//で演算

n, a, b=map(int, input().split())
com_sum=0
for i in range(1, n+1): #range(start, stop)で start ≦ i < stopの連番が生成
    com_sum+=combinations_count(n, i) 
com_sum-=combinations_count(n, a)+combinations_count(n, b)
print(com_sum%((10**9)+7))
# Judge status: Accepted
n=int(input())
ans=1
for i in range(1,n+1):
  ans *= i
  ans %= (10**9+7)
print(ans)
# Judge status: Accepted
W, a, b = map(int, input().split())

A = a + W
if b > a:
    if b - A <= 0:
        print(0)
    else:
        print(b - A)
else:
    B = b + W
    if a - B <= 0:
        print(0)
    else:
        print(a-B)
# Judge status: Accepted
s = input()
t = input()

start = [-1 for _ in range(26)]
goal  = [-1 for _ in range(26)]

for i in range(len(s)):
	a = ord(s[i]) -  ord('a')
	b = ord(t[i]) -  ord('a')

	if start[a] != -1 or goal[b] != -1:
		if start[a] != b or goal[b] != a:
			print('No')
			exit()

	else:
		start[a] = b
		goal[b]  = a

print('Yes')
# Judge status: Accepted
n,d = map(int,input().split())
range = 2*d+1
if n%range == 0:
    print(n//range)
else:
    print(n//range+1)
# Judge status: Accepted
import sys
#DEBUG=True
DEBUG=False
if DEBUG:
    f=open("202007_2nd/A_input.txt")
else:
    f=sys.stdin
l,h,d=map(int,f.readline().split())
ans=0
for _ in range(l,h+1):
    ans=ans+1 if _%d==0 else ans
print(ans)
# Judge status: Accepted
x,y = map(int,input().split())
if x==0 and y>0:
  print(y)
elif x==0 and y<0:
  print(abs(y)+1)
elif y==0 and x>0:
  print(abs(x)+1)
elif y==0 and x<0:
  print(abs(x))
elif x>0 and y>0:
  if x>y:
    print(2+(x-y))
  else:
    print(y-x)
elif x>=0 and y<0:
  a = abs(x+y)
  print(1+a)
elif x<=0 and y>0:
  a = abs(y+x)
  print(a+1)
else:
  if x>y:
    print(2+(x-y))
  else:
    print(y-x)
# Judge status: Accepted
import collections

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = collections.Counter(A)
    for i in range(1,N+1):
        print(A[i] if A[i] is not None else 0)

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
def resolve():
    N,M = map(int,input().split())
    for i in range(M):
        print(str(N//2 - i) + " " + str(N//2+1 + i))
resolve()
# Judge status: Accepted
s=input()
count=0

for i in range(len(s)):
  if i%2==0:
    if s[i]=="R" or s[i]=="U" or s[i]=="D":
      count+=1
  else:
    if s[i]=="L" or s[i]=="U" or s[i]=="D":
      count+=1

if count==len(s):
  print("Yes")
else:
  print("No")
# Judge status: Accepted
def main():
	n,k=map(int,input().split())
	a=list(map(int,input().split()))
	for i in range(k):
		b=[0]*(n+1)
		for j in range(n):
			b[max(j-a[j],0)]+=1
			b[min(j+a[j]+1,n)]-=1
		for j in range(n):
			b[j+1]+=b[j]
		a=b[:n]
		if min(a)==n:
			break
	print(*a)
if __name__ == '__main__':
	main()
# Judge status: Accepted
s = input()
  
if "7" in s:
	print("Yes")
else:
  	print("No")
# Judge status: Accepted
A,B,K =map(int,input().split())
cnt = 0
for i in range(101,0,-1):
    if A % i == 0 and B % i == 0:
        cnt += 1
        if cnt == K:
            print(i)
# Judge status: Wrong Answer
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.pop(0)
for _ in range(N-1):
    B=list(map(int,input().split()))
    for num in A:
        if num not in B[1:]:
            A.remove(num)

print(len(A))
# Judge status: Accepted
import sys
#input=sys.stdin.readline
from collections import deque

r=False
d=deque(list(input()))
for i in range(int(input())):
  Q=input().split()
  if Q[0]=='1':
    r=not r
  else:
    if (Q[1]=='1' and not r) or (Q[1]=='2' and r):
      d.appendleft(Q[2])
    else:
      d.append(Q[2])

if r:
  d.reverse()

print("".join(list(d)))
# Judge status: Wrong Answer
X = int(input())

if X <= 400 and X <= 599:
    print('8')
elif 600 <= X and X <= 799:
    print('7')
elif 800 <= X and X <= 999:
    print('6')
elif 1000 <= X and X <= 1199:
    print('5')
elif 1200 <= X and X <= 1399:
    print('4')
elif 1400 <= X and X <= 1599:
    print('3')
elif 1600 <= X and X <= 1799:
    print('2')
elif 1800 <= X and X <= 1999:
    print('1')
# Judge status: Accepted
import math
import itertools
n = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

cnt_p, cnt_q = 1, 1
p = tuple(P)
q = tuple(Q)
for a in sorted(itertools.permutations(P)):
  if a != p:
    cnt_p += 1
  else:
    break
for b in sorted(itertools.permutations(Q)):
  if b != q:
    cnt_q += 1
  else:
    break
print(abs(cnt_p-cnt_q))
# Judge status: Wrong Answer
h, n = map(int, input().split())
l = []
for i in range(n):
  a, b = map(int, input().split())
  l.append([a, b])

dp = [10 ** 8 + 1 for i in range(h + 10**4 + 1)]
dp[0] = 0

for i in range(h+1):
  for j in range(n):
    if dp[i] == 10 ** 8 + 1:
      continue

    x = dp[i] + l[j][1]
    if dp[i + l[j][0]] > x:
      dp[i + l[j][0]] = x

print(dp[h])
# Judge status: Accepted
W,H,x,y = map(int,input().split())
print(W*H/2)
if(x == W/2 and y == H/2):
    print("1")
else:
    print("0")
# Judge status: Accepted
import math
A,B,H,M=map(int,input().split())

kaku=abs(30*H-5.5*M)
rad=math.radians(kaku)
#print(rad)

sq=A**2+B**2-2*A*B*math.cos(rad)
print(math.sqrt(sq))
# Judge status: Accepted
from  functools import reduce
def gcd(v1,v2):
  v=v1%v2
  if v==0:
    return v2
  else :
    return gcd(v2,v)
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=[i//2 for i in a]
#print(a)
lc=reduce(lambda x,y: (x*y)//gcd(x,y) , a)
#print(lc)
flag=True
for i in a:
  if (lc//i)%2==0:
    flag=False
    break
if flag==False:
  print(0)
else:
  x=m//lc
  print(x//2) if (x%2)==0 else print((x//2)+1)
# Judge status: Accepted
a=int(input())
b=int(a/500)
c=int((a%500)/5)
print(b*1000+c*5)
# Judge status: Accepted
N = int(input())
A = int(input())
if N%500 > A:
    print("No")
else:
    print("Yes")
# Judge status: Wrong Answer
n, m = map(int, input().split())

if abs(n-m)>1:
    ans = 0
else:
    if m > n:
        n, m = m, n
        print(n, m)

    total_n = 1
    for i in range(1,n+1):
        total_n *= i
        if total_n >= 1000000007:
            total_n = total_n % 1000000007

    if n != m:
        ans = (total_n * total_n / n) % 1000000007
    else:
        ans = (total_n * total_n * 2) % 1000000007

print(int(ans))
# Judge status: Wrong Answer
ans = 0
n = int(input())+1
for i in range(1,n):
    for j in range(1,n,i):
        ans += j
print(ans)
# Judge status: Accepted
N = int(input())

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


ALL = 0
for a in A:
    ALL ^= a

ans = []
for a in A:
    ans.append(ALL ^ a)

print(*ans)
# Judge status: Wrong Answer
N, X = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]

x.append(X)
num_list = sorted(x)

D = min(map(lambda x: abs(x[0] - x[1]), zip(num_list[:-1],num_list[1:])))
print(D)
# Judge status: Accepted
A = []
B = []
for i in range(5):
    n = int(input())
    B.append(n)
    tmp = -(-n//10)*10
    A.append(tmp)

C = []
for j in range(5):
    tmp = A[j] - B[j]
    C.append(tmp)
L = max(C)

print(sum(A)-L)
# Judge status: Accepted
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    h = [0] * (max(a) + 2)
    minus = 0
    for i in a:
        h[i] += 1
        h[i + 1] += 1
        if i == 0:
            minus += 1
        else:
            h[i - 1] += 1

    print(max(minus, max(h)))
# Judge status: Accepted
input()
paper_values = list(map(int, input().split()))
is_approved = True

for val in paper_values:
    if val % 2 != 0:
        continue

    if val % 3 == 0:
        continue

    if val % 5 == 0:
        continue

    is_approved = False

print("APPROVED" if is_approved else "DENIED")
# Judge status: Wrong Answer
list = list(input())
print(list.count(1))
# Judge status: Wrong Answer
n,m=map(int,input().split())
ans=n*(n-1)/2+m*(m-1)/2
print(ans)
# Judge status: Wrong Answer
List = input().split()
HP_T = int(List[0])
AT_T = int(List[1])
HP_A = int(List[2])
AT_A = int(List[3])
result = 0

Turn_T = HP_A/AT_T 
Turn_A = HP_T/AT_A 
print(Turn_T, Turn_A)
if Turn_T - Turn_A >= 0:
  result = "No"
else:
  result = "Yes"

print(result)
# Judge status: Wrong Answer
n, m = map(int, input().split())
H = list(map(int, input().split()))
ans = [1] * n
for i in range(m):
    a, b = map(int, input().split())
    if H[a-1]<H[b-1]:
        ans[a-1] = 0
    elif H[b-1]>H[a-1]:
        ans[b-1] = 0
    else:
        ans[a-1], ans[b-1] = 0, 0
print(sum(ans))
# Judge status: Accepted
s=input()
if s[0]==">":a=[0,1]
if s[0]=="<":a=[1]
for i in range(1,len(s)):
  if s[i-1]!=s[i]:a.append(1)
  else:a[-1]+=1
if len(a)%2:a.append(0)
ans=0
for i in range(len(a)//2):
  m=max(a[i*2],a[i*2+1])
  ans+=m*(m+1)//2
  m=min(a[i*2],a[i*2+1])
  ans+=m*(m-1)//2
print(ans)
# Judge status: Wrong Answer
s = list(map(int, input().split()))
if(max(s) == (sum(s)//2)):
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
N = int(input())
M = 0
for K in range(1, N+1):
    A = [d for d in range(1,K+1) if K % d ==0]
    print(len(A))
    M += K * len(A)
print(M)
# Judge status: Accepted
p=list(input())
ans=''
for i in p:
    if i=='P':
        ans+='P'
    else:
        ans+='D'
print(ans)
# Judge status: Accepted
N,A,B = map(int,input().split())

if N < 1 or B - A < 0:
  print(0)
  exit(0)
  
if N == 1 and A < B:
  print(0)
  exit(0)
  
  
if A == B or N <= 2:
  print(1)
  exit(0)
  
c = N-2
r = B-A+1

ans = c*(r-1) + 1
print(ans)
# Judge status: Accepted
N = int(input())

ans = 1000-(N%1000)

if ans != 1000:
    print(ans)
else:
    print(0)
# Judge status: Accepted
from collections import Counter
n,k,q = map(int,input().split())
a = [int(input()) for _ in range(q)]
a = Counter(a)
for i in range(1,n+1):
    if a[i] > q-k:
        print('Yes')
    else:
        print('No')
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))
bottom = sum(A)

if A[0] >= 1:
  print(-1)
  exit()

ret = 1
children = 1

for i in range(N):
    children = children * 2 - A[i+1]
    if children <= -1:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
    print(children)
    print(bottom)
print(ret)
# Judge status: Accepted
n = int(input())
s = input()
lst_search = [chr(i) for i in range(65, 65+26)]
lst = [chr(i) for i in range(65, 65+26)] *2


ans = ''
for i in s:
    idx = lst_search.index(i)
    ans += lst[idx+n]

print(ans)
# Judge status: Accepted
a, b =map(int, input().split())
c = a*b
print(c)
# Judge status: Accepted
n = int(input())
if n % 2 == 1:
    print('No')
    exit()
s = input()
if s[:n//2] == s[n//2:]:
    print('Yes')

else:
    print('No')
# Judge status: Wrong Answer
n, m = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(m)]

ans = [1] * (n)
ans[0] = 1
ball = {0}
for i in range(m):
    x, y = xy[i]
    if (x - 1) in ball:
        ans[y-1] += 1
        ans[x-1] -= 1
        ball.add(y - 1)
    if ans[x-1] == 0:
      ball -= set([x-1])

cnt = 0
for i in list(ball):
  if ans[i] > 0:
    cnt += 1

print(cnt)
# Judge status: Wrong Answer

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

x = 0
for a in range(n-1):
    if l[a]>l[a+1] :
        x=l[a] - l[a+1] + x
        l[a+1]=l[a]
    print("l[a],x,l[a+1]=", l[a], x, l[a+1])
print(x)
# Judge status: Wrong Answer
n = int(input())
s = list(input())
ans = 0
for i in range(1,n-1):
    sa = set(s[:i])
    sb = set(s[i+1:])
    ans = max(ans,len(sa&sb))

print(ans)
# Judge status: Accepted
from math import ceil
n,k = map(int,input().split())
a=list(map(int,input().split()))
#index = a.index(1)
#left, right = index, n-index-1
#if n!=k: print(ceil(left/(k-1))+ceil(right/(k-1)))
if n!=k: print(1+ceil((n-k)/(k-1)))
else: print(1)
# Judge status: Accepted
A,B=map(int , input().split())
a,b=str(A),str(B)
if len(a)>1 or len(b)>1:
    print("-1")
else:
    print(A*B)
# Judge status: Accepted
i = [p+2 for p in range(12)]
i.append(1)
x, y = map(int, input().split())
if i.index(x) == i.index(y):
    print("Draw")
if i.index(x) > i.index(y):
    print("Alice")
if i.index(x) < i.index(y):
    print("Bob")
# Judge status: Wrong Answer
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    S = int(input())
    M = 10**9
    X = (S+M-1) // M
    print(0,0,M,1,M-S%M,X)

if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
a=int(input())
s=input()
print(s if a<3200 else 'red')
# Judge status: Wrong Answer
# https://atcoder.jp/contests/arc099/tasks/arc099_a
n, k = map(int, input().split())
nums = [int(i) for i in input().split()]

MIN = min(nums)
index = nums.index(MIN)
ans = index // (k - 1) + (len(nums) - index) // (k - 1)
print(ans)
# Judge status: Accepted
import sys
input = sys.stdin.readline
x=int(input())
print(x//11*2-(-(x%11))//6)
# Judge status: Accepted
n=int(input())

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

r=1000
k=0
for ii in range(n-1):
	if a[ii+1]<a[ii]:
		r+=k*a[ii]
		k=0
	else:
		dk=r//a[ii]
		r-=dk*a[ii]
		k+=dk
	#print(ii,r,k)
print(r+k*a[n-1])
# Judge status: Wrong Answer
s=input()
frag=False
count=0
ans=0
for i in range(len(s)):
    if frag:
        count+=1
    if s[i]=="A":
        frag=True
        count+=1
    elif s[i]=="Z":
        frag=False
        ans=max(ans,count)

print(ans)
# Judge status: Accepted
from collections import deque

o = deque(input())
e = deque(input())

if len(o) > len(e):
    e.append('')
ans = ''

while len(o):
    ans += o.popleft()
    ans += e.popleft()
print(ans)
# Judge status: Accepted
n = int(input())
for i in range(int(n**0.5)+1):
    if i*i <= n:
        ans = i*i
print(ans)
# Judge status: Wrong Answer
import collections

n, m = map(int, input().split())
a = []

for _ in range(m):
    tmp1,tmp2 = map(int, input().split())
    a.append(tmp1)
    a.append(tmp2)

ans = collections.Counter(a)
ans_sorted = sorted(ans.items(), key=lambda x:x[0])
#print(ans_sorted)

for i in ans_sorted:
    print(i[1])
# Judge status: Wrong Answer
k,x=map(int,input().split())
s=list(range(x-k+1,x+k))

print(s)
# Judge status: Accepted
l = [int(input()) for i in range(5)]
a = min(l, key=lambda x: (x-1)%10)
ret = 0
flag = 0
for i in l:
    if i != a or flag == 1:
        ret += i
    else:
        flag = 1
        
    if ret%10 != 0:
        ret += 10-(ret%10)
ret += a
print(ret)
# Judge status: Accepted
N = int(input())
a = []
for i in range(5):
    a.append(int(input()))
if N % min(a) == 0:
    ans = N//min(a)+4
else:
    ans = N//min(a)+5
print(ans)
# Judge status: Wrong Answer
n = int(input())
s = input()
t = input()

cnt = 0
for i in range(n):
  for j in range(n-i):
    if not s[i+j] == t[j]:
      break
    else:
      print(i+n)
      exit()

print(2*n)
# Judge status: Accepted
import math
n = int(input())
for i in range(n, 0, -1):
    if math.log2(i).is_integer():
        print(i)
        exit()
# Judge status: Wrong Answer
S = input()

ans = 0
cnt = 0
for i in range(len(S)):
    if S[i] in "ACGT":
        cnt += 1
    else:
        ans = max(ans, cnt)
        cnt = 0

print(ans)
# Judge status: Accepted
x = int(input())
n = 1
while n*(n+1)//2 < x: n += 1
print(n)
# Judge status: Accepted
from sys import stdin
input = stdin.readline

a = int(input())

print(a ** 3 + a ** 2 + a)
# Judge status: Accepted
p, q, r = map(int, input().split())
a = max(p, q, r)
print(p+q+r-a)
# Judge status: Wrong Answer
N = int(input())

mylist = []
for i in range(5):
    mylist.append(N//int(input()))
print(5+max(mylist))
# Judge status: Accepted
import sys

input = sys.stdin.readline


def main():
    _, s, _ = input().split()
    ans = "A" + s[0].upper() + "C"
    print(ans)


if __name__ == "__main__":
    main()
# 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):
    if B[i] - A[i] >= 0:
        ans += A[i]
        B[i] = B[i] - A[i]
        if B[i] - A[i+1] >= 0:
            ans += A[i+1]
            A[i+1] = 0
        else:
            ans += B[i]
            A[i+1] = A[i+1] - B[i]
    else:
        ans += B[i]

print(ans)
# Judge status: Accepted
import re

s = input()

c0, c1 = 0, 0
for i in s:
    if i=='0':
        c0 += 1
    else:
        c1 += 1

print(min(c0, c1)*2)

"""TLE
def trans_word(text):
    replacements = {'01': '', '10': ''}
    return re.sub('({})'.format('|'.join(map(re.escape, replacements.keys()))), lambda m: replacements[m.group()], text)

ans = 0
flag = True

while flag:
    s_tmp = s
    s = trans_word(s)
    ans += (len(s_tmp) - len(s))
    flag = len(s_tmp) - len(s)

print(ans)
"""
# Judge status: Wrong Answer
S = input()

# Pythonでは S[3]='8' のような操作は許されないので間接的な方法を用いる
print('2018/01' + S[-2])
# Judge status: Accepted





def main():
    n = int(input())
    al = list(map(int, input().split()))

    #print(n)
    #print(al)

    #print(len(al))

    cnt = 1
    bl = []
    for ai in al:
        if ai == cnt:
            bl.append(ai)
            cnt += 1
    b_cnt = len(al) - len(bl)
    if(cnt == 1):
        print(-1)
    else:
        print(b_cnt)

if __name__ == "__main__":
    main()
# Judge status: Accepted
n = int(input())
s = input()

to_int = {"R":0, "G":1, "B":2}
cnt = [0] * 3
for char in s:
    cnt[to_int[char]] += 1

ans = 1
for num in cnt:
    ans *= num

for i in range(n):
    for length in range(1, n):
        if i - length < 0 or i + length >= n:
            break
        if len(set([to_int[s[i - j * length]] for j in (-1, 0, 1)])) == 3:
            ans -= 1

print(ans)
# Judge status: Accepted
import sys

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

while flg == 0:
  for i in range(N):
    if A[i]%2 == 0:
      A[i] = int(A[i]/2)
    elif A[i]%2 ==1 or A[i] == 1:
      print(cnt)
      sys.exit()
  cnt += 1
print(max(0,cnt-1))
# Judge status: Wrong Answer
def solve():
    N = int(input())
    t_i, x_i, y_i = map(int, input().split())
    for i in range(N-1):
        t_j, x_j, y_j = map(int, input().split())
        dt = t_j - t_i
        dxy = x_i + x_j - y_i - y_j
        if (dt > (t_j - t_i)) | (dt < (t_i - t_j)):
            return "No"
        if ((t_i - t_j) % 2) != (dxy % 2):
            return "No"
    return "Yes"


if __name__ == "__main__":
    print(solve())
# Judge status: Accepted
Weather=["Sunny", "Cloudy", "Rainy"]
Today=input()
for i in range(3):
  if Today== Weather[i]:
     if i==0 or i==1:
       print(Weather[i+1])
     else:
       print(Weather[0])
# Judge status: Wrong Answer
# A - Weather Prediction

S = input()

if S == 'Sunny':
    print('Cloudy')
elif S == 'Rainy':
    print('Sunny')
elif S == 'Cloudy':
    print('Sunny')
# Judge status: Wrong Answer
a,b=map(int,input().split())
if a==b==1:
  print(1)
elif a%2==1 and b%2==1:
  print((a*b)//2+1)
else:
  print(a*b//2)
# Judge status: Wrong Answer
X, Y = map(int, input().split())

if X % Y == 0:
    print(-1)
else:
    for i in range(10**18):
        X1 = int(X*i)
        if X1 % Y != 0:
            print(str(X1))
        break
# Judge status: Wrong Answer
N = int(input())
A = sorted(list(map(int, input().split())))
print(sum(A[0::2])-sum(A[1::2]))
# Judge status: Accepted
N,A,B = map(int, input().split())
if A > B or (A != B and N == 1):
    print(0)
else:
    N -= 2
    print(N*(B-A)+1)
# Judge status: Wrong Answer
import collections

N = int(input())

a = [int(i) for i in input().split()]
c = collections.Counter(a)


s = 0
for k,v in c.items():
    s += abs(v - k)
    
print(s)
# Judge status: Accepted
n=int(input())
count=0
a = input().split(" ")
lista = [int(n) for n in a]
for i in range(0,n,2):
  if lista[i]%2==1:
    count+=1
print(count)
# Judge status: Wrong Answer
import math
x = int(input())

print(math.ceil(x/11 * 2))
# Judge status: Accepted
import math
a,b,n = map(int,input().split())

if (b-1) <= n:
    ans = math.floor(a*(b-1)/b) - (a * math.floor((b-1)/b))
else:
    ans = math.floor(a*n/b) - (a * math.floor(n/b))

print(ans)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
maxim = max(A)
counter = [0]*(maxim+1)
dif = [-1, 0, 1]
for a in A:
    for d in dif:
        i = a + d
        if i < 0 or maxim < i:
            continue
        else:
            counter[i] += 1
print(max(counter))
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))
l = []
for i in range(n):
  if a.count(a[i]) >= 2 and a[i] not in l:
    l.append(a[i])
l.sort()
print(a[-1]*a[-2])
# Judge status: Wrong Answer
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

points = [K - Q] * N

for i in A:
    points[i - 1] += 1
for p in points:
    if p > 0:
        print("yes")
    else:
        print("No")
# Judge status: Accepted
n,m,k = map(int,input().split())
nya = False
for i in range(n+1):
    for j in range(m+1):
        if i*m + j*n - 2*i*j == k:
            nya = True
            break
if nya:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
"""
Nは10**5以下。O(N)なら通る
"""

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

count = 0
for i in reversed(range(N)):
    if A[i] % B[i] == 0:
        continue
    else:
        s = B[i] - (count + A[i]) % B[i]
        count += s

print(count)
# Judge status: Accepted
N, M = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

if N >= M:
    print(0)
    exit()
Xs = sorted(X)
dst = []
for i in range(M-1):
    dst.append(Xs[i+1] - Xs[i])
#print(Xs)
#print(dst)
dsts = sorted(dst)
#print(dsts[:len(dsts)-N+1])
print(sum(dsts[:len(dsts)-N+1]))