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: Accepted

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

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

Submission status: Accepted

Solution code:
def a():return input()#s
def ai():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y
k= []
l = []
f = 0
def say(i):return print("Yes" if i == 0 else "No")
def Say(i):return print("YES" if i == 0 else "NO")

a,b,c = ma()
if c<b:print(0)
elif a==1 and b!=c:print(0)
else:
    print((a-2)*c-(a-2)*b+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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(B * (N - 2) - A * (N - 2) + 1)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

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


def main():
    """Function."""
    n, a, b = map(int, input().split())

    if a > b:
        print(0)

    elif n == 1:
        if a == b:
            print(1)
        else:
            print(0)

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
# 自明な条件 
if A > B or (N == 1 and A != B):
    print(0)
    exit()
print((N-2)*(B-A) + 1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n, a, b = [int(i) for i in input().split()]

print(max(0, (b*(n-2)) - a*(n-2) + 1))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = [int(_) for _ in input().split()]
ans = 0
if N == 1 or A == B:
    ans += A == B
elif N == 2:
    ans = 2 * (A < B)
elif B > A:
    ans = (N - 2) * (B - A) + 1
print(ans)

Submission status: Accepted

Solution code:
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def next_int() -> int:
    return int(next_str())


def main() -> None:
    n = next_int()
    a = next_int()
    b = next_int()
    print(max(0, (b - a) * (n - 2) + 1))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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(1)
else:
    print((n-2)*b - (n-2)*a +1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
if 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: Accepted

Solution code:
n,a,b=[int(i) for i in input().split()]
if a>b or (a!=b and n==1):
    print(0)
else:
    maxt=b*(n-1)+a
    mint=a*(n-1)+b
    print(maxt-mint+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


margin = B - A
if N == 1 and margin >0:
    print(0)
    exit()


if margin < 0:
    print(0)
    exit()
elif margin == 0:
    print(1)
    exit()


print(margin * (N-2) + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

    print(maxS - minS+1)

Submission status: Accepted

Solution code:
[n,a,b] = [int(i) for i in input().split()]
c = 1
#aの方が小さい場合
if a > b:
    c = 0
#nが1なのにaとbが等しくない場合
if n == 1 and a != b:
    c = 0
#nが1でaとbが等しい場合
if n == 1 and a == b:
    c = -1

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

Submission status: Accepted

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

if n == 1:
    if a != b:
        print(0)

    elif a == b:
        print(1)

    exit(0)

if a > b:
    print(0)
    exit(0)

num = n - (b - a)

count = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,A,B = inpl()

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

Submission status: Accepted

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

mx = A + (N-1)*B
mn = B + (N-1)*A
print(mx - mn + 1)

Submission status: Accepted

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

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

Submission status: Accepted

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

def judge(a: int, b: int, n: int) -> int:
    if b < a:
        return 0
    elif n == 1 and a != b:
        return 0
    elif n == 1:
        return 1
    else:
        return (b * (n-1) + a) - (a * (n-1) + b) + 1
    
print(judge(a,b,n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B = (int(i) for i in input().split())

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

print(ans)

Submission status: Accepted

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

souwa_saisyou = a + b + a * (n - 2)
souwa_saidai =  a + b + b * (n - 2)


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

Submission status: Accepted

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

Submission status: Accepted

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

def func(n, a, b):
    if n < 2:
        if (n == 1) and (a == b):
            return 1
        else:
            return 0
    if a > b:
        return 0
    return 1 + (n - 2) * (b - a)

print(func(n, a, b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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((n-2)*b - (n-2)*a + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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((b-a)*(n-2)+1)

Submission status: Accepted

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

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

Submission status: Accepted

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

if N==1 and A!=B:
  print(0)
elif A>B:
  print(0)
elif N==2 or A==B:
  print(1)
else:
  mi=A*(N-1)+B
  ma=B*(N-1)+A
  print(ma-mi+1)

Submission status: Accepted

Solution code:
N, A, B = [int(_) for _ in input().split()]

vmin = A * (N - 1) + B
vmax = A + B * (N - 1)

result = vmax - vmin + 1

if result < 0:
    result = 0
    
print(result)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if a > b:
	print(0)

else:
	if n == 1:
		if a == b:
			print(1)
		else:
			print(0)

	elif n == 2:
		print(1)

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

Submission status: Accepted

Solution code:
import sys

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

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



print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if N==2:
    print (1)
    sys.exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def a_plus_problem(N, A, B):
    if A > B:
        return 0  # 最小がA,最大がBであることと矛盾
    if N == 1:  # 最小と最大が一致していれば1通り、していなければ矛盾
        if A == B:
            return 1
        else:
            return 0
    # 区間[A,B]からN-2個選ぶ。区間[(N-1)A+B,A+(N-1)B]内の数はすべて作れる
    return (B - A) * (N - 2) + 1

N, A, B = [int(i) for i in input().split()]
print(a_plus_problem(N, A, B))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

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

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

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

max_ = A + (N-1)*B
min_ = A*(N-1) + B

print(max_ - min_ + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N,A,B = [int(i) for i in input().split()]

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

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

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
minnum = A * (N - 1) + B
maxnum = B * (N - 1) + A
key = maxnum - minnum + 1
if key < 0:
    key = 0
print(key)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def lii():
    return list(map(int, input().split(' ')))

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

Submission status: Accepted

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

# AtCoder Grand Contest
# Problem A


if __name__ == '__main__':
    n, a, b = list(map(int, input().split()))
    print(max((b - a) * (n - 2) + 1, 0))

Submission status: Accepted

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

# AtCoder Grand Contest
# Problem A


if __name__ == '__main__':
    n, a, b = list(map(int, input().split()))
    min_value = a * (n - 1) + b
    max_value = a + b * (n - 1)

    print(max(max_value - min_value + 1, 0))

Submission status: Accepted

Solution code:
tmp = list(map(int,input().split()))
n , a, b = tmp[0],tmp[1],tmp[2]
if a>b:
 print(0)
 quit()
if (n ==2):
  print(1)
elif (n == 1):
  if a != b:
    print(0)
  else:
    print(1)
else:
  print((b-a) * (n-2) + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n, a, b = map(int, input().split())
    mi = a * (n - 1) + b
    ma = a + b * (n - 1)
    res = ma - mi + 1
    res = max(0, res)
    print(res)

main()

Submission status: Accepted

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

    _min = (N - 1) * A + B
    _max = (N - 1) * B + A
    ans = max(_max - _min + 1, 0)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


n,a,b=map(int,input().split())
if(b<a):print(0)
elif(b==a):print(1)
else:
    if(n==1):print(0)
    elif(n==2):print(1)
    else:
        num=((n-1)*b+a)-((n-1)*a+b)+1
        print(num)

Submission status: Accepted

Solution code:
n,a,b = (int(i) for i in input().split())
if n==1 and a!=b: answer = 0
elif n==1 and a==b: answer = 1
elif n!=1 and a>b: answer = 0
elif n!=1:
	x,y = a*(n-1)+b,a+b*(n-1)
	answer = (y-x+1)
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

lo = A * (N-1) + B
hi = B * (N-1) + A
print(max(0, hi - lo + 1))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
line = input().split(" ")
a = list(map(int, line))
ans = 0
if a[0] == 1 and a[1] != a[2]:
    ans = 0
elif a[0] == 1 and a[1] == a[2]:
    ans = 1
elif a[1] > a[2]:
    ans = 0
else:
    ans = (a[0] - 2) * (a[2] - a[1]) + 1
print(ans)

Submission status: Accepted

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

if n==1 and a!=b:
    print(0)
    exit()
elif n==1 and a==b:
    print(1)
    exit()

if b<a:
    print(0)
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/ust/bin/env python

N,A,B=[int(i) for i in input().split()]

def main():
    if(A>B):
        print(0)
        return
    elif(A==B):
        print(1)
        return

    ### A<B
    Max=(A+B)+(N-2)*B
    Min=(A+B)+(N-2)*A

    if(N==1):
        print(0)
    elif(N==2):
        print((B+B)-(A+A)+1)
    elif(Max-Min+1<=0):
        print(0)
    else:
        print(Max-Min+1)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = [int(x) for x in raw_input().split()]
print max((b - a + 1) * (n - 2) - (n - 3), 0)
		#^^THIS IS LENGTH OF [a, ..., a, a+1, ..., b]
							  #^^THIS IS THE PART WHICH IS UNAVAILABLE

Submission status: Accepted

Solution code:
n, a, b = map(int, raw_input().split())
print max((n - 2) * (b - a) + 1, 0)

Submission status: Accepted

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((B - A) * (N - 2) + 1)
    else:
        print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    N, A, B = map(int, input().split())
    print(max(((N - 1) * B + A) - ((N - 1) * A + B) + 1, 0))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def a_plus_b():
	n, a, b = map(int, raw_input().split(" "))
	if a>b:
		print 0
		return
	if n==1:
		if a==b:
			print 1
		else:
			print 0
		return
	min_sum = a*(n-1)+b
	max_sum = b*(n-1)+a
	print max_sum-min_sum+1


if __name__ == "__main__":
	a_plus_b()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N,A,B = map(int, input().split())
ans = (N-2) * (B-A) + 1
if ans <= 0:
   print(0)
else:
   print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np
from math import *
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()

    [N, A, B] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    result = (B-A)*(N-2) + 1
    if result < 0:
        result = 0

    print result

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,A,B=map(lambda x:int(x) , raw_input().split(' '))

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

Submission status: Accepted

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

z = (n - 2) * (b - a) + 1

if z < 0:
    print("0")
elif z == 0:
    print("1")
else:
    print(z)

Submission status: Accepted

Solution code:
import fileinput

iterator = fileinput.input()

n, a, b = map(int, iterator.next().split())

def compute(n, a, b):
    # edge cases
    if n == 0:
        return 0
    if n == 1:
        if a == b:
            return 1
        else:
            return 0
    if a > b:
        return 0

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

print compute(n, a, b)

Submission status: Accepted

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