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:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,a,b=nii()

min_v=a*(n-1)+b
max_v=b*(n-1)+a

print(max(0,max_v-min_v+1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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

Submission status: Accepted

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 A!=B and N==1:
    print(0)
elif N<=2:
    print(1)
else:
    MIN = A*(N-1)+B
    MAX = B*(N-1)+A
    print(MAX-MIN+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:
    totmin = A*(N-1)+B
    totmax = A+B*(N-1)
    print(totmax-totmin+1)

Submission status: Accepted

Solution code:
n,a,b = map(int,input().split())
#法則乱れ
if a > b:
  print(0)
elif (b-a+1) >= 2 and n == 1:
  print(0)
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(0)
    exit()
  else:
    print(1)
    exit()
if A>B:
  print(0)
  exit()
MIN = A*(N-1)+B
MAX = A+B*(N-1)
ans = MAX-MIN +1
print(ans)

Submission status: Accepted

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

if 0 < n < 2 and a != b:
    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 N==1:
    print(1*(A==B))
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 (n == 1 and a == b):
  ans = 1
elif (n == 1):
  ans = 0
elif 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())
if (n == 1 and a != b) or a > b:
    print(0)
else:
    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)
    exit()

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

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

Submission status: Accepted

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
print(ans)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, a, b = map(int, readline().split())
    ans = max(b * (n - 2) - a * (n - 2) + 1, 0)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
N, A, B = list(map(int, input().split()))
if A > B:
    print(0)
    sys.exit()
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 and a != b: 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)
    exit()
else:
    if N == 1:
        if A != B:
            print(0)
            exit()
        else:
            print(1)
            exit()
    else:
        # (N-1)*A+B以上 A+(N-1)*B以下の全ての値が可能
        ans = (N - 2) * (B - A) + 1
        print(ans)

Submission status: Accepted

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(max(ans,0))

Submission status: Accepted

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

if (A < B and N > 1) or (A==B):
  minimum_sum = A*(N-1) + B
  maximum_sum = A + B*(N-1)
  print(maximum_sum - minimum_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)
else:
    print(b*(n-1) + a - a*(n-1) - b + 1)

Submission status: Accepted

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

N,A,B = list(map(int,input().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:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, a, b = [int(x) for x in input().split()]
    print(max(0, ((n-1) * b + a) - ((n-1) * a + b) + 1))

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc015/tasks/agc015_a
# 最小と最大は必ず一つは存在するのか
n, a, b = map(int, input().split())
if b < a or (n == 1 and a != b):  # コーナーケース
    print(0)
    exit()
ma = b * (n - 1) + a
mi = a * (n - 1) + b
print((ma - mi + 1))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

Submission status: Accepted

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) +1
  if ans > 0:
    print(ans)
  else:
    print(0)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
if N < 1 or 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:
# ~10m AC
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
ans = max_s - min_s + 1
if ans < 0:
    ans = 0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,a,b = readInts()
if a > b:
    print(0)
else:
    if n == 1:
        if a != b:
            print(0)
        else:
            print(1)
    elif a == b:
        print(1)
    else:
        print((b * (n-1) + a) - ((a*(n-1)) + b) + 1)

Submission status: Accepted

Solution code:
import sys

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

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

if ma - mi + 1 < 0:
  print(0)
  sys.exit()

print(ma - mi + 1)

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n,a,b=MI()
if a>b:
    print(0)
    sys.exit()
if a!=b and n<2:
    print(0)
    sys.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())
X = A*(N-1)+B
Y = A+B*(N-1)
print(max(Y-X+1,0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, A, B = inm()


def solve():
    if A > B:
        return 0
    if N == 1:
        return 0 if A != B else 1
    a = A * (N - 1) + B
    b = B * (N - 1) + A
    return b - a + 1


print(solve())

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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 and a!=b:
    print(0)
    exit()
if a>b:
    print(0)
    exit()
mi=(n-1)*a+b
ma=(n-1)*b+a
print(ma-mi+1)

Submission status: Accepted

Solution code:
# vinegar that will do it!!!!!!!!!!!
 
 
N,A,B = map(int, input().split())
 
 

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[16]:


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


# In[27]:


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


# In[ ]:

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
n, a, b = [int(x) for x in input().split()]
val = max(0, (a + (n - 1) * b) - ((n - 1) * a + b) + 1)
print(val)

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n, a, b = tin()
	#s = input()
	if n == 1 and a != b:
		return 0
		
	if n == 1:
		return 1
		
	if a > b:
		return 0
	
	max_v = b * (n-1) + a
	min_v = b + a *(n-1)
	return max_v - min_v + 1


	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
if b < a or (a != b and n == 1):
    print(0)
    exit()
if a == b:
    print(1)
    exit()
_min = a*(n-1)+b
_max = a+b*(n-1)
ans = _max - _min + 1
print(ans)

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(A+B*(N-1)-(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)
elif A == B:
    print(1)
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())
if A > B:
    print(0)
elif A == B:
    print(1)
else:
    if N == 1:
        print(0)
    else:
        minimum = A*(N-1)+B
        maximum = B*(N-1)+A
        print(maximum-minimum+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((a+b*(n-1))-(a*(n-1)+b)+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

n = N-2 # Nの両端の間の数
C = 0 # 通り数

if (N == 1 and A != B) or B < A:
    C = 0
else:
    C = (B*n-A*n)+1
print(int(C))

Submission status: Accepted

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

Submission status: Accepted

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


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

    ans= s_b - s_a + 1

print(ans)

Submission status: Accepted

Solution code:
N, A, B = [int(x) for x in input().split()]
ans = max(0, (A + (N - 1) * B) - ((N - 1) * A + B) + 1)
print(ans)

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,a,b = map(int,ipt().split())
    if a > b:
        print(0)
    else:
        print(max(0,(n-2)*b-(n-2)*a+1))

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,a,b = list(map(int, input().split()))
if n == 1:
    if a==b:
        print(1)
    else:
        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: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

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

# corner case
if A>B:
    print(0)
elif N==1 and A!=B:
    print(0)
elif N==1 and A==B:
    print(1)
else:
    ans = (N-2)*(B-A) + 1
    print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())

n,a,b = readInts()
if n == 1 and not a == b:
    print(0)
elif a == b:
    print(1)
elif a > b:
    print(0)
else:
    wa = a+b
    m = wa + b*(n-2)
    i = wa + a*(n-2)
    print(m-i+1)

Submission status: Accepted

Solution code:
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter


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


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


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n, a, b = map(int, input().split())
if a > b:
    print(0)
    exit()
if n == 1 and not(a == b):
    print(0)
    exit()
if n == 1 and(a == b):
    print(1)
    exit()
max_x = b*(n-1)+a
min_x = a*(n-1)+b
print(max_x-min_x+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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()
    
m = B+A*(N-1)
M = A+B*(N-1)
print(max(0, M-m+1))

Submission status: Accepted

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

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


if __name__ == "__main__":
    print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = map(int, 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 A>B:
    print(0)
elif N==1 and A<B:
    print(0)
elif N==1 and A==B:
    print(1)
elif N==2:
    print(1)
else:
    print(A+B*(N-1)-(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()
if N == 1 and A == B:
    print(1)
    exit()
mx = A+B+B*(N-2)
mn = A+B+A*(N-2)
print(mx-mn+1)

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
#整数の数はb-a+1
#最小の１つと最大の1つを除いたn-2個について考える
if n==1 and a!=b:
    print(0)
    exit()
elif n==1 and a==b:
    print(1)
    exit()
elif a>b:
    print(0)
    exit()
elif a==b:
    print(1)
    exit()
m=a*(n-2)#最小
M=b*(n-2)#最大
ans=M-m+1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, A, B = MAP()

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

MIN = A*(N-1)+B
MAX = B*(N-1)+A

print(MAX - MIN + 1)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, A, B = MAP()

MIN = A*(N-1)+B
MAX = B*(N-1)+A

if MAX < MIN:
	print(0)
	exit()

print(MAX - MIN + 1)

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N, A, B = map(int, input().split())
    if N == 1 and A>B:
        print(0)
    else:
        mn=B+A*(N-1)
        mx=A+B*(N-1)
        print(max(mx-mn+1,0))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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