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:
def cmb(n, r):
	if n - r < r:
		r = n - r
	if r == 0:
		return 1
	if r == 1:
		return n
	
	num = [n - r + k + 1 for k in range(r)] #numerator(分子)
	den = [k + 1 for k in range(r)] #denominator(分母)
	
	for p in range(2, r + 1):
		pivot = den[p - 1]
		if pivot > 1:
			offset = (n - r) % p
			for k in range(p - 1, r, p):
				num[k - offset] /= pivot
				den[k] /= pivot
	
	result = 1
	for k in range(r):
		if num[k] > 1:
			result *= int(num[k])
	
	return result

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

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

Submission status: Time Limit Exceeded

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

mod = 10**9 + 7

import time
start = time.time()


# x ** a をmodで割った余りを、O(log(a))時間で求める。
def power(x, a):
	if a == 0:
		return 1
	elif a == 1:
		return x
	elif a % 2 == 0:
		return power(x, a//2) **2 % mod
	else:
		return power(x, a//2) **2 * x % mod

# xの逆元を求める。フェルマーの小定理より、 x の逆元は x ^ (mod - 2) に等しい。計算時間はO(log(mod))程度。
# https://qiita.com/Yaruki00/items/fd1fc269ff7fe40d09a6
def modinv(x):
	return power(x, mod-2)

modinv_table = [-1] * (b+1)
for i in range(1, b+1):
    modinv_table[i] = modinv(i)

end = time.time()
# print("time: ", end - start)

def binomial_coefficients2(n, k):
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table[i + 1]
        ans %= mod
    return ans

# (2 ** n - 1) - nCa - nCb
ans = power(2, n) - 1

ans -= (binomial_coefficients2(n, a) + binomial_coefficients2(n, b))
print(ans % mod)


# print(binomial_coefficients2 (5, 2) % mod)

Submission status: Time Limit Exceeded

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

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

from functools import lru_cache

@lru_cache(maxsize=1000)
def c(n,k): 
    return 1 if(k<=0 or n<=k) else ( c(n-1, k-1) + c(n-1, k) ) %4

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 )
    
res = 2 ** n - 1

res -= cmb(n,a,mod)
res -= cmb(n,b,mod)

print(res)

Submission status: Time Limit Exceeded

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


N, A, B = map(int, input().split())
tmp = (2 ** N - 1) % mod 
a = cmb(N, A, mod)
b = cmb(N, B, mod)
print(((tmp + mod) - a - b ) % mod)

Submission status: Time Limit Exceeded

Solution code:
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_left # bisect_left(list, value)
#from fractions import gcd
from operator import mul
from functools import reduce

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

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

num = pow(2, n, div)
'''
for _ in range(n):
    num *= 2
    num %= div
'''

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
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

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

num -= cmb(n, a, mod)
num -= cmb(n, b, mod)
num %= div

print(num-1)

Submission status: Time Limit Exceeded

Solution code:
import math
NUM=10**9+7
n,A,B = map(int,input().split())

s=(2**(n))%NUM
k=math.factorial(n)
a1=math.factorial(A)
a2=math.factorial(n-A)

b1=math.factorial(B)
b2=math.factorial(n-B)

a=a1*a2
b=b1*b2
print(s-1-k//a-k//b)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
import math
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())
kouho=[]
goukei=2**n-1
print((goukei-cmb(n,a)-cmb(n,b))%(10**9+7))

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

def main():
    n,a,b = map(int, input().split())
    score = 2**n-1
    score_nigate= 0

    score_nigate = combinations_count(n,a)
    score_nigate = combinations_count(n,b) + score_nigate

    print((score - score_nigate)% (10**9 + 7))



if __name__ == '__main__' :
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
from math import factorial

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

def comb(n,k,p):
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p

def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return pow(d,2)%p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

ans -= comb(n,a,mod)
ans -= comb(n,b,mod)
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,a,b = map(int,input().split())
arr = []
arrs = [j for j in range(1,n+1)]
count = 0
for i in range(1,n+1):
    if i != a and i != b:
        arr.append(i)
        ans = len(list(itertools.combinations(arrs, i)))
        count += ans
print (count)

Submission status: Time Limit Exceeded

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

p = 10**9+7

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

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)

print((pow(2, n, p) - 1 - cmb(n, a, p) - cmb(n, b, p))%p)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,a,b = map(int,input().split())
arr = []
arrs = [j for j in range(1,n+1)]
count = 0
for i in range(1,n+1):
    if i != a and i != b:
        arr.append(i)
for j in arr:
    ans = len(list(itertools.combinations(arrs, j)))
    count += ans
print (count)

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 = 2**n-1
ans = sum - cmb(n,a)-cmb(n,b)

print(ans if ans <= 10**9+7 else ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

# from math import factorial as fact

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


def cnk(n, k):
    output = 1
    if k > n-k:
        k = n-k

    for i in range(1, k+1):
        output *= (n-k+1)//k

    return output


print((2**n) - 1 - (cnk(n, a) + cnk(n, b)) % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import math

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

tem = 0
for i in range(1,n+1):
  if i != a and i != b :
    tem += math.factorial(n) // (math.factorial(n - i) * math.factorial(i))

print(tem % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
import math
n,a,b=map(int,input().split())
total=0
def count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if (n-1)%2==0:
  for i in range(1,(n-1)//2+1):
    t=count(n,i)
    total+=t
  else:
    at=count(n,a)
    bt=count(n,b)
    ans=2*total-(at+bt)+1
    print(ans)
    
else:
  for i in range(1,(n-1)//2+1):
    t=count(n,i)
    total+=t
  else:
    at=count(n,a)
    bt=count(n,b)
    tt=count(n,(n-1)//2+1)
    ans=2*total-(at+bt)+1+tt
    print(ans)

Submission status: Time Limit Exceeded

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

def factorial(n):
    fact = 1
    while n > 1:
        fact *= n
        n -= 1
    return fact

sumv = 2**n - 1
f = factorial(n)
sumv -= f // (factorial(a) * factorial(n - a))
sumv -= f // (factorial(b) * factorial(n - b))
print(sumv)

Submission status: Time Limit Exceeded

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

for i in range(n):
    x = x * (n - i) // (i + 1)
    if i != a - 1 and i != b - 1:
        s = s + x

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

Submission status: Time Limit Exceeded

Solution code:
p = 10 ** 9 + 7
n,a,b = map(int,input().split())
k=max(a,b)
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
com=1
for i in range(1, k+1):
  com=(((com*(n-i+1))%p)*modinv(i,p))%p
  if i==a:
    coma=com
  if i==b:
    comb=com
print((2**n-1-coma-comb)%p)

Submission status: Time Limit Exceeded

Solution code:
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

mod = 10 ** 9 + 7



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

m = 10 ** 5 * 2 + 100
fact = [0 for _ in range(m)]
fact[0] = 1
for i in range(m-1):
    fact[i+1] = (fact[i] * (n - i) * pow((i + 1), mod - 2, mod)) % mod



nca = fact[a] #comb(n, a, mod)#factorial(n) // factorial(a) // factorial(n-a)
ncb = fact[b] #comb(n, b, mod)#factorial(n) // factorial(b) // factorial(n-b)

ans = pow_k(2, n)

ans -= 1 + nca + ncb
ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,a,b =map(int, input().split())
c=2**n-1
def kai(n,x):
    result=1
    for i in range(x,n+1):
        result=result*i
    return result
A=kai(n,n-a+1)
B=kai(b,1)
C=kai(b,a+1)
D=kai(n-a,n-b+1)
c=c-A*(C+D)//B
print(c)

Submission status: Time Limit Exceeded

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

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

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

print((2**n -cmb(n,a,p)-cmb(n,b,p)-1)%p)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
MOD = 10**9 + 7
def modpow(a:int, p:int, mod:int)->int:
    if p==0: return 1
    if p%2==0:
        half = modpow(a, p//2, mod)
        return half*half % mod
    else:
        return a * modpow(a, p-1, mod) % mod

def cmb2(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

A = list(map(int, input().split()))
n = A[0]
a = A[1]
b = A[2]

tot = modpow(2, n, MOD)

tot = tot-1
tot -= cmb2(n,a)
tot -= cmb2(n,b)
tot = tot % MOD

print(tot)

Submission status: Time Limit Exceeded

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

allComb = 2 ** N - 1

factA = 1
factB = 1
factNA = 1
factNB = 1
for indx in range(0, b):
  factB  = factB  * (indx + 1)
  factNB = factNB * (N - indx)
  if indx < a:
    factA  = factA  * (indx + 1)
    factNA = factNA * (N - indx)

Ans = allComb - int(factNA / factA) - int(factNB / factB)
Ans = Ans % ((10**9) + 7)

print(Ans)

Submission status: Time Limit Exceeded

Solution code:
import math

n,a,b = map(int,input().split())
k=math.factorial(n)
t=(n-1)//2
L=[1]*(n+1)
L2=[1]*(n+1)
s=1
NUM=10**9+7
for i in range(t):
    L[i+1]*=(n-i)*L[i]
    L2[i+1]*=L[i+1]
    L2[n-i-1]*=L[i+1]
if(n%2==0):
    L2[t+1]*=k
for i in range(t,n):
    L[i+1]*=(n-i)*L[i]
    L2[i+1]*=L[i+1]/k
    L2[n-i-1]*=L[i+1]/k
    L2[i+1]%=NUM
    L2[n-i-1]%=NUM

print(int(sum(L2)-L2[a]-L2[b]-1))

Submission status: Time Limit Exceeded

Solution code:
# ABC 156 D
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nms = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))
# def factorial_mod(n, mod):
#     a = 1
#     for i in range(1, n + 1):
#         a *= i
#         a %= mod
#     return a
# def comb_mod(n, k, mod):
#     if k > n or k < 0:
#         return 0
#     fact_n = factorial_mod(n, mod)
#     fact_k = factorial_mod(k, mod)
#     fact_n_k = factorial_mod(n - k, mod)
#     return (fact_n * pow(fact_k, mod - 2, mod) * pow(fact_n_k, mod - 2, mod)) % mod
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
def spow(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
n,a,b=nm()
MOD = 10**9 + 7
cn=spow(2,n,MOD)
ca=cmb(n,a)
cb=cmb(n,b)
# t=1
# for i in range(n):
#     t*=2%MOD
#     print(t)
# cn=(2**n)%MOD
print((cn-ca-cb-1)%MOD)
# print(ca)
# print(cb)
# ca=comb_mod(n, a, MOD)
# cb=comb_mod(n, b, MOD)
# cn=n*(n+1)*(2*n+1)//12-n*(n+1)//2
# # cn=cn%MOD
# # ca=ca%MOD
# # cb=cb%MOD
# print((cn-ca-cb))

Submission status: Time Limit Exceeded

Solution code:
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
Mod = 10**9+7
n, a, b = map(int, input().split())
N = n+1

def COMinit():
  #N_C_kのN
  for i in range(2, N):
    fac.append(fac[-1]*i%Mod)
    inv.append((-inv[Mod%i] * (Mod//i)) % Mod)
    finv.append(finv[-1] * inv[-1] % Mod)


def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod

COMinit()
#xのn乗をmで割った余り
def pos(x, n, m):
    if n == 0:
        return 1
    res = pos(x*x%m, n//2, m)
    if n%2 == 1:
        res = res*x%m
    return res


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((power_func(2, n, Mod)-COM(n,a)-COM(n,b)-1)%Mod)

Submission status: Time Limit Exceeded

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




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

ans = cmb(n,2,mod)
print(ans+1)

Submission status: Time Limit Exceeded

Solution code:
i = list(map(int, input().split()))
import math
ans=0
j=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] and k!=i[2]:
    ans+=(combinations_count(i[0], k)%(10**9+7))
answ=ans%(10**9+7)
print(answ)

Submission status: Time Limit Exceeded

Solution code:
import math
from scipy.misc import comb


n, a, b = map(int, input().split())
if n == 2:
    print(0)
else:
    print(((2**n -1) - comb(n, a, exact = True) - comb(n, b, exact = True)) % (10**9 + 7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def binomial(n, k):

    if 0 <= k <= n:
        ntok = 1
        ktok = 1
        for t in range(1, min(k, n - k) + 1):
            ntok *= n
            ktok *= t
            n -= 1
        return ntok // ktok
    else:
        return 0
    
n, a, b= map(int, input().split())
  
ans=2**n-1
    
ans_b=binomial(n, a)+binomial(n, b)

print(ans-ans_b)

Submission status: Time Limit Exceeded

Solution code:
import math
def comb(a,b,p):
    if b==0:
        return 1
    elif b%2==0:
        d=comb(a,b//2,p)
        return (d*d)%p
    else:
        return (a*comb(a,b-1,p))%p

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

l=[]
for i in [a,n-a,b,n-b]:
    temp=1
    for j in range(1,i+1):
        temp*=comb(j,num-2,num)

    l.append(temp%num)

ans = comb(2,n,num)-1-((math.factorial(n)%num)*(l[0]*l[1]+l[2]*l[3]))%num
print(ans)
#print(l)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

n,a,b = input().rstrip().split(' ')

n = int(n)
a = int(a)
b = int(b)

x =  [a,b]
count = 0
ti = 1

for d in range(1,n+1):
    if d in x:
        ti = (ti*(n-d+1))/d
        continue
        
    ti = (int((ti*(n-d+1))/d))%(10**9+7)
    #print(ti)
   
    count +=  ti
    count = count%(10**9+7)
   
count = count%(10**9+7)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_left # bisect_left(list, value)
#from fractions import gcd
from operator import mul
from functools import reduce

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

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

num = pow_r(2, n)
num %= div

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
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

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

num -= cmb(n, a, mod)
num -= cmb(n, b, mod)
num %= div

print(num-1)

Submission status: Time Limit Exceeded

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

# 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

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 )

# for i in range(N+1, )

# 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

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

Submission status: Time Limit Exceeded

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

res = int(2**n-1)
caa = 1
cab = 1
abu = 1
abs = 1
bbu = 1
bbs = 1

for y in range(a):
  abs *= n - y
  abu *= y + 1
caa = int(abs/abu)
  
for z in range(b):
  bbs *= n - z
  bbu *= z + 1
cab = int(bbs/bbu)

res -= int(caa+cab)
print(int(res%(10**9+7)))

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
def cmb(N2,n,r):
  return N2 / factorial(r) / factorial(n - r)

list = input().split()
N = int(list[0])
a = int(list[1])
b = int(list[2])
N2 = factorial(N)
S = 0
k = N // 2
x = 10**9 + 7
S = 2**N - 1
S += -cmb(N2,N,a) -cmb(N2,N,b)
S = S % x
print(int(S))

Submission status: Time Limit Exceeded

Solution code:
n,a,b= map(int,input().split())
if a>n/2:
    a=n-a
if b>n/2:
    b=n-b
p = (10**9+7)
from functools import reduce
from fractions import Fraction
nca = (reduce(lambda x,y:x*y%p, (Fraction((n-i),(i+1)) for i in range(a)), 1) )
ncb = (reduce(lambda x,y:x*y%p, (Fraction((n-i),(i+1)) for i in range(b)), 1) )
print(int(2**n - 1 - nca - ncb)%p)

Submission status: Time Limit Exceeded

Solution code:
def cmb(n, r, mod):
    num = 1
    cnt = 1
    for i in range(1, r+1):
        num *= (n-i+1)
        cnt *= i
        if num % cnt == 0:
            num = num//cnt
            cnt = 1
    return (num//cnt) % mod


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

mod = 10**9+7

nCa = cmb(n, a, mod)
nCb = cmb(n, b, mod)


if n <= 10**7:
    nCr = 2**n % mod
else:
    sy = n // 10**7
    am = n % (10**7)
    t = 2**(10**7) % mod
    am = 2**am % mod
    nCr = 1
    for i in range(sy):
        nCr = nCr * t % mod
    nCr = nCr * am % mod

print((nCr-1-nCa-nCb) % mod)

Submission status: Time Limit Exceeded

Solution code:
def framod(n, mod, a=1):
    for i in range(1, n + 1):
        a = a * i % mod
    return a


def power(n, r, mod):
    if r == 0:
        return 1
    if r % 2 == 0:
        return power(n * n % mod, r // 2, mod) % mod
    if r % 2 == 1:
        return n * power(n, r - 1, mod) % mod


def cmb(n, k, mod=10**9+7):
    a = framod(n, mod)
    b = framod(k, mod)
    c = framod(n - k, mod)
    return (a * power(b, mod - 2, mod) * power(c, mod - 2, mod)) % mod


def modpow(n, m, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (modpow(n, m, p//2)**2) % m
    return (modpow(n, m, p-1)*n) % m


def resolve():
    n, a, b = map(int, input().split())
    mod = 10 ** 9 + 7
    ans = modpow(2, mod, n) - 1
    ans -= cmb(n, a)
    ans -= cmb(n, b)
    print(ans % mod)


if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
n, a, b = [int(x) for x 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
"""
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
"""

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

Submission status: Time Limit Exceeded

Solution code:
P = 10 ** 9 + 7
N = 10 ** 9  # N は必要分だけ用意する
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]


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 combinations_count(n, r):
#     return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


if __name__ == '__main__':
    n, a, b = list(map(int, input().split(" ")))
    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)

    total = pow(2, n, P)
    # print(total)
    a_total = cmb(n, a)
    # print(a_total)
    b_total = cmb(n, b)
    print(total - a_total - b_total - 1)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = list(map(int,input().split()))
p=10**9+7
c=[1]
for i in range(n):
    c.append((2*c[i])%p)
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)

print((c[n]-cmb(n, a, p)-cmb(n, b, p)-1)%p)

Submission status: Time Limit Exceeded

Solution code:
import math
string = input().split(' ')
n = int(string[0])
a = int(string[1])
b = int(string[2])

sum_pattern = 2 ** n -1
  
exp_A = math.factorial(n) / (math.factorial(a) * math.factorial(n - a))
exp_B = math.factorial(n) / (math.factorial(b) * math.factorial(n - b))

print(int(sum_pattern - exp_A - exp_B) % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 22 21:22:44 2020

@author: H_Hoshigi
"""
#from scipy.special import comb
from scipy.misc import comb

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

answer =\
    2**n\
    -comb(n, a, exact=True)\
    -comb(n, b, exact=True)\
    -1
print(answer%(10**9 + 7))

"""
counter = 0
for i in range(1, n+1):
    if (i != a) and (i != b):
        counter += comb(n, i, exact=True)
    else:
        pass
print(counter%(10**9 + 7))
"""

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import math

MOD = 1000000007  # type: int

def fast_pow(a,b):
    if b == 0:
        return 1
    elif b % 2 == 0:
        d = fast_pow(a, b // 2)
        return (d * d) % MOD
    else:
        return (a * fast_pow(a, b - 1)) % MOD

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 ** 9 + 1  # N 
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 solve(n: int, a: int, b: int):
    print(str((fast_pow(2,n) - cmb(n,a,MOD) - cmb(n,b,MOD)-1)%MOD))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(n, a, b)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
n,a,b = i2()
def com(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def pow_k(x, n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K = K * x
            x = x ** 2
            n = (n - 1) // 2
        else:
            x = x ** 2
            n = n // 2
    return K * x
c = pow_k(2,n)-1
aa = com(n,a)
bb = com(n,b)
cc = 10**9+7
print((c-aa-bb)%cc)

Submission status: Time Limit Exceeded

Solution code:
from scipy.misc import comb
n,a,b = map(int,input().split())
# n = 1000000000
# a = 141421
# b = 173205
result = 0



if n % 2 == 1:
	for i in range(1,(n+1)//2):
		tmp_res = comb(n, i, exact=True) % (10**9+7)
		result += tmp_res
	result *= 2

else:
	for i in range(1,n//2):
		tmp_res = comb(n, i, exact=True) % (10**9+7)
		result += tmp_res
	result *= 2
	result += comb(n, n//2, exact=True) % (10**9+7)

result -= (comb(n, a, exact=True) + comb(n, b, exact=True)) % (10**9+7)


print( (result+1) % (10**9+7) )

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N, a, b = map(int, input().split())

def get_combi_mod(n, k, MOD):
    if n < k:
        return 0
    if n-k < k:
        k = n-k
    comb = 1
    for x in range(n-k+1, n+1):
        comb = (comb * x) % MOD
    d = 1
    for x in range(1, k+1):
        d = (d * x) % MOD
    comb *= pow(d, MOD-2, MOD)
    return comb % MOD

ans = 1
mod_case = 1 if N % 1000 != 0 else 0
div_num = 10 ** 9 + 7
for i in range(N // 1000 + mod_case):
    ans = (ans * (2 ** 1000)) % div_num

print((2 ** N - 1 - get_combi_mod(N, a, div_num) - get_combi_mod(N, b, div_num)) % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from math import factorial

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

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


ok_list = [i for i in range(1, n+1) if not (i==a or i==b)]

sum_flower = 0
for ok_num in ok_list:
    sum_flower += combinations_count(n, ok_num)


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