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

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:
N,A,B=map(int,input().split())
ans=(A+B*(N-1))-(A*(N-1)+B)+1
print(ans if ans>=0 else 0)

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#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 n == 1 and a != b:
    print(0)
elif n == 1 and a == b:
    print(1)
    
else:
    print(result)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
print(0 if N == 1 and A != B else max(0, max(0, 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:
    print(1)
elif n==2:
    print(1)
else:
    if a==b:
        print(1)
    else:
        n-=2
        print((b-a)*n+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)
elif n == 2:
    print(1)
else:
    # min = a*n +b-a max = b*n + a -b までを全て取れる。
    print(1 + (b - a) * (n - 2))

Submission status: Accepted

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

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

print(max(0, 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)
elif n == 1 and a != b:
    print(0)
else:
    min_num = a * (n - 2)
    max_num = b * (n - 2)
    print(max_num - min_num + 1)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, A, B = [int(x) for x in input().split()]

    if A > B:
        print(0)
        return
    if N == 1 and A != B:
        print(0)
        return

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

    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n, a, b = list(map(int, input().split()))
    if (n == 1 and a != b) or (b < a):
        print(0)
        exit()
    mini = a * (n - 1) + b
    maxi = a + b * (n - 1)
    print(maxi - mini + 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,A,B = map(int, input().split())
if A > B or (A != B and N == 1):
    print(0)
else:
    N -= 2
    print(N*(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 A>B:
    print(0)
  else:
    n=N-2
    ans=n*B-n*A+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)
  exit()
print((b-a)*(n-2)+1)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N, A, B = [int(x) for x in input().strip().split()]
    if N == 1 and A != B:
        print(0)
        return
    elif A > B:
        print(0)
        return
    print((B * (N - 1) + A) - (B + A * (N - 1)) + 1)

if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

if N == 1:
    if diff != 0:
        print(0)
    else:
        print(1)
else:
    if diff < 0:
        print(0)
    elif diff == 0:
        print(1)
    else:
        max_val = B * (N-1) + A
        min_val = A * (N-1) + B
        print(max_val - min_val + 1)

Submission status: Accepted

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

x = b*(a-1)+c
y = c*(a-1)+b

print(max(0,y-x+1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
#sys.stdin = open("input.txt", "r")
#sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)



n,A,B=l()

mnn=A*(n-1)+B
mxx=A+B*(n-1)
print(max(mxx-mnn+1,0))

Submission status: Accepted

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

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

    print(max_sum - min_sum + 1)

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,A,B = LI()
if A>B:
    print(0)
    exit()
if N==1:
    print(1 if A==B else 0)
    exit()
print((N-2)*(B-A)+1)

Submission status: Accepted

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

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

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:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

if max_value >= min_value:
    print(max_value - min_value + 1)
else:
    print(0)

Submission status: Accepted

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

if a > b:
    ans = 0
elif a != b and n == 1:
    ans = 0

print(ans)

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:
n, a, b = map(int, input().split())
mx = a+(n-1)*b
mn = b+(n-1)*a
print(max(0, mx-mn+1))

Submission status: Accepted

Solution code:
import itertools

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

N, A, B = map(int, sys.stdin.readline().strip().split())

min_sum = A*(N-1) + B
max_sum = B*(N-1) + A
print(max(0, max_sum - min_sum + 1))

Submission status: Accepted

Solution code:
N, A, B = list(map(int,input().split()))
if (B * (N-1) + A) - (B + (N-1) * A) < 0:
  print(0)
elif A == B:
  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())

ans = 0
if n >= 2 and a <= b:
    lst_min = a * (n - 1) + b
    lst_max = a + b * (n - 1)
    
    ans = lst_max - lst_min + 1

elif n == 1 and a == b:
    ans = 1

print(ans)

Submission status: Accepted

Solution code:
# A - A+...+B Problem
# https://atcoder.jp/contests/agc015/tasks/agc015_a

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
import sys
from functools import reduce
import math

input = sys.stdin.readline


def main():
    n, a, b = input_list()
    if a > b:
        print(0)
        exit(0)
    if n == 1 and a != b:
        print(0)
        exit(0)
    if n == 1 and a == b:
        print(1)
        exit(0)
    min_num = (a*(n-1))+b
    max_num = (b*(n-1))+a
    print(max_num-min_num+1)


def get_camulative(l):
    import itertools
    # 累積和
    return [0] + list(itertools.accumulate(l))

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


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


if __name__ == "__main__":
    main()

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:
import itertools

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,a,b = map(int, input().split())
if n == 1 and abs(a-b) + 1 != n: print(0)
elif 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())
print(max((N-1)*B+A-(N-1)*A-B+1,0))

Submission status: Accepted

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

ans_min = B + A * (N - 1)
ans_max = B * (N - 1) + A

ans = max(0, ans_max - ans_min + 1)

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

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

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

if N==1 and A!=B:
    print(0)
    exit()
    
low = A+B+(N-2)*A
high = A+B+(N-2)*B
print(high-low+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = list(map(int,input().split()))
M = (N[2] - N[1]) * (N[0] - 2) + 1
if N[0] == 1 and N[1] == N[2]:
    print(1)
elif N[0] == 1:
    print(0)
elif N[0] == 2:
    print(1)
elif N[1] > N[2]:
    print(0)
else:
    print(M)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if max_num - min_num + 1 >= 0:
    print(max_num - min_num + 1)
else:
    print(0)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def read():
    N, A, B = map(int, input().strip().split())
    return N, A, B


def solve(N, A, B):
    low = (N-1) * A + B - 1
    high = A + (N-1) * B
    return max(high - low, 0)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    import itertools
    n,a,b=map(int, input().split())
    if n==1 and a==b:
        print(1)
    elif n==1 and a!=b:
        print(0)
    elif b<a:
        print(0)
    else:
        print((a+(n-1)*b)-((n-1)*a+b)+1)
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,A,B=MI()
    N-=1
    print(max(0,B*N+A-(A*N+B)+1))
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

min_sum = 0

min_sum = a*(n-1) + b
max_sum = b*(n-1) + a

print(max(0,max_sum-min_sum+1))

Submission status: Accepted

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

am = N - 2
# 最小
minv = A + B + am*A
# 最大
maxv = A + B + am*B
print(maxv - minv + 1)

Submission status: Accepted

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

max_sum = b*(n-1)+a
min_sum = a*(n-1)+b

if max_sum - min_sum >= 0:
    print(max_sum - min_sum + 1)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def answer(n, a, b):
    if (a > b): return 0
    if n == 1 and a != b: return 0
    n = n-2
    small = a*n
    big = b*n
    return big - small + 1

n, a, b = map(int, input().split())
print(answer(n, a, b))

Submission status: Accepted

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

small = A * N + (B - A)
big = B * N - (B - A)
ans = big - small + 1

print(ans if ans > 0 else 0)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,a,b=[int(_) for _ in input().split()]
if n==1:
  if a==b:
    print(1)
  else:
    print(0)
  exit()
print(max(0,(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)
elif a > b:
    print(0)
else:
    print((b-a)*(n-2)+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 - 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(0)
    else:
        print(1)
else:
    print(((N - 1) * B + A) - ((N - 1) * A + B) + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
if n == 1:
	if a != b:
		print (0)
	else:
		print (1)
else:
	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 (0)
	else:
		print (1)
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 n == 1:
	if a != b:
		print (0)
	else:
		print (1)
elif a > b:
	print (0)
else:
	mn = a + b + (n-2)*a
	mx = a + b + (n-2)*b
	print (mx-mn+1)

Submission status: Accepted

Solution code:
# A - A+...+B Problem

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

Submission status: Accepted

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

Submission status: Accepted

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

left = A*(N-1)+B
right = A + (N-1)*B
print(max(0,right-left+1))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, a, b = ns()

    if n == 2:
        print(1)
        exit(0)

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

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

    minimum_sum = a * n + (b - a)
    maximum_sum = b * n - (b - a)
    print(maximum_sum - minimum_sum + 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n,a,b=map(int, input().split())
pot = b-a+1
if(b<a):
    print(0)
    exit()
if n==0:
    print(0)
elif n==1:
    if a==b:
        print(1)
    else:print(0)
elif n==2:
    if a==b:print(1)
    print(1)
else:
    k = n-1
    m = k*b
    high = m+a
    low = a*k + b
    print(high-low+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ma = A + B * (N - 1)
mi = B + A * (N - 1)

if ma < mi:
    print(0)
elif ma==mi:
    print(1)
else:
    print(ma - mi + 1)

Submission status: Accepted

Solution code:
import numpy as np
import math
import scipy
import itertools

def solve():
    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*(n-1)+a)-(a*(n-1)+b)+1)
    return 0

if __name__ == "__main__":
    solve()

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:
    ans = (B * (N - 1) + A) - (A * (N - 1) + B) + 1
    print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

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

if a==b:
    print(1)
    exit()

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

mi = a*(n-1)+b
ma = a+b*(n-1)

print(ma-mi+1)

Submission status: Accepted

Solution code:
def main(n: int, a: int, b: int):
    if a > b:
        print(0)
        return

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

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

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


if __name__ == "__main__":
    n, a, b = map(int, input().split())

    main(n, a, b)