peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
def solve(n, CSF):
    # https://atcoder.jp/contests/abc084/tasks/abc084_c
    times = [0] * n
    for i, (c, s, f) in enumerate(CSF):
        for j in range(i + 1):
            if times[j] < s:
                times[j] = s
            else:
                times[j] += times[j] % f
            times[j] += c
    return times

_n = int(input())
_CSF = [map(int, input().split()) for _ in range(_n - 1)]
print(*solve(_n, _CSF), sep='\n')
# Judge status: Accepted
import sys

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

N,M = map(int,S().split())

# Mは、a1,…,aNの最大公約数の倍数になることに注意

divisor = []  # Mの約数

for i in range(1,int(M**.5)+1):
    if M % i == 0:
        divisor.append(i)
        if i != M//i:
            divisor.append(M//i)

ANS = []

for d in divisor:
    if d >= N:
        ANS.append(M//d)

print(max(ANS))
# Judge status: Accepted
A, B = map(int, input().split())
a = set([])
b = set([])
n = 1
while n**2 <= max(A, B):
  if A%n == 0 and n**2 <= A:
    a.add(n)
    a.add(A//n)
  if B%n == 0 and n**2 <= B:
    b.add(n)
    b.add(B//n)
  n += 1
ab = a & b
ab.discard(1)
ab = list(ab)
answer = 0
for i, n in enumerate(ab):
  prime = True
  for j, m in enumerate(ab):
    if i != j and n%m == 0:
      prime = False
      break
  if prime:
    answer += 1
print(answer+1)
# Judge status: Accepted
import math

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

lower = 0
upper = max(A)
mid = math.ceil((lower + upper) / 2)
while lower < upper:
    mid = math.ceil((lower + upper) / 2)
    if mid == upper:
        break
    # print(lower, mid, upper)
    cut = 0
    for a in A:
        cut += math.ceil(a / mid) - 1
    if cut <= K:
        upper = mid
    else:
        # K < cut
        lower = mid

print(mid)
# Judge status: Wrong Answer
# AさんBさんCさんが直接的または間接的に話せるか判断せよ
# 自分の頭で考えて答えだせた。嬉
# はじめのコードめちゃめちゃ凡庸性高いし覚えたい

a , b , c, d= map ( int, input ().split())
if (a-b < d) or (b-c < d):
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
D, T, S = input().split()
d = int(D)
t = int(T)
s = int(S)

if (d // s) > t:
    print('No')
else:
    print('Yes')
# Judge status: Accepted
n = int(input())
f = 0
for x in range(1,10):
    for y in range(1,10):
        if x*y == n:
            f = 1
            break
    if f == 1:
        break
if f ==0:
    print("No")
else:
    print("Yes")
# Judge status: Wrong Answer
a,b,t = map(int,input().split())
if t < a:
    print('0')
elif a<= t < 2*a:
    print(b)
elif 2*a <= t < 3*a:
    print(2*b) 
else:
    print(3*b)
# Judge status: Wrong Answer
s = input()
if all(elem in 'abc' for elem in s):
  print('Yes')
else:
  print('No')
# Judge status: Accepted
import math

line = input().rstrip()
line = line.split(' ')
A = int(line[0])
B = line[1].split('.')
if len(B) == 1:
    B = int(B[0]) * 100
elif len(B[1]) == 1:
    B = int(B[0]) * 100 + int(B[1]) * 10
else:
    B = int(B[0]) * 100 + int(B[1])

C = A * B // 100
print(C)
# Judge status: Wrong Answer
h,m,H,M,k = map(int,input().split())
v = H*60+M
u = h*60+M+k
print(v-u)
# Judge status: Accepted
from collections import Counter
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
ans2=0
A1=Counter(A)
A2=A1.most_common()
for i in range(K,len(A1)):
    ans2+=A2[i][1]
print(ans2)
# Judge status: Accepted
def main():
	N = int(input())
	tasks = []
	for i in range(N):
		A, B = [int(x) for x in input().split(" ")]
		tasks.append({
			"time" : A,
			"deadline" : B
		})
	tasks.sort(key=lambda task: task["deadline"])
	tot = 0
	in_time = "Yes"
	for i in range(len(tasks)):
		t = tasks[i]["time"]
		d = tasks[i]["deadline"]
		tot += t
		if tot > d:
			in_time = "No"
			break
	print(in_time)

main()
# Judge status: Accepted
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

import bisect

def main():
	s,c=MI()

	ans=min(s,c//2)

	c-=s*2

	if c>0:
		ans+=c//4

	print(ans)





if __name__ == "__main__":
	main()
# Judge status: Accepted
n, k = map(int, input().split())
A = list(map(int, input().split()))

for i in range(k, n):
    if A[i] > A[i-k]:
        print('Yes')
    else:
        print('No')
# Judge status: Accepted
n,x = map(int,input().split())
l = list(map(int,input().split()))
d , count = 0 , 0

for i in range(0,n):
    d += l[i]
    #print(d)
    if d<=x:
        count+=1
print(count+1)
# Judge status: Wrong Answer
#146 b
n=int(input())
s=input()
ans=""
for x in s:
    num=(ord(x)+n)
    if num>90:
        num=65+num%90
    ans+=chr(num)
print(ans)
# Judge status: Accepted
sd = input()
t = input()
ans = []
if len(sd) < len(t):
    print('UNRESTORABLE')
    exit(0)
for i in range(len(sd)-len(t)+1):
    s = sd
    for j in range(len(t)):
        if sd[i+j] == t[j] or sd[i+j] == '?':
            s = s[:i+j] + t[j] + s[i+j+1:]
        else:
            break
    else:
        ans.append(s.replace('?', 'a'))
if len(ans) == 0:
    print('UNRESTORABLE')
else:
    print(sorted(ans)[0])
# Judge status: Accepted
s = input()
if s[2] == s[3] and s[4] == s[5]:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
N, *X = map(int, open(0).read().split())
sorted_X = sorted(X)
median_l = sorted_X[N // 2 - 1]
median_r = sorted_X[N // 2]

for x in X:
    if x < median_l:
        print(median_r)
    elif x == median_l:
        print(median_r)
    elif x == median_r:
        print(median_l)
    else:
        print(median_l)
# Judge status: Accepted
N=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))
z=[abs(A-T+i*0.006) for i in H]
print(z.index(min(z))+1)
# Judge status: Wrong Answer
#AGC015-A
n,a,b = map(int,input().split())

mi = a * (n-2)
ma = b * (n-2)
result = ma - mi + 1
if a > b:
    print(0)
elif a == b and n != 1:
    print(0)
elif a == b and n == 1:
    print(1)
elif result < 0:
    print(0)
    
else:
    print(result)
# Judge status: Accepted
s=input()
print(chr(ord(s)+1))
# Judge status: Wrong Answer
n = int(input())
h = list(map(int,input().split()))

dp = [0]*n

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,n):
    a = dp[i-1] + abs(h[i]-h[i-1])
    b = dp[i-2] + abs(h[i]-h[i-2])
    dp[i] = min(a,b)

print(dp)
print(dp[n-1])
# Judge status: Wrong Answer
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
b = [a[i]^a[i+1] for i in range(n-1)]
res = [0]
for i in range(n-1):
    res.append(res[-1]^b[i])
print(*res)
# Judge status: Accepted
N=int(input())
s=input()
t=s[len(s)-1]
S=[s]
for i in range(N-1):
  s = input()
  if s in S:
    print("No")
    break
  elif t==s[0]:
    t=s[len(s)-1]
    S.append(s)
  else:
    print("No")
    break

if len(S)==N:
  print("Yes")
# Judge status: Accepted
d = {'SUN': 0, 'MON' : 1, 'TUE' : 2,'WED' : 3,'THU' : 4,'FRI' : 5,'SAT' : 6}

s = input()

ans = 7 - d[s]
print(ans)
# Judge status: Wrong Answer
N = int(input())
S = input()
ans = 1
for i in range(N):
  ans = max(ans,len(set(S[:i])&set(S[i:])))
print(ans)
# Judge status: Wrong Answer
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    n=s[0]
    if int(s)<100:
        print(0)
        sys.exit()
    if int(s[1:3])<=int(n)*5:print(1)
    else:print(0)

if __name__=='__main__':
    main()
# Judge status: Accepted
n=int(input())
a=a=list(map(int,input().split()))
a.sort(reverse=True)
ans=0
if n%2==0:
  for i in range(1,n//2):
    ans +=2*a[i]
  ans+=a[0]
else:
  for i in range(1,n//2):
    ans +=2*a[i]
  ans +=a[n//2]
  ans+=a[0]
print(ans)
# Judge status: Wrong Answer
from math import ceil

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

if K >= N:
    print(1)
    exit()

one = A.index(1)
print(one)
print(ceil((one)/(K-1)) + ceil((N-one-1)/(K-1)))
# Judge status: Accepted
s = input()
if (s.count('N')>0)^(s.count('S')>0) or (s.count('E')>0)^(s.count('W')>0):
    print('No')
else:
    print('Yes')
# Judge status: Accepted
x = int(input())
ans = x // 11 * 2
if x % 11 >= 7:
    ans += 2
elif x % 11 == 0:
    pass
else:
    ans += 1
print(ans)
# Judge status: Accepted
import sys

n,m=map(int,input().split())
l=[[] for i in range(n)]

for i in range(m):
  a,b=map(int,input().split())
  l[a-1].append(b)
# print(l)


for i in l[0]:
  for j in l[i-1]:
    if j==n:
      print("POSSIBLE")
      sys.exit()

print("IMPOSSIBLE")
# Judge status: Accepted
n, m = map(int, input().split())
if m >= n:
    print("unsafe")
else:
    print("safe")
# Judge status: Accepted
n,c,k = map(int,input().split())
t = [int(input()) for nesya in range(n)]
t.sort()
bus = 0
wait = []
for i in range(n):
  wait.append(t[i])
  if wait[0] + k < t[i]:
    bus += 1
    wait = [t[i]]
  elif len(wait) == c:
    bus += 1
    wait = []
  elif wait[0] + k == t[i]:
    bus += 1
    wait = []
  if i == n-1 and len(wait) > 0:
    bus += 1
print(bus)
# Judge status: Accepted
a, b = map(int, input().split())
if abs(a-b)%2 == 0:
    print(int((a+b) / 2))
else:
    print('IMPOSSIBLE')
# Judge status: Accepted
import heapq

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(reverse=True)

ans = 0
work = []
# 最終日からさかのぼっていって、できるバイトの中で一番収入が多いやつをする
for i in range(1, M + 1):
    while AB:
        if AB[-1][0] <= i:
            _, b = AB.pop()
            heapq.heappush(work, -b)
        else:
            break

    if work:
        ans -= heapq.heappop(work)

print(ans)
# Judge status: Accepted
A, B, C = map(int, input().split())
if A%2 == 0 or B%2 == 0 or C%2 == 0:
  print(0)
else:
  print(min(A*B, B*C, C*A))
# Judge status: Accepted
def main():
    H, N, *A = map(int, open(0).read().split())
    print("No" if sum(A) < H else "Yes")
    return


main()
# Judge status: Accepted
N, M = map(int,input().split())
if N%2 == 1:
    for i in range(1,M+1):
        print(i,N+1-i)
else:
    for i in range(1,M+1):
        if i == N//4+1:
            break
        print(i,N+1-i)
        if i == M:
            quit()
    for j in range(i,M+1):
        print(j+1,N+1-j)
# Judge status: Wrong Answer
N,M=map(int,input().split())
B=[1]+[1]+[0]*(N-1)
for j in range(M):
    a=int(input())
    B[a]=-1
i=1
while i<=N:
    if B[i]==-1:
        B[i]=0
    else:
        B[i] = (B[i - 1] + B[i - 2]) % (10 ** 9 + 7)
    i+=1
print(B[N])
# Judge status: Accepted
# A - Between Two Integers
def main():
    a, b, c = map(int, input().split())

    if a<=c<=b:
        print('Yes')
    else:
        print('No')


if __name__ ==  "__main__":
    main()
# Judge status: Wrong Answer
n=int(input())
money=1000
while(1):
    if n<=money:
        break
    money+=1000
print(money%n)
# Judge status: Accepted
s = input()
a = 0
b = 0
for i in range(len(s)):
         if s[i] == "0":
                 a += 1
         else:
                  b += 1
print(min(a,b)*2)
# Judge status: Accepted
n=int(input())
print("ABC" if n<=999 else "ABD")
# Judge status: Accepted
n,m=map(int,input().split())
h=list(map(int,input().split()))
t=[]
for i in range(m):
    t.append(list(map(int,input().split())))
ans=[True]*n
for i in range(m):
    a,b=t[i]
    if(h[a-1]<=h[b-1]):
        ans[a-1]=False
    if(h[b-1]<=h[a-1]):
        ans[b-1]=False
print(ans.count(True))
# Judge status: Wrong Answer
n = int(input())
ans = 'No'

a = [input().split() for i in range(n)]

for i in range(0,n-3):
    if a[i][0]== a[i][1] and a[i+1][0] == a[i+1][1] and a[i+2][0] == a[i+2][1]:
        ans = 'Yes'
        break

print(ans)
# Judge status: Accepted
a,b,c=map(int,input().split(" "))
print(["No","Yes"][a+b>=c])
# Judge status: Accepted
a = int(input())
b = int(input())
h = int(input())

S = (a+b) * h / 2
print( int(S))
# Judge status: Accepted
from collections import defaultdict

N = int(input())

cnt = defaultdict(int)
for i in range(1, N + 1):
    i = str(i)
    l = i[0]
    r = i[-1]
    cnt[(l, r)] += 1
    cnt[(r, l)] += 0

ans = 0
for (l, r), c in cnt.items():
    ans += cnt[(r, l)] * c

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

if b%x == 0:
    print(b//x-a//x+1)
else:
    if a%x == 0 and a != 0:
        print(b//x-a//x+1)
    else:
        print(b//x-a//x)
# Judge status: Wrong Answer


s = input()

if s == 'AAA' or 'BBB':
    print('No')
else:
    print('Yes')
# Judge status: Accepted
x,y = map(int, input().split())
if x>=y:
  if x%y==0:
    print(-1)
    exit()
print(x)
# Judge status: Accepted
a, b = input().split()
a = int(a)
b = int(b)

c = 0
d = 0

if a >= b:
    c = b
    d = a
else:
    c = a
    d = b
print(str(c)* d)
# Judge status: Accepted
D, N = map(int, input().split())

d = 100 ** D

if N == 100:
    N = 101
print(d * N)
# Judge status: Accepted
n, k, s = map(int, input().split())

ans = []
for i in range(k):
  ans.append(s)

if s == pow(10, 9):
  s = 0
  
for j in range(k, n):
  ans.append(s+1)
  
print(' '.join(list(map(str, ans))))
# Judge status: Wrong Answer
n= int(input())

alp=list([
    "a","b","c","d","e",
    "f","g","h","i","j",
    "k","l","m","n","o",
    "p","q","r","s","t",
    "u","v","w","x","y","z"
          ])

answer=""
while True:
    answer=alp[(n-1)%26]+answer
    if n<=26:
        break
    n=n//26

print(answer)
# Judge status: Accepted
h,n= map(int,input().split())

l= list(map(int,input().split()))
sum=0
i=0
for i in range (n):
    sum=sum+l[i]
    i=i+1
if h>sum:
    print("No")
else:
    print("Yes")
# Judge status: Accepted
# solution
import io

nim,mike = map(int,input().split())

sets={int(input()) for _ in range(mike)}

modulous=10**9+7

array=[0]*(nim+1)
array[0]=1
array[1]=1
if 1 in sets:
  array[1]=0

for i in range(2,nim+1):
  if i in sets:
    continue
  array[i]=(array[i-1]+array[i-2])%modulous
print(array[nim])
# Judge status: Wrong Answer
N, K = list(map(int, input().split()))


def x(N, K):
    y = N
    f = 0
    while True:
        N = abs(N - K)

        if y > N:
            y = N

        if y == N:
            f += 1

        if f > 5:
            return y


# if K == 0:
#     print(N)
# elif K == 1:
#     print(0)
# else:
#     print(x(N, K))
print(x(N, K))
# Judge status: Accepted
import collections
a = input()
b = []
c = int(len(str(a)))

for i in range(c):
  b.append(a[i])

d = collections.Counter(b)
e = d.most_common()[0][1]

if e != 1:
  print("no")
else:
  print("yes")
# Judge status: Wrong Answer
a, b = map(int, input().split())

ans = (b-a)*(b-a-1)*0.5-a

print(ans)
# Judge status: Wrong Answer
n,m=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
l=[n]*m
for i in range(n):
  for j in range(a[i][0]):
    l[a[i][j]-1]-=1
print(l.count(0))
# Judge status: Accepted
import math
X=int(input())
#print(math.log(X/100)//math.log(1.01))
count=0
XX=100
while(X>XX):
    XX=math.floor(XX*1.01)
    count+=1
print(count)
# Judge status: Accepted
N,M = map(int,input().split())

se = set(range(M+1))
for _ in range(N):
  enquete = [int(x) for x in input().split()]
  se &= set(enquete[1:])

answer = len(se)
print(answer)
# Judge status: Wrong Answer
def nyu():
    N,K = map(int,input().split())
    A = [list(map(int,input().split())) for _ in range(N)]
    return N,K,A

def kansu(N,K,A):
    
    sum = 0
    ans = -1


    for a in range(len(A)):
        sum += A[a][1]
        if (K >= sum):
            ans = A[a][0]
            break
    print(ans)




N,K,A = nyu()
kansu(N,K,A)
# Judge status: Wrong Answer
l = input()
m = input()
if l[0] == m[2] and l[1] == m[1] and l[2] == l[0]:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n, x = map(int, input().split())
L = list(map(int, input().split()))

point = 0
ans = 1

for l in L:
    point += l
    if point > x:
        break
    ans += 1

print(ans)
# Judge status: Accepted
import sys
input = sys.stdin.readline
S = list(input().rstrip())
from collections import Counter
c = Counter(S)
for i in c.values():
    if i != 1:
        print("no")
        sys.exit()
print("yes")
# Judge status: Accepted
n, m, k = map(int, input().split())
exists = False
for i in range(n + 1):
  for j in range(m + 1):
    if i * m + j * n - 2 * i * j == k:
      exists = True
      break
  if exists:
    break
print('Yes' if exists else 'No')
# Judge status: Accepted
import sys

input = sys.stdin.readline


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

    for i in range(1, 10):
        if N <= 111 * i:
            ans = 111 * i
            break

    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Accepted
from collections import Counter
n = int(input())
d = [input() for _ in range(n)]
c = Counter(d).most_common()
now = c[0][1]

data = []
for x in c:
    if x[1] < now:
        break
    data.append(x[0])
data.sort()
for x in data:print(x)
# Judge status: Wrong Answer
a, b, c = map(int, input().split())

ab = a - b
cab = c - ab

if cab >= 0:
    print(0)
# Judge status: Wrong Answer
S=input()
T=input()
l=len(S)
if S==T:
    print("Yes")
    exit()
 
for i in range(l-1):
    tmp=S[-1]
    S=S.strip(S[-1])
    new_string=tmp+S
    
    if new_string==T:
        print("Yes")
        exit()
    
    S=new_string
 
print("No")
# Judge status: Accepted
s = input()
t = input()
s = sorted(s)
t = sorted(t, reverse=True)
s_t = [s, t]
s_t.sort()
if s_t[0] == s and s_t[1] != s:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
S=input()
while len(S)>=2:
  if S[:2]=='hi':
    S=S[2:]
  else:
    break
if len(S)==0:
  print('YES')
else:
  print('NO')
# Judge status: Wrong Answer
import math

a, b, h, m = map(int, input().split())
mins= 60 * h + m
ho = mins%720
so = mins % 60
ho /= 720
so /= 60
shita = abs(ho-so) * 360
if shita > 180:
    shita -= 180
shita = math.radians(shita)
ans = (a ** 2  + b ** 2 )*10000000
ans -= 2 * a * b * math.cos(shita)* 10000000
ans /= 10000000
ans = math.sqrt(ans)

print(ans)
# Judge status: Accepted
def resolve():
    '''
    code here
    '''
    N, A, B = [int(item) for item in input().split()]

    if A <= B:
        if N >=3:
            res = (N-1)*B + A - ((N-1)*A + B) + 1

        elif N == 2:
            res = 1
        else:
            if A == B:
                res = 1
            else:
                res = 0
    else:
        res = 0

    print(res)

if __name__ == "__main__":
    resolve()
# Judge status: Wrong Answer
A = list(map(int, input().split()))
a = A[1]//A[0]
if a >= A[2]:
    print(a)
else:
    print(A[2])
# Judge status: Accepted
a,b=input().split()
if int(a)>=10:
    c=b
else:
    c=int(b)+100*(10-int(a))
print(c)
# Judge status: Accepted
N = int(input())
D = [tuple(map(int, input().split())) for _ in range(N)]
cnt = 0
for d1, d2 in D:
    if d1 == d2:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        print('Yes')
        exit()
print('No')
# Judge status: Wrong Answer
N = int(input())
a = list(map(int,input().split()))
Q = int(input())
B = [0]*(10**5+1)
C = [0]*(10**5+1)

for i in range(Q):
  B[i],C[i] = map(int,input().split())

cou = [0]*(10**5+1)
for i in range(1,N+1):
  cou[i] = a.count(i)
allS = sum(a)

for i in range(Q): 
  N_b=0
  N_b = cou[B[i]]
  cou[B[i]] -= N_b
  cou[C[i]] += N_b

  allS = allS + (C[i]-B[i])*N_b
  print(allS)
# Judge status: Accepted
a,b,c,k = map(int,input().split())

if k<=a:
    print(k)
elif a<k<=a+b:
    print(a)
else:
    print(a-(k-(a+b)))
# Judge status: Accepted
import math
mod = 10**9+7
ans = 1
n, m = map(int, input().split())
if abs(n - m) > 1:
  print(0)
  quit()
elif n == m:
  ans = 2
ans = ans * math.factorial(n) % mod
ans = ans * math.factorial(m) % mod
print(ans)
# Judge status: Accepted
H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
x=max(a for a,b in ab)
dp=[0]*(H+x)
for i in range (1,H+x):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(dp[H])
# Judge status: Wrong Answer
def rolling(str , n):
    return str[n:len(str)] + str[:n]

a=list(input())
b=list(input())

for i in range(len(a)):
    a=rolling(a,i)
    if a==b:
        print('Yes')
        exit()
print('No')
# Judge status: Accepted
def main():
  N, A, B = map(int, input().split())

  if N == 1:
    if A != B:
      ans = 0
    else:
      ans = 1
  else:
    if A > B:
      ans = 0
    elif A == B:
      ans = 1
    else:
      ans = (A + (N - 1) * B) - (A * (N - 1) + B) + 1

  print(ans)

main()
# Judge status: Accepted
N = int(input())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[1])
flag = 0
cur = 0
for i in range(N):
    a,b = A[i]
    cur += a
    if cur>b:
        flag = 1
        break
if flag==1:
    print("No")
else:
    print("Yes")
# Judge status: Wrong Answer
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l=sorted(l)
count=0
for i in range(n-1):
    l_range=l[i][1]+l[i+1][1]
    x_range=l[i+1][0]-l[i][0]

    if l_range>x_range:
        count+=1
        l[i+1]=l[i]

print(n-count)
# Judge status: Accepted
a,b,c = map(int, input().split())
if min(a,b) <= c <= max(a,b):
  print('Yes')
else:
  print('No')
# Judge status: Accepted
a,b = map(int,input().split())

if a % 3 == 0 or b % 3 == 0 or (a + b) % 3 == 0:
	print("Possible")
else:
  	print("Impossible")
# Judge status: Accepted
n = int(input())
ais = list(map(int, input().split()))
if len(ais) == 1:
  print(1)
  quit()
if ais[0] < ais[1]:
  tend = 1
elif ais[0] > ais[1]:
  tend = -1
else:
  tend = 0
pref = ais[1]
ans = 1
for a in ais[2:]:
  if pref < a and tend == -1:
    ans += 1
    tend = 0
  elif pref > a and tend == 1:
    ans += 1
    tend = 0
  elif tend == 0:
    if pref < a:
      tend = 1
    elif pref > a:
      tend = -1
    elif pref == a:
      pass
  pref = a
print(ans)
# Judge status: Wrong Answer
ABC = list(map(int, input().split()))

res = 1

if ABC[0]%2 == ABC[1]%2 == ABC[2]%2 == 0:
    print(0)
else:
    ABC.sort(reverse=True)
    for i in range(len(ABC)):
        if ABC[i]%2 == 1:
            ABC.pop(i)
            for j in range(2):
                res *= ABC[j]
            print(res)
            exit()
# Judge status: Wrong Answer
import math

n, k = map(int, input().split())
log2 = math.log10( 2)
ans = 0
for i in range(1,n+1):
    temp = i
    cnt = 0
    if i >= k :
        ans += (1/n)*(n-i)
        print(ans)
        exit()
    while temp < k:
        cnt += 1
        temp *= 2
    ans += (1/n) * 0.5**cnt

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

if S == 'ABC':
    print('ARC')
else:
    print('ARC')
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
if N%2==0:
  B = [A[i] for i in range(N) if i%2==0]
  C = [A[(N-i-1)] for i in range(N) if (N-i-1)%2==1]
  print(*C+B)
else:
  B = [A[i] for i in range(N) if i%2==1]
  C = [A[(N-i-1)] for i in range(N) if (N-i-1)%2==0]
  print(*C+B)
# Judge status: Accepted
s = input()
if s.count('A') == 3 or s.count('B') == 3:
    print('No') 
else:
    print('Yes')
# Judge status: Wrong Answer
l = list(map(int, input().split()))
print("Yes" if sum(l) // 2 in l else "No")
# Judge status: Accepted
N = int(input())
S = input()
if N%2==0:
    if S[:int(N/2)] == S[int(N/2):]:
        print("Yes")
    else:
        print("No")
else:
    print("No")
# Judge status: Wrong Answer
a,b=map(int,input().split())
if (a+b)%3==0:
    print ('Possible')
else:
    print('Impossible')
# Judge status: Wrong Answer
x , y = map(int , input(). split())
if x < 11 and y < 11 :
    print(x * y)
else:
    print(-1)
# Judge status: Accepted
N, A, B = map(int, input().split())

if (A > B):
    print(0)
    exit()
elif (B > A and N == 1):
    print(0)
    exit()
elif (A == B and N == 1):
    print(1)
    exit()
else:
    ma = B * (N - 2)
    mi = A * (N - 2)
    print(ma - mi + 1)
# Judge status: Accepted
x, y = map(int, input().split())
cnt = 0
ai = x
for i in range(2**60):
    if ai <= y:
        cnt += 1
        ai *= 2
    else:
        break
print(cnt)