Problem:


Score : 200 points

Problem Statement

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

Constraints

1 ≤ N,A,B ≤ 10^9

A and B are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of the different possible sums.

Sample Input 1

4 4 6

Sample Output 1

5

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

Sample Input 2

5 4 3

Sample Output 2

0

Sample Input 3

1 7 10

Sample Output 3

0

Sample Input 4

1 3 3

Sample Output 4

1



Sample input:
4 4 6


Sample output:
5

Submission status: Wrong Answer

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

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
rr = lambda: stdin.readline().strip()
rrM = lambda: map(int,rr().split())
debug=0
if debug:
    fi = open('in.txt','r')
    rr=lambda: fi.readline().replace('\n','')

N,A,B = rrM()
smallest = A * (N-1) + B
largest = A + B * (N-1)
print largest - smallest + 1

Submission status: Time Limit Exceeded

Solution code:
def anotherpair(x, y):                
    l = []
    c=1
    for i in range(x, y+1):
        if c==0:
            l.append([i, i-1])
        c=0
    return l
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 = len(anotherpair((n-2)*a, (n-2)*b))+1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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-2
    ans=0

    for i in range(k):
        ans+=pot
        pot-=1
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

r = range(a,b+1)
tmp = []
ans = 0

if a == b:
    print(1)
elif n == 1:
    print(0)
else:
    for v in itertools.combinations_with_replacement(r, n-2):
        if not sum(v) in tmp:
            ans += 1
            tmp.append(sum(v))

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
if a > b:
    print(0)
    exit()
elif a == b:
    print(1)
    exit()
elif n == 1 and b - a > 0:
    print(0)
    exit()
elif n == 2:
    print(1)
    exit()
else:
    mid_num = n - 2
    num_num = b - a + 1
    ans = 0
    for i in range(mid_num-1):
        ans += num_num-1
    ans += num_num
    print(ans)

Submission status: Time Limit Exceeded

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:
    c = 0
    for _ in range(N-2):
        c += (B-A)
    print(c+1)

Submission status: Time Limit Exceeded

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

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

def main():
    def sum(count, num):
        tmp=0
        for i in range(0, count):
            tmp+=num
        # print("tmp",tmp)
        return tmp

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

    ### A<B
    Max=(A+B)+sum(N-2, B)
    Min=(A+B)+sum(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: Time Limit Exceeded

Solution code:
inputs = input().split()                                                                
n = int(inputs[0])
a = int(inputs[1])
b = int(inputs[2])
minnum = 0 
maxnum = 0 
n = n+1 
for i in range(1, n): 
    if(i==n-1):
        minnum += b
    else:
        minnum += a



for i in range(1, n): 
    if(i==n-1):
        maxnum += a
    else:
        maxnum += b

maxnum = maxnum+1
diff = maxnum-minnum
if(diff<0):
    diff=0

print(diff)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

ans = max(0, 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: print(0)
elif a == b:
    print(n*(b-a)+1)
else:
    if n == 1 : 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(max(0,(b * (n - 1) + a) - (a * (n - 1) + b) + 1))
elif a > b:
    print("0")

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n,a,b=map(int,input().split())
ans=(b*(n-1)+a-a*(n-1)-b)+1
if ans<0:
  print(0)
  exit()
print(ans)

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

Submission status: Accepted

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

if N < 1 or B - A < 0:
  print(0)
  exit(0)
  
if N == 1 and A < B:
  print(0)
  exit(0)
  
  
if A == B or N <= 2:
  print(1)
  exit(0)
  
c = N-2
r = B-A+1

ans = c*(r-1) + 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

n,a,b = mint()
if (n==1 and a!=b) or 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())
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,input().split())

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

ans = maximum-minimum+1

if a > b or (n == 1 and a != b):
    print(0)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
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)
    else:
        print(0)
    sys.exit(0)

x = B*(N-1)+A
n = A*(N-1)+B
print(x-n+1)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#23 A - A+...+B Problem
N,A,B = map(int,input().split())

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

Submission status: Accepted

Solution code:
import sys, math
from functools import lru_cache
import numpy as np
import heapq
from collections import defaultdict
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def lcm(a, b):
    return a*b//math.gcd(a, b)


def main():
    N, A, B = mi()
    if A > B or (N == 1 and A != B):
        print(0)
        return

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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 b<a:
  print(0)
  exit()
  
if a==b:
  print(1)
  exit()
  

n-=2

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

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

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

Submission status: Accepted

Solution code:

import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, a, b = input_int_list()
    if b < a or (n == 1 and a != b):
        print(0)
        sys.exit()
    n -= 2
    if n == 0:
        print(1)
    else:
        ans = (b * n) - (a * n) + 1
        print(ans)

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

minans = a*(n-1)+b
maxans = a+b*(n-1)

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

Submission status: Accepted

Solution code:
a = [int(s) for s in input().split()]
if a[1] > a[2]:
    print("0")
elif a[1] == a[2]:
    print("1")
elif a[0] == 1:
    print("0")
else:
    mini = a[2] + a[1] * (a[0] - 1)
    maxi = a[1] + a[2] * (a[0] - 1)
    print(int(maxi) - int(mini) + 1)

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,a,b = LI()
    ans = 0
    if n == 1:
        if a == b:
            ans = 1
        else:
            ans = 0
    elif n == 2:
        if a <= b:
            ans = 1
        else:
            ans = 0
    else:
        if a <= b:
            summin = a*(n-1) + b
            summax = a + b*(n-1)
            ans = summax - summin + 1
        else:
            ans = 0

    print(ans)
        
main()

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(0)
    else:
      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())
fst = (n - 1) * b + a
sec = (n - 1) * a + b
if a > b:
  print(0)
elif n == 1 and a != b:
  print(0)
else:
  print(fst - sec + 1)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

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


def main():
    N, A, B = MAP()

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

Submission status: Accepted

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

n,a,b = I()

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

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

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

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




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

def check(n):
    if 

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

for i in 
"""

Submission status: 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 n == 1 and a != b:
    ans = 0
elif b < a:
    ans = 0
else:
    ans = (b * (n - 1) + a) - (a * (n - 1) + b) + 1

print(ans)

Submission status: Accepted

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

N, A, B = MAP()

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

print(ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, A, B = MAP()
b = N - 2
mi = A * b
ma = B * b
print(max(ma - mi + 1, 0))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B=list(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:
n,a,b=[int(i) for i in input().split()]
if b<a 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 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())

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

print(max(0, ma - mi + 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 = 1
        else:
            ans = 0
    elif N == 2:
        if A == B:
            ans = 1
        else:
            ans = B - A + 1
    else:
        ans = (N - 2) * B - (N - 2) * A + 1

print(ans)

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

  print(ans)

main()

Submission status: Accepted

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

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

  if ans < 0:
    ans = 0
  else:
    ans += 1

  print(ans)

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
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 b < a:
    print(0)
    exit()

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import sys
import bisect
readline = sys.stdin.readline


def main():
    n, a, b = map(int, readline().rstrip().split())
    if n == 1:
        print(1 if a == b else 0)
        return
    if a > b:
        print(0)
        return

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	A
# CreatedDate:  2020-07-29 16:51:04 +0900
# LastModified: 2020-07-29 16:59:15 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n, a, b = map(int, input().split())
    down = (n-1)*a + b
    up = (n-1)*b + a
    if up-down+1 > 0:
        print(up-down+1)
    else:
        print(0)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,A,B = [int(i) for i in 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 a>b:print(0);exit()
if n==1 and 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:print(0);exit()
if n==1 and 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:
    print(0)
    exit()
elif a != b and n == 1:
    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 N>=2:
    if A<=B:
        print(B*(N-1)+A-(A*(N-1)+B)+1)
    else:
        print(0)
else:
    if A==B:
        print(1)
    else:
        print(0)

Submission status: Accepted

Solution code:
n,Min,Max = map(int,input().split())
sum_min = Min * (n-1) + Max
sum_max = Max * (n-1) + Min
ans = sum_max - sum_min + 1
print(max(0,ans))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, a, b = map(int, input().split())
print((n - 2) * (b - a) + 1 if (n - 2) * (b - a) >= 0 else 0)

Submission status: Accepted

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

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

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

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

print(M - m + 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())

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

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