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: Time Limit Exceeded

Solution code:
import math
def Bouquets(n, a, b):
  bouquets = 2 ** n - 1 - nCx(n, a) - nCx(n, b)
  return bouquets
  
def nCx(n, x):
  numerator = math.factorial(n) / math.factorial(n - x)
  denominator = math.factorial(x)
  kinds = int(numerator / denominator)
  return kinds % (10**9 + 7)
 
n, a, b = map(int, input().split())
print (Bouquets(n, a, b))

Submission status: Time Limit Exceeded

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

def cmb(n,r):
    ans = 1
    for i in range(r):
      ans *= n-i
    for i in range(1,r+1):
      ans //= i
    return ans
n,a,b = map(int,input().split())
mod = 10**9 + 7
def exp_2(n):
  if n == 0: return 1
  if n % 2: return 2 * exp_2(n//2)**2
  else: return exp_2(n//2)**2
print((exp_2(n) - 1 - cmb(n,a) - cmb(n,b))%mod)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,a,b = np.array(input().split()).astype(int)
mod = 10**9+7
import math
def power(x, n):
    ans = 1
    while(n > 0):
        if(bin(n & 1) == bin(1)):
            ans = ans*x%mod
        x = x*x%mod
        n = n >> 1 #ビットシフト
    return ans
def fact(m, n):
    val = 1
    for i in range(m, n + 1):
        val = (val*i)%mod
    return val
def cmb(N, r):
    A = fact(N-r+1, N)
    B = math.factorial(r)
    A = (A*power(B, mod-2))%mod
    return A
print((power(2, N)-1-cmb(N, a)-cmb(N, b))%mod)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# 互いに素なa,bについて、a*x+b*y=1の一つの解[x,y]を出力
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]]

# aの逆元(mod M)を求める（aとMは互いに素）
def mod_inv(a,M=mod):
    x = extgcd(a,M)[0]
    return (M+x%M)%M

def nCk(n,k):
    if k == 0:
        return 1
    else:
        return nCk(n-1,k-1)*n*mod_inv(k) %mod

n,a,b = LI()

ans = pow(2,n,mod)-1
ans -= nCk(n,a)
ans %= mod
ans -= nCk(n,b)
ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,a,b = np.array(input().split()).astype(int)
mod = 10**9+7
import math
def power(x, n):
    ans = 1
    while(n > 0):
        if(bin(n & 1) == bin(1)):
            ans = ans*x
        x = x*x%mod
        n = n >> 1 #ビットシフト
    return ans
def fact(m, n):
    val = 1
    for i in range(m, n + 1):
        val = (val*i)%mod
    return val
def cmb(N, r):
    A = fact(N-r+1, N)
    B = math.factorial(r)
    A = (A*power(B, mod-2))%mod
    return A
print((power(2, N)-1-cmb(N, a)-cmb(N, b))%mod)

Submission status: Time Limit Exceeded

Solution code:
import math
from operator import mul
from functools import reduce
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
 
n, a, b = map(int, input().split(' '))
s = 0
for i in range(1, n+1):
    if i == a or i == b:
        continue
    s += cmb(n, n-i)
print(int(s % (math.pow(10, 9)+7)))

Submission status: Time Limit Exceeded

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

p = 10 ** 9 + 7
N = 10 ** 9
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

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)
    
def comb(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
  
print(pow(2, n, p) -1 -comb(n, a, p) - comb(n, b, p))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
N,a,b = np.array(input().split()).astype(int)
def cmb(N, r, mod):
  return (math.factorial(N)%mod)//((math.factorial(r)%mod)*(math.factorial(N-r)%mod))
print(2**N-1-cmb(N, a, 10**9+7)-cmb(N, b, 10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
N,a,b = np.array(input().split()).astype(int)
print(2**N-1-math.factorial(N)//(math.factorial(a)*math.factorial(N-a))-math.factorial(N)//(math.factorial(b)*math.factorial(N-b)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
N,a,b = np.array(input().split()).astype(int)
S = 0
for i in range(1,N+1):
  if((i!=a)&(i!=b)):
    S += math.factorial(N)//(math.factorial(i)*math.factorial(N-i))
print(S%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n,a,b = map(int, input().split())
n_list = [i+1 for i in range(n)]
count = 0
for i in n_list:
    if i !=a and i !=b:
        for p in combinations(n_list,i):
            count = count+1
print(count)

Submission status: Time Limit Exceeded

Solution code:
LARGE = 10 ** 9 + 7


def solve(n, a, b):

    pow_ab = [1] * (b + 1)
    for i in range(b):
        pow_ab[i + 1] = pow_ab[i] * (i + 1)
    pow_ab_inv = [1] * (b + 1)
    pow_ab_inv[-1] = pow(pow_ab[-1], LARGE - 2, LARGE)
    for i in range(b - 1, 0, -1):
        pow_ab_inv[i] = pow_ab_inv[i + 1] * (i + 1) % LARGE

    res_all = pow(2, n, LARGE) - 1
    res_ab = 1
    for i in range(a):
        res_ab *= (n - i)
    res_all -= res_ab * pow_ab_inv[a]
    for i in range(a, b):
        res_ab *= (n - i)
    res_all -= res_ab * pow_ab_inv[b]
    return res_all % LARGE


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


def test():
    assert solve(4, 1, 3) == 7
    assert solve(1000000000, 141421, 173205) == 34076506


if __name__ == "__main__":
    test()
    main()

Submission status: Time Limit Exceeded

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

#output
mod = pow(10, 9) + 7

def cmb(n, r):
    res = 1
    fac = 1
    for i in range(r):
        res *= (n-i) % mod
        fac *= (i+1) % mod
    return res*pow(fac, mod-2, mod) % mod

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

Submission status: Time Limit Exceeded

Solution code:
N,a,b=map(int,input().split())
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
s=2**N-cmb(N,a)-cmb(N,b)-1
print(s%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
n,a,b = list(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**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 )

nCa = cmb(n,a,mod)
nCb = cmb(n,b,mod)
ans = (int(pow(2,n)) - nCa - nCb - 1)%10**9+7

print(ans)

Submission status: Time Limit Exceeded

Solution code:
tmp = input().split(" ")
N = int(tmp[0])
a = int(tmp[1])
b = int(tmp[2])

def nCr(n,r):
  x = 1
  t = n
  for i in range(r):
    x *= t
    t-=1
  for i in range(r,1,-1):
    x %= (10**9+7)
    x = int(x/i) 
  return int(x%(10**9+7))

ans = 0
for i in range(1,N+1):
  if i!=a and i!=b:
    ans += nCr(N,i)
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
#D 復習
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
whole_sum = (2 ** n % mod) - 1

def combinations_mod(n, k, mod):
    X, Y = 1, 1
    for i in range(1, k+1):
        X = (X * (n-i+1))%mod
    for j in range(1, k+1):
        Y = (Y*j)%mod
    result = X * (pow(Y, mod-2, mod))
    return result%mod

whole_sum -= combinations_mod(n, a, mod)
whole_sum -= combinations_mod(n, b, mod)

print(whole_sum % mod)

Submission status: Time Limit Exceeded

Solution code:
import math
def f(x):
    return x**2
n,a,b=map(int,input().split())
sum=2
sum_a=1
sum_b=1
if n%2==0:
    for i in range(int(math.log2(n))):
        sum=f(sum)
else:
    for i in range(int(math.log2(n))):
        sum=f(sum)
    sum*=2
    
for i in range(n-a+1,n+1):
    sum_a*=i
for i in range(n-b+1,n+1):
    sum_b*=i
sum=sum-1-(sum_a//math.factorial(a)+sum_b//math.factorial(b))
print(sum%(1000000007))

Submission status: Time Limit Exceeded

Solution code:
def comb2(n, r):
    if r<0 or r>n:
        return 0
    r=min(r, n-r)
    res=1
    for i in range(r):
        res*=(n-i)%MOD*pow(i+1, MOD-2, MOD)%MOD
    return res

MOD=10**9+7

N, A, B=map(int, input().split())
ans=pow(2, N, MOD)-comb2(N, A)-comb2(N, B)-1
print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
def comb2(n, r):
    if r<0 or r>n:
        return 0
    r=min(r, n-r)
    res=1
    for i in range(r):
        res*=(n-i)%MOD*pow(i+1, MOD-2, MOD)%MOD
    return res%MOD

MOD=10**9+7

N, A, B=map(int, input().split())
ans=pow(2, N)-comb2(N, A)-comb2(N, B)-1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#D 復習
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
whole_sum = pow(2, n, mod) - 1

def combinations_mod(n, k, mod):
    X, Y = 1, 1
    for i in range(1, k+1):
        X *= (n-i+1)
    for j in range(1, k+1):
        Y *= j
    result = X * (pow(Y, mod-2, mod))
    return result

whole_sum -= combinations_mod(n, a, mod)
whole_sum -= combinations_mod(n, b, mod)

print(whole_sum % mod)

Submission status: Time Limit Exceeded

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

flower_all = pow(2,n,mod)

def calc(n,a):
    ans = 1
    for i in range(a):
        ans *= (n - i) % mod
        
    ans = ans * (pow(factorial(a),mod - 2,mod)) % mod
        
    return ans

f_a = calc(n,a)
f_b = calc(n,b)
print(flower_all - (f_a + f_b) % mod  - 1)

Submission status: Time Limit Exceeded

Solution code:
import math
n,a,b = map(int,input().split())
def combinations_count(n,r):
    return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
#
ans = (2**n - combinations_count(n,a) - combinations_count(n,b) - 1) % (10**9 + 7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from scipy.misc import comb

if __name__ == '__main__':
    n, a, b = map(int, input().split())
    x = 0
    for i in range(1, n + 1):
        if i == a or i == b:
            pass
        else:
            x += comb(n, i, exact=True)

    print(x)

Submission status: Time Limit Exceeded

Solution code:
n = [int(i) for i in 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**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 )
tmp = cmb(n[0],n[0],mod) - cmb(n[0],n[1],mod) - cmb(n[0],n[2],mod)
print(tmp%mod_num)

Submission status: Time Limit Exceeded

Solution code:
n = [int(i) for i in input().split()]
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
tmp = 2**n[0]-1
tmp = tmp - cmb(n[0],n[1]) - cmb(n[0],n[2])
mod_num = 10**9+7
print(tmp%mod_num)

Submission status: Time Limit Exceeded

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

def iterative_square_method(N, P, M):

    if P == 0:
        return 1
    elif P%2 == 0:
        return (iterative_square_method(N, P//2, M) ** 2) % M
    else:
        return (N * iterative_square_method(N, P-1, M)) % M

def inv_felmat(a, p):
    return iterative_square_method(a, p-2, p)

all = iterative_square_method(2, n, 10**9 + 7) - 1 
tmp1 = 1
tmp2 = 1
for i in range(n-a+1, n+1):
    tmp1 *= i % (10**9 + 7)
for i in range(1, a+1):
    tmp2 *= i % (10**9 + 7)
tmp1 = (tmp1 * inv_felmat(tmp2, 10**9 + 7)) % (10**9 + 7)
tmp3 = 1
tmp4 = 1
for i in range(n-b+1, n+1):
    tmp3 *= i % (10**9 + 7)
for i in range(1, b+1):
    tmp4 *= i % (10**9 + 7)
tmp3 = (tmp3 * inv_felmat(tmp4, 10**9 + 7)) % (10**9 + 7)

result = all - tmp1 - tmp3
print(result%(10**9 + 7))

Submission status: Time Limit Exceeded

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

def iterative_square_method(N, P, M):

    if P == 0:
        return 1
    elif P%2 == 0:
        return (iterative_square_method(N, P//2, M) ** 2) % M
    else:
        return (N * iterative_square_method(N, P-1, M)) % M

def inv_felmat(a, p):
    return iterative_square_method(a, p-2, p)

all = iterative_square_method(2, n, 10**9 + 7) - 1 
tmp1 = 1
tmp2 = 1
for i in range(n-a+1, n+1):
    tmp1 *= i % (10**9 + 7)
for i in range(1, a+1):
    tmp2 *= i % (10**9 + 7)
tmp1 = (tmp1 * inv_felmat(tmp2, 10**9 + 7)) % (10**9 + 7)
tmp3 = 1
tmp4 = 1
for i in range(n-b+1, n+1):
    tmp3 *= i
for i in range(1, b+1):
    tmp4 *= i
tmp3 = (tmp3 * inv_felmat(tmp4, 10**9 + 7)) % (10**9 + 7)

result = all - tmp1 - tmp3
print(result%(10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
def pow(x, n, mod):
  ans = 1
  while(n > 0):
    if(bin(n & 1) == bin(1)):
      ans = ans*x % mod
    x = x*x % mod
    n = n >> 1
  return ans

def kaijou_k(n, k, mod):
    a = 1
    for i in range(k, n+1):
        a *= i % mod
    return a

def main():
    n, a, b = map(int, input().split())
    mod = 10**9 +7
    allsum = pow(2, n, mod)-1
    abunbo = kaijou_k(n, n-a+1, mod)
    abunsi = kaijou_k(a, 1, mod)
    asum = abunbo * pow(abunsi, mod-2, mod) % mod
    bbunbo = kaijou_k(n, n-b+1, mod)
    bbunsi = kaijou_k(b, 1, mod)
    bsum = bbunbo * pow(bbunsi, mod-2, mod) % mod
    ans = allsum - asum - bsum
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
n,a,b=map(int,input().split())
k=2**n-1
s=math.factorial(n)//(math.factorial(n-a)*math.factorial(a))
h=math.factorial(n)//(math.factorial(n-b)*math.factorial(b))
print((k-s-h)%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int,input().split())
mod=10**9+7
def comb(n,k):
  x,y=1,1
  for i in range(k):
    x*=n-i
    y*=i+1
  return ((x//y)%mod)

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

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int,input().split())
import math
def comb(n,k):
  return math.factorial(n)//math.factorial(k)//math.factorial(n-k)

print(2**n-1-comb(n,a)-comb(n,b))

Submission status: Time Limit Exceeded

Solution code:
def choose(n, r, mod = 10 ** 9 + 7):
    bumbo = 1
    bunshi = 1
    for i in range(r):
        bumbo *= (n - i)
        bunshi *= (i + 1)
    return [bumbo%mod, bunshi%mod]

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

ans = pow(2, n, mod)    # 全体
ans -= 1    # 花を選ばない場合をひく

# nCa を求める
a1, a2 = choose(n, a)
nCa = a1 * pow(a2, mod-2, mod)

b1, b2 = choose(n, b)
nCb = b1 * pow(b2, mod-2, mod)


ans -= (nCa + mod) % mod
ans -= (nCb + mod) % mod
print(ans)

Submission status: Time Limit Exceeded

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


def pow(n):
    if n == 0:
        return 1
    x = pow(n//2)
    x *= x
    if n % 2 == 1:
        x *= 2
    return x


# 逆元配列の作成
inv = [1] * (2 * (10 ** 5))
for i in range(2, 2 * (10 ** 5)):
    inv[i] = -inv[mod % i] * (mod // i)
    inv[i] %= mod


def comb(n, a):
    res = 1
    for i in range(a):
        res *= n - i  # 分子
        res *= inv[i + 1]  # 分母
        res %= mod  # modで割ったあまり
    return res


ans = pow(n) - 1 - comb(n, a) - comb(n, b)

ans %= mod
if ans < 0:
    ans += mod

print(ans)

Submission status: Time Limit Exceeded

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


M = 10**9+7

def pow(x,n):
    if n==0:
        return 1
    res = pow((x*x)%M,n//2)
    if (n%2)==1:
        res = (res*x)%M
    return res


def power(x,n):
    res = 1
    if(n>0):
        res = power(x,n//2)
        if (n%2)==0:
            res = (res*res)%M
        else:
            res = (((res*res)%M)*x)%M
    return res

def comb(n,a):
    ans = 1
    for i in range(a):
        ans = (ans*(n-i))%M
        ans = (ans*power(i+1,M-2))%M 
    return ans

#print(pow(10,2))
#print(power(5,8))

print((power(2,N)-1-comb(N,a)-comb(N,b))%M)

Submission status: Time Limit Exceeded

Solution code:
def get_exp_mod(base, exp, mod):
    exp_bin = str(format(exp, 'b'))  # ２進表現
    res = 1
    for i in range(len(exp_bin)):
        if exp_bin[-i - 1] == '1':
            res = res * base % mod
        base = base * base % mod  # base^2^nをmodで割ったあまり

    return res


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

## TODO:0の時

# 2^n -1のmodを求める
all_case = (get_exp_mod(2, n, mod) - 1) % mod
#print(all_case)

# nCa modを求める
case_a = 1
for i in range(a):
    case_a = case_a * (n - i) % mod
    case_a = case_a * get_exp_mod(i+1, mod-2, mod) % mod
#print(case_a)

case_b = 1
for i in range(b):
    case_b = case_b * (n - i) % mod
    case_b = case_b * get_exp_mod(i+1, mod-2, mod) % mod
#print(case_b)

print((all_case - case_a - case_b) % mod)

Submission status: Time Limit Exceeded

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

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

for i in [a,b]:
    tmp = comb(n,i)
    ans_tmp -= tmp
print(ans_tmp%mod)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
mod=10**9+7

def f(A):
 dem=reduce(lambda x,y:x*y,range(n,n-A,-1))
 num=reduce(lambda x,y:x*y,range(1,A+1))
 return dem*pow(num,mod-2,mod)%mod

stdin=open(0)
n,a,b=map(int,stdin.read().split())
ans=pow(2,n,mod)-f(a)-f(b)-1
ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
mod=10**9+7

def f(A):
 dem=functools.reduce(lambda x,y:x*y,range(n,n-A,-1))
 num=functools.reduce(lambda x,y:x*y,range(1,A+1))
 return dem*pow(num,mod-2,mod)%mod

stdin=open(0)
n,a,b=map(int,stdin.read().split())
ans=pow(2,n,mod)-f(a)-f(b)-1
ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
mod=10**9+7

def f(A):
 dem=functools.reduce(lambda x,y:x*y,range(n,n-A,-1))
 num=functools.reduce(lambda x,y:x*y,range(1,A+1))
 return dem*pow(num,mod-2,mod)%mod

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

Submission status: Time Limit Exceeded

Solution code:
import math
from operator import mul
from functools import reduce
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

n, a, b = map(int, input().split(' '))
s = 0
for i in range(1, n+1):
    if i == a or i == b:
        continue
    s += cmb(n, n-i)
print(int(s % (math.pow(10, 9)+7)))

Submission status: Time Limit Exceeded

Solution code:
def c_count(n, r):
  a ,b = 1, 1
  for x,y in zip(range(n, n-r, -1),range(r, 0, -1)): 
    a *= x%(10**9+7)
    b *= y%(10**9+7)
  return a//b
n,a,b = map(int, input().split())
sub = (c_count(n,a)+c_count(n,b)+1)
total = (2**n)%(10**9+7)
print(total - sub)

Submission status: Time Limit Exceeded

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

p = 10 ** 9 + 7
N = 10 ** 5 *5  # 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)


def f(x):
    if x==1:
        return 2
    elif x==2:
        return 4
    elif x%2==0:
        return f(x//2)**2
    else:
        return f(x//2)**2*2


fact2 = []
fact2num = max(a,b)+2
now = 1
for i in range(fact2num):
    now *= (n-i)
    now %= p
    fact2.append(now)

def ncr(n,r):
    return (fact2[r-1]*factinv[r])%p

print(f(n)-1-ncr(n,a)-ncr(n,b))

Submission status: Time Limit Exceeded

Solution code:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n, a, b = map(int,input().split())
f = (2 ** n) % ((10 ** 9) + 7) - 1
#print(f)
f1 = combinations_count(n, a) % ((10 ** 9) + 7)
f2 = combinations_count(n, b) % ((10 ** 9) + 7)
print(f - f1 - f2)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
 
def com(n, r):
  return factorial(n) // factorial(n - r) // factorial(r)
 
n, a, b = [int(s) for s in input().split()]
 
print((2**n - com(n, a) - com(n, b) - 1) % (10**9 + 7))

Submission status: Time Limit Exceeded

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

d = 10**9 + 7

ans = 0

def cmb(n, r, mod):
    from operator import mul
    from functools import reduce

    N = n + r
    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)

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


for x in range(1, n+1):
    if x == a or x == b:
        pass
    else:
        ans += cmb(n, x, d)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

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

def cmb(m,r):
    r = min(m-r,r)
    if r == 0: return 1
    over = reduce(mul, range(m, m - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

aa=cmb(n,a)
bb=cmb(n,b)
c=2**n-1-aa-bb
print(c%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7
 
class ModInt:
    def __init__(self, x):
        if isinstance(x, ModInt):
            self.x = x.x
        else:
            self.x = x % MOD
    
    # str関数を使用したとき
    def __str__(self):
        return str(self.x)
    
    def __int__(self):
        return self.x
    
    __index__ = __int__
    
    # print関数を使用したとき
    __repr__ = __str__
 
    ## 四則演算
    def __add__(self, other):
        return ModInt(self.x + ModInt(other).x)
    
    def __sub__(self, other):
        return ModInt(self.x - ModInt(other).x)
 
    def __mul__(self, other):
        return ModInt(self.x * ModInt(other).x)
    
    # /
    def __truediv__(self, other):
        # a * a^(p - 2) ≡ 1 (mod p) 逆元から求める
        return ModInt(self.x * pow(ModInt(other).x, MOD - 2, MOD))
 
    # //
    def __floordiv__(self, other):
        return self.x // ModInt(other).x
 
    # 累乗
    def __pow__(self, other):
        return ModInt(pow(self.x, ModInt(other).x, MOD))
 
    ## 四則演算の順序
    __radd__ = __add__
 
    def __rsub__(self, other):
        return ModInt(other - self.x)
    
    __rmul__ = __mul__
 
    def __rtruediv__(self, other):
        return ModInt(other * pow(self.x, MOD - 2, MOD))
 
    def __rfloordiv__(self, other):
        return ModInt(other // self.x)
    
    # 累乗の順序
    def __rpow__(self, other):
        return ModInt(pow(other, self.x, MOD))
    
    ## 不等号
    def __lt__(self, other):
        return self.x < ModInt(other).x
    
    def __gt__(self, other):
        return self.x > ModInt(other).x
 
    def __le__(self, other):
        return self.x <= ModInt(other).x
    
    def __ge__(self, other):
        return self.x >= ModInt(other).x
    
    def __eq__(self, other):
        return self.x == ModInt(other).x
    
    def __ne__(self, other):
        return self.x != ModInt(other).x
 
def comb(n, r):
    res = ModInt(1)
    for i in range(n-r+1, n+1):
        res = res * i
    for i in range(2, r+1):
        res = res / i
    return res
 
n, a, b = map(ModInt, map(int, input().split()))
 
ans = 2 ** n
 
ans = ans - comb(n, a)
ans = ans - comb(n, b)
ans = ans - 1
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7

class ModInt:
    def __init__(self, x):
        if isinstance(x, ModInt):
            self.x = x.x
        else:
            self.x = x % MOD
            if self.x < 0:
                self.x += MOD
    
    def get_mod(self):
        return MOD
    
    def inv(self, other):
        return ModInt(pow(ModInt(other).x, MOD - 2, MOD))
    
    # str関数を使用したとき
    def __str__(self):
        return str(self.x)
    
    def __int__(self):
        return self.x
    
    __index__ = __int__
    
    # print関数を使用したとき
    __repr__ = __str__

    ## 四則演算
    def __add__(self, other):
        return ModInt(self.x + ModInt(other).x)
    
    def __sub__(self, other):
        return ModInt(self.x - ModInt(other).x)

    def __mul__(self, other):
        return ModInt(self.x * ModInt(other).x)
    
    # /
    def __truediv__(self, other):
        # a * a^(p - 2) ≡ 1 (mod p) 逆元から求める
        return ModInt(self.x * pow(ModInt(other).x, MOD - 2, MOD))

    # //
    def __floordiv__(self, other):
        return self.x // ModInt(other).x

    # 累乗
    def __pow__(self, other):
        return ModInt(pow(self.x, ModInt(other).x, MOD))

    ## 四則演算の順序
    __radd__ = __add__

    def __rsub__(self, other):
        return ModInt(other - self.x)
    
    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return ModInt(other * pow(self.x, MOD - 2, MOD))

    def __rfloordiv__(self, other):
        return ModInt(other // self.x)
    
    # 累乗の順序
    def __rpow__(self, other):
        return ModInt(pow(other, self.x, MOD))
    
    ## 不等号
    def __lt__(self, other):
        return self.x < ModInt(other).x
    
    def __gt__(self, other):
        return self.x > ModInt(other).x

    def __le__(self, other):
        return self.x <= ModInt(other).x
    
    def __ge__(self, other):
        return self.x >= ModInt(other).x
    
    def __eq__(self, other):
        return self.x == ModInt(other).x
    
    def __ne__(self, other):
        return self.x != ModInt(other).x
    
    ## in-place 演算子(+=, -=, *=, /=)
    def __iadd__(self, other):
        self.x += ModInt(other).x
        if self.x >= MOD:
            self.x -= MOD
        return self.x
    
    def __isub__(self, other):
        self.x -= ModInt(other).x
        if self.x < 0:
            self.x += MOD
        return self.x
    
    def __imul__(self, other):
        self.x = ModInt(self.x * ModInt(other).x)
        return self.x

    def __itruediv__(self, other):
        self.x = ModInt(self.x * pow(ModInt(other).x, MOD - 2, MOD))
        return self.x
    
    def __ifloordiv__(self, other):
        self.x = self.x // ModInt(other).x

def comb(n, r):
    res = ModInt(1)
    for i in range(n-r+1, n+1):
        res *= i
    for i in range(2, r+1):
        res /= i
    return res

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

ans = 2 ** n

ans = ans - comb(n, a)
ans = ans - comb(n, b)
ans = ans - 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
N, a, b = map(int, input().split())
m=0
for i in range(N):
    k=factorial(N) // (factorial(N - i) * factorial(i))
    m=m+k
amath=k=factorial(N) // (factorial(N - a) * factorial(a))
bmath=k=factorial(N) // (factorial(N - b) * factorial(b))
print(m-amath-bmath)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

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

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

sum = pow(2,n,1000000007) -1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7

class ModInt:
    def __init__(self, x):
        if isinstance(x, ModInt):
            self.x = x.x
        else:
            self.x = x % MOD
    
    # str関数を使用したとき
    def __str__(self):
        return str(self.x)
    
    def __int__(self):
        return self.x
    
    __index__ = __int__
    
    # print関数を使用したとき
    __repr__ = __str__

    ## 四則演算
    def __add__(self, other):
        return ModInt(self.x + ModInt(other).x)
    
    def __sub__(self, other):
        return ModInt(self.x - ModInt(other).x)

    def __mul__(self, other):
        return ModInt(self.x * ModInt(other).x)
    
    # /
    def __truediv__(self, other):
        # a * a^(p - 2) ≡ 1 (mod p) 逆元から求める
        return ModInt(self.x * pow(ModInt(other).x, MOD - 2, MOD))

    # //
    def __floordiv__(self, other):
        return self.x // ModInt(other).x

    # 累乗
    def __pow__(self, other):
        return ModInt(pow(self.x, ModInt(other).x, MOD))

    ## 四則演算の順序
    __radd__ = __add__

    def __rsub__(self, other):
        return ModInt(other - self.x)
    
    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return ModInt(other * pow(self.x, MOD - 2, MOD))

    def __rfloordiv__(self, other):
        return ModInt(other // self.x)
    
    # 累乗の順序
    def __rpow__(self, other):
        return ModInt(pow(other, self.x, MOD))
    
    ## 不等号
    def __lt__(self, other):
        return self.x < ModInt(other).x
    
    def __gt__(self, other):
        return self.x > ModInt(other).x

    def __le__(self, other):
        return self.x <= ModInt(other).x
    
    def __ge__(self, other):
        return self.x >= ModInt(other).x
    
    def __eq__(self, other):
        return self.x == ModInt(other).x
    
    def __ne__(self, other):
        return self.x != ModInt(other).x

def comb(n, r):
    res = 1
    for i in range(n-r+1, n+1):
        res *= i
    for i in range(2, r+1):
        res //= i
    return res

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

sum = 2 ** n
sub_a = comb(n, a)
sub_b = comb(n, b)

ans = sum - sub_a - sub_b - 1

print(ans)