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 sys
from io import StringIO
import unittest

import math

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 )

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
        x = x%mod #
        n //= 2

    return K * x

def resolve():

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

    ptn = pow_k(2,n)
    ptn -= 1


    comba=cmb(n,a,mod)
    combb=cmb(n,b,mod)

    ptn -= (comba+combb)
    ptn = ptn%mod

    print(ptn)

    return 

resolve()

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

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

tot = modpow(2, n, MOD)

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

print(tot)

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

num = (2**n)%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:
from math import factorial

def modpow(a, n, p):
    bi=str(format(n,"b"))
    res=1
    for i in range(len(bi)):
        res=(res*res) %p
        if bi[i]=="1":
            res=(res*a) %p
    return res

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

g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

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

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 )

ans = modpow(2, n, mod) - 1
ans -= (cmb(n, a, mod) + cmb(n, b, mod))

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

mod = 1000000007
def choiceCnt(target_cnt, select_cnt):

    ret_1 = 0
    temp_list = []
    for temp in range(select_cnt):
        temp_list.append(target_cnt - temp)

    bunnsi = 1
    for sub in temp_list:
        bunnsi *= sub

    bunbo = 1
    for sub in range(1, select_cnt + 1):
        bunbo *= sub

    return bunnsi // bunbo


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

hana_kind_cnt = n

result = 0
for hanataba_koho_select_cnt in range(1, hana_kind_cnt + 1):
    if not(hanataba_koho_select_cnt == a or hanataba_koho_select_cnt == b):
        result += choiceCnt(n, hanataba_koho_select_cnt) % mod

print(int(result))

Submission status: Time Limit Exceeded

Solution code:
import itertools
from math import factorial
from scipy.misc import comb
"""
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
"""


n, a, b = map(int, input().split())
"""
counter = 0
UpperLimit = n//2
if n%2 == 0:
    for r in range(UpperLimit):
        counter += cmb(n,r)#comb(n, r, exact = True)
    counter *= 2
    counter += cmb(n,UpperLimit)#comb(n, UpperLimit, exact = True)
    counter -= 1
else:
    for r in range(UpperLimit+1):
        counter += cmb(n,r)#comb(n, r, exact = True)
    counter *= 2
    counter -= 1

counter -= cmb(n,a)#comb(n, a, exact = True)
counter -= cmb(n,b)#comb(n, b, exact = True)

print(counter%(10**9+7))
"""

numerator = n
denominator = 1
counter = 0
for i in range(1,n+1):
    counter += numerator//denominator
    numerator *= (n-i)
    denominator *= (1+i)

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

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int, input().split())
f_num=0
if n==2:
    print('0')
else:
    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
    for i in range(1,n+1):
        if i!=a and i!=b:
            f_num+=cmb(n,i)
    print(f_num%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:

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


def main():
    n,a,b = map(int, input().split())
    score = 0

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

    for i in range(1,n+1):
        if not(i == a or i == b):
            temp = (cmb(n, i, p,fact,factinv))
            score += temp
    print(score)




if __name__ == '__main__' :
    main()

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

    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


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

A = 2 ** n - 1
  
ans = A % mod - cmb(n, a) % mod -cmb(n, b) % mod

print(ans % mod)

Submission status: Time Limit Exceeded

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

div = 10 ** 9 + 7

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

C = 1
ans = 0

for i in range(1, n + 1):
    C = C * ((n - i + 1) % div) % div
    C = C * calc(i, div - 2, div) % div
    if i != a and i != b:
        ans += C
        ans %= div

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
N,a,b=map(int,input().split())
MOD=10**9+7
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
cnt=0
for i in range(1,N+1):
  cnt+=cmb(N,i)
A=cmb(N, a)
B=cmb(N, b)
cnt=cnt-A-B
ans=cnt%MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
import math

debug = False

def log(text):
    if debug:
        print(text)

def comb(n, r):
 
    result = 1
    for i in range(n, n - r, -1):
        result = result * i 

    for i in range(1, r+1):
        result = result // i
    
    return result

      

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
    
    (n, a, b) = [int(e) for e in lines[0].split(" ")]

    return (n, a, b)


def solve(n, a, b):

    result = int(2**n) - 1 - comb(n, a) - comb(n, b) % int(10**9 + 7)


    return result


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

Solution code:
n , a , b = map(int,input().split())
p = 10**9 +7
def comb(n,k,p):
  """power_funcを用いて(nCk) mod 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*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 d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
 
A = comb(n, a, p)
B = comb(n, b, p)
 
 
print(pow(2,n,p) -A - B-1)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

ans = 0

for i in range(1,n+1):
    if i == a or i == b:
        continue
    else:
        ans += c_c(n,i)

print(ans % 1000000007)

Submission status: Time Limit Exceeded

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

f = math.factorial(n) % mod

inv = pow(f, mod - 2, mod)
invs = {}
invs[n] = inv
for m in range(n, 1, -1):
    inv *= m
    inv %= mod
    invs[m - 1] = inv

memo = {}

for i in range(1, n//2+1):
  memo[i] = f*invs[i]*invs[n-i]%mod

for i in range(1, n+1):
  if i != a and i != b:
    if i == n:
      ans += 1
    elif i <= n//2:
      ans += memo[i]
    else:
      ans += memo[n-i]
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
mod = 10**9+7
n,a,b = map(int, input().split())
ans = 0
c = 1
x = n
y = 1
if a!=n and b!=n: ans+=c
for i in range(1,(n+2)//2):
    c = c*x//y
    x-=1
    y+=1
    ans += c*2
    if i==a or n-i==a:
        ans -= c
    if i==b or n-i==b:
        ans -= c
    if i==n/2:
        ans -= c

print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
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]]
    
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
    
def comb(n, r):
    q = 1
    p = 1
    for i in range(r):
        q = q * (n-i) % MOD
        p = p * (i+1)
    return (q * mod_inv(p, MOD)) % MOD

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

y = (2**n-1)%MOD

ca = comb(n, a)
cb = comb(n, b)
print((y-ca-cb)%MOD)

Submission status: Time Limit Exceeded

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

ncr = 1
for r in range(1, n+1):
    ncr = ncr * (n + 1 - r) / r
    if a != r and b != r:
        pattern += ncr
        if pattern > 10 ** 9 + 7:
            pattern -= 10 ** 9 + 7
if pattern > 10 ** 9 + 7:
    pattern -= 10 ** 9 + 7
print(int(pattern))

Submission status: Time Limit Exceeded

Solution code:
n,a,b=(int(x) for x in input().split())
mod=1000000007
n1=int(n/2)
list=[1]
for i in range(n1):
	k=list[i]*(n-i)/(i+1)
	k%=mod
	list.append(k)
su=sum(list)%mod
su*=2
if n%2==0:
	su-=list[n1]
if 2*a>n:
	a=n-a
if 2*b>n:
	b=n-b
su-=list[a]
su-=list[b]
su-=1
print(int(su%mod))

Submission status: Time Limit Exceeded

Solution code:
n,a,b = [int(x) for x in input().rstrip().split()]
l=[]
ans=0
ans1=1
for i in range(1,n+1):
    ans1 = ans1*((n-i+1)/i)
    if i==a or i==b:
        l.append(ans1)
        continue
    
    if n<(i/2):
            ans+=l[n-i]
    else:
        ans+=ans1
        l.append(ans1)
print(round(ans%(10**9+7)))

Submission status: Time Limit Exceeded

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

import math
from collections import defaultdict

(n, a, b) = [int(s) for s in input().split()]

comb_sum = 0
pn = math.factorial(n)
pc = 1

for c in range(1, n + 1):
    pc *= c
    if c != a and c != b:
        comb_sum += pn // (math.factorial(n - c) * pc)

ans = int(comb_sum % (1e9 + 7))

print(ans)

Submission status: Time Limit Exceeded

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

S = 0
for i in range(1,n+1):
    if i != a and i != b:
        S = S + math.factorial(n) / (math.factorial(i)*math.factorial(n-i))
print(int(S % (10**9 + 7)))

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

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

A = cmb(n , a, p)
B = cmb(n , b, p)

print(pow(2,n,p) -A - B-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
'''
n = int(input())
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [int(input()) for i in range n]
p = [list(map(int, input().split()))]

a = input()
a, b = input().split()
a = [input() for i in range n]
'''
n, a, b = map(int, input().split())

from math import factorial
import math


def nCr(n,r):
    return factorial(n) / factorial(r) / factorial(n - r)
mod = 10**9 + 7
sum = 2**(n%mod) - 1
sum -= (nCr(n,a) + nCr(n,b))

print(math.floor(sum%(10**9+7)))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(2000000)
input=sys.stdin.readline


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

mod = 10**9+7

power={}

def xpower(x, y):
    key=str(x) + " " + str(y)
    try:
        return power[key]
    except:
        pass
    if   y == 0     :
        power[key]=1
        return power[key]
    elif y == 1     :
        power[key]=x % mod
        return power[key]
    elif y % 2 == 0 :
        power[key]=xpower(x, y/2)**2 % mod
        return power[key]
    else            :
        power[key] =xpower(x, y//2)**2 * x % mod
        return power[key]



def mul(a, b):
    return ((a % mod) * (b % mod)) % mod
def div(a, b):
    return mul(a, xpower(b, mod-2)) % mod


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


cnt=(xpower(2,n)-1)%mod


res=1
c=min(a,b)
d=max(a,b)
for i in range(1,d+1):
    res=res*div(n-i+1,i)%mod
    if i==c:
        cnt=(cnt-res)%mod
cnt=(cnt-res)%mod


# cnt-=cmb(n,a)+cmb(n,b)
print(cnt)

Submission status: Time Limit Exceeded

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

f = math.factorial(n)

inv = pow(f, mod - 2, mod)
invs = {}
invs[n] = inv
for m in range(n, 1, -1):
    inv *= m
    inv %= mod
    invs[m - 1] = inv

memo = {}

for i in range(1, n//2+1):
  memo[i] = f*invs[i]*invs[n-i]%mod

for i in range(1, n+1):
  if i != a and i != b:
    if i == n:
      ans += 1
    elif i <= n//2:
      ans += memo[i]
    else:
      ans += memo[n-i]
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
inList = list( map(int,input().split()) )
n = inList[0]
a = inList[1]
b = inList[2]

#print( int(factorial(4) / factorial(2) )  )
sum = 0

for i in range(1,n+1):
    if i!= a and i!=b:
        #print(i,int(factorial(n) // (factorial(n-i)*factorial(i)) ))
        sum+= int(factorial(n) // (factorial(n-i)*factorial(i)) )

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

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
ans = 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

mod = 10**9+7 #出力の制限
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):
  if i+1 == a or i+1 == b:
    pass
  else:
    ans += cmb(n, i+1, mod)

print(ans)

Submission status: Time Limit Exceeded

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

def comb(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)%p
    denom = reduce(mul, range(1, r + 1), 1)%p
    return (numer // denom)%p

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

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())
o = 0
for i in range(1, n+1):
  if i != a and i != b:
    o += combinations_count(n,i)
print(o)

Submission status: Time Limit Exceeded

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

def conv(A, B):
    count = float(1)
    a = float(A)
    c = float(A)
    d = float(1)
    for i in range(B - 1):
        a -= 1
        c *= a
        count += 1
        d *= count
    return c / d

ans = 0
for i in range(1, int(N / 2) + 1):
    ans += conv(N, i)
ans *= 2

if N % 2 == 0:
    ans -= conv(N, int(N / 2))

ans -= conv(N, a)
ans -= conv(N, b)
ans += 1

n = 10
for i in range(8):
  n *= 10
ans = ans % (n + 7)
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
def combi(n, r):
    p = 1
    for i in range(1, r+1):
        p = p * (n-i+1) // i
    return p

n, a, b = [int(n) for n in input().split()]
c = 0
m = 0
d = 10**9+7
if n%2==0:
    for i in range(0, n//2):
        c = c + combi(n,i) * 2 
    c += combi(n, n//2)
else:
    for i in range(0, n//2+1):
        c = c + combi(n,i) * 2
m += combi(n, a)
m += combi(n, b)
m += 1
print((c-m)%d)

Submission status: Time Limit Exceeded

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

cmba=1
cmbb=1
p=(10**9)+7
lst=[]
num=pow(2,n,p)-1
for i in range(1,b+1):
  cmbb*=(n-i+1)*(pow(i,p-2,p))%p
  cmba=cmbb
  if i==a:
    lst.append(cmba)
    
num=num-lst[0]-cmbb
num=num%p

print(num)

Submission status: Time Limit Exceeded

Solution code:
k,a,b=map(int,input().split())
n=k
z=10**9+7
q=1
x=2
while n>1:
    if n%2!=0:
        q*=x%z
    x*=x%z
    n//=2
ans=q*x%z

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

    return result%z
ans = ans - cmb(k,a)  - cmb(k,b)
print(ans%z-1)

Submission status: Time Limit Exceeded

Solution code:
#ABC156 D - Bouquet

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

n,a,b = map(int,input().split(' '))
mod = 10**9+7 #出力の制限
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 )

cnt = 0
for i in range(1,n+1):
    if(i != a and i != b):
        cnt += cmb(n,i,mod)

print(cnt)

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

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


A = cmb(n, a, p)
B = cmb(n, b, p)


print(pow(2,n,p) -A - B-1)

Submission status: Time Limit Exceeded

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

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


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

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

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

count = 0
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]

range2_n1 = range(2, n+1)
range1_n1 = range(1, n+1)

for i in range2_n1:
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

for m in range1_n1:
    if not (m == a or m == b):
        count += cmb(n,m,p)
        count %= p

print(count)

Submission status: Time Limit Exceeded

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


def pow_k(x, n):
    res = 1
    while n > 0:
        if n & 1:
            res *= x
        x *= x
        n //= 2
    return res


total = pow_k(2, n) - 1

now = 1
div = 1
for i in range(max(a, b) + 1):
    now *= (n - i)
    div *= i + 1
    if i == a - 1 or i == b - 1:
        total -= now // div
print(total % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
n, a, b  = map(int,input().split())
ans = 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)

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

Submission status: Time Limit Exceeded

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

# def cmb(n, r):
#     nCr = {}
#     if r == 0 or r == n: return 1
#     if r == 1: return n
#     if (n,r) in nCr: return nCr[(n,r)]
#     nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
#     return nCr[(n,r)]
#
# sum = 0
# for i in range(n):
#     i = i+1
#     x = cmb(n, i)
#     sum += x
#
# reigai = cmb(n, a) + cmb(n, b)
# sum = sum -reigai
# ans = sum % (10**9+7)
# print(ans)

def comb(n,k,p):
  """power_funcを用いて(nCk) mod 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*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 d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

p =10**9+7

sum = 0
for i in range(n):
    i = i+1
    x = comb(n, i, p)
    sum += x

reigai = comb(n, a, p) + comb(n, b, p)
sum = sum -reigai
ans = sum % (10**9+7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# D

from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

N,A,B = map(int,input().split())
if (N == 2):
    print(0)
else:
    print((2**N - 1 - combinations_count(N, A) - combinations_count(N, B)) % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import math
n,a,b = map(int,input().split())
if n == 2 :
    print(0)
else:
    ans = 2**n -1
    numa = 1
    for i in range(1,a+1):
        numa = numa *(n - i + 1) // i
    numb = numa
    for i in range(a+1,b+1):
        numb = numb * (n - i + 1) //i
    ans = ans -(numa+numb)
    print(ans%(10**9+7))

Submission status: Time Limit Exceeded

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

# 有理数クラスをインポート
from fractions import Fraction

# 組合せの総数
def comb(n, k):
    
    if n < 0 or k < 0:
        pdt = 0
    
    else:
        pdt = 1
        for s in range(1, k + 1):
            pdt *= Fraction(n - s + 1, s)
    
    # 戻り値をint型にするために分子を取り出す
    return pdt.numerator

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

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
mod = 1000000007
factorial = [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

p = 10 ** 9 + 7
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(cmb(4,2, mod))

def modpow(x,e,mod):
    a = 1
    p = x
    while e>0:
        if e%2 ==0:
            p*=p%mod
            e/=2
        else:
            a*=p%mod
            e-=1

    return a

ans = modpow(2,n,mod) - cmb(n,a,mod) - cmb(n,b,mod) - 1

print(ans)

Submission status: Time Limit Exceeded

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

from math import factorial
cmb_a = factorial(n) / factorial(a) / factorial(n-a)
cmb_b = factorial(n) / factorial(b) / factorial(n-b)

print(int((2**n - 1 - cmb_a - cmb_b) % mod))

Submission status: Time Limit Exceeded

Solution code:
import math

def comb(N,R):
    return int(math.factorial(N))/int(math.factorial(N-R))/int(math.factorial(R))   

if __name__=="__main__":
    n, a, b = map(int, input().split())

    ans = 2**n - int(comb(n,a)) - int(comb(n,b)) - 1

    print(ans % 1000000007)

Submission status: Time Limit Exceeded

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

ja=cmb(n,a)
jb=cmb(n,b)
ans=(2**n-ja-jb-1)%(10**9+7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
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 = 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%p-cmb(n, a, p)-cmb(n, b, p)-1)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
p = int(10e9+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]  # 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 modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


ans = modpow(2, N, p)-1-cmb(N, A, p)-cmb(N, B, p)
print(ans)