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:

n,a,b = map(int, input().split())
MOD = 10**9 + 7
allpair = pow(2,n,MOD)

def combo(n,k):
    c = 1
    for i in range(k):
        c *= n - i
        c %= MOD

    d = 1
    for i in range(1, k+1):
        d *= i
        d %= MOD

    return (c * pow(d, mod-2, MOD)) % MOD

print((allpair - combo(n, a) - combo(n, b) - 1) % MOD)

Submission status: Runtime Error

Solution code:

n,a,b = map(int, input().split())
MOD = 10**9 + 7
allpair = pow(2,n,MOD)

N = n
# 早いnCrの準備ここから
fact = [0] * (N+1)
fact_inv = [0] * (N+1)
inv = [0] * (N+1)

fact[0] = fact[1]  = 1
fact_inv[0] = fact_inv[1] = 1
inv[1] = 1

for i in range(2, N+1):
    fact[i] = fact[i-1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD # //で良いのかな?
    fact_inv[i] = fact_inv[i-1] * inv[i] % MOD

def combo(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fact[n] * (fact_inv[k] * fact_inv[n-k] % MOD) % MOD

print((allpair - combo(n, a) - combo(n, b) - 1) % MOD)

Submission status: Runtime Error

Solution code:
from itertools import combinations

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

cnt = 0
n_2 = int(n / 2)
for i in range(n_2):
    if i == a or i == b:
        continue
    cnt += combinations(n, i) * 2
if n % 2 == 1:
    cnt += combinations(n, i)
print(cnt)

Submission status: Runtime Error

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

res = 0

def comb(n, k):
    """nCkを計算する関数"""
    fact = [1] * (n+1)
    for i in range(1, n+1):
        fact[i] = fact[i-1] * i % MOD

    # k!と(n-k)!の逆元はそれぞれ、(k!) ** (MOD-2), (n-k)!**(MOD-2)
    res = fact[n] * pow(fact[k], -1, MOD) * pow(fact[n-k], -1, MOD)
    return res % MOD


for i in range(n):
    if i != a and i != b:
        res += comb(n, i)

print(res)

Submission status: Runtime Error

Solution code:
n,a,b=map(int,input().split())
mod=10**9+7
from math import pow
def comb(n,k,mod):
  if k>n-k:
    k=n-k
  c=1
  for i in range(n-k+1,n+1):
    c*=i
  d=1  
  for i in range(1,k+1):
    d*=i
return(c*pow(d,mod-2,mod)%mod)

ans=(2**n-1)-comb(n,a,mod)-comb(n,b,mod)
return (ans%mod)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [float('inf')]*N
dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        if N > i+j:
            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]))

print(dp[N-1])

Submission status: Runtime Error

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

fact = [0] * (n+1)
inv_fact = [0] * (n+1)

fact[0] = 1
for i in range(1, n+1):
    fact[i] = fact[i-1] * i % MOD

inv_fact[n] = pow(fact[n], MOD-2, MOD)
for i in range(n, 0, -1):
    inv_fact[i-1] = inv_fact[i] * i % MOD


def nCk(n, k):
    return (fact[n] * inv_fact[k] * inv_fact[n-k]) % MOD


ans = 0
for k in range(1, n+1):
    if k == a or k == b:
        continue
    ans += nCk(n, k) % MOD
    
print(ans % MOD)

Submission status: Runtime Error

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

for i in range(b):
    if i < a:
        aa = aa *(n-i) /(i+1)

    bb = bb *(n-i) /(i+1)

ans = int((ans -aa -bb) % inf)
print(ans)

Submission status: Runtime Error

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


dp = [0] * int((n+2)/2)

dp[1] = n

for i in range(1,len(dp)-1):
    dp[i+1] = dp[i] * (dp[i] -1) /(i+1)

dpr = dp[::-1]

if int(n/2) * 2 == n: #nが偶数
    dpr = dpr[:-1]

dp += dpr

dp[-1] = 1

ans = sum(dp)

ans -= dp[a]
ans -= dp[b]
ans = ans%(10**9+7)

print(int(ans))

Submission status: Runtime Error

Solution code:
MOD=10**9+7

def powmod(a,n,m): #a^n mod m
    ans=1
    while n!=0:
        if n&1: ans=ans*a%m
        a=a*a%m
        n>>=1
    return ans%m

def fact(n):
    ans=1
    for i in range(n): ans=ans*(i+1)%MOD
    return ans

def fact(a,b):
    ans=1
    for i in range(a,b+1): ans*=ans*i%MOD
    return ans

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

ans=powmod(2,n,MOD)-1
ta1=fact(n-a+1,n)
tb1=fact(n-b+1,n)
ta2=pow(fact(a),MOD-2,MOD)
tb2=pow(fact(b),MOD-2,MOD)
a=ta1*ta2%MOD
b=tb1*tb2%MOD
print((ans-a-b)%MOD)

Submission status: Runtime Error

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

def f(A):
    bunsi = reduce(lambda x, y: x*y%mod, range(N, N-A, -1))
    bunbo = reduce(lambda x, y: x*y%mod, range(1, A+1))
    return bunsi * pow(bunbo, mod-2, mod) % mod
  
ans = pow(2, n, mod) - f(a) -f(b) - 1
ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
import math
from operator import mul
from functools import reduce
n, a, b = map(int, input().split())
s=0
mod = pow(10, 9) + 7
def combinations_count(n, r):
    #return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
if n==2:
    print('0')
a=combinations_count(n, a)

b=combinations_count(n, b)
else:
    print((pow(2, n, mod) -1 -a -b) % mod)

Submission status: Runtime Error

Solution code:
from functools import reduce
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n, a, b = map(int, read().split())
MOD = 10 ** 9 + 7


def combo_mod(n, a):
    t = reduce(lambda x, y: x * y % MOD, range(n, n - a, -1))
    b = reduce(lambda x, y: x * y % MOD, range(1, a + 1))
    return t // b


ans = pow(2, n, MOD) - combo_mod(a) - combo_mod(b) - 1
ans %= MOD

print(ans)

Submission status: Runtime Error

Solution code:
def powerDX(n, r, mod):
  if r == 0: return 1
  if r%2 == 0:
    return powerDX(n*n % mod, r//2, mod) % mod
  if r%2 == 1:
    return n * powerDX(n, r-1, mod) % mod
 
def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod
 
ans = pow(2, n, mod) - 1
ans -=  combination(n, a, mod)
ans -=  combination(n, b, mod)
ans += 3*mod
ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
def powerDX(n, r, mod):
  if r == 0: return 1
  if r%2 == 0:
    return powerDX(n*n % mod, r//2, mod) % mod
  if r%2 == 1:
    return n * powerDX(n, r-1, mod) % mod
 
def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * powerDX(denom, mod-2, mod) % mod
 
ans = pow(2, n, mod) - 1
ans -=  combination(n, a, mod)
ans -=  combination(n, b, mod)
ans += 3*mod
ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
def powerDX(n, r, mod):
  if r == 0: return 1
  if r%2 == 0:
    return powerDX(n*n % mod, r//2, mod) % mod
  if r%2 == 1:
    return n * powerDX(n, r-1, mod) % mod
 
def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * powerDX(denom, mod-2, mod) % mod
 
ans = power(2, n, mod) - 1
ans -=  combination(n, a, mod)
ans -=  combination(n, b, mod)
ans += 3*mod
ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
from math import comb

M = 10**9 + 7
n,a,b = map(int, input().split())

print(pow(2, n, M) - comb(n, a) % M - comb(n, b) % M)

Submission status: Runtime Error

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

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



x=mod_comb_k(n,a,mod)+mod_comb_k(n,b,mod)
y=((pow(2,n)-1)%(10**9+7))
ans=(y-x%(10**9+7))
while ans<0:
          ans+=10**9+7
print(ans)

Submission status: Runtime Error

Solution code:

n,a,b=map(int,input().split
mod = 10**9+7
MAX_N = 10**6

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



x=mod_comb_k(n,a,mod)+mod_comb_k(n,b,mod)
y=((pow(2,n)-1)%(10**9+7))
ans=(y-x%(10**9+7))
while ans<0:
          ans+=10**9+7
print(ans)

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce
n,a,b=map(int,input(),split())
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

x=cmb(n,a)+cmb(n,b)
y=pow(2,n)-1
ans=(y-x%(10**9+7))
print(ans)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
import math
n,a,b = map(int,input().split())
Mod = 10**9+7



def Mod_pow(x, n):
    x = x%Mod
    if n==0:
        return 1
    elif n%2==1:
        return (x*Mod_pow(x,n-1)%Mod)
    else:
        return (Mod_pow(x*x,n/2)%Mod)


def comb(n,r):
    x,y = 1,1
    for i in range(n-r+1,n+1):
        x = x*i%Mod

    for i in range(1,r+1):
        y = y*i%Mod

    #この問題の特徴，フェルマーの小定理よりyで除算することはy^(Mod-2)をかけることと同値
    y = Mod_pow(y,Mod-2)
    return x*y%Mod

ans = (Mod_pow(2,n)-1-comb(n,a)-comb(n,b))
while ans<0:
    ans += Mod

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def combinations_mod(n, r, mod=1000000007):
    """Returns nCr in mod."""
    r = min(r, n - r)
    combs = 1
    for i, j in zip(range(n - r + 1, n + 1), range(1, r + 1)):
        combs *= (i % mod) * pow(j, mod - 2, mod)
        combs %= mod
    return combs


def main():
    n, a, b = NMI()
    all = pow_mod(2, n, MOD) - 1
    ans = all - combinations_mod(n, a) - combinations_mod(n, b)
    ans %= MOD
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def combinations_mod(n, r, mod=1000000007):
    """Returns nCr in mod."""
    combs = 1
    for i, j in zip(range(n - r + 1, n + 1), range(1, r + 1)):
        combs = combs % mod * i % mod * pow(j, mod - 2, mod) % mod
    return combs


def main():
    n, a, b = [int(x) for x in input().split()]
    combs = [0] * (n + 1)  # memorize
    combs[0] = 1  # Pick no flower
    ans = 0
    for pick in range(1, n + 1):
        tmp = combs[n - pick]
        if tmp != 0:
            comb = tmp
        else:
            comb = combinations_mod(n, pick)
        combs[pick] = comb
        if pick not in (a, b):
            ans += comb
            ans %= 1000000007

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

mod = 10 ** 9 + 7

def comb( n, r, mod ):
  c = 1
  m = 1
  r = min( n - r, r )
  for i in range( r ):
    c = c * ( n - i ) % mod
    m = m * ( i + 1 ) % mod
  return c * pow( m, mod - 2, mod ) % mod

N = pow( 2, n, mod )
A = comb( n, a )
B = comb( n, b )
print(( N - A - B ) % mod )

Submission status: Runtime Error

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

def nCr(n_, r_, m_):
  c = min(r_ , n_ - r_)
  bunshi = 1
  bunbo = 1
  for i in range(1,c+1):
    bunshi = bunchi * (n_+1-i) % m_
    bunbo = bunbo * i % m_
  return bunshi * pow(bunbo, m_-2, m_) % m_


ans = pow(2,n,m)-1
ans -= nCr(n,a,m)
ans %= m
ans -= nCr(n,b,m)
ans %= m
print(ans)

Submission status: Runtime Error

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

from scipy.special import comb
from math import factorial

MOD = 10**9 + 7

ttl = pow(2, n, MOD) - 1

n_a = factorial(n) / factorial(n-a) / factorial(a) % MOD
n_b = factorial(n) / factorial(n-b) / factorial(b) % MOD

ttl = (ttl - n_a - n_b) % MOD

print(int(ttl))

Submission status: Runtime Error

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

from scipy.special import comb

MOD = 10**9 + 7

ttl = pow(2, n, MOD) - 1

n_a = comb(n, a, exact = True) % MOD
n_b = comb(n, b, exact = True) % MOD

ttl = (ttl - n_a - n_b) % MOD

print(ttl)

Submission status: Runtime Error

Solution code:
import math

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

MOD = 10**9 + 7

def make_fact_list(n, MOD):
    # make factorial list from 0 to n
    fact = [0] * (n+1)
    inv = [0] * (n+1)
    factinv = [0] * (n+1)

    fact[0]=fact[1]=1
    inv[1]=1
    factinv[0]=factinv[1]=1

    for i in range(2,n+1):
        fact[i] = fact[i-1] * i % MOD
        inv[i] = MOD - (( inv[MOD % i] *  (MOD // i)) % MOD )
        factinv[i] = factinv[i-1] * inv[i] % MOD
    
    return fact, factinv

def cbn(n_f, k, MOD, fact = [], factinv = []):
    if len(fact) == 0 and len(factinv) == 0:
        fact, factinv = make_fact_list(n, MOD)
    return fact[n] * factinv[n-k] * factinv[k] % MOD

def power_with_mod(x, n, MOD):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return power_with_mod(x*x % MOD , n // 2, MOD) % MOD
    else:
        return x * power_with_mod(x * x % MOD, n // 2, MOD) % MOD

s = power_with_mod(2, n, MOD)-1

fact, factinv = make_fact_list(n, MOD)

s -= cbn(n, a, MOD, fact, factinv)
s -= cbn(n, b, MOD, fact, factinv)


print(s)

Submission status: Runtime Error

Solution code:
import math

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

MOD = 10**9 + 7

def make_fact_list(n, MOD):
    # make factorial list from 0 to n
    fact = [0] * (n+1)
    inv = [0] * (n+1)
    factinv = [0] * (n+1)

    fact[0]=fact[1]=1
    inv[1]=1
    factinv[0]=factinv[1]=1

    for i in range(2,n+1):
        fact[i] = fact[i-1] * i % MOD
        inv[i] = MOD - (( inv[MOD % i] *  (MOD // i)) % MOD )
        factinv[i] = factinv[i-1] * inv[i] % MOD
    
    return fact, factinv

def cbn(n_f, k, MOD, fact = [], factinv = []):
    if len(fact) == 0 and len(factinv) == 0:
        fact, factinv = make_fact_list(n, MOD)
    return fact[n] * factinv[n-k] * factinv[k] % MOD

def power_with_mod(x, n, MOD):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return power_with_mod(x*x % MOD , n // 2, MOD) % MOD
    else:
        return x * power_with_mod(x * x % MOD, n // 2, MOD) % MOD

s = power_with_mod(2, n, MOD)-1

fact, factinv = make_fact_list(b, MOD)

s -= cbn(n, a, MOD, fact, factinv)
s -= cbn(n, b, MOD, fact, factinv)


print(s)

Submission status: Runtime Error

Solution code:
from functools import reduce
def cmb(n,r):
    numerator = reduce(lambda x, y: x * y % mod, [n - r + k + 1 for k in range(r)])
    denominator = reduce(lambda x, y: x * y % mod, [k + 1 for k in range(r)])
    return numerator * pow(denominator, mod - 2, mod) % mod

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

# ans=imp_pow(2,n)-1
ans=pow(2,c,10**9+7)-1
ans-=cmb(n,a)
ans-=cmb(n,b)
print(ans%10**9+7)

Submission status: Runtime Error

Solution code:
from functools import reduce
def cmb(n,r):
    numerator = reduce(lambda x, y: x * y % mod, [n - r + k + 1 for k in range(r)])
    denominator = reduce(lambda x, y: x * y % mod, [k + 1 for k in range(r)])
    return numerator * pow(denominator, mod - 2, mod) % mod

ans=0
c,a,b = map(int,(input().split()))

# ans=imp_pow(2,n)-1
ans=pow(2,c,10**9+7)-1
ans-=cmb(c,a)
ans-=cmb(c,b)
print(ans%10**9+7)

Submission status: Runtime Error

Solution code:
mod=10**9+7

n,a,b=map(int,input().split())
res=pow(2,n,mod)
res=(res-1)%mod

up=1
down=1
for i in range(1,b+1):
	up*=(n-i+1)
	up%mod
	down*=i
	if i==a:
		upa=up
		downa=down

nca=upa%mod
nca*=pow(downa,mod-2,mod)
nca%=mod
ncb=(up%mod)
ncb=*pow(down,mod-2,mod)
ncb%=mod
print((res-nca-ncb)%mod)

Submission status: Runtime Error

Solution code:
mod=10**9+7

class Combination:
	def __init__(self,size):
		self.size = size + 2
		self.fact = [1, 1] + [0] * size
		self.factInv = [1, 1] + [0] * size
		self.inv = [0, 1] + [0] * size
		
		for i in range(2, self.size):
			self.fact[i] = self.fact[i - 1] * i % mod
			self.inv[i] = -self.inv[mod % i] * (mod//i) % mod
			self.factInv[i] = self.factInv[i - 1] * self.inv[i] % mod
			
	def npk(self,n,k):
		if n < k or n < 0 or k < 0:
			return 0
		return self.fact[n] * self.factInv[n - k] % mod
		
	def nck(self,n,k):
		if n < k or n < 0 or k < 0:
			return 0
		return self.fact[n] * (self.factInv[k] * self.factInv[n - k] % mod) % mod
		
	def nhk(self,n,k):
		return self.nck(n + k - 1, n - 1)
		
n,a,b=map(int,input().split())

ca=Combination(n+a)
cb=Combination(n+b)
nca=ca.nck(n,a)
ncb=cb.nck(n,b)

print(((2**n-1)%mod-nca-ncb)%mod)

Submission status: Runtime Error

Solution code:
  import sys

stdin = sys.stdin

ni = lambda: int(ns())
ns = lambda: stdin.readline().rstrip()
na = lambda: list(map(int, stdin.readline().split()))

# code here
n, a, b = na()
mod = 1000000007

def c(n, r):
    nu = 1
    de = 1
    for i in range(r):
        # nCr の分子
        nu = nu * (n - i) % mod
        # nCr の分母
        de = de * (i + 1) % mod
    # フェルマーの小定理より
    return nu * pow(de, mod - 2, mod) % mod

print((pow(2, n, mod) - c(n, a) - c(n, b) - 1) % mod)

Submission status: Runtime Error

Solution code:
# ABC156D

import numpy as np
def f(n, x):
    mean =  np.mean(x)
    s1 = sum((x-np.floor(mean))**2)
    s2 = sum((x-np.ceil(mean))**2)
    print(int(min(s1, s2)))

n = int(input())
x = list(map(int, input().split()))
f(n, x)

Submission status: Runtime Error

Solution code:
N,A,B=map(int,input().split())
MOD=10**9+7

def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
  
print((pow(2,N,MOD)-1-comb(N,A)-comb(N,B))%MOD)

Submission status: Runtime Error

Solution code:

def create_array(n: int, r: int, mod, mod2):
    m_ls = [1] * (r + 1)

    for i, j in zip(range(n, 0, -1), range(1, r + 1)):
        m_ls[j] = (m_ls[j - 1] * i * pow(j, mod2, mod)) % mod
    return m_ls


def main():
    n, a, b = map(int, input().split())
    _mod = 1_000_000_007
    _mod2 = 1_000_000_005

    m_ls = create_array(n, b, _mod, _mod2)

    _all_cnts = pow(2, n, _mod) - 1
    ans = _all_cnts + (_mod - m_ls[a]) + (_mod - m_ls[b])
    ans %= _mod

    print(ans)


main()

Submission status: Runtime Error

Solution code:
class Comb:
    m_vals = []
    _mod = 1_000_000_007
    _mod2 = 1_000_000_005

    def __init__(self, n: int, r: int):
        m_ls = [1] * (r + 1)

        for i, j in zip(range(n, 0, -1), range(1, r + 1)):
            m_ls[j] = (m_ls[j - 1] * i * pow(j, self._mod2, self._mod)) % self._mod

        self.m_vals = m_ls

    def vv(self, x):
        return self.m_vals[x]


def main():
    n, a, b = map(int, input().split())
    _mod = 1_000_000_007
    cmb = Comb(n, b)
    _all_cnts = pow(2, n, _mod) - 1
    ans = _all_cnts + (_mod - cmb.vv(a)) + (_mod - cmb.vv(b))
    ans %= _mod

    print(ans)


main()

Submission status: Runtime Error

Solution code:
import math


class Comb:
    m_vals = []
    _mod = 1_000_000_007
    _mod2 = 1_000_000_005

    def __init__(self, n: int, r: int):
        m_ls = [1] * (r + 1)

        for i,j in zip(range(n, 0, -1), range(1, r+1)):
            m_ls[j] = (m_ls[j-1]*i * pow(j, self._mod2, self._mod)) % self._mod

        self.m_vals = m_ls

    def vv(self, x):
        return self.m_vals[x]


def main():
    n, a, b = map(int, input().split())
    _mod = 1_000_000_007
    cmb = Comb(n,b)
    all = pow(2,n, _mod) -1
    ans = all + (_mod - cmb.vv(a)) + (_mod - cmb.vv(b))
    ans %= _mod

    print(ans)


main()

Submission status: Runtime Error

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

import math

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

MDO = 10 ** 9 + 7

total = 2 ** n - 1
ans = total - combinations_count(n, a) - combinations_count(n, b)
print(ans % MOD)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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


all_c = pow(2, n, MOD)-1
a_c = 1
b_c = 1
for i in range(n-a+1, n+1):
    a_c *= i
    a_c %= MOD
for i in range(1, a+1):
    a_c *= pow(i, MOD-2, MOD)
    a_c %= MOD
for i in range(n-b+1, n+1):
    b_c *= i
    b_c %= MOD
for i in range(1, b+1):
    b_c *= pow(i, MOD-2, MOD)
    b_c %= MOD

ans = (all_c - a_c - b_c) % MOD
print(ans)

Submission status: Runtime Error

Solution code:
n,a,b = map(int,input().split())
lim = 10**9+7
class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv
combination = Combination(n)
print((pow(2,n,lim)-combination(n,a)-combination(n,b)-1) % lim)

Submission status: Runtime Error

Solution code:
class Combinatorics:
    def __init__(self, N, mod):
        '''
        Preprocess for calculating binomial coefficients nCr (0 <= r <= n, 0 <= n <= N)
        over the finite field Z/(mod)Z.
        Input:
            N (int): maximum n
            mod (int): a prime number. The order of the field Z/(mod)Z over which nCr is calculated.
        '''
        self.mod = mod
        self.fact = {i: None for i in range(N+1)}         # n!
        self.inverse = {i: None for i in range(1, N+1)}   # inverse of n in the field Z/(MOD)Z
        self.fact_inverse = {i: None for i in range(N+1)} # inverse of n! in the field Z/(MOD)Z
        
        # preprocess
        self.fact[0] = self.fact[1] = 1
        self.fact_inverse[0] = self.fact_inverse[1] = 1
        self.inverse[1] = 1
        for i in range(2, N+1):
            self.fact[i] = i * self.fact[i-1] % self.mod
            q, r = divmod(self.mod, i)
            self.inverse[i] = (- (q % self.mod) * self.inverse[r]) % self.mod
            self.fact_inverse[i] = self.inverse[i] * self.fact_inverse[i-1] % self.mod
    
    def perm(self, n, r):
        '''
        Calculate nPr = n! / (n-r)! % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return (self.fact[n] * self.fact_inverse[n-r]) % self.mod
    
    def binom(self, n, r):
        '''
        Calculate nCr = n! /(r! (n-r)!) % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return self.fact[n] * (self.fact_inverse[r] * self.fact_inverse[n-r] % self.mod) % self.mod
        
    def hom(self, n, r):
        '''
        Calculate nHr = {n+r-1}Cr % mod.
        Assign r objects to one of n classes.
        Arrangement of r circles and n-1 partitions:
            o o o | o o | | | o | | | o o | | o
        '''
        if n == 0 and r > 0:
            return 0
        if n >= 0 and r == 0:
            return 1
        return self.binom(n + r - 1, r)
n,a,b=map(int,input().split())
c = Combinatorics(n+k,lim)
ans = (2**n-1-c.binom(n,a)-c.binom(n,b))
print(ans%lim)

Submission status: Runtime Error

Solution code:
p=10**9+7
ans1=1
ans2=1

for i in range(n-a+1,n+1):
    ans1*=i
    ans1%=p

for i in range(1,a+1):
    ans1*=pow(i,p-2,p)
    ans1%=p
    
for i in range(n-b+1,n+1):
    ans2*=i
    ans2%=p

for i in range(1,b+1):
    ans2*=pow(i,p-2,p)
    ans2%=p

print((pow(2,n,p)-ans1-ans2-1)%p)

Submission status: Runtime Error

Solution code:
import math

n,a,b = map(int,input().split())
mod = 10**9+7
total = pow(2,n,mod) - 1

nPa = math.factorial(n) // math.factorial(n-a) 
nPa %= mod
nPb = math.factorial(n) // math.factorial(n-b) 
nPb %= mod
a!_1 = 1
for i in range(1,a+1):
  a!_1 = pow(i,mod-2,mod)
  a!_1 %= mod
b!_1 = 1
for i in range(1,b+1):
  b!_1 = pow(i,mod-2,mod)
  b!_1 %= mod
nCa = nPa * a!_1
nCb = nPb * b!_1
print((total-nCa-nCb)%mod)

Submission status: Runtime Error

Solution code:
n,a,b = map(int,input().split())
mod = 10**9+7
ALL = pow(2,n,m)-1
x = y = 1
for i in range(b):
    x = x * (i+1)%m
    y = y * (n-i)%m
    if i + 1 == a:
        a = b
        ALL -= y * pow(x,m-2,m)
print(ALL%m)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;
const long long N = 1000000001;
const long long MOD = 1000000007;

long long modpow(long long a, long long n,long long mod)
{
    long long res = 1;
    while(n > 0){
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long fac[N],finv[N],inv[N];

void cominit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2;i < N;i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}

long long com(long long n,long long k)
{
    if (n < k || n < 0 || k < 0){
        return 0;
    }
    else {
        return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
    }
}

int main()
{
    long long n;
    long long a,b;
    
    cin >> n >> a  >> b;
    
    long long ans = modpow(2,n,MOD) - com(n,a) - com(n,b) - 1;
    
    cout << ans << endl;
}

Submission status: Runtime Error

Solution code:
"""n<10**7の場合に使える。
https://drken1215.hatenablog.com/entry/2018/06/08/210000"""


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


mod=10**9+7
n,a,b=map(int,input().split())
k=max(a,b)
g1=[1,n]
g2=[1,1]
inverse=[0,1]

for i,j in enumerate(range(n-1,n-k+1,-1)):
    i=i+2
    g1.append((g1[-1]*j)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1]%mod))

N=pow(2,n,mod)-1
print((N-cmb(n,b,mod)-cmb(n,a,mod))%mod)

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce
import math

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

so=10**9+7

large=(pow(2,n,so))

def kumiawase(n,r):
    return math.fractorial(n) / (math.fractorial(n-r) * math.fractorial(r)

ajogai = kumiawase(n,a) % so
bjogai = kumiawase(n,b) % so
print((large - ajogai - bjogai + 2*so) % so)

Submission status: Runtime Error

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

r_1 = a
n_r_1 = ( n - a )
r_2 = b
n_r_2 = ( n - b )
n_ = 1
N = n % max_mod
for i in range( 1, N + 1 ):
  n_ *= i
  n_ %= max_mod
  if i == r_1:
    r_1 = n_
  if i == n_r_1:
    n_r_1 = n_
  if i == r_2:
    r_2 = n_
  if i == n_r_2:
    n_r_2 = n_
    
k_1 = n_ // ( r_1 * n_r_1 )
k_2 = n_ // ( r_2 * n_r_2 )
x = pow( 2, n, max_mod ) - 1
x -= ( k_1 + k_2 ) 
print( x )