Problem:


Score : 400 points

Problem Statement

Akari has n kinds of flowers, one of each kind.

She is going to choose one or more of these flowers to make a bouquet.

However, she hates two numbers a and b, so the number of flowers in the bouquet cannot be a or b.

How many different bouquets are there that Akari can make?

Find the count modulo (10^9 + 7).

Here, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet.

Constraints

All values in input are integers.

2 \leq n \leq 10^9

1 \leq a < b \leq \textrm{min}(n, 2 \times 10^5)

Input

Input is given from Standard Input in the following format:

n a b

Output

Print the number of bouquets that Akari can make, modulo (10^9 + 7). (If there are no such bouquets, print 0.)

Sample Input 1

4 1 3

Sample Output 1

7

In this case, Akari can choose 2 or 4 flowers to make the bouquet.

There are 6 ways to choose 2 out of the 4 flowers, and 1 way to choose 4, so there are a total of 7 different bouquets that Akari can make.

Sample Input 2

1000000000 141421 173205

Sample Output 2

34076506

Print the count modulo (10^9 + 7).



Sample input:
4 1 3


Sample output:
7

Submission status: Runtime Error

Solution code:
def prepare(n, MOD):
    f = 1
    for m in range(1, n + 1):
        f *= m
        f %= MOD
    fn = f
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return fn, invs

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

    mod = 10**9+7
    ans = pow(2, n, mod)

    fn, inv_fact =  prepare(n, mod)

    ans_1 = fn*inv_fact[a]*inv_fact[n-a]%mod
    ans_2 = fn*inv_fact[b]*inv_fact[n-b]%mod

    ans = ans - ans_1 - ans_2
    ans = ans %mod

    print ans -1

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n, a, b = map(int, input().split())
mod = 10**9 + 7
ans = 2**n - 1

from numba import jit, i8

@jit("i8(i8, i8)")
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

ans -= cmb(n, a)
ans -= cmb(n, b)

print(ans % (10**9 + 7))

Submission status: Runtime Error

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

INF = (10**9 + 7)

def f(n):
    if n == 1:
        return 1
    return (f(n-1) * 2) + 1

if n == 2:
    print(0)
else:
    ans = f(n) - f(a) - f(b)
    print(ans % INF)

Submission status: Runtime Error

Solution code:
import sys
import math
MOD = 10 ** 9 + 7

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

def mod_inv(a):
    x = extgcd(a,MOD)[0]
    return (MOD+x%MOD)%MOD

input = sys.stdin.readline
n,a,b = map(int,input().split())
x1 = 1

a = min(a,n-a)
b = min(b,n-b)
if a > b:
    a,b = b,a

for i in range(n-a+1,n+1):
    x1 = x1 * i % MOD
for i in range(1,a+1):
    x1 = x1 * mod_inv(i)

x2 = x1
for i in range(n-b+1,n-a+1):
    x2 = x2 * i % MOD
for i in range(a+1,b+1):
    x2 = x2 * mod_inv(i)
    x2 = x2 % MOD

t = []
nn = n
while nn > 0:
    t.append[nn % 2]
    nn //= 2
t.reverse()
x0 = 1
for i in t:
    x0 = x0 ** 2
    x0 = x0 % MOD
    if i == 1:
        x0 *= 2
        x0 = x0 % MOD
print ((x0 - x1 - x2 - 1) % MOD)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
MOD = 10 ** 9 + 7

def cmb(n, k):
    if k > n:
        return 0
    return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD

def cumprod(arr, MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64); x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv

def power_func(a,n,p):
    bi=str(format(n,"b"))#2進表現に
    res=1
    for i in range(len(bi)):
        res=(res*res) %p
        if bi[i]=="1":
            res=(res*a) %p
    return res

U = N+1 # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)
answer = power_func(2, N, MOD) - 1 - cmb(N, A) - cmb(N, B)
print(answer%MOD)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
n,a,b = map(int, input().split())
print(int( (2**n - 1 - comb(n, a, exact=True) - comb(n, b, exact=True)) % (10e9+7) ))

Submission status: Runtime Error

Solution code:
p = 10 ** 9 + 7
n,a,b = map(int,input().split())

def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p

def pow_r(x, n):
    if n == 0:
        return 1
    if n % 2 == 0:
        return pow_r(x ** 2 % p, n // 2)
    else: 
        return x * pow_r(x ** 2 % p, (n - 1) // 2)

for i in range(2, n + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

plus = pow_r(2, (n - 1))
sum = 2 * plus - 1 % p

fact = [1, 1] 
factinv = [1, 1] 
inv = [0, 1] 
print(sum - cmb(n,a) % p - cmb(n,b) % p)

Submission status: Runtime Error

Solution code:
n,a,b=map(int,input().split())
MOD=10**9+7

s=((2**n) - 1)%MOD 
def factorial_cor(n,k,MOD):
    fact = 1
    for integer in range(n-k+1, n + 1):
        fact *= integer
        fact=fact%MOD
    return fact
def factorial(n,MOD):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
        fact=fact%MOD
    return fact

def mod_combination(n, k, mod):
    # nCk (mod m)
    def mod_permutation(n, k, mod):
        if n<=k:
            return 1
        else:
            return (n * mod_permutation(n-1,k,mod))%mod

    def mod_inv_permutation(k, mod):
        k, mod = int(k), int(mod)
        if k<=1:
            return 1
        else:
            return (pow(k,mod-2,mod) * mod_inv_permutation(k-1, mod))%mod

    return (mod_permutation(n,n-k,mod) * mod_inv_permutation(k, mod))%mod
nca=mod_combination(n,a,MOD)
ncb=mod_combination(n,b,MOD)
ans=int(s-nca-ncb)%MOD
print(ans)

Submission status: Runtime Error

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

mod = 10**9+7
MAX_N = 10**9

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%mod


def mod_comb_k(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

s=(2**n-1)%mod-mod_comb_k(n,a,mod)-mod_comb_k(n,b,mod)

print(s)

Submission status: Runtime Error

Solution code:
n,a,b =map(int, input().split())
c=2**n-1
from scipy.special import comb
A= comb(n, a, exact=True)
B= comb(n, b, exact=True)
c=c-A-B
print(c)

Submission status: Runtime Error

Solution code:
import itertools
ans=0
n,a,b = map(int, input().split())
# def remove_specified_values(arr, value):
#     while value in arr:
#         arr.remove(value)
tmp=(10**9+7)
for i in range(1,n+1):
    if i==a:
        continue
    if i==b:
        continue
    ans+=len(list(itertools.combinations(list(range(0,n)), i)))
    if ans>tmp:
        ans=ans-tmp
print(ans)

Submission status: Runtime Error

Solution code:
n, a, b = map(int, input().split())
ans = 1
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

pr1 = cmb(n,a,mod)
pr2 = cmb(n,b,mod)
for i in range(0,n):
    ans *= 2
    ans %= 1000000007

print(ans-pr1-pr2-1)

Submission status: Runtime Error

Solution code:
import sys
import math
MOD = 10 ** 9 + 7

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

def mod_inv(a):
    x = extgcd(a,MOD)[0]
    return (MOD+x%MOD)%MOD

input = sys.stdin.readline
n,a,b = map(int,input().split())
x1 = 1

a = min(a,n-a)
b = min(b,n-b)
if a > b:
    a,b = b,a

for i in range(n-a+1,n+1):
    x1 = x1 * i % MOD
for i in range(1,a+1):
    x1 = x1 * mod_inv(i)

x2 = x1
for i in range(n-b+1,n-a+1):
    x2 = x2 * i % MOD
for i in range(a+1,b+1):
    x2 = x2 * mod_inv(i)
    x2 = x2 % MOD

t = []
nn = n
while nn > 0:
    t.append[nn % 2]
    nn //= 2
t.reverse()
x0 = 1
for i in t:
    x0 = x0 ** 2
    x0 = x0 % MOD
    if i == 1:
        x0 *= 2
        x0 = x0 % MOD
print ((x0 - x1 - x2 - 1) % MOD)

Submission status: Runtime Error

Solution code:
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

n,a,b = map(int, input().split())
Ca = cmb(n, a)
Cb = cmb(n, a)
r = (2**n - Ca - Cb - 1) % (10**9 + 7)
print(r)

Submission status: Runtime Error

Solution code:
def cmb(n, r, mod):
	if ( r<0 or r>n ):
		return 0
	r = min(r, n-r)
	return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def main():
	n,a,b=map(int, input().split())
	count = 0
	for i in range(1,n+1):
		if i!=a and i!=b:
			count +=cmb(n,i,mod)
		else:
			count = count
	print(count%(1000000000+7))
main()

Submission status: Runtime Error

Solution code:
n,a,b=map(int, input().split())
mod,ans=1000000007,0
#階乗（をmodで割ったあまり）のテーブルを作る
fac=[0]*(n+1)
finv=[0]*(n+1)
inv=[0]*(n+1)
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,n+1):
    fac[i]=fac[i-1]*i%mod
    inv[i]=mod-inv[mod%i]*(mod//i)%mod
    finv[i]=finv[i-1]*inv[i]%mod

def comb_count(n,r): #組み合わせを数える関数
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod

for i in range(1,n+1):
    if i==a or i==b:
        continue
    else:
        ans+=comb_count(n,i)
print(ans)

Submission status: Runtime Error

Solution code:
import math
n, a, b = map(int,input().split())
score = 1
total = 0
if n % 2 == 1:
  for i in range(1,n//2+1):
    score = score * (n-i+1) // i
  if i != a and i != b and i != n-a and i != n-b:
    total += 2 * score
  else:
    total += score
else:
  for i in range(1,n//2):
    score = score * (n-i+1) // i
  if i != a and i != b and i != n-a and i != n-b:
    total += 2 * score
  else:
    total += score
  k = n//2 
  if k != a and k != b and k != n-a and K != n-b:
    total += score * (n-k+1) // k
print(total % (10**9 + 7))

Submission status: Runtime Error

Solution code:
n,a,b = map(int, input().split())
if n/2 < a: a=n-a
if n/2 < b: b=n-b
total, combination = 0,1

for i in range(1,(n-1)//2+1):
    combination = combination*(n-i+1)/i
    total += combination
    if a == i: a_cnt = combination
    if b == i: b_cnt = combination
        
    total = total%(10**9+7)

if n == 2:
    print(0)
elif n%2==0:
    answer = total*2+combination*(n-i)/(i+1)-a_cnt-b_cnt+1
    print(answer%(10**9+7))
else:
    answer = total*2-a_cnt-b_cnt+1
    print(answer%(10**9+7))

Submission status: Runtime Error

Solution code:
import math
from scipy.special import comb

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

q = 10 ** 9 + 7

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

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K*x

ans = pow_k(2,n)
ans -= combinations_count(n,a) + combinations_count(n,b) + 1

print(ans % q)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def powr(i, j, d):
    p = j
    ans = 1
    while p != 0:
        if p % 2 == 1:
            ans = (ans * i) % d
        i = i**2 % d
        p >>= 1
    return ans

def div(i, j):
    # 1/i mod(j)
    # calc i**(j-2) mod(j)
    return powr(i, j-2, j)

def make_comb(m, d):
    fac = [0] * (m+1)
    ifac = [0] * (m+1)
    # nCk
    fac[0] = 1
    ifac[0] = 1
    for i in range(m):
        fac[i+1] = (fac[i] * (i+1)) % d
        ifac[i+1] = (ifac[i] * div(i+1, d)) % d
    def comb(n, k):
        if n == 0 and k == 0:
            return 1
        if n < k or n < 0:
            return 0
        return (fac[n] * ifac[k] * ifac[n-k]) % d
    return comb

def main():
    n, a, b = list(map(int, input().strip().split()))
    d = 10**9+7
    comb = make_comb(10**6, d)
    ans = (powr(2, n, d) - 1 - comb(n, a) - comb(n, b)) % d
    if ans < 0:
        print(ans + d)
    else:
        print(ans)

    # print(comb(10, 2))
    # print(comb(5, 2))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

ans = 2**n-1
ans -= comb(n ,a , exact=True)
ans -= comb(n ,b, exact=True)

print(ans%(10**9+7))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
def main(n,a,b):
    return (2**n - 1) - (ccount(n,a) + ccount(n,b))
def ccount(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,a,b = map(int, input().split())
print(np.mod(main(n,a,b), 10**9+7))

Submission status: Runtime Error

Solution code:
mod = 1000000007

def cmb(n, r):
    nCr = {}
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

def bouquet(n,a,b):
    n_bouquet = 0
    for i in range(n+1):
        if(i == 0 or i == a or i == b):
            #print(i)
            continue
        n_bouquet += cmb(n, i)
    return n_bouquet

N, A, B= map(int, input().split())
d = bouquet(N,A,B)
print(d % mod)

Submission status: Runtime Error

Solution code:
i = list(map(int, input().split()))
import math
ans=0
def combinations_count(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for k in range(1,i[0]+1):
  if k==i[1] or k==i[2]:
    pass
  else:
    ans+=((combinations_count(i[0], k)%(10**9+7))
while ans>=10**9+7:
	ans=ans%(10**9+7)
print(ans)

Submission status: Runtime Error

Solution code:
import math
n, a, b = map(int,input().split())
score = 1
total = 0
if n % 2 == 1:
  for i in range(1,n//2+1):
  score = score * (n-i+1) // i
  if i != a and i != b and i != n-a and i != n-b:
    total += 2 * score
  else:
    total += score
else:
  for i in range(1,n//2):
  score = score * (n-i+1) // i
  if i != a and i != b and i != n-a and i != n-b:
    total += 2 * score
  else:
    total += score
  k = n//2 
  if k != a and k != b and k != n-a and K != n-b:
    total + score * (n-k+1) // k
print(total % (10**9 + 7))

Submission status: Runtime Error

Solution code:
import math
n, a, b = map(int,input().split())
score = 1
total = 0
if n % 2 = 1:
  for i in range(1,n//2+1):
  score = score * (n-i+1) // i
  if i != a and i != b and i != n-a and i != n-b:
    total += 2 * score
  else:
    total += score
else:
  for i in range(1,n//2):
  score = score * (n-i+1) // i
  if i != a and i != b and i != n-a and i != n-b:
    total += 2 * score
  else:
    total += score
  k = n//2 
  if k != a and k != b and k != n-a and K != n-b:
    total + score * (n-k+1) // k
print(total % (10**9 + 7))

Submission status: Runtime Error

Solution code:
import math
from scipy.special import comb
q = 10 ** 9 + 7

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

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K*x

ans = pow_k(2,n)
ans -= comb(n,a,exact=True) + comb(n,b,exact=True) + 1

print(ans % q)

Submission status: Runtime Error

Solution code:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

s = list(map(int, input().split()))
n = s[0]
a = s[1]
b = s[2]
ans = 0
for i in range(n):
    if i+1 == a or i+1 ==b:
        continue
    else:
        ans += cmb(n, i+1 ,mod)
print(ans)

Submission status: Runtime Error

Solution code:
import math
import sys
from functools import lru_cache
#from scipy.special import comb
from operator import mul
from functools import reduce

n,a,b=map(int,input().split())
'''
def memoize(f): #メモ化関数
    table = {}
    def func(*args):
        if not args in table:
            table[args] = f(*args)
        return table[args]
    return func

@memoize
def memFrac(n):
    if ( n==0 ):
        return 1
    else:
        return n*memFrac(n-1)

def perm(n,r):
    return memFrac(n) // (memFrac(n - r)*memFrac(r))

sys.setrecursionlimit(1000000007)
@lru_cache(maxsize=1000)
def frac(n):
    if n<2:
        return n
    else:
        return n*frac(n-1)

def perm(n,r):
    return frac(n) // (frac(n - r)*frac(r))
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p


p = 10 ** 9 + 7
N = 10 ** 10  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
'''
p = 10 ** 9 + 7

@lru_cache(maxsize=1000)
def frac(n):
    if n<2:
        return n
    else:
        return n*frac(n-1)

def perm(n,r):
    return frac(n) // (frac(n - r)*frac(r))


a1=perm(n,a)
b1=perm(n,b)

#a1=cmb(n,a)
#b1=cmb(n,b)

print((pow(2,n)-1-a1-b1)%p)

Submission status: Runtime Error

Solution code:
import math
from scipy.special import comb
q = 10 ** 9 + 7

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

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    c = K*x

    if K * x >= q:
        c %= q

    return c

ans = pow_k(2,n)
ans -= comb(n,a,exact=True) + comb(n,b,exact=True) + 1

print(ans % q)

Submission status: Runtime Error

Solution code:
import math
n, a, b = map(int,input().split())
score = 1
total = 0
if n % = 1:
  for i in range(1,n//2+1):
  score = score * (n-i+1) // i
  if i != a and i != b and i != n-a and i != n-b:
    total += 2 * score
  else:
    total += score
else:
  for i in range(1,n//2):
  score = score * (n-i+1) // i
  if i != a and i != b and i != n-a and i != n-b:
    total += 2 * score
  else:
    total += score
  k = n//2 
  if k != a and k != b and k != n-a and K != n-b:
    total + score * (n-k+1) // k
print(total % (10**9 + 7))

Submission status: Runtime Error

Solution code:
inp = [int(i) for i in input().split()]
n = inp[0]
a = inp[1]
b = inp[2]

C = {}
def cmb(n,r):
  print(n,r)
  if r==0 or r ==n:
    return 1
  if r==1:
    return n
  if (n,r) in C:
    return C[(n,r)]
  C[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
  return C[(n,r)]
  
A = cmb(n,a)
B = cmb(n,b)
ans = 2**n-1-A-B
print(ans%(10**9+7))

Submission status: Runtime Error

Solution code:
import math
from scipy.special import comb
q = 10 ** 9 + 7

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

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    c = K*x

    if K * x >= q:
        c %= q

    return c

ans = pow_k(2,n)
print(ans)
ans -= comb(n,a,exact=True) + comb(n,b,exact=True) + 1

print(ans % q)

Submission status: Runtime Error

Solution code:
def extgcd(a, b):
    r = [1, 0, a]
    w = [0, 1, b]
    while w[2] != 1:
        q = r[2] // w[2]
        r2 = w
        w2 = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]]
        r = r2
        w = w2
    return [w[0], w[1]]

def mod_inv(a, m):
    x = extgcd(a, m)[0]
    return (m + x % m) % m

def mod_e(n, p):
    res = 0
    while n >= p:
        res += n // p
        n = n // p
    return res

def mod_fact(n, p):
    if n == 0:
        return 1

    res = mod_fact(n // p, p)

    if n // p % 2 != 0:
        return res * (p - fact[n % p]) % p
    return res * fact[n % p] % p

def cmb(n, k, p):
    if n < 0 or k < 0 or n < k:
        return 0
    e1 = mod_e(n, p)
    e2 = mod_e(k, p)
    e3 = mod_e(n - k, p)
    if e1 > e2 + e3:
        return 0
    a1 = mod_fact(n, p)
    a2 = mod_fact(k, p)
    a3 = mod_fact(n - k, p)
    return a1 * mod_inv(a2 * a3 % p, p) % p

p =10**9+7

fact = [1]
k = 1
for i in range(1,10**6+1):
    k = k*i%p
    fact.append(k)

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

sum = 0
for i in range(n // 2):
    sum = sum + 2 * cmb(n, i, p)
    sum = sum % p

if n % 2 == 0:
    sum = sum + cmb(n, n // 2, p)

sum = sum - cmb(n, a, p) - cmb(n, b, p)

sum = sum % p

print(sum - 1)

Submission status: Runtime Error

Solution code:
def cmb(n, r, p):
	if (r < 0) or (n < r):
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % p


p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
	fact.append((fact[-1] * i) % p)
	inv.append((-inv[p % i] * (p // i)) % p)
	factinv.append((factinv[-1] * inv[-1]) % p)


n,a,b=map(int,input().split())
ans=((2**n-1)%p-cmb(n,a,p)-cmb(n,b,p))
print(0 if ans<0 else ans)

Submission status: Runtime Error

Solution code:
n,a,b=map(int,input().split())
mod=10**9+7
bikkuri=[0 for i in range(n+5)]
bikkuri[0]=1
gyaku=[0 for i in range(n+5)]
gyaku[0]=1
for i in range(1,n+5):
    bikkuri[i] = (i * bikkuri[i-1])%mod
for i in range(n+4, -1, -1)
    gyaku[i]=pow(bikkuri[i], mod-2, mod)
def comb(a,b):
    return bikkuri[a]*gyaku[b]*gyaku[a-b]
ans=(2**n)-1-comb(n,a)-comb(n,b)
print(ans%mod)

Submission status: Runtime Error

Solution code:
n,a,b=map(int,input().split())
mod=10**9+7
bikkuri=[0 for i in range(n+5)]
bikkuri[0]=1
gyaku=[0 for i in range(n+5)]
gyaku[0]=1
for i in range(1,n+5):
    bikkuri[i] = (i * bikkuri[i-1])%mod
gyaku[n+3]=
for i in range(n+4, -1, -1)
    gyaku[i]=pow(bikkuri[i], mod-2, mod)
def comb(a,b):
    return bikkuri[a]*gyaku[b]*gyaku[a-b]
ans=(2**n)-1-comb(n,a)-comb(n,b)
print(ans%mod)

Submission status: Runtime Error

Solution code:
n,a,b = list(map(int,input().split()))
kumiawase_bunshi = 1
kumiawase_bunbo = 1
t=0
ans = 0
for i in range (1,n+1):
    if(i != a and i != b):
        t=n
        for j in range (n-i+1,n+1):
            kumiawase_bunshi = kumiawase_bunshi * j
        for k in range (1,i+1):
            kumiawase_bunbo = kumiawase_bunbo * k
        ans = ans + (kumiawase_bunshi / kumiawase_bunbo)
        kumiawase_bunshi = 1
        kumiawase_bunbo = 1
ans = ans % 1000000007
print(ans)

Submission status: Runtime Error

Solution code:
n, a, b = map(int, input().split())
counts = [0]*(n+1)
counts[1] = n
mod = 10**9+7
for i in range(2, n+1):
    counts[i] = counts[i-1] * (n-i+1) // i % mod
counts[a] = 0
counts[b] = 0
print(sum(counts))

Submission status: Runtime Error

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

mod = 1000000007
def choice(target, i, select_cnt):
    ret = 0
    temp_list = list(target)
    temp = []
    for n in range(i, len(target)):
        temp.append(target[n])
        if len(temp) == select_cnt:
            ret += 1
            temp.pop()

    return ret


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

hana_kind = list(range(1, n + 1))

hanataba_koho = list(set(hana_kind) - {a, b})

result = 0
for hanataba_koho_select_cnt in hanataba_koho:
    for i in range(len(hana_kind) - hanataba_koho_select_cnt + 1):
        result += choice(hana_kind, i, hanataba_koho_select_cnt) % mod

print(result)

Submission status: Runtime Error

Solution code:
#abc156 d
n,a,b=map(int,input().split())
ans=[1]*(n+1)
for i in range(1,n+1):
    ans[i]=int(ans[i-1]*(n+1-i)/i)

x=sum(ans)-ans[a]-ans[b]-1
print(x)

Submission status: Runtime Error

Solution code:
n, a, b = map(int, input().split())
mod = 10**9+7

#print(x*pow(y,(mod-2),mod)%mod)

def conv(n, x, mod):
    X = 1
    for i in range(x):
        k = i+1
        X *= (n-k+1)*pow(k,(mod-2),mod)%mod
        X %= mod
    return X

def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

#print(conv(n, a, mod))
#print(conv(n, b, mod))

ans = power_func(2, n, mod) - conv(n, a, mod) - conv(n, b, mod) - 1
ans %= mod
print(ans)n, a, b = map(int, input().split())
mod = 10**9+7

#print(x*pow(y,(mod-2),mod)%mod)

def conv(n, x, mod):
    X = 1
    for i in range(x):
        k = i+1
        X *= (n-k+1)*pow(k,(mod-2),mod)%mod
        X %= mod
    return X

def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

#print(conv(n, a, mod))
#print(conv(n, b, mod))

ans = power_func(2, n, mod) - conv(n, a, mod) - conv(n, b, mod) - 1
ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
from copy import deepcopy
n=0
a=0
b=0

nf = 0
af = 0
bf =0
naf = 0
nbf=0
def factorial(n):
    global nf
    global af
    global bf
    global naf
    global nbf
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
        if integer == a:
            af = deepcopy(fact)
        if integer == b:
            bf = deepcopy(fact)
        if integer == n-a:
            naf = deepcopy(fact)
        if integer == n-b:
            nbf = deepcopy(fact)

    nf = deepcopy(fact)


if __name__ == '__main__':
    n ,a, b = map(int, input().split())
    sum = 2 ** n -1
    factorial(n)


    sum = sum - nf / (af * naf )
    sum = sum - nf / (bf * nbf )


    sum = sum % (10 ** 9 + 7)

    print(int(sum))

Submission status: Runtime Error

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

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if(n==2):
  print('0')
else:
  sigma = 0
  cc = 1
  for i in range(n):
    cc = int((n-i)/(i+1)*cc)
    if(i != (n-a-1) and i != (n-b-1)):
      sigma += cc
  print(sigma%(10**9+7))

Submission status: Runtime Error

Solution code:
n=0
a=0
b=0

nf = 0
af = 0
bf =0
naf = 0
nbf=0
def factorial(n):
    global nf
    global af
    global bf
    global naf
    global nbf
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
        if integer == a:
            af = deepcopy(fact)
        if integer == b:
            bf = deepcopy(fact)
        if integer == n-a:
            naf = deepcopy(fact)
        if integer == n-b:
            nbf = deepcopy(fact)

    nf = deepcopy(fact)


if __name__ == '__main__':
    n ,a, b = map(int, input().split())
    sum = 2 ** n -1
    factorial(n)


    sum = sum - nf / (af * naf )
    sum = sum - nf / (bf * nbf )


    sum = sum % (10 ** 9 + 7)

    print(int(sum))

Submission status: Runtime Error

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

mod = 10**9+7
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

fac = [0]*(n+1)
fac[0] = 1
fac[1] = 1
for i in range(2,n+1):
    fac[i] = fac[i-1] * i % mod

c = 0
if n % 2 == 0:
    for i in range(1,n//2 ):
        c += ( fac[n] * modinv(fac[i]) )%mod * modinv(fac[n-i]) % mod
    c *= 2
    c += ( fac[n] * modinv(fac[n//2]) )%mod * modinv(fac[n-n//2]) % mod
    c -= ( fac[n] * modinv(fac[a]) )%mod * modinv(fac[n-a]) % mod
    c -= (fac[n] * modinv(fac[b])) % mod * modinv(fac[n-b]) % mod
    c += 1
    if c > 0:
        c = c % mod
else:
    for i in range(1, n // 2 + 1):
        c += (fac[n] * modinv(fac[i])) % mod * modinv(fac[n - i]) % mod
    c *= 2
    c -= (fac[n] * modinv(fac[a])) % mod * modinv(fac[n - a]) % mod
    c -= (fac[n] * modinv(fac[b])) % mod * modinv(fac[n - b]) % mod
    c += 1
    if c >0:
        c = c % mod

print(max(c,0))

Submission status: Runtime Error

Solution code:
from scipy.special import comb
n, a, b = (int(i) for i in input().split())
ans = 0
for i in range(1,n+1):
    if i != a and i != b:
        ans += comb(n,i, exact=True)
print(ans%(10**9 + 7))

Submission status: Runtime Error

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

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if(n==2):
  print('0')
else:
  sigma = 0
  cc = 1
  for i in range(n):
    cc = int((n-i)/(i+1)*cc)
    if(i != (n-a-1) and i != (n-b-1)):
      sigma += cc
  print(sigma)

Submission status: Runtime Error

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

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**4
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def pow(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans
    
if n==2:
    print(0)
else:
    ans=pow(2,n)-1-comb(n,a,mod)-comb(n,b,mod)
    print(ans%(10**9+7))

Submission status: Runtime Error

Solution code:
n,a,b = map(int, input().split())
if n/2 < a: a=n-a
if n/2 < b: b=n-b
total, combination = 0,1

for i in range(1,(n-1)//2+1):
    combination = combination*(n-i+1)/i
    total += combination
    if a == i: a_cnt = combination
    if b == i: b_cnt = combination
        
    total = total%(10**9+7)

if n%2==0:
    print(total*2+combination*(n-i)/(i+1)-a_cnt-b_cnt+1)
else:
    print(total*2-a_cnt-b_cnt+1)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
def main():
	n,a,b=map(int, input().split())
	count = 0
	for i in range(1,n+1):
		if i!=a and i!=b:
			count +=comb(n,i,exact=True)
		else:
			count = count
	print(count%(1000000000+7))
main()

Submission status: Runtime Error

Solution code:
n,a,b = map(int,input().split())
mod=10**9+7

def sig(n):
    #return 2**n
    if n==1:
        return 2
    elif n%2==0:
        return (sig(n//2)**2)%mod
    else:
        return (2*sig((n-1)//2)**2)%mod
    
s = sig(n) - 1

MAX = 10**5*3

facts = [1 for i in range(n)]
invs = [1 for i in range(n)]

def inv(x):
	return pow(x,mod-2,mod)
 
for i in range(1,MAX):
		facts[i] = (facts[i-1] * i)% mod
		invs[i] = inv(facts[i])

def nCr(n,r):
	return facts[n]*invs[r] * invs[n-r] % mod

x = nCr(n,a)%mod
y = nCr(n,b)%mod

if s-(x+y) < 0:
    print(s-(x+y)+mod)
else:
    print(s-(x+y)%mod)