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

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

def resolve():
    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:
        import itertools
        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()

Submission status: Runtime Error

Solution code:
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    if (N == 1) {
        cout << (A == B ? 1 : 0) << endl;
        return 0;
    }

    int Min = A * (N - 2);
    int Max = B * (N - 2);
    cout << max(0, Max - Min + 1) << endl;
}

Submission status: Runtime Error

Solution code:
n,a,b=[int(_) for_ in input().split()]
if n==1:
  if a==b:
    print(1)
  else:
    print(0)
print(max(0,(n-2)*(b-a)+1)

Submission status: Runtime Error

Solution code:
import itertools


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

if (N == 1 and A != B) or (B < A):
    print(0)
    exit()

combi = list(itertools.combinations_with_replacement(
    range(A, B + 1, 1), N - (B - A)))


sum_array = []
for x in combi:
    sumX = A + sum(x) + B
    sum_array.append(sumX)
print(len(set(sum_array)))

Submission status: Runtime Error

Solution code:
import itertools


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

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

combi = list(itertools.combinations_with_replacement(
    range(A, B + 1, 1), N - (B - A)))


sum_array = []
for x in combi:
    sumX = A + sum(x) + B
    sum_array.append(sumX)
print(len(set(sum_array)))

Submission status: Runtime Error

Solution code:
# A - A+...+B Problem

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

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

Submission status: Runtime Error

Solution code:
from itertools import combinations


def main(n: int, a: int, b: int):

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

    if n < 3:
        if n == 1:
            print(0)
        elif n == 2:
            print(2)

        return

    ans = 2
    ans += sum(1 for _ in combinations(range(a, b + 1), n - 2))

    print(ans)


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

    main(n, a, b)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import itertools
n, a, b = map(int, input().split())
if n < b-a:
    print(0)
    exit()
N = list(range(a, b+1))
su = []
if n > 2:
    for v in itertools.combinations_with_replacement(N, n-2):
        if not sum(v) in su: su.append(sum(v))
    ans = len(su)
else:
    A = b-a+1
    if n == 1: ans = A
    else: ans = A * (A-1) * (A-2) // 6
print(ans)

Submission status: Runtime Error

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

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

if b < a:
    print(0)
elif a != b and n == 1:
    print(0)
else:
    t = b - a + 1 - 2
    ans = math.factorial(t + n) // (math.factorial(t) * math.factorial(n))
    print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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


comb = list(itertools.combinations_with_replacement(range(A,B+1),N-2))

lis=[]
for x in comb:
    lis.append(sum(x))

lis = set(lis)
print(len(lis))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=input()
A=input()
B=input()
print((2-N)(A-B))

Submission status: Runtime Error

Solution code:
import sys
import itertools
n, a, b = map(int, input().split())
if n == 1:
    if a != b:
        print(0)
    else:
        print(1)
    sys.exit()
if n == 2:
    if a > b:
        print(0)
    else:
        print(1)
    sys.exit()

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

if a > 1000000007 or b > 1000000007:
    a = a%1000000007
    b = b%1000000007

total = set([sum(i)%1000000007 for i in itertools.combinations_with_replacement(range(a,b+1), n-2)])
print(len(total))

Submission status: Runtime Error

Solution code:
import sys
import itertools
n, a, b = map(int, input().split())
if n == 1:
    if a != b:
        print(0)
    else:
        print(1)
    sys.exit()
if n == 2:
    if a > b:
        print(0)
    else:
        print(1)
    sys.exit()

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

if a > 1000000007 and b > 1000000007:
    a = a%1000000007
    b = b%1000000007

total = set([sum(i) for i in itertools.combinations_with_replacement(range(a,b+1), n-2)])
print(len(total))

Submission status: Runtime Error

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

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

if a > b:
    print(0)
    sys.exit()
    
total = set([sum(i)+a+b for i in itertools.combinations_with_replacement(range(a,b+1), n-2)])
print(len(total))

Submission status: Runtime Error

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

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

if a > b:
    print(0)
    sys.exit()
    
for i in itertools.combinations_with_replacement(range(a,b+1), n-2):
    sum_combination = sum(i) + a + b
    if not sum_combination in total:
        total.add(sum_combination)

print(len(total))

Submission status: Runtime Error

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

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

if a < b:
    print(0)
    sys.exit()
    
for i in itertools.combinations_with_replacement(range(a,b+1), n-2):
    sum_combination = sum(i) + a + b
    if not sum_combination in total:
        total.add(sum_combination)

print(len(total))

Submission status: Runtime Error

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

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

for i in itertools.combinations_with_replacement(range(a,b+1), n-2):
    sum_combination = sum(i) + a + b
    if not sum_combination in total:
        total.add(sum_combination)

print(len(total))

Submission status: Runtime Error

Solution code:
import sys
import itertools
n, a, b = map(int, input().split())
total = set()
count = 0

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

for i in itertools.combinations_with_replacement(range(a,b+1), n-2):
    sum_combination = sum(i)
    if not sum_combination in total:
        count += 1
        total.add(sum_combination)

print(count)

Submission status: Runtime Error

Solution code:
a=int(input())
b=int(input())
if a==b:
  print(1)
  exit()
abin=bin(a)[2:]
bbin=bin(b)[2:]
la=len(abin)
lb=len(bbin)
if la==lb:
  while abin[0]==bbin[0]:
    abin=abin[1:]
    bbin=bbin[1:]
  while len(abin)>1 and abin[0]=="0":
    abin=abin[1:]
cbin=bbin[1:]
while cbin and cbin[0]=="0":
  cbin=cbin[1:]
c=2**(len(cbin))-1
a=int(abin,2)
b=int(bbin,2)
lb=len(bbin)
lbnd=2**(lb-1)+c
hbnd=2**(lb-1)+a
if lbnd>=hbnd:
  print(2**lb-a)
else:
  print(2**(lb-1)-a+lbnd-a+1)

Submission status: Runtime Error

Solution code:
n = int(input())
a = int(input())
b = int(input())
print((b - a) * (n - 2) + 1)

Submission status: Runtime Error

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


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


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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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


if a == b:
    print(1)
elif a > b or n <= 2:
    print(0)
else:
    candidates = list(combinations_with_replacement(range(a, b + 1), n - 2))
    sum_variations = []

    for candidate in candidates:
        if sum(candidate) not in sum_variations:
            sum_variations.append(sum(candidate))
    
    print(len(sum_variations))

Submission status: Runtime Error

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

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


if a == b:
    print(1)
elif a > b or n == 1:
    print(0)
else:
    candidates = list(combinations_with_replacement(range(a, b + 1), n - 2))
    sum_variations = []

    for candidate in candidates:
        if sum(candidate) not in sum_variations:
            sum_variations.append(sum(candidate))
    
    print(len(sum_variations))

Submission status: Runtime Error

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

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

if a > b or n == 1:
    print(0)
elif a == b:
    print(1)
else:
    candidates = list(combinations_with_replacement(range(a, b + 1), n - 2))
    sum_variations = []

    for candidate in candidates:
        if sum(candidate) not in sum_variations:
            sum_variations.append(sum(candidate))
    
    print(len(sum_variations))

Submission status: Runtime Error

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

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

if a > b:
    print(0)
elif a == b:
    print(1)
else:
    candidates = list(combinations_with_replacement(range(a, b + 1), n - 2))
    sum_variations = []

    for candidate in candidates:
        if sum(candidate) not in sum_variations:
            sum_variations.append(sum(candidate))
    
    print(len(sum_variations))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a,b;
    cin>>n>>a>>b;
    if(n>1 && b>=a || n==1 && a==b
        cout<<(n-2)*(b-a)+1<<endl;
    else
        cout<<0<<endl; 
 }

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include<iostream>
using namespace std;
int main()
{
    long long n,a,b;
    cin>>n>>a>>b;
    if(n>1&&b>=a||n==1&&a==b)
        cout<<(n-2)*(b-a)+1<<endl;
    else
        cout<<0<<endl; 
 }

Submission status: Runtime Error

Solution code:
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	unsigned long long a,b,c,d,e,n;
	cin>>n>>a>>b;
	e=(a+b)*n/2;
	cout<<e;
	return 0;
}

Submission status: Runtime Error

Solution code:
a=int(input())
b=int(input())
c=0
for i in range(a,b+1):
    c+=i
print(c)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if N == 1 :
    if A != B :
        ans = 0
    elif :
        ans = 1



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

print(ans)

Submission status: Runtime Error

Solution code:
# AGC015A - A+...+B Problem
import sys
sys.setrecursionlimit(10 ** 9)

from itertools import product


def main():
    n, a, b = tuple(map(int, input().rstrip().split()))
    if a > b or (n == 1 and abs(a - b) > 1):
        print(0)
        return
    if (n == 1 and a == b) or n == 2:
        print(1)
        return
    ans = {sum(i) for i in product(range(a, b + 1), repeat=n - 2)}
    print(len(ans))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# AGC015A - A+...+B Problem
from itertools import product


def main():
    n, a, b = tuple(map(int, input().rstrip().split()))
    if a > b or (n == 1 and abs(a - b) > 1):
        print(0)
        return
    if (n == 1 and a == b) or n == 2:
        print(1)
        return
    ans = {sum(i) for i in product(range(a, b + 1), repeat=n - 2)}
    print(len(ans))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
s = input().split(" ");
n = s[0];
a = s[1];
b = s[2];
if a > b :
  print(0);
else
  if n = 1 or n = 2:
    print(1);
  else
    ans = (b - a)*(n - 2)+1;
    print(ans);

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import  itertools
N,A,B = map(int,input().split())
num = [i for i in range(A,B+1)]
counts = []
for nums in list(itertools.combinations_with_replacement(num,N)):
    if num[0] not in nums or num[-1] not in nums:
        continue
    else:
        counts.append(sum(nums))
print(len(set(counts)))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

cnt = 0

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

Solution code:
n = int(input())
a = int(input())
b = int(input())

def add(n,a,b):
    print((n * b + (a - b)) - (n * a + (b - a)) + 1)
    return (n * b + (a - b)) - (n * a + (b - a)) + 1

add(n,a,b)

Submission status: Runtime Error

Solution code:
n = int(input())
a = int(input())
b = int(input())


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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import itertools
N,A,B = map(int,input().split())
data = range(A,B+1)
if N-2>=0:
  tmp = list(itertools.combinations_with_replacement(data,N-2))
  ans = []
  for i in range(len(tmp)):
    ans.append(sum(tmp[i]))
  print(len(set(ans)))
elif N == 1:
  print('1')
else:
  print('0')

Submission status: Runtime Error

Solution code:
import itertools
N,A,B = map(int,input().split())
data = range(A,B+1)
if N-2>=0:
  tmp = list(itertools.combinations_with_replacement(data,N-2))
  ans = []
  for i in range(len(tmp)):
    ans.append(tmp[i][0]+tmp[i][1])
  print(len(set(ans)))
else:
  print('0')

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,a,b=map(int,input().split())
    
if n==1:    
    if a==b:
        print(1)
    else:
        print(0)
elif n==2:
    if b<a:
        print(0)
    else:
        print(1)
else:
    if b<a:
        print(0)
    elif a==b:
        print(1)
    else:
        print(sum(list(range(b-a+2))[::-1][:n-2]))

Submission status: Runtime Error

Solution code:
n,a,b=map(int,input().split())
    
if n==1:    
    if a==b:
        print(1)
    else:
        print(0)
elif n==2:
    if b<a:
        print(0)
    else:
        print(1)
else:
    if b<a:
        print(0)
    else:
        print(sum(list(range(b-a+2))[::-1][:n-2]))

Submission status: Runtime Error

Solution code:
import itertools

n, a, b = map(int, input().split())
if n < 2 and a != b:
    print(0)
elif n == 1:
    print(1)
else:
    c = set()
    for i in itertools.combinations_with_replacement(range(a, b + 1), n - 2):
        c.add(sum(i))
    print(len(c))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
1 3 3

Submission status: Runtime Error

Solution code:
a = int(input())
b = int(input())

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

# 二進数xの長さを求める時、len(bin(x)) - 2　では、xが0のとき1を返してしまい、バグる原因になる
# よって、二進数の長さを計算する関数を用意しておく
def bitlen(x):
    return 1 + bitlen(x >> 1) if x else 0

t = a ^ b
n = bitlen(t)

T = 1 << (n - 1)

a = a & (T * 2 - 1)
b = b & (T * 2 - 1)

sb = b & (T - 1)
b_max = (2 ** bitlen(sb) - 1) | T

if (T + a) > b_max:
    print((b_max - a + 1) + (2 * T - 1 - (T + a) + 1))
else:
    print(2 * T - 1 - a + 1)

Submission status: Runtime Error

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

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

print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
c=int(input()),a=int(input()),b=int(input())
print((a+b*c-b)-(a*c-a+b)+1)

Submission status: Runtime Error

Solution code:
from itertools import combinations_with_replacement as h_func
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()
x = [i for i in range(a, b+1)]
ans = set()
y = h_func(x, n-2)
for p in y:
    ans.add(sum(p))
print(len(ans))

Submission status: Runtime Error

Solution code:
from itertools import combinations_with_replacement as h_func
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()
x = [i for i in range(a, b+1)]
ans = set()
for p in h_func(x, n-2):
    ans.add(sum(p))
print(len(ans))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=input().slipt()
print(int(n[2]*(n[0]-2)-(n[1]*n[0]-2)+1))

Submission status: Runtime Error

Solution code:
n=input()
a=input()
b=input()
print(int(b*(n-2)-(a*n-2)+1))

Submission status: Runtime Error

Solution code:
#include<iostream>
using namespace std;
unsigned long long n,a,b;
int main(){
    cin>>n>>a>>b;
    cout<<(b*(n-2)-a*(n-2)+1);
    return 0;
}

Submission status: Runtime Error

Solution code:
#include<iostream>
#define ll long long
using namespace std;
ll n,a,b;
int main(){
    cin>>n>>a>>b;
    cout<<(b*(n-2)-a*(n-2)+1);
    return 0;
}

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
	n, a, b = [int(x) for x in raw_input().split()]
	if a == b:
		print 1
		return
	if n == 1:
		print 0
		return
	from itertools import combinations
	s = set()
	for t in combinations(sorted(range(a, b + 1) * 2), n - 2):
		ans = a + b
		for e in t:
			ans += e
		s.add(ans)
	print len(s)
	print s
	return
	
main()

Submission status: Runtime Error

Solution code:
N,A,B=map(lambda x:int(x) , raw_input().split(' '))
if A>B or N<2:
	print 0
elif A==B:
	print 1
else:
	li= range(0,B-A+2)[::-1]
        print li
	print sum(li[:N-2])

Submission status: Runtime Error

Solution code:
s = list(input())

z = 0

for i in s:
    if s[i] == "U":
        z += (len(s) - i)*1 + i * 2
    else:
        z += (len(s) - i)*2 + i * 1

print(z)

Submission status: Runtime Error

Solution code:
s = list(input())

count = 0L

for i in range(len(s)):
    for j in range(len(s)):
        #print(i, j)
        if (i < j and s[i] == "D") or (i > j and s[i] == "U"):
            count += 2
        elif (i < j and s[i] == "U") or (i > j and s[i] == "D"):
            count += 1

print(count)

Submission status: Runtime Error

Solution code:
f=lambda s,h,w,a,q:s[h+1].__setitem__(w+1,s[h+1][w]+s[h][w+1]-s[h][w]+a[h][w]*q)
g=lambda s,y1,x1,y2,x2:s[y2][x2]-s[y2][x1-1]-s[y1-1][x2]+s[y1-1][x1-1]
H,W,N=map(int,raw_input().split())
a=[map(int,raw_input())for _ in[0]*H]
s,s1,s2=[[[0]*(W+1)for _ in[0]*-~H]for _ in[0]*3]
for h in range(H):
	for w in range(W):
		f(s,h,w,a,1)
		f(s1,h,w,a,w+1<W and a[h][w+1])
		f(s2,h,w,a,h+1<H and a[h+1][w])
for _ in[0]*N:
	y1,x1,y2,x2=map(int,raw_input().split())
	print g(s,y1,x1,y2,x2)-g(s1,y1,x1,y2,x2-1)-g(s2,y1,x1,y2-1,x2)

Submission status: Runtime Error

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

    s = set()
    ary = np.arange(a, b+1)
    it = itertools.combinations_with_replacement(ary, n-2)
    for x in it:
        s.add(sum(x))

    return len(s)

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


print(calc(N, A, B))

Submission status: Runtime Error

Solution code:
n,m,q=map(int,input().split())
s,v,el,eu=([[0]*(m+2) for _ in range(n+2)] for _ in range(4))
for i in range(1,n+1):
    s[i][1:m+1]=map(int,input())
    for j in range(1,m+1):
        v[i][j]=v[i][j-1]+s[i][j]
        el[i][j]=el[i][j-1]+s[i][j]*s[i][j-1]
        eu[i][j]=eu[i][j-1]+s[i][j]*s[i-1][j]
for i in range(2,n+1):
    for j in range(1,m+1):
        v[i][j]+=v[i-1][j]
        el[i][j]+=el[i-1][j]
        eu[i][j]+=eu[i-1][j]
for _ in range(q):
    x1,y1,x2,y2=map(int,input().split())
    print(v[x2][y2]-v[x1-1][y2]-v[x2][y1-1]+v[x1-1][y1-1]
            -(el[x2][y2]-el[x1-1][y2]-el[x2][y1]+el[x1-1][y1])
            -(eu[x2][y2]-eu[x1][y2]-eu[x2][y1-1]+eu[x1][y1-1]))

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3
import itertools
N, A, B = map(int, input().split())
t = B - A + 1
if B <= A or N < 2:
    if A == B:
        print(1)
    else:
        print(0)
else:
    s = set()
    print(len({sum(i) for i in itertools.product(range(t), repeat = N - 2)}))

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3
import itertools
N, A, B = map(int, input().split())
t = B - A + 1
s = set()
if B <= A or N < 3:
    if A == B:
        print(1)
    else:
        print(0)
else:
    print(len({sum(i) for i in itertools.product(range(t), repeat = N - 2)}))

Submission status: Runtime Error

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)

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

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

def fact(n, c):
    if c == 0:  return 1
    return n * fact(n - 1, c - 1)

if B < A:
    print(0)
elif N == 1:
    if B == A:
        print(1)
    else:
        print(0)
elif A == B:
    print(1)
elif N == 2:
    print(3)
else:
    result1 = fact(B - A + 2, N - 2) / fact(N - 2, N - 2)
    result2 = (B - A) * (N - 2) + 1
    result = min(result1, result2)
    print(result)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import itertools
N,A,B = map(int,raw_input().split())# 文字列の入力

wa = A+B
list1=[]

if N ==1:
    print 0
elif N ==2:
    print A+B
else:


    plus=list(itertools.product(range(A,B+1), repeat=N-2))
    
    for x in plus:
        su=wa+sum(x)
        if su in list1:
            pass
        else:
            list1.append(su)
    
    print len(list1)

Submission status: Runtime Error

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

    num = tuple(range(A, B+1))
    n = len(num)
    cmb = n ** (N - 2)
    ans = (cmb + 1) // 2
    print(int(ans))

main()

Submission status: Runtime Error

Solution code:
import sys

N = input().split()

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



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

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

Submission status: Runtime Error

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

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

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

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

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

Submission status: Runtime Error

Solution code:
import sys

N = input().split()

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

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

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

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

Submission status: Runtime Error

Solution code:
A=int(input())
B=int(input())
S=[]
times=len(format(A^B,"b"))
for i in range(A,B+1):
  S+=[i]
D=S[:] #Dは基礎集合
SET=set(S)
#for t in range(times):
for i in range(len(S)):
  for j in range(len(D)):
    S+=[S[i]|D[j]]
    SET.add(S[i]|D[j])
print(len(SET))

Submission status: Runtime Error

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

def fact(n, c):
    if c == 0:  return 1
    return n * fact(n - 1, c - 1)

if B < A:
    print(0)
elif N == 1:
    if B == A:
        print(1)
    else:
        print(0)
elif A == B:
    print(1)
else:
    result1 = fact(B - A + 2, N - 2) / fact(N - 2, N - 2)
    result2 = ((B - A) * (N - 2)) + 1
    result = min(result1, result2)
    print(result)

Submission status: Runtime Error

Solution code:
import itertools

def solve(N,A,B):
    if (A>B) or (N==1 and A<B):
        return 0

    if (N==1 and A==B) or N==2:
        return 1

    N = N-2
    nums_memo = set()
    for nums in itertools.combinations_with_replacement(range(A,B+1), N):
        nums_memo.add(sum(nums))
    return len(nums_memo)

if __name__ == '__main__':
    [N,A,B] = input().split()
    print(solve(int(N),int(A),int(B)))

Submission status: Runtime Error

Solution code:
from itertools import combinations
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:
    m = range(n[1],n[2]+1)
    if n[0] != 2:
        c = list(combinations(m,n[0]-2))
        c.extend([(i,i) for i in m])
    else:
        c = [(i,i) for i in m]
    print(len(set([i+j for i,j in c])))

Submission status: Runtime Error

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

def fact(n, c):
    if c == 0:  return 1
    return n * fact(n - 1, c - 1)

if B < A:
    print(0)
elif N == 1:
    if 1 < (B - A):
        print(0)
    else:
        print(1)
elif A == B:
    print(1)
else:
    result1 = fact(B - A + 2, N - 2) / fact(N - 2, N - 2)

    minimum = A * (N - 1) + B
    maximum = A + B * (N - 1)
    result2 = maximum - minimum + 1

    result = min(result1, result2)
    print(result)

Submission status: Runtime Error

Solution code:
import combinations from itertools
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:
    m = range(n[1],n[2]+1)
    c = list(combinations(m,n[0]-2))
    c.extend([(i,i) for i in m])
    print(len(set([i+j for i,j in c])))