peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N= int(input())
li = [list(map(int,input().split())) for _ in range(N-1)]

for i in range(N-1):
    ci,si,fi = li[i]
    time = si+ci
    for j in range(i+1,N-1):
        cj,sj,fj = li[j]
        if time%fj != 0:
            time = ((time//fj)+1)*fj
        #print(i,time)
        if time < sj:
            time = sj
        time += cj
    print(time)
print(0)
# Judge status: Accepted
N = int(input())
B = list(map(int, input().split())) 

ans = B[0] + B[N-2]

for i in range(1, N-1):
    ans += min(B[i-1], B[i])

print(ans)
# Judge status: Wrong Answer
import sys
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
plus, minus = 0, 0

if n == 1:
    if a[0] < b[0]:
        print('Yes')
    else:
        print('No')
    sys.exit()

for i, j in zip(a, b):
    num = j-i
    if num >= 0:
        plus += num
    else:
        minus -= num
        
if plus >= minus*2:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
leaf = sum(a) - 1
now = 1
ans = 0
for i, num in enumerate(a):
    ans += now
    now -= num
    if leaf >= now:
        leaf -= now
        now *= 2
    elif leaf > 0:
        now += leaf
        leaf = 0
    if now < 0:
        print(-1)
        exit()
print(ans)
# Judge status: Accepted
N = int(input())

result = []

for c in input():
    r = ord(c) + N

    # Zを超えている
    if r > 90:
        r = 65 + r % 90 - 1

    result.append(chr(r))

print(''.join(result))
# Judge status: Wrong Answer
ans = 0
for i in range(3):
  k = list(map(int,input().split()))
  ans += sum(k)
if ans >= 6 and ans%3 == 0:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
a  = int(input())
b = a // 500 *1000
c = (a - a // 500 * 500) // 5 * 5
print(b+c)
# Judge status: Accepted
N=int(input())
A=list(map(int,input().split()))
b=sum(A)//N
a=b+1
c=b+1

x=0
y=0
z=0
for i in A:
  x+=(a-i)**2
  y+=(b-i)**2
  z+=(c-i)**2
print(min(x,y,z))
# Judge status: Wrong Answer
l,r=map(int,input().split())
x=[]
if r-l>=2018:
    print(0)
else:
    for i in range(l,r+1):
        x.append(i%2019)
    x.sort()
    print((x[0]*x[1])%2019)
# Judge status: Wrong Answer
N, A, B = map(int, input().split())

if ((B-A)+1)%2==0:
    print(min(B-1,(A-1)+((B-A)//2)+1))
else:
    print(int((B-A)/2))
# Judge status: Accepted
x = int(input())

s = set([1])
for i in range(2,501):
    for j in range(2,10):
        if (i**j) <= x:
            s.add(i**j)

print(max(list(s)))
# Judge status: Accepted
K,A,B=map(int,input().split(' '))
if K<A+1:
    print(K+1)
else:
    print(max(K+1,B+(B-A)*max(0,(K-(A+1))//2)+max(0,(K-(A+1)))%2))
# Judge status: Wrong Answer
c,a,b=map(int,input().split())
s=(a+b+c)/3
print(int(s*(s-a)*(s-b)*(s-c)))
# Judge status: Accepted
n, k = map(int, input().split())
s = input()

pre=s[0]
tmp=0
ans=0
check=0
for i in range(1, n):
    if s[i] != pre:
        check+=1
        pre=s[i]
        if check%2==1 and tmp < k:
            tmp+=1
            ans+=1
        if check%2==0 and tmp < k+1:
            ans+=1
            if tmp == k:
                tmp+=1
    else:
        ans+=1

print(ans)
# Judge status: Wrong Answer
n = int(input())
s = list(input())
num = 0
k = -1
for i in range(1,n):
  if i + k >= n-1:
    break
  if s[-i] == 'R':
    j = k+1
    while True:
      if j +i == n-1:
        k = j
        break
      if s[j] == 'W':
        s[j] = 'R'
        s[-i] = 'W'
        k = j
        num += 1
        break
      j += 1
      

print(num)
# Judge status: Wrong Answer
n,m=map(int,input().split())

print((n+m)*(n+m-1)/2-n*m)
# Judge status: Wrong Answer
a=int(input())
b=list(map(int,input().split()))
c=0
if a==0:
  print(0)
else:
  for i in range(a-1):
    if b[i]>b[i+1]:
      b[i+1]=b[i+1]+1
      c=c+1
  print(c)
# Judge status: Wrong Answer
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
ans = 0
for i in a:
  if i > sum(a)/(4*m):
    ans += 1
    if ans == m:
      print("Yes")
      exit()
  else:
    print("No")
    exit()
# Judge status: Accepted


N = int(input())
S = str(input())
sum = 0
L = []
for i in range(N):
    if S[i] == "I":
        sum += 1
        L.append(sum)
    elif S[i] == "D":
        sum -= 1
        L.append(sum)

if max(L) > 0:
    print(max(L))

else:
    print(0)
# Judge status: Accepted
mod=2019
L,R = map(int,input().split())

ls =[]

if R-L>=mod-1:
    print(0)
    exit()
else:
    for i in range(R-L+1):
        ls.append((L+i)%mod)

ans=10000
for i in range(len(ls)-1):
    for j in range(i+1,len(ls)):
        ans = min(ans,(ls[i]*ls[j])%mod)

print(ans)
# Judge status: Accepted
def main():
    n,m = map(int,input().split())
    sa = set()
    sb = set()
    for i in range(m):
        a,b = map(int,input().split())
        if a == 1:
            sb.add(b)
        if b == n:
            sa.add(a)
    if len(sa&sb) > 0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

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

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

CNT = [0] * (10 ** 7)

ans = 0
for i in range(N):
    a = A[i]
    p = i - a

    if 0 <= p <= (10 ** 7):
        ans += CNT[p]

    if 0 <= i + a <= (10 ** 7):
        CNT[i + a] += 1

print(ans)
# Judge status: Accepted
K, A, B = map(int, input().split())
CNT = K - A + 1     # 最初、A枚になるまでビスケットを増やす
# 残り回数でできるだけAとBを行う
# 残り回数が1余ったならビスケットを増やす
print(max(A + CNT // 2 * (B - A) + CNT % 2, K + 1))
# Judge status: Accepted
x, y, z = map(int, input().split())
i = x + y + z
print(max(x, y, z)* 10 + i - max(x, y, z))
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))
ans_1 = max(A)
ans_2 = 0
d = 1000000
for e in A:
    if d > abs(ans_1/2-e):
        d = abs(ans_1/2-e)
        ans_2 = e
print(ans_1,ans_2)
# Judge status: Wrong Answer
s = str(input())
start = 0
end = 0
for i in range(len(s)):
    if s[i]=='A' and start==0:
        start = i
    if s[-(i+1)]=='Z' and end==0:
        end = len(s)-i
    if start != 0 and end != 0:
        break
print(end-start)
# Judge status: Accepted
# C
N = int(input())

X_list = list(map(int, input().split()))
mean_X = round(sum(X_list)/N)

res = 0
for x in X_list:
    res += (x - mean_X)**2

print(res)
# Judge status: Wrong Answer
a,b,x=map(int,input().split())
if a+b>x:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
n=int(input())
c=0
for i in range(1,n+1):
  if i*(i+1)//2>=n:
    c=i
    break
for i in range(c,0,-1):
  if i<=n:
    print(i)
    n-=i
# Judge status: Wrong Answer
from math import floor


def main():
    a, b = map(float, input().split())
    print(floor(a * b))


if __name__ == '__main__':
    main()
# Judge status: Accepted
D = int(input())
c = list(map(int, input().split()))
s = []
for k in range(D):
    s.append(list(map(int, input().split())))

#print(s)
ans = [s[k].index(max(s[k]))+1 for k in range(D)]

for k in range(D):
    print(ans[k])
# Judge status: Wrong Answer
n, x, t = map(int, input().split())

print(((n // x) + 1)*t)
# Judge status: Accepted
from itertools import product

X = int(input())
for a, b in product(range(-200, 201), repeat=2):
    if a**5 - b**5 == X: print(a, b); break
# Judge status: Accepted
n=int(input())
x=(10**n)%(10**9+7)
y=(9**n)%(10**9+7)
z=(8**n)%(10**9+7)
print((x-2*y+z)%(10**9+7))
# Judge status: Accepted
A,B,K=map(int,input().split())
while A%B!=0:
  C=A%B
  A=B
  B=C
cnt=0
for i in range(B+1,0,-1):
  if B%i==0:
    cnt+=1
    if cnt==K:
      print(i)
      exit()
# Judge status: Accepted
n, a, b = map(int, input().split())
mod = 10**9+7
sum = pow(2, n, mod) - 1 #(2**n-1)%modと同じ

def comb(m):
    x = 1
    y = 1
    for i in range(m):
        x = x*(n-i)%mod #コンビネーションの分子
        y = y*(i+1)%mod #コンビネーションの分母
    return (x * pow(y, mod-2, mod) % mod)

print((sum-comb(a)-comb(b))%mod)
# Judge status: Wrong Answer
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re


def main_chk():
    N = int(input())

    ans = 0
    for i in range(1,N+1):
        m = N // i
        ans += ( m + 1 ) * m * i / 2

    print(ans)
main_chk()
# Judge status: Accepted
n = int(input())
tot = n//11
rem = n%11
tot = tot*2
if rem==0:
	print(tot)
elif rem<=6:
	print(tot+1)
else:
	print(tot+2)
# Judge status: Accepted
o = list(input())
s = list(input()) + ['']
print(*[o + s for o, s in zip(o, s)], sep='')
# Judge status: Accepted
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]

for i in range(n-1):
  t=l[i][1]
  t+=l[i][0]
  for j in range(i+1,n-1):
    if t<l[j][1]:
      t=l[j][1]
    elif t%l[j][2]!=0:
      t+=l[j][2]-t%l[j][2]
    t+=l[j][0]

  print(t)
print(0)
# Judge status: Accepted
from functools import reduce

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

def div_ceil(x, y): return (x + y - 1) // y

N, M = map(int, input().split())
*A, = map(int, input().split())
A = list(set([a // 2 for a in A]))
L = reduce(lcm, A)
for a in A:
    if (L // a) % 2 == 0:
        ans = 0
        break
else:
    ans = div_ceil(M // L, 2)
print(ans)
# Judge status: Wrong Answer
S = input()

cnt = 1
for i in range(len(S)-1):
    if S[i] == S[i+1] and S[i] == "R":
        cnt += 2
    elif S[i] != S[i+1] and S[i+1] == "R":
        cnt += 1
    else:
        cnt = 0
print(cnt)
# Judge status: Wrong Answer
s = input()
t = input()

import fnmatch

if set(s) == {'?'} and set(t) =={'?'}:
    print('UNRESTORABLE')
else:
    for  i in range(len(s) - len(t)+1):
        if fnmatch.fnmatch(t, s[i:i+len(t)]):
            x = s[0:i] + t + s[i+len(t):]
            print(x.replace('?', 'a'))
            break
    else:
        print('UNRESTORABLE')
# Judge status: Accepted
N, M = map(int, input().split())
ball_count = [1 for _ in range(N)]
if_red_exists = [1] + [0 for _ in range(N-1)]
count = 1
for _ in range(M):
    x, y = map(int, input().split())
    if if_red_exists[x-1]:
        # 赤が存在する場合
        if_red_exists[y-1] = 1
        if ball_count[x-1] <= 1:
            if_red_exists[x-1] = 0
    ball_count[x-1] -= 1
    ball_count[y-1] += 1

count = 0
for e in if_red_exists:
    if e == 1:
        count += 1
print(count)
# Judge status: Accepted
s=input()

for i in range(len(s)):
    for j in range(len(s)):
        if s[i]==s[j] and i!=j:
            print("no")
            exit()

print("yes")
# Judge status: Accepted
from collections import Counter

def main():
    N = int(input())
    A = list(map(int,input().split()))
    Q = int(input())

    Co = Counter(A)
    # print(Co)
    SUM = sum(A)
    for _ in range(Q):
        b,c = map(int,input().split())
        SUM += (c-b) * Co[b]
        Co[c] += Co[b]
        Co[b] = 0
        # print(Co)
        print(SUM)



main()
# 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):
    print(i)
    if A[i-1] == A[i]-1 and i != 0:
        print(B[A[i]-1])
        m += B[A[i]-1] + C[A[i-1]-1]
    else:
        m += B[A[i]-1]
    print(m)
print(m)
# Judge status: Accepted
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = []
for j in range(n-k+1):
    if x[j] > 0:
        ans.append(x[j+k-1])
    elif x[j] <= 0 <= x[j+k-1]:
        ans.append(min(2*abs(x[j])+x[j+k-1], abs(x[j])+2*x[j+k-1]))
    else:
        ans.append(-x[j])
print(min(ans))
# Judge status: Accepted
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
c = collections.OrderedDict(sorted(c.items(), key=lambda x:x[0],reverse=True))
high=0
low=0
for i,j in zip(c.keys(),c.values()):
    if(j>=4):
        if(high==0):
            high=i
        if(low==0):
            low =i
        break
    elif(j>=2):
        if(high==0):
            high=i
        else:
            low=i
            break
print(high*low)
# Judge status: Wrong Answer
from collections import deque

N=int(input())
S=input()
stack= deque([])
ans=""

for i in range(N):
  if S[i]=="(":
    stack.append(S[i])
  else:
    if len(stack)>0:
      ans += stack.pop()+")"
    else:
      ans = "(" + ans + ")"

nokori=len(stack)
ans += nokori * "(" + nokori * ")"

print(ans)
# Judge status: Wrong Answer
k = int(input())
s_num = input()
s = list(s_num)

if len(s) < k:
  ans = s_num
else:
  ans = s_num[0:k] + "..."
  
print(ans)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))
B = sum([a<0 for a in A])
C = sum([abs(a) for a in A])

if B%2==0:
  print(C)
else:
  print(C-2*min(A,key=abs))
# Judge status: Accepted
import math
n, l = map(int, input().split())
t = []
for i in range(1, n+1):
    t.append(l+i-1)
fab = []
sum_t = sum(t)
tmp = 0
if n+l > 0:
    for i in range(n):
        fab.append(sum_t-t[i])
    ans = []
    for i in range(n):
        ans.append(math.fabs(sum_t-fab[i]))
    print(int(sum_t-min(ans)))

else:
    for i in range(n-1):
        tmp += t[i]
    print(tmp)
# Judge status: Wrong Answer
n = int(input())
a = input()
a = a.split()
count = 0

boo = False

for i in a:
    if int(i) >= n:
        boo = True

if(boo):
    print(n - 1)
else:
    print(0)
# Judge status: Accepted
l = int(input())

r = l / 3
print(r**3)
# Judge status: Accepted
n , m = map(int,input().split())
mojiretsu =''
str_list = [input() for _ in range(n)]
str_listss = sorted(str_list) 
for i in str_listss:
  mojiretsu += i
print(mojiretsu)
# Judge status: Accepted
n=int(input())
s=input()

wcount=0
for i in range(n):
    if s[i]=="R" :
        wcount+=1

wwcount=0
for i in range(wcount):
    if s[i]=="R" :
        wwcount+=1

print(wcount-wwcount)
# Judge status: Accepted
s=input()
n=len(s)
a=str()
b=str()
k='keyence'
l='ecneyek'
j=0
for i in range(n):
  if a+s[i] in k:
    a+=s[i]
    j=i+1
  else:
    break
for i in range(7-j):
  if b+s[n-i-1] in l:
    b+=s[n-i-1]
  else:
    break
if a+b[::-1]==k:
  print('YES')
else:
  print('NO')
# Judge status: Wrong Answer
n = int(input())
a_input = input()
a = a_input.split(" ")
b_input = input()
b = b_input.split(" ")
c_input = input()
c = c_input.split(" ")

b_sum = 0
for i in range(n):
    b_sum += int(b[i])

c_sum = 0
for i in range(n-1):
    if int(a[i]) != n:
        c_sum += int(c[int(a[i])-1])
    else:
        continue

sum = b_sum + c_sum
print(sum)
# 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
# Judge status: Accepted
x,y=map(int,input().split())
x_=-x
y_=-y
ans=10**9+6
if x<=y:
  ans=min(ans,y-x)
if x_<=y:
  ans=min(ans,y-x_+1)
if x_<=y_:
  ans=min(ans,y_-x_+2)
if x<=y_:
  ans=min(ans,y_-x+1)
print(ans)
# Judge status: Accepted
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    N,K,S=map(int,input().split())
    if S<10**9:
        L=[S]*K+[S+1]*(N-K)
    else:
        L=[S]*K+[S-1]*(N-K)


    print(*L)

resolve()
# Judge status: Wrong Answer
from bisect import *
A = {1}
for p in range(2,11):
    for b in range(1,33):
        A.add(p**b)
A = list(A)
A.sort()
X = int(input())
print(A[bisect_right(A,X)-1])
# Judge status: Accepted
s = list(map(str, input().split()))
print("A",s[1][0],"C",sep="")
# Judge status: Wrong Answer
X = int(input())
u = 1000*(X//500) + 5*((X%1000)//5)
print(u)
# Judge status: Accepted
__DEUBG__ = 0


from collections import Counter

N, K = map(int, input().split())
balls = map(int, input().split())

balls = Counter(balls)
b2 = sorted(balls.items(), key=lambda item: item[1], reverse=True)

uniq_num = len(balls)

if __DEUBG__:
    print('\n'*2)
    print(len(balls))
    print(balls)
    print(b2)

if uniq_num <= K:
    print(0)
else:
    total = 0
    for i in range(uniq_num-K):
        tmp = b2.pop()
        if __DEUBG__:
            print(tmp)
        total += tmp[-1]
    print(total)
# Judge status: Wrong Answer
w,a,b = map(int,input().split())
#print(w,a,b)
if a+w == b:
  print(0)
elif a+w < b:
  print(b-(a+w))
elif a < b and b < a+w:
  print(0)
elif a == b:
  print(0)
# Judge status: Wrong Answer
a,b,c= map(int, input().split())
if a<c<b or b<c<b:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
N = int(input())
cmin = 10**5
for x in range(1,N-1):
    y = str(N-x)
    x = str(x)
    cnt = 0
    for i in range(len(x)):
        cnt += int(x[i])
    for j in range(len(y)):
        cnt += int(y[j])
    cmin = min(cmin,cnt)
print(cmin)
# Judge status: Wrong Answer
N = int(input())
L_0 = 2
L_1 = 1
cur = 0
for i in range(N):
    if i==0:
        cur = L_0
    elif i==1:
        prev = L_1
        cur += L_1 
    else:
        tmp = cur
        cur += prev
        prev = tmp
print(cur)
# Judge status: Wrong Answer
N,C,K = map(int,input().split())
T = []
for _ in range(N):
    t = int(input())
    T.append(t)
T.sort()
angry = 0
ans = 0
c = 0
for i in T:
    if angry == 0:
        angry = i + K
    c += 1
    if i >= angry :
        #print(i,angry)
        angry = i + K
        ans += 1
        c = 1
    if c == C:
        angry = 0
        ans += 1
        c = 0
    #print(ans,angry,c)
if c > 0:
    ans += 1
print(ans)
# Judge status: Wrong Answer
s = input()
k = int(input())

all1 = True
if len(s) > k:
    for i in range(k):
        if s[i] != '1':
            all1 = False
    if all1:
        print(s[k-1])
        exit()
if s[0] == '1':
    if len(s) == 1:
        print(s[0])
    else:
        print(s[1])
else:
    print(s[0])
# Judge status: Accepted
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=0,10**9
f=0
while r-l>1:
    m=(l+r)//2
    count=0
    for i in a:
        count+=math.ceil(i/m)-1
    if count<=k:
        r=m
    else:
        l=m
print(r)
# Judge status: Accepted
a, b = map(int, input().split())
answer = (a * b)
print(answer)
# Judge status: Wrong Answer
def soma(n):
    x = sum(int(digit) for digit in str(n))
    if x < 10:
        return x
    else:
        return soma(x)

def main():
    n = int(input())

    somad = soma(n) # soma(n)+soma(0)

    n-=n%10
    
    while(n>=1):
        somaf=soma(n-1)+1
        
        if(somaf>somad):
            somad=somaf
        
        n=n//10
    
    print(somad,"\n")
       
main()
# Judge status: Accepted
L,R=map(int,input().split())
left,right=L%2019,R%2019
print(0 if R-L>=2019 else min([i*j%2019 for i in range(left,right+1) for j in range(i+1,right+1)]))
# Judge status: Wrong Answer
# dijkstraで解く
# 格子上の最短経路，障害なし，なのでまっすぐ行って帰るを繰り返す

sx, sy, tx, ty = map(int, input().split())
dx = tx - sx
dy = ty - sy

ans = ""

# s -> t
ans += "U" * dy
ans += "R" * dx

# t -> s
ans += "D" * dy
ans += "L" * dx

# 1マス外側 s -> t
ans += "L"
ans += "U" * (dy + 1)
ans += "R" * (dx + 1)
ans += "D"


# 1マス外側 t -> s
ans += "R"
ans +=" D" * (dy + 1)
ans += "L" * (dx + 1)
ans += "U"

print(ans)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))

delete = 0

for i in range(n):
  if a.count(i) < i:
    delete += a.count(i)
  elif a.count(i) > i:
    delete += a.count(i) - i
    
print(delete)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
result = sum(map(int, input().split()))
c = list(map(int, input().split()))
for i in range(n-1):
    if a[i] == a[i+1]-1:
        result += c[a[i]-1]
print(result)
# Judge status: Accepted
from collections import deque
n,m=map(int,input().split())
maze=[[]for i in range(n)]
for i in range(m):
    r,l=map(int,input().split())
    maze[r-1].append(l-1)
    maze[l-1].append(r-1)

stamp=[-1]*n
queue=deque([0])
while queue:
    d=queue.popleft()
    for i in maze[d]:
        if stamp[i]==-1:
            stamp[i]=d
            queue.append(i)

print("Yes")
for i in range(1,n,1):
    print(stamp[i]+1)
# Judge status: Accepted
N=int(input())
c=input()
C=[]
for i in range(N):
    C.append(c[i])
num= C.count("W")
CC=C[(N-num):]
numnum=CC.count("W")
print(num-numnum)
# Judge status: Accepted
N = int(input())

print(N*800-N//15*200)
# Judge status: Wrong Answer
n=int(input())
x=list(map(int,input().split()))
X = sorted(x)

for i in range(n):
    if x[i] <= X[n//2-1]:
        print(X[n//2]) 
    elif x[i] >= x[n//2]:
        print(X[n//2-1])
# Judge status: Wrong Answer
K, S = map(int, input().split())
ans = 0

for X in range(K+1):
    for Y in range(K+1):
        Z = K -(X + Y)
        if 0 <= Z <= K:
            ans += 1
print(ans)
# Judge status: Wrong Answer
def fact(n,mod):
    ret=1
    for i in range(2,n+1):
        ret=(ret*i)%mod
    return ret

def pCq(p,q,mod):
  pCq=1
  for i in range(q):
    pCq*=p-i
    pCq=pCq%mod
  den=fact(q,mod)
  inv=pow(den,mod-2,mod)
  pCq=(pCq*inv)%mod
  return pCq

X,Y=map(int,input().split())
MOD=10**9+7
ans=0
n,m=2*X-Y,2*Y-X
if n%3==0 and m%3==0:
  n//=3
  m//=3
  ans=pCq(m+n,min(m,n),MOD)
print(ans)
# Judge status: Wrong Answer
n,k=map(int,input().split())
a=list(map(int,input().split()))
import numpy as np
a=np.array(a)
temp=np.argmin(a)
import math
ans=math.ceil(temp/(k-1))+math.ceil((n-temp)/(k-1))
print(ans)
# Judge status: Wrong Answer
a,b,c = map(int,input().split())
#print(a,b,c)

if a+b == c or b+c == a or c+a == b:
  print("YES")
else:
  print("NO")
# Judge status: Accepted
n,m = map(int, input().split())

if abs(n-m) > 1:
  print(0)
  exit()

mod = 10**9+7
ans = 1
for i in range(1,n+1):
  ans *= i
  ans %= mod
for i in range(1,m+1):
  ans *= i
  ans %= mod
if (n+m)%2 == 0:
  ans *= 2
  ans %= mod
print(ans)
# Judge status: Accepted
S=input()
N=len(S)
lst=[abs(int(S[i:i+3])-753) for i in range(N-2)]
print(min(lst))
# Judge status: Accepted
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
  if sorted([p[i-1],p[i],p[i+1]])[1]==p[i]:ans+=1
print(ans)
# Judge status: Accepted
S = input()
N = len(S)
T = input()
M = len(T)

st = -1

for i in range(N-M, -1, -1):
  if all(S[i+j] in (T[j], "?") for j in range(M)):
    st = i
    break

newS = S.replace("?", "a")

if st == -1:
  print("UNRESTORABLE")
else:
  ans = ""
  for i in range(N):
    if st <= i <= st+M-1:
      ans += T[i-st]
    else:
      ans += newS[i]
  print(ans)
# Judge status: Accepted
from collections import defaultdict

w = input()
d = defaultdict(int)

for key in w:
    d[key] += 1

for value in d.values():
    if value % 2 != 0:
        print('No')
        exit()
print('Yes')
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))
s = sum(A)
ans = abs(s - A[0]*2)
for i in range(1,N-1):
    ans = min(ans, abs(ans - 2*A[i]))
print(ans)
# Judge status: Wrong Answer
A,B,K=map(int,input().split())
S=[]
for i in range(1,101):
  if A%i==0 and B%i==0:
    S.append(i)

S.sort(reverse=True)
print(S)
print(S[K-1])
# Judge status: Accepted
from collections import deque
n = int(input())
s = lambda i: i * (i+1) // 2
ans = deque()
for i in range(1, 10**7):
    ans.append(i)
    if s(i) >= n:
        ans = list(ans)
        if s(i) > n:
            ans.pop(s(i) - n - 1)
        break
print(*ans, sep="\n")
# Judge status: Accepted
N = int(input())
W = list(map(int, input().split()))

m = 10**10
for i in range(1, N):
  a, b = 0, 0
  for j in range(i):
    a += W[j]
  for j in range(i, N):
    b += W[j]
  m = min(m, abs(a-b))
print(m)
# Judge status: Wrong Answer
class atcorder:
    
    K,N=map(int,input().split())
    A=list(map(int,input().split()))
    ans=0
    i=N-1
    if A[i]-A[i-1]<K-A[i]+A[0]:
        for n in range(i):
            ans+=A[i-n]-A[i-n-1]
    else:
        ans+=K-A[i]-A[0]
        for n in range(i-1):
            ans+=abs(A[n]-A[n+1])
    print(ans)
# Judge status: Accepted
def get_ints():
    return map(int, input().split())

s, t = input().split()
a, b = get_ints()
u = input()
if u == s:
    print(str(a - 1) + ' ' + str(b))
else:
    print(str(a) + ' ' + str(b - 1))
# Judge status: Accepted
n = int(input())
p = 2
ans = 0
while n > 1:
    if p > 10 ** 6:
        ans += 1
        break
    e = 1
    while n % (p ** e) == 0:
        n = n // (p ** e)
        e += 1
        ans += 1
    while n % p == 0:
        n = n // p
    p += 1
    
print(ans)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
ans = 1
if 0 in A:
    print(0)
    exit()
for i in range(len(A)):
    ans *= A[i]
    if ans > 10 ** 18:
        print(-1)
        exit()
print(ans)