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
#xCy=x!/y!(x-y)!
def com(x,y):
    bunb = ((math.factorial(y)%mod) * (math.factorial(x-y)%mod))%mod
    buns = math.factorial(x)%mod
    bunb_inv = pow(bunb,mod-2,mod)
    d = (buns * bunb_inv) % mod
    return d
    
n,a,b = map(int,input().split())
mod = 10**9 + 7

ans = (2**n - 1) % mod
ans -= com(n,a) + com(n,b)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def cmb(n, r, mod,g1,g2):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
def main():
  n,a,b=map(int,input().split())
  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_sum=0
  for i in range(1,n+1):
    a_cmb = cmb(n,i,mod,g1,g2)
    if((i==a)or(i==b)):
      continue
    else:
      a_sum=a_sum+a_cmb
  print(a_sum)
if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
n,a,b = [int(x) for x in input().split()]
mod = 10**9 + 7
def comb(x,y):
    child = 1
    mother = 1
    for i in range(y):
        child *= (x-i)%mod
        mother *= (i+1)%mod
    return child * pow(mother,mod-2,mod) % mod
ans = pow(2,n,mod) - 1
ans -= comb(n,a)
ans %= mod
ans -= comb(n,b)
ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = [int(x) for x in input().split()]
mod = 10**9 + 7
def comb(x,y):
    child = 1
    mother = 1
    for i in range(y):
        child *= x-i
        mother *= i+1
    return child * pow(mother,mod-2,mod)
ans = pow(2,n,mod)  - comb(n,a) - comb(n,b) - 1
print(int(ans%mod))

Submission status: Time Limit Exceeded

Solution code:
n,a,b = [int(x) for x in input().split()]
mod = 10**9 + 7
import math
#再起限界突破
import sys
sys.setrecursionlimit(1000000000)
#メモ化再帰
from functools import lru_cache
@lru_cache(maxsize=1000000000)
def action(k):
    if k == 1:
        return 1
    else:
        return k * action(k-1) % mod
ans = pow(2,n,mod)  - action(n)/action(n-a)/action(a) - action(n)/(action(n-b)*action(b)) - 1
print(int(ans%mod))

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
n,a,b=map(int,input().split())
num1=1
num2=1
num3=1
num4=1
p=pow(10,9)+7
for i in range(a):
    num1=num1*(n-i)
    num2=num2*(a-i)
ca=num1//num2
for i in range(b):
    num3=num3*(n-i)
    num4=num4*(b-i)
cb=num3//num4
ans=pow(2,n,p)-1-(ca+cb)

ans=ans%p
if ans==0:
    print(0)
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
n,a,b=map(int,input().split())
ca=factorial(n)//(factorial(a)*factorial(n-a))
cb=factorial(n)//(factorial(b)*factorial(n-b))
ans=2**n-1-(ca+cb)
if ans==0:
    print(0)
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
n,a,b=map(int,input().split())
sum=0
for i in range(1,n+1):
    if i==a or i==b:
        continue
    com=factorial(n)//(factorial(i)*factorial(n-i))
    sum+=com
if sum==0:
    print(0)
else:print(sum%(10**9+7))

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1, n+1):
  if i == a or i == b:
    continue
  else:
    ans += math.factorial(n) // (math.factorial(i) * math.factorial(n-i))

if ans < (10**9 + 7):
  print(ans)
else:
  print(ans // (10**9 + 7))

Submission status: Time Limit Exceeded

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

def C(n, k):
    a = 1
    b = 1
    for i in range(k):
        a *= (n-i) % P
        b *=(i+1) % P
    return a * pow(b, P-2, P) % P

print((pow(2, N, P) - 1 - C(N, A) - C(N, B)) % P)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
n,a,b=map(int,input().split())
ans=1
for i in range(n):
  ans*=2%1000000007
ans-=(factorial(n)//(factorial(a)*factorial(n-a)))%1000000007
ans-=(factorial(n)//(factorial(b)*factorial(n-b)))%1000000007
print(max(ans-1,0))

Submission status: Time Limit Exceeded

Solution code:
def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n = n>>1
    return res

def COM(n, k):
    child = 1
    mother = 1
    for i in range(1, k+1):
        child = child * (n-i+1) % MOD
        mother = mother * i
    return child * modpow(mother, MOD-2, MOD)


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

ans = -1

ans += modpow(2, n, MOD)
ans -= COM(n, a)
ans -= COM(n, b)
if ans < 0:
    ans += MOD
print(ans % MOD)

Submission status: Time Limit Exceeded

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

ans = -1

def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n = n>>1
    return res

ans += modpow(2, n, MOD)



fac = [0 for i in range(n+1)]
finv = [0 for i in range(n+1)]
inv = [0 for i in range(n+1)]

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

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

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

print(ans)

Submission status: Time Limit Exceeded

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

def inv(k):
    return pow(k, mod - 2, mod)

def comb(n, k):
    bunshi = 1
    bunbo = 1
    for i in range(k):
        bunshi *= (n - i) % mod
        bunbo *= (i + 1) % mod
    return bunshi * inv(bunbo) % mod

mod = 1000000007
all_num = pow(2, n, mod)

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

Submission status: Time Limit Exceeded

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

def inv(k):
    return pow(k, mod - 2, mod)

def comb(n, k):
    bunshi = 1
    bunbo = 1
    for i in range(k):
        bunshi *= (n - i)
        bunbo *= (i + 1)
    return bunshi * inv(bunbo) % mod

mod = 1000000007
all_num = pow(2, n, mod)

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

Submission status: Time Limit Exceeded

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

def comb(n, k, p):
    if k > n-k:
        return comb(n, n-k, p)
    num, den = 1, 1
    for i in range(k):
        num = num * (n-i) % p
        den = den * (i+1) % p
    return num * pow(den, p-2) % p

print((total - 1 + (M - comb(n,a,M)) + (M - comb(n,b,M))) % M)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, a, b = map(int, input().split())
MOD = 10**9+7
MAX = 2*10**5
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX


def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i-1]*i % MOD
        inv[i] = MOD-inv[MOD % i]*(MOD//i) % MOD
        finv[i] = finv[i-1]*inv[i] % MOD


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


COMinit()

memo = defaultdict(int)


def RECOM(n, k):
    if memo[(n, k)] != 0:
        return memo[(n, k)]
    if MAX < n:
        return n*RECOM(n-1, k-1)//k
    else:
        memo[(n, k)] = COM(n, k)
        return memo[(n, k)]

ans = pow(2, n, MOD)-RECOM(n, a)-RECOM(n, b)-1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, a, b = map(int, input().split())
MOD = 10**9+7
MAX = 2*10**5
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX


def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i-1]*i % MOD
        inv[i] = MOD-inv[MOD % i]*(MOD//i) % MOD
        finv[i] = finv[i-1]*inv[i] % MOD


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


COMinit()

memo = defaultdict(int)


def RECOM(n, k):
    if memo[(n, k)] != 0:
        return memo[(n, k)]
    if MAX < n:
        return RECOM(n-1, k)+RECOM(n-1, k-1)
    else:
        memo[(n, k)] = COM(n, k)
        return memo[(n, k)]

ans = pow(2, n, MOD)-RECOM(n, a)-RECOM(n, b)-1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(100000000)
def mod_combination(n, k, mod):
    def mod_permutation(n, k, mod):
        if n<=k:
            return 1
        else:
            return (n * mod_permutation(n-1,k,mod))%mod

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

    return (mod_permutation(n,n-k,mod) * mod_inv_permutation(k, mod))%mod

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

Submission status: Time Limit Exceeded

Solution code:
import math
def f(N, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,a,b=map(int,input().split())
mod=1000000007
x=n//100
y=n%100
s=((x*976371285)%mod+(2**y)%mod)%mod
A=f(n,a)%mod
B=f(n,b)%mod
print(s-A-B-1)

Submission status: Time Limit Exceeded

Solution code:
import math
def f(N, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,a,b=map(int,input().split())
mod=1000000007
s=(2**n)%mod
A=f(n,a)%mod
B=f(n,b)%mod
print(s-A-B-1)

Submission status: Time Limit Exceeded

Solution code:
def comb(n,k,p):
  from math import factorial
  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*pow(b,p-2,p)*pow(c,p-2,p))%p

p=pow(10,9)+7
n,a,b=map(int,input().split())
sum=pow(2,n,p)
print(sum-1-comb(n,a,p)-comb(n,b,p))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

def table(n:int, p=10**9+7):
    global fact, factinv, inv
    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)

m, a, b = mi()

P = 10**9+7
N = 2*(10**5)
table(N)

mca = 1
for i in range(1, a+1):
    #mca *= (m-i+1) * inv[i]
    mca *= (m-i+1) * pow(i, P-2, P)
    mca %= P

mcb = mca
for i in range(a+1, b+1):
    #mcb *= (m-i+1) * inv[i]
    mca *= (m-i+1) * pow(i, P-2, P)
    mcb %= P

print((pow(2, m, P)-1-mca-mcb) % P)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

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

m, a, b = mi()

P = 10**9+7
N = 2*(10**5)+1
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

mca = mcb = 1

for i in range(1, a+1):
    mca *= (m-i+1) * inv_t[i]
    mca %= P

for i in range(1, b+1):
    mcb *= (m-i+1) * inv_t[i]
    mcb %= P

print((pow_r(2, m)-1-mca-mcb) % P)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

m, a, b = mi()

P = 10**9+7
N = 2*(10**5)+1
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

mca = mcb = 1

for i in range(1, a+1):
    mca *= (m-i+1) * inv_t[i]
    mca %= P

for i in range(1, b+1):
    mcb *= (m-i+1) * inv_t[i]
    mcb %= P

print(((2**m)-mca-mcb-1)%P)

Submission status: Time Limit Exceeded

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


def comb(x, y):
    return math.factorial(x) // (math.factorial(x-y) * math.factorial(y))


count = 0
for i in range(1, n+1):
    if i == a:
        continue
    if i == b:
        continue
    elif i != a or i != b:
        count += comb(n, i)

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

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x) if isinstance(other, ModInt) else
            ModInt(other - self.x)
        )

    __rmul__ = __mul__

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

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )

def cmb(fact, n, r):
    return fact[n] / fact[n-r] / fact[r]

def solve(n, a, b):
    fact = [ModInt(1)]
    for i in range(1, max(n, a, b) + 1):
        fact.append(fact[i-1] * i)

    return  ModInt(2**n) - 1 - cmb(fact, n, a) - cmb(fact, n, b)

if __name__ == '__main__':
    n, a, b = map(int, input().split())
    ret = solve(n, a, b)
    print(ret)

Submission status: Time Limit Exceeded

Solution code:
import math
n,a,b=map(int, input().split())
f=math.factorial
#c=f(n)
#print((2**n-c//(f(a)*f(n-a))-c//(f(b)*f(n-b))-1)%(10**9+7))
p=10**9+7
c=pow(2,n,p)
#d=(f(n)//(f(a)*f(n-a)))%p
#e=(f(n)//(f(b)*f(n-b)))%p
fn=f(n)
d=fn*pow(f(a)*f(n-a),p-2,p)%p
e=fn*pow(f(b)*f(n-b),p-2,p)%p
print(c-d-e-1)

Submission status: Time Limit Exceeded

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7

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

ans = pow(2, n, mod) - 1

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]  # 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) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)

print(ans - cmb(n, a, mod) - cmb(n, b, mod))

Submission status: Time Limit Exceeded

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

n_sum = 0
for i in range(1, n+1):
  i_sum = 1
  for j in range(i):
    i_sum *= (n-j)/(j+1)
  n_sum += i_sum
    
a_sum = 1
for x in range(a):
  a_sum *= (n-x)/(x+1)

b_sum = 1
for y in range(b):
  b_sum *= (n-y)/(y+1)
  
print(int((n_sum - a_sum - b_sum)%(10**9+7)))

Submission status: Time Limit Exceeded

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

#二分累乗法
#nnが1以上の時使える
#powと同じ
#aa**nn
#2**35=2*2**2)
def powT(aa,nn):
	if nn==1:
		return aa
	if nn%2==0:
		v = powT(aa,nn//2)**2
	else:
		v = aa*powT(aa,nn//2)**2
	return v

#二分累乗法
#pow()%10**9
def powTmod(aa,nn):
	mod=10**9+7
	if nn==1:
		return aa
	if nn%2==0:
		v = powTmod(aa,nn//2)**2
	else:
		v = aa*powTmod(aa,nn//2)**2
	return v%(mod)

#nCa mod(10**9+7)
#フェルマーの小定理
def powTnCa(n,a):
	temp=1
	mod=10**9+7
	for i in range(n-a+1,n+1):
		temp*=i%mod
	temp2=1
	for i in range(1,a+1):
		temp2*=i%mod
	temp2=powTmod(temp2,10**9+7-2)

	return temp*temp2%mod

result=powT(2,n)-powTnCa(n,a)-powTnCa(n,b)-1

print(result)

Submission status: Time Limit Exceeded

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

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

MOD = 10**9 + 7

n, a, b = LI()

total = pow(2, n) - 1

ans = total - (combination(n, a) + combination(n,b))

print(ans % MOD)

Submission status: Time Limit Exceeded

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

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 = pow(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(pow(2,n,p) - cmb(n, a, p) -cmb(n, b, p) -1)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

def cmb(n, r, p, fact, factinv):
    if r < 0 or n < r:return 0
    return fact[n] * factinv[r] * factinv[n-r] % p
def main():
    n, a, b = map(int, input().split())
    ans = 0
    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)
    for i in range(1, n+1):
        if i == a or i == b:continue
        ans += cmb(n, i, p, fact, factinv)
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# ncrかなと思うが実験すると1 3 6 10 15 21みたいなのが出てくる
# あらかじめN個作っとくんだけどこれ間に合うん？
# 無理ですね はい  解説

# 愚直にみればそれぞれ選ぶか選ばないかで2通りがn回続く
# a,bの2数も含むとすると、すなわち、2^(n) - 1（かならず1本は選ぶので）。これは繰り返し二乗法で解く。
# ここからa,bを考えたものを引く。具体的にはnCr(n, a) mod p とnCr(n, b) mod pを引く。
# nCr mod pで間に合わんやんけと思って諦めたけどよくよく読んだら条件はa = min(n, 2*10^5)なので間に合うやんけ
# nCrの式変形で分母と分子をそれぞれ作ってやるっていう愚直なやつでもいけるんじゃねこれ

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


# 繰り返し二乗法
def repMod(a, n, p):
    if n == 1:
        return a % p
    if n % 2 == 1:
        return a * repMod(a, n - 1, p) % p
    ret = repMod(a, n // 2, p) % p
    return (ret * ret) % p


all_comb = repMod(2, n, MOD)
# nCr = n!/(r!(n-r)!) ゆえ ((n-r+1) * (n-r+2) * .. * n)/(1*2*3*..*r)
# これがr = min(n, 2*10^5)なので愚直にやっても間に合う


def nCrMod(n, r, p):
    ret = 1
    # 分子
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret %= p
    # 分母
    for i in range(2, r + 1):
        # ret //= i なんかこれがおかしい（なんでだろうね）
        ret *= repMod(i, p - 2, p)  # なぜかここでやらないと駄目だった
        ret %= p
    # ret = repMod(ret, p - 2, p) # なぜかここでやると駄目だった
    return ret % p


print((all_comb - nCrMod(n, a, MOD) - nCrMod(n, b, MOD) - 1) % MOD)

Submission status: Time Limit Exceeded

Solution code:
a=pow(2,10**7)
print(a)

Submission status: Time Limit Exceeded

Solution code:
import math

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


def cc(n, r):
    if not d.get(n):
        d[n] = math.factorial(n)
    if not d.get(n-r):
        d[n-r] = math.factorial(n-r)
    if not d.get(r):
        d[r] = math.factorial(r)

    return d[n] // (d[n-r] * d[r])


x=10**9 +7
r=0
for i in range(1,n+1):
    if i == a or i == b:continue
    
    r+=cc(n,i)



print(r%x)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(4100000)

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

#繰り返し2乗法
def  mod_pow(a:int, b:int, mod:int)->int:
    if b % 2 == 0:
        return (mod_pow(a, b//2, mod) ** 2) % mod
    elif b == 1:
        return a % mod
    else:
        return ((mod_pow(a, b//2, mod) ** 2) * a) % mod

#逆元を求める関数
def mod_inverse(mod:int, b:int)->int:
    return mod_pow(b, mod-2, mod)

#aCbをmodで割った余りを求める関数(bが小さい)
def nCr_mod(n:int, r:int, mod:int)->int:
    num, den = 1, 1 #numerator, denominator

    for i in range(r):
        num *= (n-i) % mod
        den *= (i+1) % mod

    return (num * mod_inverse(mod, den)) % mod
    
ans = (mod_pow(2, n, mod) - 1 - nCr_mod(n, a, mod) - nCr_mod(n, b, mod)) % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
n, a, b = map(int, input().split())
a1 = factorial(n) / factorial(a) / factorial(n - a)
b1 = factorial(n) / factorial(b) / factorial(n - b)
ans = 2**n - a1 - b1 - 1 
print(int(ans)%1000000007)

Submission status: Time Limit Exceeded

Solution code:
def powl(x, n, l):#繰り返し2乗法 O(log n)
    ans = 1
    while n > 0:
        if bin(n & 1) == bin(1):
            ans = ans*x
        x = (x*x)%l
        n = n >> 1 #ビットシフト
    return ans

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

out=powl(2,n,pow(10,9)+7)-1
X,Y=1,1
for i in range(a):
    X=X*(i+1)
    Y=Y*(n-i)
out-=Y*powl(X,pow(10,9)+5,pow(10,9)+7)

for i in range(a,b):
    X=X*(i+1)
    Y=Y*(n-i)
out-=Y*powl(X,pow(10,9)+5,pow(10,9)+7)

print(out%(pow(10,9)+7))

Submission status: Time Limit Exceeded

Solution code:
mod =10**9+7
n,a,b = map(int,input().split())
ans = 2**n-1
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

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

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

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

    return result
ans -= cmb(n,a) + cmb(n,b)
print(ans%mod)

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

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

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

def main():
    n, a, b = map(int, input().split())
    whole = 2**n-1
    a = combinations_count(n, a)
    b = combinations_count(n, b)
    print((whole-a-b)%(10**9+7))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

def choose(n,a):
    x = 1
    y = 1
    for i in range(a):
        x *= n - i
        y *= i+1
    return x//y

print( ((2**n - 1) - choose(n,a) - choose(n,b)) % MOD )

Submission status: Time Limit Exceeded

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

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

for i in range(n):
    REC += combinations_count(n, i)

REC = REC - combinations_count(n, a)
REC = REC - combinations_count(n, b)
print(REC)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int, input().split())
mod = 10**9+7
 
def minus(n,k):
    x,y =1,1
    for i in range(k):
        x*=(n-i)%mod
        y*=(k-i)%mod
    return x*pow(y, mod-2, mod)%mod
 
ans = pow(2,n,mod)-1-minus(n,a)-minus(n,b)
while ans<0:
    ans+=mod
print(ans)

Submission status: Time Limit Exceeded

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

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

ans = pow(2,n,mod)-1-minus(n,a)-minus(n,b)
while ans<0:
    ans+=mod
print(ans)

Submission status: Time Limit Exceeded

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

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

ans = pow(2,n,mod)-1-minus(a)-minus(b)
while ans<0:
    ans+=mod
print(ans)

Submission status: Time Limit Exceeded

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

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

ans = pow(2,n,mod)-1-minus(a)-minus(b)
if ans<0:
    ans+=mod
print(ans)

Submission status: Time Limit Exceeded

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

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

ans = pow(2,n,mod)-1-minus(a)-minus(b)
while ans<0:
    ans+=mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = (int(x) for x in input().split())
mod = pow(10,9)+7

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

ans = pow(2,n,mod)-1-minus(a)-minus(b)
while ans<0:
    ans+=mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
def combination(n,r,mod=10**9+7):
    n1 = n+1
    r = 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
  
mod = int(1e9+7)
n,a,b= map(int,input().split())
 
S = (pow(2,n)-1)%mod
A = combination(n,a)
B = combination(n,b)
ans = (S-A-B)%mod
 
print(ans)

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=0
for i in range(1,N+1):
  if i==a or i==b:
    continue
  else:
    sum+=cmb(N,i)
ans=sum%((10**9)+7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    n,a,b = map(int, input().split())
    def nCr(n, r, mod):#mod=10**9+7 
        r = min(r, n-r)
        numer = denom = 1
        for i in range(1, r+1):
            numer = numer * (n+1-i) % mod
            denom = denom * i % mod
        return numer * pow(denom, mod-2, mod) % mod

    res = (2**n - 1)%mod
    x = nCr(n, a, mod)
    y = nCr(n, b, mod)
    print((res-x-y)%mod)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    n,a,b = map(int, input().split())
    def nCr(n, r, mod):#mod=10**9+7 
        r = min(r, n-r)
        numer = denom = 1
        for i in range(1, r+1):
            numer = numer * (n+1-i) % mod
            denom = denom * i % mod
        return numer * pow(denom, mod-2, mod) % mod

    res = 0

    for i in range(1, n+1):
        if i==a or i==b:
            continue
        res += nCr(n, i, mod)
        res %= mod

    print(res)

if __name__ == '__main__':
    main()