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:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n,a,b = m()

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

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

Solution code:
import sys, 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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, A, B = MAP()
if A > B or N == 1 and A != B:
	print(0)
	exit()
mi = A*(N-1)+B
ma = A+B*(N-1)
print(ma-mi+1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def check():
    if a > b:
        return 0
    elif a != b and n == 1:
        return 0
    elif n <= 2:
        return 1

    else:
        ba = b - a
        return 1 + ba * (n - 2)

print(check())

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:
#template
from collections import Counter
def inputlist(): return [int(j) for j in input().split()]
#template
N,A,B = inputlist()
if A>B:
    print(0)
    exit()
ans = (B-A)*(N-2) +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 A == B:
    print(1)
else:
    if N == 1:
        print(0)
    else:
        print((N - 2)*(B - A) + 1)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

smin = (N-1)*A + B
smax = A + (N-1)*B
print(smax-smin+1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys


while True:
    try:
        line = sys.stdin.readline().strip()
        if line == "":
            break
        nums = list(map(int, line.split()))
        N, A, B = nums[0:3]

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

    except:
        break

Submission status: Accepted

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

print(ret)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


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


def MS(): return map(str, input().split())


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


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


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

    if A > B:
        print(0)
        return

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

    min_v = A * (N - 1) + B
    max_v = A + B * (N - 1)
    print(max_v - min_v + 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

if a >= b or n < b - a:
    print (0)
    exit ()

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

Submission status: Accepted

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


def solve(N: int, A: int, B: int):
    if A > B:
        print(0)
        return
    
    if N == 1:
        if A==B:
            print(1)
        else:
            print(0)
        return
    
    min_sum = A*(N-1)+B
    max_sum = A+B*(N-1)
    print(max_sum-min_sum+1)
    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())

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

Submission status: Accepted

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

if A > B:
    print(0)

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

else:
    min_n = A * (N - 1) + B
    max_n = A + (N - 1) * B
    print(max_n - min_n + 1)

Submission status: Accepted

Solution code:
def main():
    length, min_number, max_number = map(int, input().split())
    print(max(0, (length - 2) * (max_number - min_number) + 1) if min_number <= max_number else 0)


if __name__ == '__main__':
    main()

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

"""
MIN: (N - 1) * A + B
MAX: A + (N - 1) * B

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


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


if __name__ == "__main__":
	main()

Submission status: Accepted

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

    ans = 0

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

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, A, B = (int(i) for i in input().split())
    if (N == 1 and A != B) or (B - A < 0):
        print(0)
    elif N == 1:
        print(1)
    else:
        print((N-2)*B - (N-2)*A + 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, a, b = map(int,input().split())

if b < a:
    print(0)
elif n == 1 and a != b:
    print(0)
else:
    ans = ((n - 1) * b + a) - ((n - 1) * a + b) + 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
def input(): return sys.stdin.readline().strip()
def STR(): return input()
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 = sys.maxsize
mod = 10 ** 9 + 7

n, a, b = MAP()
if b < a:
    print(0)
    exit()
if a == b and n == 1:
    print(1)
    exit()
if a != b and n == 1:
    print(0)
    exit()
if n == 2:
    print(1)
    exit()
if b - a - 1 <= 0:
    print(1)
    exit()
print(a + (n - 1) * b - (n - 1) * a - b + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, A, B = (int(i) for i in input().split())
    if (N == 1 and A != B) or (B - A < 0):
        print(0)
    elif N == 1:
        print(1)
    elif N == 2:
        print(1)
    else:
        print((N-2)*B - (N-2)*A + 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

high = (N - 1) * B + A
low = (N - 1) * A + B
ans = high - low + 1
ans = max(0, ans)

print(ans)

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()
if N == 2:
    print(1)
    exit()

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
mod = 10**9 + 7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))


n, a, b = na()
sum_min = a * (n-1) + b
sum_max = a + (n-1) * b

if n == 0 and a != b:
    print(0)
else:
    print(max(0, sum_max - sum_min + 1))

Submission status: Accepted

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

min_  = a + a*(n-2) + b
max_ = a + b*(n-2) + b

print(max(0, max_-min_+1))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if N==0:
    print(0)
elif N==1 and A==B:
    print(1)
elif N==1 and A!=B:
    print(0)
elif A>B:
    print(0)
elif N>=2:
    mx = B*(N-1)+A
    mn = A*(N-1)+B
    print(mx-mn+1)

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

# 全部A〜全部Bまでの範囲
ans = B * (N - 2) - A * (N - 2) + 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

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

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

min = A*(N-1)+B
max = A+B*(N-1)

print(max-min+1)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n,a,b = get_nums_l()

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

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

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

print(ans)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if a > b:
    print(0)
elif n == 1 and a != b:
    print(0)
else:
    minimum = a * (n-1) + b
    maximum = a + (n-1) * b
    print(maximum - minimum + 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()
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
    ans += (num_num-1) * (mid_num-1) + num_num
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
方針
O(1)
"""
#solution:
#潜 影 蛇 手 ! !
N,A,B=pin()
if A==B:
    print(1)
elif A>B or N==1:
    print(0)
else:
    print((N-2)*(B-A)+1)
#print(["NO","YES"][1-cond])
#print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin

mod = 1000000007
inf = 1 << 60
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n, a, b = na()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
'''
制約
1≦N,A,B≦10^9
N  = 1の時ABもない

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

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

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

Submission status: Accepted

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


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

Submission status: Accepted

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

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

min_s = a*(n-1) + b
max_s = b*(n-1) + a

print(max(max_s - min_s + 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)
else:
    lower = (N - 1) * A + B
    upper = (N - 1) * B + A
    print(upper - lower + 1)

Submission status: Accepted

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