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

Solution (Python):
N,a,b = [int(i) for i in input().split()]
mod = 10**9+7
def power(x, n):
    ans = 1
    while(n > 0):
        if(bin(n & 1) == bin(1)):
            ans = ans*x%mod
        x = (x*x)%mod
        n = n >> 1 
    return ans
def fact(m, n):
    val = 1
    for i in range(m, n+1):
        val = val*i % mod
    return val
    
def cmb1(N, r):
    A = fact(N-r+1, N)%mod
    B = fact(1, r)%mod
    return A, B, (A*power(B, mod-2))%mod
def cmb2(a, b, A, B):
    A = fact(N-a+1, N-b)*A%mod
    B = fact(b+1, a)*B%mod
    return (A*power(B, mod-2))%mod
if(a>N//2):
    a = N-a
if(b>N//2):
    b = N-b
tmp = max(a,b)
b = min(a,b)
a = tmp
A, B, K1 = cmb1(N, b)
K2 = cmb2(a, b, A, B)
print((power(2, N)-1-K1-K2)%mod)

Solution (Python):
import numpy as np
N,a,b = np.array(input().split()).astype(int)
mod = 10**9+7
def power(x, n):
    ans = 1
    while(n > 0):
        if(bin(n & 1) == bin(1)):
            ans = ans*x%mod
        x = (x*x)%mod
        n = n >> 1 
    return ans
def fact(m, n):
    val = 1
    for i in range(m, n+1):
        val = val*i % mod
    return val
    
def cmb1(N, r):
    A = fact(N-r+1, N)%mod
    B = fact(1, r)%mod
    return A, B, (A*power(B, mod-2))%mod
def cmb2(a, b, A, B):
    A = fact(N-a+1, N-b)*A%mod
    B = fact(b+1, a)*B%mod
    return (A*power(B, mod-2))%mod
if(a>N//2):
    a = N-a
if(b>N//2):
    b = N-b
tmp = max(a,b)
b = min(a,b)
a = tmp
A, B, K1 = cmb1(N, b)
K2 = cmb2(a, b, A, B)
print((power(2, N)-1-K1-K2)%mod)

Solution (Python):
def dv(x, y, mod):
    
    return x * pow(y, mod - 2, mod) % mod

def comb(n, r, mod):
    
    p, q = 1, 1
    if n < r or n < 0 or r < 0: return 0
    for i in range(r):
        p = p * (n - i) % mod
        q = q * (i + 1) % mod
    return dv(p, q, mod)

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

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

Solution (Python):
mod = 1000000007

def pw(x, n):
    if n == 0: return 1
    elif n == 1: return x
    elif n % 2 == 0:
        return pw(x, n // 2) ** 2 % mod
    else:
        return x * pw(x, n // 2) ** 2 % mod

def dv(x, y):
    return x * pow(y, mod - 2, mod) % mod

def comb(n, r):
    p, q = 1, 1
    if n < r or n < 0 or r < 0: return 0
    for i in range(r):
        p = p * (n - i) % mod
        q = q * (i + 1) % mod
    return dv(p, q)

n, a, b = map(int, input().split())
ans = pow(2, n, mod) - 1 + mod * 10
if a <= n: ans -= comb(n, a)
if b <= n: ans -= comb(n, b)
print(ans % mod)

Solution (Python):
def comb_mod(n,m,mod):
  p = q = 1
  for i in range(m):
    p = p*(n-i) % mod
    q = q*(i+1) % mod
  return p* pow(q,mod-2,mod) % mod

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

Solution (Python):
def nCr(n, r, mod=10**9+7):
    n1, r = n+1, 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 = 10 ** 9 + 7  

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

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

print(ans%mod)

Solution (Python):
MOD = 1000000007

def fastpow(a, n):
    x = a
    ans = 1
    while n:
        if n & 1:
            ans = (ans*x)%MOD
        n>>=1
        x = (x*x)%MOD;
    return ans

def inv(a):
    return fastpow(a, MOD-2)

def comb(n,r):
    ret = 1
    for i in range(r):
        ret = (ret*(n-i))%MOD
        ret = (ret*inv(i+1))%MOD
    return ret

n,a,b = map(int,input().split()) 
ans = fastpow(2,n)-1-comb(n,a)-comb(n,b)
while ans < 0:
    ans += MOD
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
def inputS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

def nCr(n, r, mod=10**9+7):
    n1, r = n+1, 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 = 10**9+7  
N, A, B = map(int, input().split())

ans = pow(2, N, MOD)-1
ans -= nCr(N, A)
ans -= nCr(N, B)
print(ans%MOD)

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

mod = 10**9+7

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

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

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline

    mod = 1000000007
    nmax = 2 * 10 ** 5 + 10  
    fac = [0] * nmax
    finv = [0] * nmax
    inv = [0] * nmax
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2, nmax):
        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 comb(n, r):
        ret = finv[r]
        for i in range(r):
            ret = (ret * (n-i))%mod
        return ret
    N, a, b = map(int, input().split())
    print((pow(2, N, mod) - 1 - comb(N, a) - comb(N, b))%mod)


if __name__ == '__main__':
    main()

Solution (Python):
MOD = 10**9 + 7
MAX = int(2e5)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
    FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
    INV[i-1] = (INV[i] * i) % MOD


def combi(n, x):
    ret = 1
    for i in range(x):
        ret = ret * (n-i) % MOD
    ret = ret * INV[x] % MOD
    return ret


def main():
    n, a, b = map(int, input().split())
    ans = pow(2, n, MOD) - 1
    ans = (ans - combi(n, a) - combi(n, b)) % MOD
    print(ans)


if __name__ == "__main__":
    main()

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

ans = pow(2, n, mod) - 1
an = 1
for i in range(n - a + 1, n + 1):
    an *= i
    an %= mod
for i in range(1, a + 1):
    an *= pow(i, mod - 2, mod)
    an %= mod
bn = 1
for i in range(n - b + 1, n + 1):
    bn *= i
    bn %= mod
for i in range(1, b + 1):
    bn *= pow(i, mod - 2, mod)
    bn %= mod

ans -= (an + bn)
print(ans % mod)

Solution (Python):
x=input().split()
n=int(x[0])
a=int(x[1])
b=int(x[2])

def fast_expo(b,n,p):
    if n==0:
        return 1
    if n==1:
        return b%p
    if n%2==0:
        return fast_expo(((b%p)*(b%p))%p,n//2,p)
    else:
        return (b*fast_expo(((b%p)*(b%p))%p,n//2,p))%p
def combi(n,k,p):
    X=1
    Y=1
    for i in range(k):
        X=(X*(n-i))%p
        Y=(Y*(k-i))%p
    Z=fast_expo(Y,p-2,p)
    return (X*Z)%p

p=10**9+7
res=fast_expo(2,n,p)
res=(res-1)%p
res=(res-combi(n,a,p))%p
res=(res-combi(n,b,p))%p
print(res)

Solution (Python):
n,a,b = map(int,input().split())
mod = 10**9+7
ans = pow(2,n,mod)
def cmb(n,r,mod):
  if n == r:
    return 1
  p,q = 1,1
  r = min(r,n-r)
  for i in range(r):
    p = p*(n - i)%mod
    q = q*(i + 1)%mod
    Y = pow(q,10**9+5,mod)
  return p*Y%mod
ans = ans - cmb(n,a,mod) - cmb(n,b,mod) - 1
print(ans%mod)

Solution (Python):
n,a,b = map(int,input().split())
mod = 10**9+7
def pow(n, p,mod=10**9+7): 
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod

def large_conbination(n,k,mod=10**9+7): 
    res1 = 1
    for i in range(n,n-k,-1):
        res1*=i
        res1%=mod
    res2 = 1
    for i in range(1,k+1):
        res2*= i
        res2%=mod
    return res1*pow(res2,mod-2)%mod

ans = pow(2,n) -1 

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

while ans<0:
    ans += mod
print(ans%mod)

Solution (Python):
n,a,b = map(int,input().split())
mod = 10**9+7
def pow(n, p,mod=10**9+7): 
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod

def large_conbination(n,k,mod=10**9+7): 
    res1 = 1
    for i in range(n,n-k,-1):
        res1*=i
        res1%=mod
    res2 = 1
    for i in range(1,k+1):
        res2*= pow(i,mod-2) 
        res2%=mod
    return res1*res2%mod

ans = pow(2,n) -1 

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

while ans<0:
    ans += mod
print(ans%mod)

Solution (Python):
def comb_mod(n, r, M):
    p = q = 1
    for i in range(r):
        p = p * (n - i) % M
        q = q * (i + 1) % M
    return p * pow(q, M - 2, M) % M


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

res = (pow(2, n, M) - 1 - comb_mod(n, a, M) - comb_mod(n, b, M)) % M
print(res)

Solution (Python):
MOD = 10**9+7

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

Sn = pow(2,n,MOD) - 1
a = min(a, n-a)
b = min(b, n-b)
if a > b:
    a,b = b,a
Xa, Xb = 1,1
Ya, Yb = 1,1
for i in range(b):
    if i < a:
        Xa = ( Xa * (n-i) ) % MOD
        Ya = ( Ya * pow((a-i),MOD-2, MOD)) % MOD
    Xb = ( Xb * (n-i) ) % MOD
    Yb = ( Yb * pow((b-i),MOD-2, MOD)) % MOD

ans = Sn - Xa*Ya % MOD - Xb*Yb % MOD
while ans < 0:
    ans += MOD
    
print(ans)

Solution (Python):
MOD = 10**9+7

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

Sn = pow(2,n,MOD) - 1
if a > b:
    a,b = b,a
Xa, Xb = 1,1
Ya, Yb = 1,1
for i in range(b):
    if i < a:
        Xa = ( Xa * (n-i) ) % MOD
        Ya = ( Ya * pow((a-i),MOD-2, MOD)) % MOD
    Xb = ( Xb * (n-i) ) % MOD
    Yb = ( Yb * pow((b-i),MOD-2, MOD)) % MOD

ans = Sn - Xa*Ya % MOD - Xb*Yb % MOD
while ans < 0:
    ans += MOD
    
print(ans)

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

def power(x,n): 
    T=[x]
    while 2**(len(T))<n+1: 
        T.append(T[-1]**2%mod)
    b=bin(n) 
    ans=1
    for i in range(len(b)-2):
        if int(b[-i-1])==1:
            ans=ans*T[i]%mod
    return ans


N=2*10**5+10
g1=[1,1] 
g2=[1,1] 
inverse=[0,1]
for i in range(2,N+1):
    g1.append((g1[-1]*i)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1])%mod)

nCa=1
for i in range(a):
    nCa=nCa*(n-i)%mod
nCa=nCa*g2[a]%mod
    
nCb=1
for i in range(b):
    nCb=nCb*(n-i)%mod
nCb=nCb*g2[b]%mod

ans=power(2,n)-1
ans=(ans-nCa)%mod
ans=(ans-nCb)%mod

print(ans)

Solution (Python):
def choose(n, k, mod):
  """ nCkを計算 """
  
  numerator = 1
  for i in range(k):
    numerator *= n - i
    numerator %= mod
  
  denominator = 1
  for i in range(k):
    denominator *= (i + 1)
    denominator %= mod

  
  
  return (numerator * pow(denominator, mod - 2, mod)) % mod


def main():
  MOD = 10 ** 9 + 7
  n, a, b = [int(x) for x in input().split()]

  
  ans = pow(2, n, MOD)
  
  
  ans -= 1
  
  ans -= choose(n, a, MOD)
  
  ans -= choose(n, b, MOD)
  
  
  ans %= MOD

  print(ans)

  
main()

Solution (Python):
def comb(n, k, mod):
  r = min(k, n-k)
  p = q = 1
  for i in range(r):
    p = p*(n-i)%mod
    q = q*(i+1)%mod
  return p*pow(q, mod-2, mod) % mod

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

Solution (Python):
LARGE = 10 ** 9 + 7


def solve(n, a, b):

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

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


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


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


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

Solution (Python):

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


mod = pow(10, 9) + 7

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

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

Solution (Python):
mod = 10**9+7
n, a, b = map(int, input().split())
ans = pow(2, n, mod) - 1
nCa = 1
for i in range(n-a+1, n+1):
    nCa *= i
    nCa %= mod
for i in range(1, a+1):
    nCa *= pow(i, mod-2, mod)
    nCa %= mod
nCb = 1
for i in range(n-b+1, n+1):
    nCb *= i
    nCb %= mod
for i in range(1, b+1):
    nCb *= pow(i, mod-2, mod)
    nCb %= mod
ans -= (nCa + nCb)
ans %= mod
print(ans)

Solution (Python):
MOD = 10**9 + 7
def mod_pow(p, q):
    res = 1
    while q:
        if q & 1:
            res = (res * p) % MOD
        p = (p * p) % MOD
        q //= 2
    return res

def inv(p):
    return mod_pow(p, MOD-2)

def mod_comb(p, q):
    a, b = 1, 1
    for i in range(q):
        a = (a * (p-i)) % MOD
        b = (b * (i+1)) % MOD
    return (a * inv(b)) % MOD

def solve(n, a, b):
    res = mod_pow(2, n)
    for x in [0, a, b]:
        res = (res - mod_comb(n, x)) % MOD
    return res

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

Solution (Python):
mod = 1000000007

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, y // 2) ** 2 % mod
    else:
        return power(x, y // 2) ** 2 * x % mod

def div(a, b):
    return mul(a, power(b, mod - 2))

def combination(n,r):
    bumbo = 1
    bunshi = 1
    for i in range(r):
        bumbo = (bumbo*(n-i)) % mod
    for i in range(1,r+1):
        bunshi = (bunshi*i) % mod
    return (div(bumbo, bunshi)) % mod


n, a, b = map(int, input().split())
print((power(2,n)-1-combination(n,a)-combination(n,b)) % mod)

Solution (Python):
import math


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


MOD = 10 ** 9 + 7
N, A, B = map(int, input().split())

cmb1 = fct(N, A) * pow(math.factorial(A), MOD - 2, MOD)
cmb2 = fct(N, B) * pow(math.factorial(B), MOD - 2, MOD)
print((pow(2, N, MOD) - 1 - cmb1 - cmb2) % MOD)

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

mod = 10**9+7

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

sum = pow(2,n,mod)
case = combination(n,a,mod) + combination(n,b,mod) + 1
ans = sum-case
while ans < 0 :
    ans += mod

print(ans)

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

def comb(n, r, mod) :
    ans1 = 1
    ans2 = 1
    for i in range(r) :
        ans1 = (ans1 * (n-i)) % mod
        ans2 = (ans2 * (i+1)) % mod
    return ans1 * pow(ans2, mod-2, mod)

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

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

def comb_mod(n, r, mod):
    num = 1
    den = 1
    for i in range(r):
        num = (num * (n-i)) % mod
        den = (den * (i+1)) % mod
    return num * pow(den, mod-2, mod)

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

Solution (Python):



from functools import reduce




def main():

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

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

    def comb(n, r):
        over = 1
        under = 1
        for i in range(r):
            over = over * (n - i) % mod
            under = under * (i + 1) % mod

        return over * pow(under, mod - 2) % mod

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


main()

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

MOD = 10**9+7

def comb(n,r,MOD):
    x = n+1
    y = min(r,n-r)
    
    numer = 1
    denom = 1
    
    for i in range(1,r+1):
        numer = numer*(x-i)%MOD
        denom = denom*(i)%MOD
    
    return numer * pow(denom,MOD-2,MOD) % MOD

nCa = comb(n,a,MOD)
nCb = comb(n,b,MOD)

ans = pow(2,n,MOD)-1 - nCa - nCb

if ans < 0:
    print((ans+MOD)%MOD)
else:
    print(ans%MOD)

Solution (Python):

import sys

INF = 1<<32


MOD = 1000000007  

def solve(n: int, a: int, b: int):
    def combination_with_mod(n, r, mod=10**9+7):
        n1, r = n+1, 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

    ans = pow(2, n, MOD)-combination_with_mod(n, a)-combination_with_mod(n, b)-combination_with_mod(n, 0)

    if ans < 0:
        print((MOD+ans)%MOD)
    else:
        print(ans%MOD)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    a = int(next(tokens))  
    b = int(next(tokens))  
    solve(n, a, b)

if __name__ == '__main__':
    main()

Solution (Python):

import sys

INF = 1<<32


MOD = 1000000007  

def solve(n: int, a: int, b: int):
    def combination_with_mod(n, r, mod=10**9+7):
        n1, r = n+1, 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

    ans = pow(2, n, MOD)-combination_with_mod(n, a)-combination_with_mod(n, b)-combination_with_mod(n, 0)

    if ans < 0:
        print((MOD+ans)%MOD)
    else:
        print(ans%MOD)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    a = int(next(tokens))  
    b = int(next(tokens))  
    solve(n, a, b)

if __name__ == '__main__':
    main()

Solution (Python):



def main():
    n, a, b = map(int, input().split())
    value_max = 2 * (10 ** 5)
    com = [0 for _ in range(value_max + 1)]
    com[1] = n
    mod = 10 ** 9 + 7
    mod_inverse = [pow(i, mod - 2, mod) for i in range(1, value_max + 1)]
    ans = pow(2, n, mod)

    
    
    
    
    
    for i in range(2, min(n, value_max) + 1):
        if (n - i + 1) == 0:
            break

        com[i] = com[i - 1] * (n - i + 1)
        com[i] *= mod_inverse[i - 1]
        com[i] %= mod

    diff = (com[a] + com[b] + 1) % mod
    print((ans - diff) % mod)


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    n, a, b = map(int, input().split())
    value_max = 2 * (10 ** 5)
    com = [0 for _ in range(value_max + 1)]
    com[1] = n
    mod = 10 ** 9 + 7
    mod_inverse = [pow(i, mod - 2, mod) for i in range(1, value_max + 1)]
    ans = pow(2, n, mod)

    
    
    
    
    
    for i in range(2, min(n, value_max) + 1):
        if (n - i + 1) == 0:
            break

        com[i] = com[i - 1] * (n - i + 1)
        com[i] *= mod_inverse[i - 1]
        com[i] %= mod

    diff = (com[a] + com[b] + 1) % mod
    print((ans - diff) % mod)


if __name__ == '__main__':
    main()

Solution (Python):

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

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

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

print(whole_sum % mod)

Solution (Python):


MOD = 10**9+7

def mod_prod(l, mod=MOD):
    p = 1
    for x in l:
        p = (p * x) % mod
    return p

n, *ab = list(map(int, input().split()))

m = pow(2, n, MOD) - 1


for k in ab:
    
    x = mod_prod(range(n-k+1, n+1))
    y = mod_prod(range(1, k+1))
    z = x * pow(y, MOD-2, MOD)
    
    m = (m - z) % MOD

print(m)

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

MOD=10**9+7

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

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

MOD = 10**9 + 7

def CombMod(n, r):
    p, q = 1, 1
    for i in range(r):
        p = p*(n-i)%MOD
        q = q*(i+1)%MOD
    return p * pow(q, MOD-2, MOD)%MOD

print((pow(2, n, MOD) - 1 - (CombMod(n, a) + CombMod(n, b)))%MOD)

Solution (Python):
M,A,B = [int(x) for x in input().split()]

mod = 10**9+7

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

def binary(n):
    return bin(n)[2:]


def pow_by_binary_exponentiation(a, x, n): 
    x = [int(b) for b in binary(x)]
    y = a
    for i in range(1, len(x)):
        y = (y**2) % n
        if x[i] == 1:
            y = (y * a) % n
    return y
d = pow_by_binary_exponentiation(2,M,mod)-1
    
d1 = cmb(M,A,mod)
d2 = cmb(M,B,mod)
print((d-d1-d2)%mod)

Solution (Python):
from math import factorial
N, A, B = map(int, input().split())
MOD = 10 ** 9 + 7

def calc(n):
    ret = 1
    for i in range(n):
        ret = ret * (N - i) % MOD
    return ret * pow(factorial(n), MOD - 2, MOD) % MOD

print(max(0, (pow(2, N, MOD) - ((calc(A) + calc(B)) % MOD) - 1) % MOD))

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


def choose(n, r, mod):
    r = min(r, n - r)
    x = 1
    y = 1
    for i in range(r):
        x = x * (n - i) % mod
        y = y * (i + 1) % mod
    y = pow(y, mod-2, mod)
    return x * y % mod


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

while ans < 0:
    ans += mod
print(ans)

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

MOD = 1000000007

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

x = 1
y = 1
for i in range(b):
    x = x * (n - i) % MOD
    y = y * (i + 1) % MOD
    if i == a - 1:
        ans -= x * pow(y, MOD - 2, MOD) % MOD

ans -= x * pow(y, MOD - 2, MOD) % MOD

while ans < 0:
    ans += MOD
print(ans)

Solution (Python):
n, a, b = [int(i) for i in input().split()]
mod = 10**9 + 7
 
total = pow(2, n, mod) - 1
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
    
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
 
at = combination(n,a)
bt = combination(n,b)
 
result = total - at - bt
result %= mod
if result < 0:
  result += mod
print(result)

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

ans = (pow(2,n,mod) - 1) %mod
numerator = 1%mod
denominator = 1%mod
for i in range(1,b+1):
    numerator = (numerator*(n+1-i))%mod
    denominator = (denominator*pow(i,mod-2,mod))%mod
    if i == a or i == b:
        ans = (ans - (numerator*denominator))%mod

print(ans)

Solution (Python):
n, a, b = [int(i) for i in input().split()]
mod = 10**9 + 7
 
total = pow(2, n, mod) - 1
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
 
at = combination(n,a)
bt = combination(n,b)
 
result = total - at - bt
result %= mod
if result < 0:
  result += mod
print(result)

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

i = 2
f = 1
fn = N
while i <= A:
    f = (f * i) % mod
    fn = (fn * (N + 1 - i)) % mod
    i += 1
fa, fna = f, fn
while i <= B:
    f = (f * i) % mod
    fn = (fn * (N + 1 - i)) % mod
    i += 1
fb, fnb = f, fn


def pow(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return pow(x, y // 2) ** 2 % mod
    else:
        return x * pow(x, y // 2) ** 2 % mod


nca = (fna * pow(fa, mod - 2)) % mod
ncb = (fnb * pow(fb, mod - 2)) % mod
print((pow(2, N) - 1 - nca - ncb) % mod)

Solution (Python):
k = 72
kk = k // 4
K = 1<<k
nu = lambda L: int("".join([hex(K+a)[3:] for a in L[::-1]]), 16)
st = lambda n: hex(n)[2:]
li = lambda s, l, r: [int(a, 16) % P if len(a) else 0 for a in [s[-(i+1)*kk:-i*kk] for i in range(l, r)]]

def grow(d, v, h):
    h += [0] * d
    f = [(-1 if (i+d) % 2 else 1) * fainv[i] * fainv[d-i] % P * h[i] % P for i in range(d+1)]
    nuf = nu(f)
    a = d * inv[v] % P
    t = [1] * (3*d+3)
    for i in range(1, 3*d+3): t[i] = t[i-1] * (a - d + i - 1) % P
    ti = [1] * (3*d+3)
    ti[-1] = pow(t[-1], P-2, P)
    for i in range(1, 3*d+3)[::-1]: ti[i-1] = ti[i] * (a - d + i - 1) % P
    iv = [1] * (3*d+3)
    for i in range(1, 3*d+3):
        iv[i] = ti[i] * t[i-1] % P

    
    g = [inv[i] for i in range(1, 2*d+2)]
    fg = li(st(nuf * nu(g)), d, d * 2 + 1)
    for i in range(d):
        h[i+d+1] = fg[i] * fa[d+i+1] % P * fainv[i] % P

    
    g = [iv[i] for i in range(1, 2*d+2)]
    fg = li(st(nuf * nu(g)), d, d * 2 + 1)
    for i in range(d+1):
        h[i] = h[i] * (fg[i] * t[d+i+1] % P * ti[i] % P) % P

    
    g = [iv[i] for i in range(d+2, 3*d+3)]
    fg = li(st(nuf * nu(g)), d, d * 2 + 1)
    for i in range(d):
        h[i+d+1] = h[i+d+1] * (fg[i] * t[2*d+i+2] % P * ti[d+i+1] % P) % P

    return h


def create_table(v):
    s = 1
    X = [1, v+1]
    while s < v:
        X = grow(s, v, X)
        s *= 2

    table = [1]
    for x in X:
        table.append(table[-1] * x % P)
    return table

def fact(i, table):
    a = table[i//v]
    for j in range(i//v*v+1, i+1):
        a = a * j % P
    return a

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

v = 1 << (N.bit_length() + 1) // 2
fa = [1] * (2*v+2)
fainv = [1] * (2*v+2)
for i in range(2*v+1):
    fa[i+1] = fa[i] * (i+1) % P
fainv[-1] = pow(fa[-1], P-2, P)
for i in range(2*v+1)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % P
inv = [0] * (2*v+2)
for i in range(1, 2*v+2):
    inv[i] = fainv[i] * fa[i-1] % P

T = create_table(v)
C = lambda n, k: fact(n, T) * pow(fact(k, T) * fact(n-k, T), P-2, P) % P
 
print((pow(2, N, P) - 1 - C(N, A) - C(N, B)) % P)

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

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

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline


def solve():
  n,a,b = (int(i) for i in input().split())
  mod = 10**9+7
  all = pow(2,n,mod)-1
  
  comba = 1
  inva = 1
  for i in range(1,a+1):
    comba *= (n-i+1)
    comba %= mod
    
    inva *= i
    inva %= mod

  ta = pow(inva,10**9+5,mod)
  comba = (comba * ta)%mod
  
  combb = 1
  invb = 1
  for i in range(1,b+1):
    combb *= (n-i+1)
    combb %= mod
    
    invb *= i
    invb %= mod
  tb = pow(invb,10**9+5,mod)
  combb = (combb * tb)%mod
  
  print((all-comba-combb)%mod)
  
solve()

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

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

mod=10**9+7
ans=pow(2,n,mod)-1-comb(n,a,mod)-comb(n,b,mod)
print(ans%mod)

Solution (Python):
def nCr(n, r):
    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
   
n,a,b=map(int,input().split())
s=pow(2,n,10**9+7)
ans=s-1-nCr(n,a)-nCr(n,b)
while ans<0:
   ans+=10**9+7
print(ans)

Solution (Python):
M = pow(10, 9) + 7

def pow_mod(a, n, m): 
    res = 1
    while n > 0:
        if n % 2 == 1:
            res = (res * a) % m
        a = (a * a) % m
        n = n // 2
    return res

def combi_mod(p, q, m):
    numerator, denominator = 1, 1
    for i in range(1, q+1):
        numerator *= (p - i + 1)
        numerator %= m
        denominator *= i
        denominator %= m
    return numerator * pow_mod(denominator, m-2, m) % m

n, a, b = list(map(int, input().split()))
res = pow_mod(2, n, M) - 1
res -=combi_mod(n, a, M)
if res < 0:
    res += M
res -= combi_mod(n, b, M)
if res < 0:
    res += M
print(res)

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

MOD = 10 ** 9 + 7

def rep_pow(x, n):
  ans = 1
  while(n > 0):
    if(bin(n & 1) == bin(1)):
      ans = (ans*x) % MOD
    x = (x*x) % MOD
    n = n >> 1 
  return ans

ans = rep_pow(2, n) - 1



def comb(c, n):
    x = 1
    y = 1
    for i in range(c):
        x = (x * (n - i)) % MOD
        y = (y * (i + 1)) % MOD
    return (x * rep_pow(y, MOD - 2)) % MOD

ans = ans + MOD * 2 - comb(a, n) - comb(b, n)

print(ans % MOD)