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

c = a*(n-1) + b
d = a + b*(n-1)

print(max(d-c+1, 0))

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:
n,a,b = map(int,input().split())

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
n,a,b = [int(x) for x in stdin.readline().rstrip().split()]

saisyou = a*(n-1)+b
saidai = b*(n-1)+a

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

Submission status: Accepted

Solution code:
# AGC015a
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# よくよくサンプル1をみたら1ずつインクリメントするので
n, a, b = map(int, input().split())
mins = b + a * (n - 1)
maxs = a + b * (n - 1)
print(max(0, maxs - mins + 1))

Submission status: Accepted

Solution code:
import sys

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

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

maximum = (a+b) + b*(n-2)
minimum = (a+b) + a*(n-2)

print(maximum-minimum+1)

Submission status: Accepted

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

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

if Max-Min+1<1:
    print(0)
else:
    print(Max-Min+1)

Submission status: Accepted

Solution code:
#coding:utf-8
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 ((n-2)*(b-a)+1)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, a, b = LI()
    print(max(b * n + a - b - (a * n - a + b - 1),0))
    return


#main
if __name__ == '__main__':
    solve()

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

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

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
c,d=a*(n-1)+b,a+b*(n-1)
print(max(d-c+1,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:
    maximum = b * (n - 1) + a
    minimum = a * (n - 1) + b
    print(maximum-minimum + 1)

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:
    answer = 0
elif N == 1:
    if A != B:
        answer = 0
    else:
        answer = 1
else:
    x = A * (N-1) + B
    y = A + B * (N-1)
    answer = y - x + 1

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import os
if sys.platform=="darwin":
   base = os.path.dirname(os.path.abspath(__file__))
   name = os.path.normpath(os.path.join(base, '../Documents/input.txt'))
   #print(name)
   sys.stdin = open(name)

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

Submission status: Accepted

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

if a>b:
	ans=0
elif b-a > 1 and n==1:
	ans=0	
else:
	mini= a*(n-1)+b
	maxi= a+(n-1)*b
	ans=maxi-mini+1
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:
    if A > B:
        print(0)
    elif A == B:
        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())
print(max(0,(N-2)*(B-A)+1))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: int, B: int):
    if A > B :
        print(0)
    
    elif N == 1 and A == B:
        print(1)
    
    elif N == 1 and A < B:
        print(0)

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

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
import scipy as sp

def main():
    # parse
    N, A, B = parse(get_stdin())
    # compute
    result = compute(N, A, B)
    # show result
    print(result)

def compute(N, A, B):
    if N == 0:
        return 0
    if N == 1:
        if A == B:
            return 1
        else:
            return 0
    if A > B:
        return 0
    x = B - A
    n = N - 2
    return x * n + 1

def get_stdin():
    return input()

def split_stdin(stdin_val, delimiter = ' '):
    return [x for x in stdin_val.split(delimiter) if x != '']

def parse(stdin_vars):
    vars = split_stdin(stdin_vars)
    return int(vars[0]), int(vars[1]), int(vars[2])

if __name__ == "__main__":
    main()

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
# 答えは[Aが(N-1)個+Bが1個]と[Bが(N-1)個+Aが1個]の間にある整数すべて。これを式変換。
print(max((B-A)*(N-2)+1,0))

Submission status: Accepted

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

Submission status: Accepted

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

maxi=(N-1)*B + A
mini=(N-1)*A + B

ans = maxi - mini +1

print(max(ans,0))

Submission status: Accepted

Solution code:
#AGC015 A - A+...+B Problem
n,a,b = map(int,input().split())
ans = 0
if n==1:
    if a==b:
        ans=1
    else:
        ans=0
else:
    if b>a:
        num_min = (n-2)*a+a+b
        num_max = (n-2)*b+a+b
        ans = num_max-num_min+1
    elif b<a:
        ans=0
    elif a==b:
        ans=1
print(ans)

Submission status: Accepted

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

if x <= 0:
    print(0)
else:
    print(x)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 2019-11-22 16:25:33(JST)
import sys


def main():
    n, a, b = [int(x) for x in sys.stdin.readline().split()]


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# 2019-11-22 16:25:33(JST)
import sys


def main():
    n, a, b = [int(x) for x in sys.stdin.readline().split()]

    min_possible = a * (n - 1) + b
    max_possible = b * (n - 1) + a

    ans = max_possible - min_possible + 1
    print(max(ans, 0))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

if a > b:
    print(0)
    exit()
    
if n == 0:
    print(0)
    eixt()
    
if n == 1:
    if a == b:
        print(1)
        exit()
    else:
        print(0)
        exit()
        
n_s = n - 2
s = b-a

ans = (b-a)*n_s + 1

print(ans)

Submission status: Accepted

Solution code:
# AGC 015: A – A+...+B Problem
from itertools import combinations_with_replacement

n, a, b = [int(s) for s in input().split()]


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

Submission status: Accepted

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

m = a*(n-1) + b
M = a + b*(n-1)

print(max(0, M - m + 1))

Submission status: Accepted

Solution code:
from sys import stdin
N, A, B = [int(_) for _ in stdin.readline().rstrip().split()]
if A > B:
    print(0)
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())
print(max((b*(n-1)+a)-(a*(n-1)+b)+1,0))

Submission status: Accepted

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

Submission status: Accepted

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

print(max-min + 1)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce


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


def cmb(n, r):
    # combination
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


N, A, B = inpl()

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

# N > 2
# A < B
print(A + B * (N - 1) - (A * (N - 1) + B) + 1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

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

    elif n>=2:
        ans=1
        if a>b:
            ans=0
            print(ans)
            return
# ありうる数字の種類
        dif=b-a
        #数
        num=n-2
        ans=dif*num+1
        print(ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def calc():
    n, a, b = map(int, input().split())
    if a > b:
        return 0
    if n == 1 and a < b:
        return 0

    upper = a + b * (n - 1)
    lower = b + a * (n - 1)
    return upper - lower + 1


print(calc())

Submission status: Accepted

Solution code:
# AGC015
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:
  print(int(a==b))
else:
  if a <= b:
    print((n-2)*(b-a)+1)
  else:
    print(0)

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 = list(map(int, input().split()))
#min > max n == 0
if a > b or n == 0:
    print(0)
    exit()
#n = 1 and  min != max
if n == 1 and  a != b :
    print(0)
    exit()
print((a + b * (n - 1)) - (a * (n - 1) + b) + 1)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,A,B=map(int,input().split())

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

else:
    temp1=A+B+A*(N-2)
    temp2=A+B+B*(N-2)
    print(max(temp2-temp1+1,0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def accumulate(a, b):
    k = b - a + 1
    return k * (k+1) // 2 + k * (a-1)

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

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

Submission status: Accepted

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

if(B-A<0):
    print("0")
    exit()
if(A==B):
    print("1")
    exit()

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

if(N==2):
    print("1")
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
    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())
print(max((2-n)*a+(n-2)*b+1,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 N == 1 or A == B:
    print(1)
    exit()

minS = A * (N - 1) + B
maxS = A + B * (N - 1)

print(maxS - minS + 1)

Submission status: Accepted

Solution code:

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

print (max(0,((B*(N-1)+A) - (B+(N-1)*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)
  exit()
mn=a+b+a*(n-2)
mx=a+b+b*(n-2)
print(mx-mn+1)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, a, b = list(map(int, input().rstrip('\n').split()))
    if a > b:
        print(0)
    elif a == b:
        print(1)
    elif n - 2 < 0:
        print(0)
    else:
        c = n - 2
        print(abs(a * c - b * c) + 1)


if __name__ == '__main__':
    slove()

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

Submission status: Accepted

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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    N,A,B=map(int,input().split())
    if A>B or (N==1 and A!=B):
        print(0)
        return
    if N==1:
        print(1)
    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())

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

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

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

min_val = (N - 1) * A + B
max_val = (N - 1) * B + A
print(max_val - min_val + 1)

Submission status: Accepted

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)
elif A>B : print(0)
elif 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())

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

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

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

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

digit = N - 1
min_calc = A*digit + B
max_calc = A + B*digit
ans = max_calc - min_calc + 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,a,b = LI()
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())
print(max(0, (n-2)*b - (n-2)*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-1)*b+a) - ((n-1)*a+b) + 1)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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 LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,a,b = LI()
    if b < a:
        print(0)
        return
    if n == 1 and a != b:
        print(0)
        return
    mi = a*(n-1)+b
    ma = b*(n-1)+a
    print(abs(ma-mi)+1)
    return
#B
def B():

    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    A()

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(1)
    exit()

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

Submission status: Accepted

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

    maxv = B*(N-1) + A
    minv = A*(N-1) + B
    return maxv - minv + 1

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

mid_num = n - 2

if mid_num < 0:
  print(0)
  exit()

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
#結局、上限はA+B*(N-1)、下限はA*(N-1)+B
if N == 1:
  if A == B:
    print(1)
  else:
    print(0)
elif A > B:
  print(0)
else:
  print(A+B*(N-1) - (A*(N-1)+B) + 1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, a, b = [ int(v) for v in input().split() ]
if n == 1:
    if a != b:
        ans = 0
    else:
        ans = 1
else:
    if a <= b:
        maxsum = a + b*(n-1)
        minsum = a*(n-1) + b
        ans = maxsum - minsum + 1

    else:
        ans = 0
print(ans)

Submission status: Accepted

Solution code:
# 2019/08/20

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(N: int, A: int, B: int):
    print(max(B*(N-1)+A-A*(N-1)-B+1, 0))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

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