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

Submission status: Accepted

Solution code:
import sys

n,a,b = map(int,input().split())
x = a*(n-1)+b
y = a+b*(n-1)
z = y-x+1

if z >= 0:
    print(y-x+1)
else:
    print(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((n - 2) * (b - a) + 1)

Submission status: Accepted

Solution code:

import itertools
import numpy as np

def calc(n, a, b):
    if a > b:
        return 0
    elif a == b:
        return 1
    elif n == 1:
        return 0

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

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


print(calc(N, A, B))

Submission status: Accepted

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

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

Submission status: Accepted

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

if (a != b and n == 1) or a > b:
    print(0)
else:
    lowest_pos = a * (n - 1) + b
    highest_pos = a + b * (n - 1)
    print(highest_pos - lowest_pos + 1)

Submission status: Accepted

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

if b > c :
  print (0)

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

Submission status: Accepted

Solution code:
def solve(n, a, b):
    if a > b:
        return 0
    return max(0, (b - a) * (n - 2) + 1)


print(solve(*map(int, input().split())))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys

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

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

print max(0, ans)

Submission status: Accepted

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

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

main()

Submission status: Accepted

Solution code:
# coding: utf-8

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

if a > b:
    print 0
    exit()

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

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

Submission status: Accepted

Solution code:
#! /usr/bin/env python3
import itertools
N, A, B = map(int, input().split())
if B <= A or N < 2:
    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,raw_input().split())
if n==1:
	if a==b:
		print 1
	else:
		print 0
elif 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())
ret = 0
if n == 1 and a == b: ret = 1
elif a <= b and n >= 2: ret = (n - 2) * (b - a) + 1
print(ret)

Submission status: Accepted

Solution code:
N = input().split()

N[0] = int(N[0])
N[1] = int(N[1])
N[2] = int(N[2])

if(N[0] == 1):
    if(N[1] == N[2]):
        print("1")
        exit()
    print("0")
    exit()

if(N[1] > N[2]):
    print("0")
    exit()

print((N[2] * (N[0] -1) + N[1]) - (N[1] * (N[0] - 1) + N[2]) + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
import math
N, A, B = map(int, input().split())
if N != 1 and A <= B:
    '''
    n = math.factorial(B-A+N-2)
    a = math.factorial(N-2)
    b = math.factorial(B-A)
    print(n//(a*b))
    '''
    print((B-A)*(N-2)+1)
else:
    if A != B:
        print(0)
    else:
        print(1)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if(A > B) or (N == 1 and A != B):
	print("0")
else:
	Smin = A * (N - 1) + B
	Smax = B * (N - 1) + A

	print(Smax - Smin + 1)

Submission status: Accepted

Solution code:
def solve(n, a, b):
    if a > b:
        return 0
    if a == b:
        return 1
    # if a < b
    if n == 1:
        return 0
    return (b * (n - 1) + a) - (a * (n - 1) + b) + 1

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

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

m0 = A*(N-1) +B
m1 = A+ (N-1)*B

ans=m1-m0+1
if ans<=0:
    ans=0
print(ans)

Submission status: Accepted

Solution code:
n = [int(i) for i in input().split()]
if n[0] == 1 and n[1] < n[2]:
    print(0)
elif n[1]>n[2]:
    print(0)
elif n[0] == 1 and n[1]==n[2]:
    print(1)
else:
    mi = n[1]*(n[0]-1)+n[2]
    ma = n[2]*(n[0]-1)+n[1]
    print(ma-mi+1)

Submission status: Accepted

Solution code:
# your code goes here
def max(a, b):
	if a > b:
		return a
	else:
		return b



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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def FI(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline().split())
def S(): return input()

n, a, b = LI()

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

Submission status: Accepted

Solution code:
import sys


def main():
    n, a, b = map(int, sys.stdin.readline().strip().split(" "))
    if a > b:
        print(0)
    elif a == b:
        print(1)
    else:
        if n == 1:
            print(0)
            return
        x = (n - 1) * a + b
        y = a + (n - 1) * b
        print(y - x + 1)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
data = [int(x) for x in input().split()]
n = data[0]
a = data[1]
b = data[2]
maximum = b*(n-1) + a 
minmum = b + a*(n-1)
if a > b:
    print(0)
elif n == 1 and a != b:
    print(0)
else:
    print(maximum - minmum +1)

Submission status: Accepted

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

if a > b:
  print 0
  exit()


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

# 2 < n, a <= b

# n = 3 => b-a+1
# n = 4 => (b-a)*2+1
# n = 5 => (b-a)*3+1
# ....
# n     => (b-a)*(n-2)+1
print (b-a)*(n-2)+1

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

N,A,B=map(int,raw_input().split())
s=(N-2)*(B-A)+1
if s<1:
    s=0
print s

Submission status: Accepted

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

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

mn = (N - 2) * A
mx = (N - 2) * B

print (str(mx - mn + 1))

Submission status: Accepted

Solution code:
import math

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys

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

if N < 2 and A < B:
    print(0)
    sys.exit()

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

c = B - A

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

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

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

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

Submission status: Accepted

Solution code:
def solve() :
  ar = raw_input().split()
  N = int(ar[0])
  A = int(ar[1])
  B = int(ar[2])

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

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

  return count

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

Submission status: Accepted

Solution code:
from sys import stdin
n,a,b = map(int, stdin.readline().split())
mi = (n-1)*a  + b
ma = (n-1)*b + a
ans = ma - mi + 1
print max(ans,0)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import random

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

def rdi():
        return [ int(x) for x in rd().split() ]

N, A, B = rdi()

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

Submission status: Accepted

Solution code:

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

min_ = A * (N-1) + B
max_ = B * (N-1) + A
result = 0

diff = max_ - min_
if diff < 0:
    print('{}'.format(0))
else:
    print('{}'.format(diff+1))

Submission status: Accepted

Solution code:
def a():
    n, a, b = map(int, input().split())
    if (a > b) or ((a != b)and(n == 1)):
        print(0)
        return
    elif (a == b) and (n == 1):
        print(1)
        return
    else:
        min_sum = a * (n-1) + b
        max_sum = a + b * (n-1)
        num = max_sum - min_sum + 1
        print(num)
        return
    pass

a()

Submission status: Accepted

Solution code:
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

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



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

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

Submission status: Accepted

Solution code:
def solve(n, a, b):
    if a > b: return 0
    if n == 1: return 1 if a == b else 0

    x = n - 2
    return b * x - a * x + 1

if __name__ == '__main__':
    n, a, b = map(int, input().split())
    print(solve(n, a, b))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
length,min_num,max_num = (int(n) for n in input().split(" "))
if min_num > max_num or (length == 1 and min_num != max_num):
    print(0)
elif min_num == max_num or length == 2:
    print(1)
else:
    max_max = max_num * (length - 1) + min_num
    min_min = min_num * (length - 1) + max_num
    print(max_max - min_min + 1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, A, B = [int(n) for n in input().split()]
min_ = (N-1)*A + B
max_ = A + (N-1)*B
print(max(max_ - min_ +1, 0))

Submission status: Accepted

Solution code:
import sys

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

    if a > b:
        print(0)
        return

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

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

    print(ans)
    pass

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n,a,b = LI()
    if n == 1:
        if a == b:
            return 1
        return 0

    if a > b:
        return 0

    if n == 2:
        return 1

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


print(main())

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = list(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, raw_input().split())
if not a <= b:
    print 0
else:
    print max((n-1)*b+a - (n-1)*a-b + 1, 0)

Submission status: Accepted

Solution code:
# coding: utf-8


def array2d(d1, d2, init = None):
    return [[init for _ in range(d2)] for _ in range(d1)]


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

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

    smin = (n - 1) * a + b
    smax = (n - 1) * b + a
    print(smax - smin + 1)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
temp=input().split()
N=int(temp[0])
A=int(temp[1])
B=int(temp[2])

big=A+B*(N-1)
small=A*(N-1)+B

if(big<small):
	print(0)
elif(N==1 and big!=small):
	print(0)
else:
	print(big-small+1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def rren(): return list(map(int, input().split()))


n, a, b = rren()

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

minsum = A + B + (N-2)*A
maxsum = A + B + (N-2)*B

print(max(0, maxsum - minsum + 1))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# regular
min_ = A*(N-1) + B
max_ = A + B * (N-1)

res = max_ - min_ + 1

# irregular
if res < 0:
    res = 0
if N == 1 and A != B:
    res = 0
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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 max(0,largest - smallest + 1) if A<=B else 0

Submission status: Runtime Error

Solution code:
#include <iostream> 
#include <cstdio> 
#include <cstdlib>  
#include <algorithm> 
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>
#include<functional>
using namespace std;
typedef long long ll;


long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}


int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = 0;
    if (a == b) cout << 1 << endl;
    else if (n == 1) cout << 0 << endl;
    else if (a > b) cout << 0 << endl;
    else if (n == 2) cout << 1 << endl;
    else cout << b * (n - 2) - a * (n - 2) + 1 << endl;

}

Submission status: Runtime Error

Solution code:
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: Runtime Error

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: Runtime Error

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: Runtime Error

Solution code:
import itertools
import sys
 
N,A,B=map(int,input().split())
ans=set()
 
if A>B:
  print(0)
  sys.exit()
elif N==1:
  if A==B:
    print(1)
    sys.exit()
  else:
    print(0)
    sys.exit()
elif N==2:
  print(1)
  sys.exit()
else:
  for x in itertools.combinations_with_replacement(range(A,B+1),N-2):
    if x in ans:
      continue
    ans.add(sum(x))
 
print(len(ans))

Submission status: Runtime Error

Solution code:
import itertools

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

if A>B:
  print(0)
elif N==1:
  if A==B:
    print(1)
  else:
    print(0)
elif N==2:
  print(1)
else:
  for x in itertools.combinations_with_replacement(range(A,B+1),N-2):
    if x in ans:
      continue
    ans.add(sum(x))

print(len(ans))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if loop % 2 == 0:
  ans = (check + check - loop +1)*(loop/2)
elif loop % 2 == 1:
  ans = (check + check - loop+1)*((loop-1)/2)+check -(loop -1)/2
  
print(int(ans))

Submission status: Runtime Error

Solution code:
def main():
    N = input()
    S = str(N)
    S = S[::-1]

    odd = 0
    even = 0

    for i in range(len(S)):
        if (i + 1) % 2 == 0:
            even += int(S[i])
        else:
            odd += int(S[i])
    print(even, odd)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def findleftmost(A,B):
    shift = 0
    while (A>>shift) != (B>>shift):
        shift += 1
    return shift-1
def findleftmostbit(B,n):
    for m in range(n-1,-1,-1):
        if (B>>m)%2==1:
            return m
    return -1
def solve(A,B):
    if A==B:
        return 1
    n = findleftmost(A,B)
    m = findleftmostbit(B,n)
    shared = ((A>>(n+1))<<(n+1))
    case1_l = A
    case2_u = shared + (1<<n) +(1<<(m+1)) -1
    case3_l = A + (1<<n)
    case3_u = shared + (1<<(n+1)) -1
    if (case2_u < case3_l - 1):
        return (case3_u - case3_l + 1) + (case2_u - case1_l+1)
    else:
        return case3_u - case1_l + 1
A = int(input().strip('\u202c'))
B = int(input().strip('\u202c'))
print(solve(A,B))

Submission status: Runtime Error

Solution code:
from itertools import combinations_with_replacement

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

ans = 0
if n >= 2 and a <= b:
    cmbs = combinations_with_replacement([i for i in range(a, b + 1)], n - 2)
    D = [sum([a] + list(c) + [b]) for c in cmbs]
    ans = len(set(D))
    
elif n == 1 and a == b:
    ans = 1

print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import itertools

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

candidate = list(range(a, b+1, 1))
if n == 1:
    if a == b:
        print(1)
    else:
        print(0)
elif n == 2:
    print(1)
elif n >= 3:
    if a > b:
        print(0)
    else:
        smin = a * n + (b-a)
        smax = b * n - (b-a)
        print(smax-smin+1)

Submission status: Runtime Error

Solution code:
import itertools

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

candidate = list(range(a, b+1, 1))
if n == 1:
    if a == b:
        print(1)
    else:
        print(0)
elif n == 2:
    print(1)
elif n >= 3:
    smin = a * n + (b-a)
    smax = b * n - (b-a)
    print(smax-smin+1)

Submission status: Runtime Error

Solution code:
import itertools

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

candidate = list(range(a, b+1, 1))
if n == 1:
    if a == b:
        print(1)
    else:
        print(0)
elif n == 2:
    print(1)
elif n >= 3:

    smin = a * n + (b-a)
    smax = b * n - (b-a)
    sl = list(range(smin, smax+1, 1))
    print(len(sl))

Submission status: Runtime Error

Solution code:
import itertools

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

candidate = list(range(a, b+1, 1))
if n == 1:
    if a == b:
        print(1)
    else:
        print(0)
elif n == 2:
    print(a)
elif n >= 3:
    c = list(itertools.combinations_with_replacement(candidate, n-2))
    suml = []
    for i in c:
        suml.append(sum(i) + 4 + 6)
    sum_set = set(suml)
    print(len(sum_set))

Submission status: Runtime Error

Solution code:
import itertools

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

candidate = list(range(a, b+1, 1))
if n == 1:
    if a == b:
        print(a)
    else:
        print(0)
elif n == 2:
    print(a)
elif n >= 3:
    c = list(itertools.combinations_with_replacement(candidate, n-2))
    suml = []
    for i in c:
        suml.append(sum(i) + 4 + 6)
    sum_set = set(suml)
    print(len(sum_set))

Submission status: Runtime Error

Solution code:
import itertools

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

candidate = list(range(a, b+1, 1))
if n == 1:
    print(0)
elif n == 2:
    print(a)
elif n >= 3:
    c = list(itertools.combinations_with_replacement(candidate, n-2))
    suml = []
    for i in c:
        suml.append(sum(i) + 4 + 6)
    sum_set = set(suml)
    print(len(sum_set))

Submission status: Runtime Error

Solution code:
import itertools

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

candidate = list(range(a, b+1, 1))
c = list(itertools.combinations_with_replacement(candidate, n))
suml = []
for i in c:
    if min(i) == a and max(i) == b:
        suml.append(sum(i))
sum_set = set(suml)
print(len(sum_set))

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    import itertools
    n,a,b=map(int, input().split())
    if n==1 and a==b:
        print(1)
    elif n==1 and a!=b:
        print(0)
    elif b<a:
        print(0)
    else:
        l=list(range(a,b+1))
        c=itertools.combinations_with_replacement(l,n-2)
        check=[]
        cnt=0
        for i in c:
            if sum(i) not in check:
                check.append(sum(i))
                cnt+=1
        print(cnt)
resolve()