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

input = sys.stdin.readline


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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N, A, B = [int(item) for item in input().split()]

    if A <= B:
        if N >=3:
            res = (N-1)*B + A - ((N-1)*A + B) + 1

        elif N == 2:
            res = 1
        else:
            if A == B:
                res = 1
            else:
                res = 0
    else:
        res = 0

    print(res)

if __name__ == "__main__":
    resolve()

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

Submission status: Accepted

Solution code:
import math
import sys

n, a, b = map(int, sys.stdin.readline().rstrip().split())

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

Submission status: Accepted

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

if B < A:
  print(0)
  exit()
num = B-A+1
mi = A*(N-1) + B
ma = B*(N-1) + A
ans = ma - mi + 1

print(max(ans,0))

Submission status: Accepted

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

sum_min = a + a * (n - 2) + b 
sum_max = a + b * (n - 2) + b

print(max(sum_max - sum_min + 1, 0))

Submission status: Accepted

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

Submission status: Accepted

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

def dp(n, cur):
    if n == 1:
        return 

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

Submission status: Accepted

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

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

Submission status: Accepted

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

mini = a * (n - 1) + b
maxi = b * (n - 1) + a

print(max(maxi - mini + 1, 0))

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n, a, b = map(int, input().split())
ans = None
if a == b:
    ans = 1
elif n <= 2 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 A == B:
    print(1)
elif A > B:
    print(0)
else:
    if N == 1:
        print(0)
    else:
        print((B - A) * (N - 2) + 1)

Submission status: Accepted

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, A, B = list(map(int,_in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    _min = A*(N-1)+B
    _max = A+B*(N-1)
    cnt = max(_max-_min+1,0)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Accepted

Solution code:
import sys

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


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

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

cnt = 0

n_min = (a * (n-1)) + b
n_max = (b * (n-1)) + a

if (n_max - n_min + 1) < 0:
    result = 0
else:
    result = n_max - n_min + 1
print(result)

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.buffer.readline
n,a,b=map(int,input().split())
if n==1:
    if a==b:print(1)
    if a!=b:print(0)
if n>1:
    if a>b:print(0)
    if a<=b:print((n-2)*(b-a)+1)

Submission status: Accepted

Solution code:
n, a, b = [int(i) for i in input().split()]
c = b * (n - 1) + a
d = a * (n - 1) + b

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

Submission status: Accepted

Solution code:
# AGC 015: A – A+...+B Problem
N, A, B = [int(s) for s in input().split()]

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

Submission status: Accepted

Solution code:
N,A,B=map(int, input().split())
#最小がA　最大がB　その区間でN個
if A>B:
    print(0)
    exit()
elif N==1 and A!=B:
    print(0)
    exit()
MAX=A+B*(N-1)
MIN=B+A*(N-1)
#print(MAX, MIN)
print(MAX-MIN+1)

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

mn=A*(N-1) + B
mx=A + B*(N-1)
print(mx-mn+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:
import sys
input = sys.stdin.readline

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

def main():
    mod=10**9+7
    N,A,B=MI()
    ans=0
    rem=N-2
    ans=rem*(B-A)+1
    ans=max(ans,0)
    if A>B or (rem<0 and B-A>=1):
        ans=0
    print(ans)

main()

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 heapq import heapify, heappop, heappush
 
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()

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

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N, A, B = map(int, input().split())
    if A > B: print(0)
    elif N == 1:
        if B != A: print(0)
        else: print(1)
    else:
        rem = N - 2
        minS = A + B + rem * A
        maxS = A + B + rem * B
        print(maxS - minS + 1)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

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

    n_min = b + (n-1)*a
    n_max = a + (n-1)*b

    print(n_max-n_min+1)

Submission status: Accepted

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

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


C = N - 2
l = A * C
h = B * C
print(h - l + 1)

Submission status: Accepted

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

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

print (max(0, MAX - MIN + 1))

Submission status: Accepted

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

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

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

sum_min = A * (N - 1) + B
sum_max = A + B * (N - 1)

print(max(0, sum_max - sum_min + 1))

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if n==1 and a==b:
    print(1)
    exit()
print((n-2)*(b-a)+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def myAnswer(N:int,A:int,B:int) -> int:
   if((N== 1 and  A != B )or B - A < 0): return 0
   ans = (B*(N-1) + A) - (A * (N - 1) + B) + 1
   return ans

def modelAnswer():
   return
def main():
   N,A,B = map(int,input().split())
   print(myAnswer(N,A,B))
if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
def myAnswer(N:int,A:int,B:int) -> int:
   if(B - A > N or B - A < 0): return 0
   ans = (B*(N-1) + A) - (A * (N - 1) + B) + 1
   return ans

def modelAnswer():
   return
def main():
   N,A,B = map(int,input().split())
   print(myAnswer(N,A,B))
if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

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

if N == 0:
    print(0)
    exit()
elif N == 1 and A==B:
    print(1)
    exit()
elif N == 1 and A!=B:
    print(0)
    exit()
elif A>B:
    print(0)
    exit()
elif N==2:
    print(1)
    exit()
else:
    n = N-2
    ans = B*n - A*n +1
    print(ans)
    exit()
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する

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

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

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc015/tasks/agc015_a

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

if b < a:
    print(0)
elif a != b and n == 1:
    print(0)
else:
    MIN = a * (n - 1) + b
    MAX = a + (n - 1) * b
    ans = MAX - MIN + 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


def log(v):
    print(v, file=sys.stderr)


N, A, B = map(int, input().split())
maxNum = A + B * (N - 1)
minNum = A * (N - 1) + B
print(max(maxNum - minNum + 1, 0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

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


resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,a,b = [int(x) for x in 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:
from itertools import product

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

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

Submission status: Accepted

Solution code:
n,a,b = map(int,input().split(' '))
minvalue = a*(n-1)+b
maxvalue = b*(n-1)+a
ans = (maxvalue-minvalue+1)
print(max(ans,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)
else:
    print((b-a)*(n-2)+1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N,A,B=map(int, raw_input().split())
if N==1:    #整数が1個のとき
    if A!=B:    #minとmaxが異なる場合はない
        print 0
    else:
        print 1
else:   #整数が2個以上のとき
    if B<A:
        print 0
    elif B==A:
        print 1  
    elif A<B:
        print A+B+B*(N-2)-(A+B+A*(N-2))+1

Submission status: Accepted

Solution code:
def examA():
    N, A, B = LI()
    if N==1:
        if A==B:
            print(1)
        else:
            print(0)
        return
    ans = (N-2)*max(B-A,0) + 1
    if B<A:
        ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

def test():
    i = I()
    li = LI()
    lsi = LSI()
    si = LS()
    print(i)
    print(li)
    print(lsi)
    print(si)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examA()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# python3.4.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')
def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,A,B = imn()

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if b < a:
    print(0)
elif n == 1:
    if a == b:
        print(1)
    else:
        print(0)
else:
    small = a * (n - 2)
    big = b * (n - 2)
    num = big - small + 1
    print(num)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

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

if a > b:
    print(0)
    exit()
    
print(-(a*(n-1)+b)+(a+b*(n-1))+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

B_max = B*(N-1)+A
A_min = A*(N-1)+B

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

Submission status: Accepted

Solution code:
N, MIN, MAX = map(int, input().split())

sum_min = (N-1)*MIN + MAX
sum_max = (N-1)*MAX + MIN
# print(sum_max)
# print(sum_min)

if N > 1:
    if sum_max >= sum_min:
        print(sum_max - sum_min + 1)
    else:
        print(0)
elif N == 1:
    if MIN!= MAX:
        print(0)
    else:
        print(1)

Submission status: Accepted

Solution code:
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)

#入力
n,a,b = map(int,input().split())
low = b + a*(n-1)
high = a + b*(n-1)
print(max(0,high - low +1))

Submission status: Accepted

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