Problem:


Score : 200 points

Problem Statement

Snuke has N integers. Among them, the smallest is A, and the largest is B.
We are interested in the sum of those N integers. How many different possible sums there are?

Constraints

1 ≤ N,A,B ≤ 10^9

A and B are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of the different possible sums.

Sample Input 1

4 4 6

Sample Output 1

5

There are five possible sums: 18=4+4+4+6, 19=4+4+5+6, 20=4+5+5+6, 21=4+5+6+6 and 22=4+6+6+6.

Sample Input 2

5 4 3

Sample Output 2

0

Sample Input 3

1 7 10

Sample Output 3

0

Sample Input 4

1 3 3

Sample Output 4

1



Sample input:
4 4 6


Sample output:
5

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
if N < 2:
	print(0)
	exit()
if A > B:
	print(0)
	exit()
min = A + B + ((N - 2) * A)
max = A + B + ((N - 2) * B)
print(max - min + 1)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())

if n == 1:
    if a == b:
        print(1)
    else:
        print(0)
else:
    if a > b:
        print(0)
    else:
        print((n-2)*(b-1)+1)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
min_ab = (N-1)*A+B
max_ab = (N-1)*B+A
print(max_ab-min_ab+1)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
ans = 0
if n != 0 and a == b:
    ans = 1
elif n!=0 and b>a:
    ans = 1+(b-a)*(n-2)
print(ans)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
if N == 1 and A != B:
  print(0)
else:
  print((N-2)*(B-A)+1)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
mn = A * (N - 1) + B
mx = B * (N - 1) + A
print(mx - mn + 1)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
if a > b:
    print(0)
    exit()
if n == 1:
    print(0)
    exit()
if a == b:
    print(1)
    exit()
print((n-2)*b - (n-2)*a + 1)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())

if B < A:
  print(0)
elif N == 1 and A!= B:
  print(0)
elif N == 1 and A == B:
  print(1)
else:
  x = 1
  for i in range(B-A+1):
    x *= B-A+1-i
  print(x)

Submission status: Wrong Answer

Solution code:
n,a,b = map(int,input().split())
if n == 1 or a > b:
  print(0)
else:
  print(a+b*(n-1))

Submission status: Wrong Answer

Solution code:
N,A,B=map(int,input().split())

nin=A*(N-1)+B
nax=A+B*(N-1)

if N==1 or A>B:
    print(0)
    exit()
print(nax-nin+1)

Submission status: Wrong Answer

Solution code:
import sys
import math
N, A, B = map(int, input().split())

if A > B:
    print(0)
    sys.exit(0)
if N == 1:
    if A == B:
        print(1)
    else:
        print(0)
    sys.exit(0)

def combination(n, r):
    if n < r:
        return 0
    return int(math.factorial(n) / (math.factorial(r) * math.factorial(n - r)))

R = B-A+1
cnt = 2
cnt += combination(R, N-2)
print(cnt)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
if b<a:
  print(0)
  exit()
  
if a==b:
  print(1)
  exit()
  

n-=2

if n<0:
  print(0)

if n==0:
  print(1)

print(b*n-a*n+1)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
if b<a:
  print(0)
  exit()
  
if a==b:
  print(1)
  exit()
  

n-=2

print(b*n-a*n+1)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
if b<a:
  print(0)
  exit()
  
if a==b:
  print(1)
  exit()
  

print(1+(b-a)*(n-2))

Submission status: Wrong Answer

Solution code:
n,a,b = map(int,input().split())
k = a - b + n
ans = 1
for i in range(n):
  ans *= (k-i)
for i in range(n):
  ans  = ans//(n-i)
print(ans)

Submission status: Wrong Answer

Solution code:
n,a,b = map(int,input().split())
k = a - b + 2 + n
ans = 1
for i in range(n):
  ans *= (k-i)
for i in range(n):
  ans  = ans//(n-i)
print(ans)

Submission status: Wrong Answer

Solution code:
n,a,b = map(int,input().split())
k = a - b + 1 + n
ans = 1
for i in range(n):
  ans *= (k-i)
for i in range(n):
  ans  = ans//(n-i)
print(ans)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
fst = (n - 1) * b + a
sec = (n - 1) * a + b
if a > b:
  print(0)
elif n == 1 and a == b:
  print(0)
else:
  print(fst - sec + 1)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
fst = (n - 1) * b + a
sec = (n - 1) * a + b
print(fst - sec + 1)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
print(n * b - n * a + 1)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
print(b + b - a - a + 1)

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,a,b = I()

def pc(n, r):
    return math.factorial(n) // math.factorial(n - r)

if (n == 1) and (a == b):
    print(1)
    sys.exit()

if (n == 1) or (a > b):
    print(0)
    sys.exit()

if (n == 2) or (a == b):
    print(1)
    sys.exit()

print(pc(b-a+1,n-2)//2+(b-a+1)-(b-a+1)//2)




"""
n = k()
s = v()

def check(n):
    if 

#コマンドの種類
comand = ["A","B","X","Y"]
p = list(itertools.permutations(comand,2))
for i in range(len(p)):
    p[i] = "".join(p[i])

for i in 
"""

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())

if a > b:
    print(0)
elif n == 1 and a != b:
    print(0)
elif n != 1 and a == b:
    print(0)
else:
    print((b * (n-1) + a) - (a * (n-1) + b) + 1)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())

if a > b:
    print(0)
elif a != b and n == 1:
    print(0)
elif a == b and n != 1:
    print(0)
elif n == 2:
    print(1)
else:
    print((b * (n-1) + a) - (a * (n-1) + b) + 1)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())

if a > b:
    print(0)
elif a != b and n == 1:
    print(0)
elif a == b and n != 1:
    print(0)
else:
    print((b * (n-1) + a) - (a * (n-1) + b) + 1)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())

if b-a+1 > n:
    print(0)
elif a > b:
    print(0)
elif a == b:
    print(1)
else:
    print(b*3-a*3-1)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())
if a > b:
	print(0)
else:
	print((n - 2) * (b - a) + 1)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, input().split())

if n == 1 and a != b:
    ans = 0
else:
    ans = (b * (n - 1) + a) - (a * (n - 1) + b)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, A, B = MAP()

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

print(ans)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())

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

print(ans)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())

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

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())

ans = (N - 2) * B - (N - 2) * A + 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,A,B = map(int,input().split())
if A > B:
    print(0)
if N == 1:
    if A != B:
        print(0)
    else:
        print(1)
else:
    print((B*(N-1)+A)-(A*(N-1)+B)+1)

Submission status: Wrong Answer

Solution code:
N,A,B = map(int,input().split())
if N == 1:
    if A != B:
        print(0)
    else:
        print(1)
else:
    print((B*(N-1)+A)-(A*(N-1)+B)+1)

Submission status: Wrong Answer

Solution code:
N,A,B = map(int,input().split())
if A>B:
  print(0)
elif N == 1:
  print(0)
elif A==B:
  print(1)
else:
  ans = 0
  C = (B-A+1)
  for i in range(N-2):
    ans += C
    C -= 1
  print(ans)

Submission status: Wrong Answer

Solution code:
N,A,B = map(int,input().split())

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

Submission status: Wrong Answer

Solution code:
N,A,B=map(int,input().split())

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

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())

if A>B or N==0:
    print(0)
    exit()
if A==B:
    print(1)
    exit()
if N==1:
    print(0)
    exit()

print((B-A+1)*2-1)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())

if A>B or N==0:
    print(0)
    exit()
if A==B:
    print(1)
    exit()
if N==1:
    print(0)
    exit()
print((B-A)*2+1)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
a_=a+b*(n-1)
b_=a*(n-1)+b
if n==1 and a!=b:
  print(0)
else:
  print(a_-b_+1)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
a_=a+b*(n-1)
b_=a*(n-1)+b
print(a_-b_+1)

Submission status: Wrong Answer

Solution code:
def main():
  N, A, B = map(int, input().split())

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

  print(ans)

main()

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())

if a==b:
  print(1)
elif n==1:
  print(0)
elif n==2:
  print(2)
else:
  print((b-a)*(n-2)+1)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())

if A > B:
  print(0)
  exit()

if A == B:
  if N == 1:
    print(1)
    exit()
  else:
    print(0)
    exit()

print((N-2)*(B-A)+1)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
if A > B:
  print(0)
elif A == B:
  print(1)
elif B-A >=N:
  print(0)
else: 
  print((B-A)*(N-2)+1)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
if N == 1 and A != B:
  print(0)
elif N == 1 and A == B:
  print(1)
else:
  X = N-B+A  
  print((B-A)*X+1)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
if A > B:
  print(0)
elif A == B:
  print(1)
elif B-A >=N:
  print(0)
else:
  X = N-B+A  
  print((B-A)*X+1)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
if A > B:
  print(0)
elif A == B:
  print(1)
elif B-A >N:
  print(0)
else:
  X = N-B+A  
  print((B-A)*X+1)

Submission status: Wrong Answer

Solution code:
# AtCoder Grand Contest 015
# A - A+...+B Problem

import math

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

if B<A or ( N==1 and A!=B):
    print(0)
    exit()

if B==A:
    print(1)
    exit()

c=math.factorial(B-A+N-1)/math.factorial(N)
print(int(c))

Submission status: Wrong Answer

Solution code:
import sys
N,A,B=map(int,input().split())
if N==1:
  print(0)
  sys.exit()
if N==2:
  print(1)
  sys.exit()
if A>B:
  print(0)
  sys.exit()
print(B*(N-1)+A-(A*(N-1)+B)+1)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())

if A > B:
  print(0)
  exit()

if N == 1:
  if A != B:
    print(0)
  else:
    print(1)
else:
  print((N-2) * (B - A + 1) - 1)

Submission status: Wrong Answer

Solution code:
import sys
import math
input = lambda: sys.stdin.readline().rstrip()

def comb(a, b):
    return math.factorial(a)//(math.factorial(b)*math.factorial(a-b))

def main():
    n, a, b = map(int, input().split())
    if (a > b) or (n==1 and a<b):
        print(0)
    elif n == 1 and a == b:
        print(1)
    else:
        print(comb(b-a+n, n) - comb(b-a+n-1, n) * 2)
            
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
input = lambda: sys.stdin.readline().rstrip()

def comb(a, b):
    return math.factorial(a)//(math.factorial(b)*math.factorial(a-b))

def main():
    n, a, b = map(int, input().split())
    if a > b or (n==1 and a<b):
        print(0)
    elif a == b:
        print(1)
    else:
        print(comb(b-a+n, n) - comb(b-a+n-1, n) * 2)
            
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B = mapint()
if B<A:
    print(0)
elif N<=2:
    print(1)
else:
    MIN = A*(N-1)+B
    MAX = A+B*(N-1)
    print(MAX-MIN+1)

Submission status: Wrong Answer

Solution code:
N,A,B = map(int,input().split())
totmin = A*(N-1)+B
totmax = A+B*(N-1)
print(totmax-totmin+1)

Submission status: Wrong Answer

Solution code:
n,a,b = map(int,input().split())
#法則乱れ
if a > b:
  print(0)
elif n == 1:
  print(0)
else:
  print((b-a)*(n-2)+1)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())

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

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
if A>B:
    print(0)
    exit()
ans = (B*(N-1)+A) - (A*(N-1)+B) + 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
if A>=B:
    print(0)
    exit()
ans = (B*(N-1)+A) - (A*(N-1)+B) + 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
if A>B:
    A,B = B,A
ans = (B*(N-1)+A) - (A*(N-1)+B) + 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,A,B = map(int, input().split())

if (A < B and N > 1) or (A==B and N==1):
  minimum_sum = A*(N-1) + B
  maximum_sum = A + B*(N-1)
  print(maximum_sum - minimum_sum + 1)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n,a,b = map(int, input().split())
    minN = a+ b+ (n-2)*a
    maxN = a+ b+ (n-2)*b
    print(maxN-minN+1)

Submission status: Wrong Answer

Solution code:
N,A,B=map(int,input().split())
if A>B:
    print(0)
elif A==B:
    print(1)
else:
    if N==1:
        print(0)
    else:
        print((B*N-A*N)+1)

Submission status: Wrong Answer

Solution code:
N,A,B=map(int,input().split())
if A>B:
    print(0)
elif A==B:
    print(1)
else:
    if N==1:
        print(0)
    else:
        print((B-A+1)+(B-A))

Submission status: Wrong Answer

Solution code:
N, A, B = map(int,input().split())


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

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
if N < 1 or A > B:
  print(0)
else:
  print(B * (N - 1) + A - A * (N - 1) - B + 1)

Submission status: Wrong Answer

Solution code:
N, A, B = map(int, input().split())
print(B * (N - 1) + A - A * (N - 1) - B + 1)

Submission status: Wrong Answer

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, a, b = LI()

min_s = a * (n - 1) + b
max_s = a + (n - 1) * b
print(f'{min_s=}, {max_s=}')
ans = max_s - min_s + 1
if ans < 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
ma=b*(n-1)+a
mi=a*(n-1)+b
print(ma-mi+1)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
if n==1 and a!=b:
    print(0)
    exit()
mi=(n-1)*a+b
ma=(n-1)*b+a
print(ma-mi+1)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
ans=0
if a>b or n==1:
  ans=0
elif a==b:
  ans=1
else:
  ans=(n-2)*(b-a)+1
print(ans)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
ans=0
if a>b or n==0:
  ans=0
elif a==b:
  ans=1
else:
  ans=(n-2)*(b-a)+1
print(ans)

Submission status: Wrong Answer

Solution code:
N,A,B = map(int,input().split())
check = B - A + 1
loop = N - 2
if check < loop:
  loop = check
if B < A or (N == 1 and A != B):
  print(0)
  exit(0)
elif N == 1 or N ==2:
  print(1)
  exit(0)

if loop % 2 == 0:
  ans = (check + check - loop +1)*(loop/2)
elif loop % 2 == 1:
  ans = (check + check - loop+1)*((loop-1)/2)+check -(loop -1)/2
  
print(int(ans))

Submission status: Wrong Answer

Solution code:
N,A,B = map(int,input().split())
check = B - A + 1
loop = N - 2
if check < loop:
  loop = check
if B < A or (N == 1 and A != B):
  print(0)
  exit(0)
elif N == 1:
  print(1)
  exit(0)

if loop % 2 == 0:
  ans = (check + check - loop +1)*(loop/2)
elif loop % 2 == 1:
  ans = (check + check - loop+1)*((loop-1)/2)+check -(loop -1)/2
  
print(int(ans))

Submission status: Wrong Answer

Solution code:
N,A,B = map(int,input().split())
check = B - A + 1
loop = N - 2
if B < A or (N == 1 and A != B):
  print(0)
  exit(0)
elif N == 1:
  print(1)
  exit(0)

if loop % 2 == 0:
  ans = (check + check - loop +1)*(loop/2)
else:
  ans = (check + check - loop+1)*((loop-1)/2)+check -(loop -1)/2
  
print(ans)

Submission status: Wrong Answer

Solution code:
N,A,B = map(int,input().split())
check = B - A + 1
loop = N - 2
if B < A or (N == 1 and A != B):
  print(0)
  exit(0)
elif N == 1:
  print(1)
  exit(0)
ans = 0
for i in range(loop):
  ans += check - i
if loop % 2 == 0:
  ans = (check + check - loop +1)*(loop/2)
else:
  ans = (check + check - loop+1)*((loop-1)/2)+check -(loop +1)/2
  
print(ans)

Submission status: Wrong Answer

Solution code:
n,a,b = list(map(int, input().split()))
if n == 1:
    print(0)
elif a>b:
    print(0)
else:
    MIN = a * (n-1) + b
    MAX = a * 1 + b * (n-1)
    print(MAX-MIN+1)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
if (b-a+1)>n or a>b:exit(print(0))
mi=b+(n-1)*a
ma=a+(n-1)*b
print(ma-mi+1)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
ans=b*(n-1)+a-a*(n-1)-b
if ans<=0:
  print(0)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

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

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

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,A,B = IL()
if A <= B:
  print((A+B*(N-1))-(B+A*(N-1))+1)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

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

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

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,A,B = IL()
if N != 1:
  print((A+B*(N-1))-(B+A*(N-1))+1)
else:
  if A!= B:
    print(0)
  else:
    print(1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

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

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

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,A,B = IL()
if N != 1:
  print((A+B*(N-1))-(B+A*(N-1))+1)
else:
  if A!= B:
    print(-1)
  else:
    print(N*A)