peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N=int(input())
A=list(map(int,input().split()))
import bisect
A.sort()
B=[abs(i) for i in A]
l=min(B)
count=0
for i in range(N):
  if A[i]<0:
    count+=1
  else:
    break
if count%2==1:
  for i in range(count-1):
    A[i]=-A[i]

  print(sum(A)-2*l-2*A[count-1])

if count%2==0:
  for i in range(count):
    A[i]=-A[i]
  print(sum(A))
# Judge status: Accepted
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n-k):
    ab = a[i]
    aa = a[k+i]
    if aa > ab:
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
N, M = map(int, input().split())
L = [0]*N
for i in range(M):
  a, b = map(int, input().split())
  L[a-1] += 1
  L[b-1] += 1
for i in range(N):
  print(L[i])
# Judge status: Wrong Answer
import fractions as math

MOD = 10**9 + 7


def get_lcm(xs):
    ans = xs[0] % MOD
    for a in xs[1:]:
        ans = ans * a * pow(math.gcd(ans, a), MOD-2, MOD)
    return ans


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

lcm = get_lcm(A)
res = 0
for a in A:
    res += lcm * pow(a, MOD-2, MOD)
    res = res % MOD

print(res)
# 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():
    c = readline().strip()

    if c in 'aeiou':
        print('vowel')
    else:
        print('consonant')

    return


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

def solve():
    input = sys.stdin.readline
    A, B, C = map(int, input().split())
    count = 0
    while count < C:
        if B >= A:
            count += 1
            B -= A
        else: break
    print(count)

    return 0

if __name__ == "__main__":
    solve()
# Judge status: Wrong Answer
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 2 * 10 ** 5 + 1
for i in range(n-k+1):
    path = a[i:i+k]
    time = min(abs(path[0]) + abs(path[-1] - path[0]), abs(path[-1]) + abs(path[-1] - path[0]))
    ans = min(ans, time)
print(ans)
# Judge status: Wrong Answer
a, b, c = map(int, input().split())
print("Yes") if (a + b + c) % 2 == 0 else print("No")
# Judge status: Accepted
def mips():
    return map(int,input().split())
def ii():
    return int(input())

H1,M1,H2,M2,K = mips()
Ans = (H2*60+M2 - (H1*60+M1))-K
print(Ans)
# Judge status: Wrong Answer
from fractions import gcd

def main():
    n=int(input())
    a=list(map(int,input().split()))
    s=a[0]
    mod=10**9+7
    for i in a[1:]:
        s=(s*i*pow(gcd(s,i),mod-2,mod))%mod
    ans=0
    for i in range(n):
        ans+=pow(a[i],mod-2,mod)
    ans=(ans*s)%mod
    print(ans)
          
if __name__ == '__main__':
    main()
# Judge status: Accepted
S = list(input())

for i in range(len(S)):
    S[i] = int(S[i])

f = S[0]
ans = 0

for i in range(1,len(S)):
    if S[i]+S[i-1] != 1:
        ans += 1
        S[i] = int(not S[i])

print(ans)
# Judge status: Accepted
s=input()
clist=['A','C','G','T']
count=0
a=[]
for i in s:
  if i in clist:
    count+=1
  else:
    a.append(count)
    count=0
a.append(count)
print(max(a))
# Judge status: Accepted
def reverse(string):
    string = string[::-1]
    return string


l=input()
m=input()
if l == reverse(m):
    print("YES")
else:
    print("NO")
# Judge status: Wrong Answer
import sys

l=[0]*100
l[0]=2
l[1]=1

n=int(input())

for i in range(2,100):
  l[i]=l[i-2]+l[i-1]
  if i==n:
    print(l[i])
    sys.exit()
# Judge status: Accepted
a,b,c=map(int,input().split())
if 4*a*b < (c-a-b)**2 and (c-a-b)>0:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
A,B=map(int,input().split())
if A==B: print('Draw')
else: print('Alice' if (A > B or (A==1 and B==13) or (A==1 and B==2)) else 'Bob')
# Judge status: Wrong Answer
A, B, X = map(int, input().split())
print("YES" if A+B <= X else "NO")
# Judge status: Accepted
K = int(input())
A,B = map(int,input().split())

for i in range(1020):
    if i>=A and i<= B:
        if i%K==0:
            print("OK")
            break
else:
    print("NG")
# Judge status: Accepted
a,b=map(int,input().split())

if (a>0 and b<0) or (a<0 and b>0):
  ans="Zero"
elif a==0 or b==0:
  ans="Zero"
elif a>0 and b>0:
  ans="Positive"
elif a<0 and b<0:
  if (a%2==0 and b%2==0) or (a%2!=0 and b%2!=0):
    ans="Negative"
  else:
    ans="Positive"
    
print(ans)
# Judge status: Accepted
n = int(input())
a = 0
for i in range(1, n+1, 2):
    c = 0
    for j in range(1, n+1):
        if i%j==0:
            c += 1
    if c == 8:
        a += 1
print(a)
# Judge status: Accepted
n = int(input())
ab = []
A = 0

for i in range(n):
  a,b = map(int,input().split())
  ab.append([b,a])

ab.sort()

for j in range(n):
  A += ab[j][1]
  if A>ab[j][0]:
    print('No')
    exit()
    
print('Yes')
# Judge status: Accepted
import math
a,b,c,d=map(int,input().split())

takahashi = math.ceil(a/d)
aoki = math.ceil(c/b)

if takahashi>=aoki:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n,k=map(int,input().split())
print(min(n%k,k-n%k))
# Judge status: Accepted
x=int(input())
y=x//500
z=(x%500)//5
print(1000*y+5*z)
# Judge status: Accepted
import sys
X,K,D = map(int,input().split())
X = abs(X)
if X > K * D:
    print(X - K*D)
    
elif X != 0:
    if (X // D) % 2 == K % 2:
        print(X % D)
    elif (X // D) % 2 != K % 2:
        print(abs(X % D - D))
        
else:
    if K % 2 == 0:
        print(0)
    else:
        print(D)
# Judge status: Accepted
s = int(input())

sec = [s]
count = 1
while(s):
  if sec[-1]%2 == 0:
    sec.append(sec[-1]/2)
  else:
    sec.append(3*sec[-1]+1)
  count+=1
    
  if sec[-1] in sec[:-1]:
    print(count)
    break
# Judge status: Wrong Answer
import math
a,b,hour,min = map(int,input().split())

def yogen(a,b,theta):
    result = a**2 + b**2 - 2*a*b*math.cos(theta)
    return math.sqrt(result)

theta = math.radians(360*abs(hour/12 - min/60))
print(yogen(a,b,theta))
# Judge status: Wrong Answer
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sa=sum(a)
sb=sum(b)
if sb<sa:
    print("No")
else:
    cnt=sb-sa
    res=0
    for i in range(n):
        if b[i]<a[i]:
            res+=a[i]-b[i]
    if res>cnt:
        print("No")
    else:
        print("Yes")
# Judge status: Accepted
# C - Lower

N = int(input())
H = [int(h) for h in input().split()]
cnt = []
tmp = 0
for i in range(N - 1):
    if H[i + 1] <= H[i]:
        tmp += 1
    else:
        cnt.append(tmp)
        tmp = 0
else:
    cnt.append(tmp)

print(max(cnt))
# Judge status: Wrong Answer
C1 = input()
R1 = C1[::-1]
C2 = input()
R2 = C2[::-1]
print(['No','Yes'][R2==C1 and R1==C2])
# Judge status: Wrong Answer
n, m = map(int, input().split())
mizu = [1]*n
iro = [1] + [0]*(n-1)
for i in range(m):
    x, y = list(map(lambda tmp: tmp-1, map(int, input().split())))
    iro[y] = (iro[y]+iro[x])/(mizu[y]+1)
    mizu[x]-=1; mizu[y]+=1
    if mizu[x]==0:
        iro[x] = 0
print(sum(map(lambda x: int(bool(x)), iro)))
# Judge status: Wrong Answer
x = input()
N = int(x)

if N == 1:
    print(0)
else:
    z = 10**N - 2*9**N + 8**N
    print(z)
# Judge status: Accepted
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
from collections import deque

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

K = i_i()
q = deque(range(1, 10))

for _ in range(K):
    x = q.popleft()

    for i in range(-1, 2):
        d = x % 10 + i
        if d < 0 or d > 9: continue
        q.append(x * 10 + d)
        
print(x)
# Judge status: Accepted
n=map(int,input().split())
*p,=map(int,input().split())

lmin=10**10
ans=0

for pp in p:
    ans+=1 if pp<=lmin else 0
    lmin=min(pp,lmin)

print(ans)
# Judge status: Wrong Answer
import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split()))
if n%2:
    print(" ".join(map(str, a[::2] + a[::-1][1::2])))
else:
    print(" ".join(map(str, a[::-1][::2] + a[::2])))
# Judge status: Accepted
a, b, c = map(int, input().split())
if a < c < b or b < c < a:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n = int(input())
l = list(map(int,input().split(" ")))
total = 0
for i in l:
    total += i

x = l[0]
y = total - x
a = abs(x - y)


for t in range(n):
    x = 0
    for i in range(t+1):
        x += l[i]
    y = total - x
    b = abs(x - y)
    if a > b:
        a = b

print(a)
# Judge status: Wrong Answer
A, B, M = map(int, input().split())
a_price = list(map(int, input().split()))
b_price = list(map(int, input().split()))
coupon = [list(map(int, input().split())) for i in range(M)]
min = a_price[0] + b_price[0]
for cpn in coupon:
    idx_a = cpn[0]-1
    idx_b = cpn[1]-1
    total = a_price[idx_a] + b_price[idx_b] - cpn[2]
    if min > total:
        min = total

print(min)
# Judge status: Accepted
N=int(input())
AB=[tuple(map(int, input().split())) for _ in range(N)]

ans=0
for a,b in reversed(AB):
    if b==1 or (a+ans)%b==0: continue
    ans += b - ((a+ans) % b)
print(ans)
# Judge status: Wrong Answer
N,a,b = list(int(x) for x in input().split())
ans = 0
for i in range(N+1):
  m = int(i/1000)
  n = int((i%1000)/100)
  j = int((i%100)/10)
  k = i%10
  sum = m + n + j + k 
  if sum >= a and sum <= b:
    ans = ans + i

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

if a+2 <= b:
    print(max((k-a-1) // 2, 0) * (b-a) + b + (k-a-1) % 2)
else:
    print(k+1)
# Judge status: Wrong Answer
N = int(input())
a = list(map(int, input().split()))
a.sort()
b = a[0::2][1::3]
c = a[1::2][1::3]
print((sum(b)+sum(c)))
# Judge status: Accepted
N=int(input())
H=list(map(int,input().split()))
max=0
ans=0
for i in range(N-1):
    if H[i]>=H[i+1]:
        max+=1
    else:
        max=0
    if ans<=max:
        ans=max
print(ans)
# Judge status: Accepted
L,R = map(int,input().split())
mn = 10**10
cal = 0
for i in range(L,R+1):
    for j in range(i+1,R+1):
        
        cal = ((i%2019)*(j%2019))%2019
        if cal < mn:
            mn = cal
        if cal == 0:
            break
    else:
        continue
    break
print(mn)
# Judge status: Wrong Answer
S =list(map(int,input().split()))
N=S[0]
M=S[1]

la=[]
for i in range(N):
    la.append(input())
lb=[]
for i in range(M):
    lb.append(input())


for i in range(N-M+1):
    for j in range(N-M+1):
        flag=True
        for k in range(M):
            for l in range(M):
                if la[i+k][j+l]!=lb[k][l]:
                    flag ==False
        if flag==True:
            print("Yes")
            exit()
print("No")
# Judge status: Wrong Answer
N, M = map(int, input().split())

ans = 0
if N > M//2:
    ans = N
else:
    ans = N
    M -= 2*N
    ans += M//4
print(ans)
# Judge status: Wrong Answer
K, A, B = map(int, input().split())
ans = 0
if B - A <= 2:
  print(K + 1)

else:
  K -= A - 1
  if K <= 1:
    print(K + 1)
  else:
    ans += (K//2) * (B - A) + A
    ans += K % 2
    print(ans)
# Judge status: Accepted
n = int(input())
l = list(int(i) for i in input().split())
ans = float('inf')
for i in range(n):
    tmp = abs(sum(l[i:]) - sum(l[:i]))
    if tmp < ans:
        ans = tmp
print(ans)
# Judge status: Accepted
# coding: utf-8
# Your code here!
a,b=map(int,input().split())
n=b-a
g=0
for i in range(1,n):
    g+=i
print(g-a)
# Judge status: Wrong Answer
n=int(input())
print(1000*(n//500)+5*((n-(n%500)*500)%5))
# Judge status: Wrong Answer
def main():
    X = input()
    s, t = 0, 0
    flag = False
    for x in X:
        if x == "S":
            flag = True
        if flag:
            if x == "S":
                s += 1
            else:
                t += 1
    for x in X[::-1]:
        if x == "S":
            s -= 1
        else:
            break
    print(len(X) - min(s, t) * 2)
main()
# Judge status: Accepted
from collections import Counter
n=int(input())
c=Counter(list(map(int, input().split())))
l=list()
for k,v in c.items():
    for _ in range(v//2):
        l.append(k)

l.sort()
l.reverse()
if len(l)>=2:
    print(l[0]*l[1])
else:
    print(0)
# Judge status: Accepted
n = int(input())
ans = 0
for i in range(1,n+1):
    if len(str(i)) % 2 == 1:
        ans += 1
print(ans)
# 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()))
c.append(0)
c[a[n-1]-1] = 0

print(a,b,c)

ans = 0

for i in a:
    ans += b[i-1] + c[i-1]


print(ans)
# Judge status: Accepted
a, b = map(int, input().split())
if a*b % 2 == 1:
    print("Odd")
else:
    print("Even")
# Judge status: Accepted
A = input()
B = []
for i in A:
  B.append(int(i))
if sum(B) == 1:
  print('10')
else:
  print(sum(B))
# Judge status: Accepted
x,y = map(int,input().split())
import math
print(math.floor(x + y / 2))
# Judge status: Wrong Answer
n ,x, y = map(int, input().split())

sub_degree = [0]*n
for i in range(1,n):
    for j in range(i+1, n+1):
        a = min(abs(j-i), abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x))
        sub_degree[a]+=1

for i in range(n-1):
    print(sub_degree[i])
# Judge status: Wrong Answer
n,m = map(int,input().split())
if(2*n >= m):
    print(n)
else:
    m -= 2*n
    print(n + (m//4))
# Judge status: Accepted
a,b,c=map(int,input().split())
if a==7 and b==5 and c==5:
    print("YES")
elif b==7 and a==5 and c==5:
    print("YES")
elif c==7 and a==5 and b==5:
    print("YES")
else:
  print("NO")
# Judge status: Wrong Answer
A, B, C, X, Y = map(int, input().split())
ans = 1e1000
for i in range(0, 2*min(X, Y)+1, 2):
  ans = min(ans, int(A*max(0, X-i/2)+B*max(0, Y-i/2)+C*i))
print(ans)
# Judge status: Wrong Answer
def main():
  import math
  N = int(input())
  if N % 2 != 0:
    print(0)
    exit()
  ans = 0
  i = 1
  while 2*5**i<=N:
    ans += math.floor(N/(2*(5**i)))
    i += 1
      
  print(ans)
main()
# Judge status: Accepted
n = int(input())
x = list(map(int,input().split()))

syukai = sum(x)//n
ans=0
ans1=0
ans2=0
for i in range(n):
    ans += pow(x[i]-syukai-1,2)
    ans1 += pow(x[i]-syukai,2)
    ans2 += pow(x[i]-syukai+1,2)
print(min(ans,ans1,ans2))
# Judge status: Accepted
n = int(input())
lucas = [2,1]
for i in range(2,n+1):
    luca = lucas[i-2] + lucas[i-1]
    lucas.append(luca)
print(lucas[n])
# Judge status: Wrong Answer
N, K = map(int,input().split())
List_1 = sorted(list(map(int, input().split())), reverse=True)
K = K+1
ans = sum(List_1[:K])
print(ans)
# Judge status: Accepted
N = int(input())
def f(i):
  return sum([int(j) for j in str(i)])
ans = float('inf')
for A in range(1, N):
  B = N - A
  ans = min(ans, f(A) + f(B))
print(ans)
# Judge status: Accepted
a, b = map(int, input().split())
if a == 1:
  a = 14
if b == 1:
  b = 14
if a > b:
  print("Alice")
elif a < b:
  print("Bob")
else:
  print("Draw")
# Judge status: Accepted
def main():

    N, A, B = map(int, input().split())
    if (B-A) % 2 == 0:
        return  (B-A) // 2
    else:
        a = A-1 + (B-A+1)//2
        b = N-B+1 + (B-A-1) // 2
        return min([a, b])

if __name__ == '__main__':
    print(main())
# Judge status: Accepted
x, a, b = map(int, input().split())
if abs(x-a) > abs(x-b):
    print("B")
else:
    print("A")
# Judge status: Accepted
S = input()
N = len(S)
ans = 0
for i in range(N):
    for j in range(i + 1, N + 1):
        ss = S[i:j]
        for c in ss:
            if not c in ("A", "C", "G", "T"):
                break
        else:
            ans = max(ans, len(ss))
print(ans)
# Judge status: Accepted
n=int(input())
l=list(map(int,input().split()))
txor=l[0]
for i in range(1,n):
	txor=txor^l[i]
x=[]
for i in l:
	x.append(txor^i)
[print(i,end=' ') for i in x]
# Judge status: Wrong Answer
n = int(input())

if n%4!=0 and n%7!=0 and n%11!=0:
    print("No")
else:
    print("Yes")
# Judge status: Accepted
import math
N = int(input())
T = [0]*110000
X = [0]*110000
Y = [0]*110000

for n in range(N):
    T[n+1], X[n+1], Y[n+1] = map(int, input().split())

res = True
for n in range(N):
    dt   = T[n+1] - T[n]
    dist = abs(X[n+1] - X[n]) + abs(Y[n+1] - Y[n])
    if dt < dist:
        res = False
    if dt % 2 != dist % 2:
        res = False

if res:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
A,B,C,K = map(int,input().split())

if A >= K:
  print(K*1)
else:
  K -= A
  if B >= K:
    print(A*1)
  else:
    K -= B
    print(A*1 + K*(-1))
# Judge status: Accepted
n,m = map(int,input().split())
#a = list(map(int,(input().split())))
a = list(map(lambda x: int(x)*(-1), input().split()))

import heapq
#n 買う商品数
#m 割引券の数
#a 値段
heapq.heapify(a)
while True:
   # print(a)
    tmp = (-1) * heapq.heappop(a) //2
    heapq.heappush(a,-1 * tmp)
    m -= 1
    if m == 0:
        break
print(-1*sum(a))
# Judge status: Accepted
#3問目
NM = input().split()
N,M = int(NM[0]), int(NM[1])
A = set([int(input()) for _ in range(M)])
dp = [0] * (N+1)
dp[0] = 1
dp[1] = 1
MOD = 1000000007
    
if(1 in A):
    dp[1] = 0

for i in range(2, N+1):
    #貰うdp
    if(i in A):
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]
    dp[i] %=MOD
    
print(dp[N])
# Judge status: Wrong Answer
N=int(input())
A = list(map(int, input().split()))
#print(A)
count=0
count2=0
for i in range(len(A)-1):
    if A[i]>A[i+1]:
        count=A[i]-A[i+1]
        print('count',count)
        A[i+1]=A[i]
        count2+=count
print(count2)
# Judge status: Wrong Answer
C=[list(map(int,input().split())) for i in range(3)]
a=[min(C[i]) for i in range(3)]
b=[min(C[0][i],C[1][i],C[2][i]) for i in range(3)]
for i in range(3):
    for j in range(3):
        if C[i][j]!=a[i]+b[j]:
            print("No")
            exit()
print("Yes")
# Judge status: Accepted
N, M = [int(_) for _ in input().split()]

if N == M:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
#「与えられた数列の、広義単調減少列の長さの最大値 L」
from bisect import bisect_left, bisect_right
n = int(input())
INF = 1010101010
dp = [INF] * n
a = [int(input()) for _ in range(n)]
a.reverse()
for i in a:
    dp[bisect_right(dp, i)] = i
print(bisect_left(dp, INF))
# Judge status: Accepted
d, n = map(int, input().split())

ans = 0

if n == 100:
    print((n+1) * (100**d))
else:
    print(n * (100**d))
# Judge status: Wrong Answer
N,K=map(int,input().split())
h_list=list(map(int,input().split()))
dp=[0]*N
for i in range(1,N):
    dp[i]=float("inf")
    for j in range(1,min(i,K+1)+1):
        dp[i]=min(dp[i],dp[i-j]+abs(h_list[i-j]-h_list[i]))
print(dp[-1])
# Judge status: Accepted
with open(0) as f:
    C = ''.join(f.read().split())
print('YES' if C == C[::-1] else 'NO')
# Judge status: Accepted

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

MOD = 10 ** 9 + 7
count = [0] * (N + 1)
for i in range(1, N + 1):
    count[i] += count[i - 1] + i
    count[i] %= MOD

ans = 1
for k in range(K, N + 1):
    ans += count[-1] - count[-k - 1] - count[k - 1] + 1
    ans %= MOD
print(ans)
# Judge status: Accepted
N=int(input())
from collections import Counter
c=Counter([input() for i in range(N)]).most_common()
r=[]
V=c[0][1]
for k,v in c:
    if v!=V:
        break
    r.append(k)
print(*sorted(r),sep="\n")
# Judge status: Accepted
a,b = map(int,input().split())

temp = 0
dif = b - a

for i in range(1,1000):
    temp += i
    if i == dif:
        ans = temp - b
        print(ans)
        exit(0)
# Judge status: Accepted
# -*- coding: utf-8 -*-
"""
Created on Wed May 13 14:36:38 2020

@author: shinba
"""

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

if b + w < a:
    print(a-b-w)
elif a <= b+w <= a+w or a <= b <= a+w:
    print(0)
else:
    print(b-a-w)
# Judge status: Accepted
S = input()
print("Yes" if S[2] == S[3] and S[4] == S[5] else "No")
# Judge status: Accepted
n,k,*a=map(int,open(0).read().split())
print((n+k-3)//(k-1))
# Judge status: Accepted
if __name__ == '__main__':
	n = int(input())

	cnt = 0
	ans = 0
	for x in range(1,n+1,2):
		cnt = 0
		for y in range(1,x+1):
			if x % y == 0:
				cnt += 1
		if cnt == 8:
			ans += 1

	print(ans)
# Judge status: Accepted
n = int(input())
s = input()
count = 0
r = s.count('R')
g = s.count('G')
b = s.count('B')
for i in range(0,n-2):
    for j in range(i+1,n-1):
        if j < 2*j -i <= n-1 and sorted([s[i],s[j],s[2*j-i]]) == ['B','G','R']:
            count += 1
print(r*g*b - count)
# Judge status: Wrong Answer
n, a, b = map(int, input().split())
fst = (n - 1) * b + a
sec = (n - 1) * a + b
if a > b:
  print(0)
else:
  print(fst - sec + 1)
# Judge status: Wrong Answer
import copy 
N,K=map(int,(input().split()))
A=list(map(int,(input().split())))
B= [0 for _ in range(N)]

for _ in range(K):
  B= [0 for _ in range(N)]
  C=0
  for i in A:
    for j in range(C-i,C+i+1):
      try:
        if(j>=0):
          B[j]+=1
      except:
        pass
    C+=1
  A = copy.copy(B)
  
print(B)
# Judge status: Wrong Answer
N=int(input())
V=sorted(list(map(int,input().split())))
print(V)
while len(V)!=2:
    a=(V[0]+V[1])/2
    V.pop(0)
    V.pop(1)
    V.insert(0,a)
print((V[0]+V[1])/2)
# Judge status: Accepted
N=int(input())
X=list(map(int,input().split()))
re_X=int(round(sum(X)/N,0))
ans=0
for i in range(N):
    ans+=(X[i]-re_X)**2
print(ans)
# Judge status: Accepted
#scc puzzle
n,m=map(int,input().split())
#nがs,mがｃである
if 2*n>m:
    print(m//2)
else:

    print(n+((m-2*n)//4))
# Judge status: Accepted
def main():
    N = int(input())
    d = list(map(int, input().split()))
    difficulties = sorted(d)
    l = len(difficulties)//2 - 1
    r = len(difficulties)//2
    print(difficulties[r] - difficulties[l])
main()
# Judge status: Accepted
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


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

    print(N * (N - 1) // 2)


if __name__ == "__main__":
    main()
# Judge status: Accepted
def nCr(n, r):
  return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

x, y = map(int, input().split())
mod = 10 ** 9 +7
f = [1]
 
for i in range(10**6):
  f.append(f[-1] * (i+1) % mod)
  
if (x+y) % 3 != 0 or (x+y) // 3 < abs(x-y):
  print(0)
  exit()
  
n = (x+y)//3
r = n // 2 - abs(x-y) // 2
print(nCr(n, r))
# Judge status: Wrong Answer
import math
X=int(input())
ans=0
for i in range(1,X//2):
	for j in range(2,11):
		tmp=i**j
		if tmp<=X:
			ans=max(ans,tmp)
print(ans)
# Judge status: Accepted
n = int(input())
s = str(input())
t = int(n/2)

if n % 2 == 1:
    print("No")
    
else:
    for i in range(t):
        if s[i] != s[i+t]:
            print("No")
            exit()
        else:
            continue
    print("Yes")
# Judge status: Accepted
S=input()
Q=int(input())
Query=[input().split() for i in range(Q)]

m=1
A=[]
B=[]
for i in range(Q):
  if int(Query[i][0])==1:
    m*=-1
  else:
    
    if m*((-2*int(Query[i][1]))+3)==1:
      A.append(Query[i][2])
    else:
      B.append(Query[i][2])
if m==1:
  print(''.join(A)[::-1]+S+''.join(B))
else:
  print(''.join(B)[::-1]+S[::-1]+''.join(A))
# Judge status: Accepted
from sys import stdin
import fractions

N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) // 2 for x in stdin.readline().rstrip().split()]
ans = 0
g = 1

for i in range(len(A)):
    g = g * A[i] // fractions.gcd(g % A[i], A[i])
    if g > M:
        print(0)
        exit()

for i in range(len(A)):
    if (g // A[i]) % 2 == 0:
        print(0)
        exit()

ans = M // g
if ans % 2 == 0:
    print(ans // 2)
else:
    print((ans + 1) // 2)
# Judge status: Accepted
N=int(input())
Acquisition=[]

for i in range(N):
    S=input()
    Acquisition.append(S)

Acquisition_unique=list(set(Acquisition))
print(len(Acquisition_unique))
# Judge status: Accepted
import bisect
N,M,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ac = [0]*(N+1)
bc = [0]*(M)
bc[0] = b[0]
for i,val in enumerate(a):
    ac[i+1] = ac[i] + val
for i,val in enumerate(b[1:]):
    bc[i+1] = bc[i] + val
res = 0
for i,val in enumerate(ac):
    if val > K:
        break
    rest = K-val
    idx = bisect.bisect_right(bc, rest)
    if idx+i > res:
        res = idx+i
print(res)
# Judge status: Accepted
a = str(input())
if a =="Sunny":
    print("Cloudy")
if a =="Cloudy":
    print("Rainy")
if a =="Rainy":
    print("Sunny")
# Judge status: Accepted
from math import ceil
n, k = map(int, input().split())
a = list(map(int, input().split()))
print(ceil((n-1)/(k-1)))