Problem: 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.

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

# C = {}

#   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)]


#     if n - r < r: r = n - r
#     if r == 0: return 1
#     if r == 1: return n
#

#     denominator = [k + 1 for k in range(r)]
#
#     for p in range(2,r+1):


#             offset = (n - r) % p
#             for k in range(p-1,r,p):
#                 numerator[k - offset] /= pivot

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

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 )

A = cmb(n,a,mod)
B = cmb(n,b,mod)
ans = 2**n-1-A-B
print(ans%(10**9+7))

n,a,b = [int(i) for i in input().split()]
mod = 10**9+7

def mpow(a,n):
  if n == 1:
    return a
  x = mpow(a,n//2)
  ans = x*x%mod
  if n%2==1:
    ans *= a
  return ans

def comb(n,a,b):
  if a < b:
    s, l = a, b
  else:
    s, l = b, a
  rs = 1
  for i in range(s):
    rs = rs*(n-i)%mod
  rl = rs
  for i in range(s,l):
    rl = rl*(n-i)%mod
  for i in range(1,s+1):
    rs = rs*mpow(i,mod-2)%mod
  rl = rl
  for i in range(s+1,l+1):
    rl = rl*mpow(i,mod-2)%mod
  if a < b:
    nCa, nCb = rs, rl
  else:
    nCa, nCb = rl, rs
  return nCa, nCb
nCa,nCb = comb(n,a,b)
print((mpow(2,n)-1-nCa-nCb)%mod)
print(nCa,nCb)

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

# C = {}

#   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)]


#     if n - r < r: r = n - r
#     if r == 0: return 1
#     if r == 1: return n
#

#     denominator = [k + 1 for k in range(r)]
#
#     for p in range(2,r+1):


#             offset = (n - r) % p
#             for k in range(p-1,r,p):
#                 numerator[k - offset] /= pivot

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

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 = 2*10**5
M = 10**9
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 )



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

# fact = [1]
# fact_inv = [0]*(MAX_N+4)

#     fact.append(fact[-1]*(i+1)%mod)
#


#     fact_inv[i] = fact_inv[i+1]*(i+1)%mod
#
#

#     return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

A = mod_cmb_k(n,a,mod)
B = mod_cmb_k(n,b,mod)
ans = 2**n-1-A-B
print(ans%(10**9+7))

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

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**9
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 )

A = cmb(n,a,mod)
B = cmb(n,b,mod)
ans = 2**n-1-A-B
print(ans%(10**9+7))

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

# C = {}

#   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)]


#     if n - r < r: r = n - r
#     if r == 0: return 1
#     if r == 1: return n
#

#     denominator = [k + 1 for k in range(r)]
#
#     for p in range(2,r+1):


#             offset = (n - r) % p
#             for k in range(p-1,r,p):
#                 numerator[k - offset] /= pivot

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

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 = 2*10**5
M = 10**9
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 )



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

# fact = [1]
# fact_inv = [0]*(MAX_N+4)

#     fact.append(fact[-1]*(i+1)%mod)
#


#     fact_inv[i] = fact_inv[i+1]*(i+1)%mod
#
#

#     return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

A = cmb(n,a,mod)
B = cmb(n,b,mod)
ans = 2**n-1-A-B
print(ans%(10**9+7))

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

def comb_mod(n,r):
    mod = 10**9+7
    ans = 1
    for i in range(r):
        ans *= n-i
        ans %= mod
    for i in range(1,r+1):
        ans *= pow(i,-1,mod)
        ans %= mod
    return ans

def solve():
    n, a, b = map(int, input().split())
    mod = 10**9+7
    ans = pow(2,n,mod)-comb_mod(n,a)-comb_mod(n,b)-1
    ans %= mod
    return ans
print(solve())

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Time Limit Exceeded

Time Limit Exceeded

Runtime Error

Accepted