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):
def main():
    n,a,b = map(int,input().split())
    MOD = 10**9 +7
    s = pow(2,n,MOD)-1
    
    print(comb_mod(n,MOD,a,b,s))

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


if __name__=='__main__':
    main()

Solution (Python):
def main():
    n,a,b = map(int,input().split())
    MOD = 10**9 +7
    s = pow(2,n,MOD)-1
    P_ni = 1
    F_i = 1

    s = s - comb_mod(n,a,MOD)
    s = s - comb_mod(n,b,MOD)

    print(s%MOD)

def comb_mod(n, k, mod):
    numerator = 1
    denominator = 1
    for i in range(k):
        numerator = (numerator * (n - i)) % mod
        denominator = (denominator * (i + 1)) % mod

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


if __name__=='__main__':
    main()

Solution (Python):
def combmod(n,k,mod):
    a = 1
    b = 1
    for i in range(k):
        a = a * (n-i) % mod
        b = b * (i+1) % mod
    return a * pow(b, mod-2, mod) % mod
  
num,A,B = list(map(int, input().split()))
print((pow(2,num,10**9+7) - 1 - combmod(num,A,10**9+7) - combmod(num,B,10**9+7)) % (10**9+7))

Solution (Python):
from sys import stdin
from math import factorial
n,a,b = map(int,stdin.readline().rstrip().split())
if n <= 2:
    print(0)
    exit()
def combination(n,r,mod=10**9+7):
    r=min(r,n-r)
    up,down=1,1
    for i in range(r):
        up=up*(n-i)%mod
        down=down*(i+1)%mod
    return up*pow(down,mod-2,mod)%mod
kotae = 2**n-combination(n,a)-combination(n,b)-1
kotae %= 10**9+7
print(kotae)

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

comb2  = 1
for i in range(n-b+1, n+1):
    comb2 *= i
    comb2 %= mod
for i in range(1,b+1):
    comb2 *= pow(i,mod-2,mod)
    comb2 %= mod

ans -= (comb1+comb2)
ans %= mod
print(ans)

Solution (Python):
N, A, B = map(int, input().split())
MAX = max(A, B) + 1
MOD = 1000000007
nCk = [0] * MAX
nCk[0] = 0
nCk[1] = N
inv = [0] * MAX
inv[1] = 1


for i in range(2, MAX):
    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
    nCk[i] = (nCk[i - 1] * (N - i + 1) * inv[i]) % MOD

count = (pow(2, N, MOD) - 1 - nCk[A] - nCk[B]) % MOD
print(int(count))

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

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

cn = pow(2,n,div)-1
ca = combinations(n,a,div)
cb = combinations(n,b,div)

print((cn-ca-cb)%div)

Solution (Python):
n,a,b=map(int,input().split())
mod=10**9+7
def C(n,k,mod):
    k=min(k,n-k)
    comb=1
    for i in range(k):
        temp=(n-i)*pow(i+1,mod-2,mod)
        comb=comb*temp%mod

    return comb

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

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

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












di131072 = 1
for i in range(131072):
    di131072 *= 2
    di131072 %= p

q = n//131072
r = n%131072
ans = 1
for i in range(q):
    ans *= di131072
    ans %= p
for i in range(r):
    ans *= 2
    ans %= p


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

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


print((ans-1-ncr(n,a)-ncr(n,b))%p)

Solution (Python):
N,A,B=map(int,input().split())
p=10**9+7
def f(n,x):
    a,b=1,1
    for i in range(1,x+1):
        a=a*n%p
        b=b*i%p
        n-=1
    return a*pow(b,p-2,p)
print((pow(2,N,p)-1-f(N,A)-f(N,B))%p)

Solution (Python):
from operator import mul
from functools import reduce
mod = 10**9+7
    
def nCr(n, r, mod):
    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())

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

print((ans - nCr(n, a, mod) - nCr(n, b, mod)) % mod)

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

mmod = 10**9 + 7


def comb_mod(n, r, mod=mmod):
    nume = 1
    deno = 1

    r = min(r, n - r)

    for i in range(1, r + 1):
        nume = (nume * (n + 1 - i)) % mod
        deno = (deno * i) % mod

    return (nume * pow(deno, mod - 2, mod)) % mod


result_a = comb_mod(n, a)
result_b = comb_mod(n, b)
total = (pow(2, n, mmod) - result_a - result_b - 1) % mmod

print(total)

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

mod = 10**9 + 7

import time
start = time.time()



def modinv(x):
	return pow(x, mod-2, mod)

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

end = time.time()


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


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

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

Solution (Python):




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

MOD = 10 ** 9 + 7



def mod_pow(a, n, m=10 ** 9 + 7):
    res = 1
    while n > 0:
        if n & 1 == 1:
            res = res * a % m
        a = a * a % m
        n >>= 1
    return res



def mod_inv(a, m=10 ** 9 + 7):
    b = m
    u = 1
    v = 0
    while b > 0:
        t = a // b
        a -= t * b
        c = a
        a = b
        b = c

        u -= t * v
        c = u
        u = v
        v = c
    u %= m
    return u


inv_fact_list = [1]
P_list = [1]


def combination(r):
    if r > len(inv_fact_list) - 1:
        _list_extend(r)
    return inv_fact_list[r] * P_list[r] % MOD


def _list_extend(needed):
    now = len(inv_fact_list)
    while now <= needed:
        P_list.append(P_list[-1] * (n - now + 1) % MOD)
        inv_fact_list.append(inv_fact_list[-1] * mod_inv(now) % MOD)
        now += 1


ans = (mod_pow(2, n) - combination(b) - combination(a) - 1) % MOD

print(ans)

Solution (Python):
N,a,b=map(int,input().split())
MOD=10**9+7
def comb(n,k):
  tmp=1
  for i in range(n-k+1,n+1):
    tmp*=i
    tmp%=MOD
  for i in range(1,k+1):
    tmp*=pow(i,MOD-2,MOD)
    tmp%=MOD
  return tmp
ans = pow(2,N,MOD) - 1 - comb(N,a) - comb(N,b)
print(ans%MOD)

Solution (Python):






def mod_pow(a, n, m=10 ** 9 + 7):
    res = 1
    while n > 0:
        if n & 1 == 1:
            res = res * a % m
        a = a * a % m
        n >>= 1
    return res



def mod_inv(a, m=10 ** 9 + 7):
    b = m
    u = 1
    v = 0
    while b > 0:
        t = a // b
        a -= t * b
        c = a
        a = b
        b = c

        u -= t * v
        c = u
        u = v
        v = c
    u %= m
    return u





class ModCombination:
    def __init__(self, n, mod=10 ** 9 + 7):
        self.N = n
        self.MOD = mod
        self.inv_fact_list = [1]
        self.P_list = [1]

    def combination(self, r):
        if r > len(self.inv_fact_list) - 1:
            self._list_extend(r)
        return self.inv_fact_list[r] * self.P_list[r] % self.MOD

    def _list_extend(self, needed):
        now = len(self.inv_fact_list)
        while now <= needed:
            self.P_list.append(self.P_list[-1] * (self.N - now + 1) % self.MOD)
            self.inv_fact_list.append(self.inv_fact_list[-1] * mod_inv(now) % self.MOD)
            now += 1


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

MOD = 10 ** 9 + 7

c = ModCombination(n)

ans = (mod_pow(2, n) - c.combination(b) - c.combination(a) - 1) % MOD

print(ans)

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


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


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

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

def comb_mod(n, k, mod):
    numerator = 1
    denominator = 1
    for i in range(k):
        numerator = (numerator * (n - i)) % mod
        denominator = (denominator * (i + 1)) % mod

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

def factor(a,b):
    ans = 1
    for i in range(a, b+1):
        ans*=i
    return ans

total = (pow(2,n,p) - 1) % p
case_a = comb_mod(n, a, p)
case_b = comb_mod(n, b, p)

print((total - case_a - case_b) % p)

Solution (Python):
n,a,b=map(int,input().split())
MOD=10**9+7
ans=pow(2,n,MOD)-1
def cmb(x,y):
  X=1
  Y=1
  for i in range(1,y+1):
    X= X*(x+1-i)%MOD
    Y= Y*i%MOD
  return (X*pow(Y,MOD-2,MOD))%MOD
ans-=(cmb(n,a)+cmb(n,b))
ans%=MOD
print(ans)

Solution (Python):
n, a, b = map(int, input().split())
p = 1000000007
def fast_pow(x,n,p):
    ans = 1
    while(n > 0):
        if n & 1 == 1:
            ans = ans * x % p
        x = x * x % p
        n = n >> 1
    return ans

def comb_mod(n, k, mod):
    numerator = 1
    denominator = 1
    for i in range(k):
        numerator = (numerator * (n - i)) % mod
        denominator = (denominator * (i + 1)) % mod

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

def factor(a,b):
    ans = 1
    for i in range(a, b+1):
        ans*=i
    return ans

total = (fast_pow(2,n,p) - 1) % p
case_a = comb_mod(n, a, p)
case_b = comb_mod(n, b, p)

print((total - case_a - case_b) % p)

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

n = 10 ** 9
k = 2 * 10 ** 5
mod = 10**9 + 7


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



def modinv(x):
    return power(x, mod-2)

def binomial_coefficients(n, k):
    numera = 1  
    denomi = 1  

    for i in range(k):
        numera *= n-i
        numera %= mod
        denomi *= i+1
        denomi %= mod
    return numera * modinv(denomi) % mod


print(((((power(2, q) - binomial_coefficients(q, a)) % mod) - binomial_coefficients(q, b)) % mod - 1) % mod)

Solution (Python):

"""
【競プロ】繰り返し二乗法と再帰関数
https://math.nakaken88.com/textbook/cp-binary-exponentiation-and-recursive-function/
「1000000007 で割ったあまり」の求め方を総特集！ 〜 逆元から離散対数まで 〜
https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
Pythonでmodintを実装してみた
https://qiita.com/wotsushi/items/c936838df992b706084c

"""




































def pow(a, n, MOD):
    """
    繰り返し二乗法 (半分の数の 2 乗)
    Compute nth power of a -- O(logn)
    """
    if n == 0:
        return 1
    x = pow(a, n//2, MOD)
    x = (x%MOD * x%MOD) % MOD
    if n%2 == 1:
        x = (x%MOD * a%MOD) % MOD
    return x

def choose(n, a, MOD):
    """
    nCa (Choose a from n)
        numerator (分子): n!
        denominator(分母): a! * (n-a)!
    Reduce... (約分)
        numerator:: n * (n-1) * ... * (n-a+1) = (n-i) の積の和 (i=0 ~ a-1)
        denominator: a!
    iverse (逆元)
     フェルマーの小定理
        1 ≡ x**(p-1) (mod p)
        => 1/x ≡ x**(p-2) (mod p)
        => 1/x%p = x**(p-2)%2
    """
    x = 1 
    y = 1 
    for i in range(a):
        x = (x%MOD * (n-i)%MOD) % MOD
        y = (y%MOD * (i+1)%MOD) % MOD
    return (x * pow(y, MOD-2, MOD)) % MOD

"""
AC: https://atcoder.jp/contests/abc156/submissions/10294982
N**2 - 1 - nCa - nCb

pow(2,n)
140625001
nCa
-483404860
nCb
589953354
"""

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



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

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


class modint():
    def __init__(self, value):
        self.value = value % MOD

    def __int__(self):
        return int(self.value)

    def __float__(self):
        return float(self.value)

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

    def __repr__(self):
        return str(self.value)

    def __add__(self, other):
        return (modint(self.value + other.value) if isinstance(other, modint)
                else modint(self.value + other))

    def __sub__(self, other):
        return (modint(self.value - other.value) if isinstance(other, modint)
                else modint(self.value - other))

    def __mul__(self, other):
        return (modint(self.value * other.value) if isinstance(other, modint)
                else modint(self.value * other))

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

    def __pow__(self, other):
        return (modint(pow(self.value, other.value, MOD))
                if isinstance(other, modint)
                else modint(pow(self.value, other, MOD)))

    def __eq__(self, other):
        return (self.value == other.value if isinstance(other, modint)
                else self.value == (other % MOD))

    def __ne__(self, other):
        return (self.value == other.value if isinstance(other, modint)
                else self.value == (other % MOD))

    def __radd__(self, other):
        return (modint(other.value + self.value) if isinstance(other, modint)
                else modint(other + self.value))

    def __rsub__(self, other):
        return (modint(other.value - self.value) if isinstance(other, modint)
                else modint(other - self.value))

    def __rmul__(self, other):
        return (modint(other.value * self.value) if isinstance(other, modint)
                else modint(other * self.value))

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

    def __rpow__(self, other):
        return (modint(pow(other.value, self.value, MOD))
                if isinstance(other, modint)
                else modint(pow(other, self.value, MOD)))

    def modinv(self):
        return modint(pow(self.value, MOD - 2, MOD))


def main():
    n, a, b = (int(i) for i in input().split())
    ans = modint(pow(2, n, MOD))
    c_a = modint(1)
    c_b = modint(1)
    for k in range(a):
        c_a *= (n-k)
    for k in range(1, a+1):
        c_a /= k
    for k in range(b):
        c_b *= (n-k)
    for k in range(1, b+1):
        c_b /= k
    ans -= c_a + c_b + 1
    print(ans)


if __name__ == '__main__':
    main()

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

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

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

ans = power(2, n, mod) - cmb2(n, a, mod) - cmb2(n, b, mod) -1
ans %= mod
print(ans)

Solution (Python):
import sys
stdin = sys.stdin
from math import factorial

mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n, a, b = na()

def pow(a,n,p=mod):
    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 comb(a, b, p=mod):
    res = 1
    pres = 1
    for i in range(b):
        res = (res*(a-i))%p
        pres = (pres*(i+1))%p
    return res*pow(pres, p-2, p) % p
print((pow(2, n) - 1 - comb(n, a) - comb(n, b))%mod)

Solution (Python):
def com(N,K,mod):
    n=N
    k=K
    X=1  
    Y=1  
    for _ in range(K):
        X*=n
        X%=mod
        n-=1
    for _ in range(K):
        Y*=k
        Y%=mod
        k-=1
    Y=pow(Y,mod-2,mod)  
    return X*Y%mod  

def main():
    N,a,b=map(int,input().split())
    mod=1000000007
    t=(pow(2,N,mod)-1-com(N,a,mod)-com(N,b,mod))%mod
    print(t)
    
if __name__=="__main__":
    main()

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

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

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

nca = combmod(n, a, mod) 
ncb = combmod(n, b, mod) 

ans = pow(2, n, mod)

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

Solution (Python):
N, A, B = map(int, input().split())
mod = 10 ** 9 + 7
 
fact = [1]
num = [N]
for i in range(1, B + 1):
    fact.append(fact[-1] * (i + 1) % mod)
    num.append(num[-1] * (N - i) % mod)
 
 
def comb(x):
    res = num[x-1] * pow(fact[x-1], mod - 2, mod) % mod
    return res
 
 
ans = (pow(2, N, mod) - comb(A) - comb(B) -1 ) % mod

print(ans)

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

fact = [1]
num = [N]
for i in range(1, B + 1):
    fact.append(fact[-1] * (i + 1) % mod)
    num.append(num[-1] * (N - i) % mod)


def comb(x):
    res = num[x-1] * pow(fact[x-1], mod - 2, mod) % mod
    return res


ans = (pow(2, N, mod) - comb(A) + mod) % mod
ans = (ans - comb(B) + mod) % mod
ans = (ans - 1 + mod) % mod
print(ans)

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

MAXN = B+3
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD

def comb(n,r):
    ret = 1
    for i in range(r):
        ret *= n-i
        ret *= inv[i+1]
        ret %= MOD
    return ret
ans = p-1 - comb(N,A) - comb(N,B)
ans %= MOD
print(ans)

Solution (Python):
n,a,b=map(int,input().split())
ans=pow(2,n)-1
mod=10**9+7
def ncr(n,r,mod):
    cnt=1
    for i in range(n-r+1,n+1):
        cnt*=i
        cnt%=mod
    for i in range(1,r+1):
        cnt*=pow(i,mod-2,mod)
        cnt%=mod
    return cnt
comb1=ncr(n,a,mod)
comb2=ncr(n,b,mod)
ans=(ans-comb1-comb2)%mod
print(ans)

Solution (Python):
def combmod(n,k,mod):
    a = 1
    b = 1
    for i in range(k):
        a = a * (n-i) % mod
        b = b * (i+1) % mod
    return a * pow(b, mod-2, mod) % mod
n,a,b=map(int,input().split())
mod=10**9+7
cn=pow(2,n,mod)-1
ca=combmod(n,a,mod)
cb=combmod(n,b,mod)
print((cn-ca-cb)%mod)

Solution (Python):
MOD = 10**9 + 7
def comb(n, k, MOD):
    if n < k or n < 0 or k < 0:
        return 0
    if k == 0:
        return 1
    iinv = [1] * (k + 1)
    ans = n
    for i in range(2, k + 1):
        iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
        ans *= (n + 1 - i) * iinv[i] % MOD
        ans %= MOD
    return ans
n, a, b = map(int, input().split())
print((pow(2,n,MOD)-1-comb(n,a,MOD)-comb(n,b,MOD)+MOD*10)%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):
def comb(n, r, mod):
    r = min(r, n-r)
    mol = 1
    deno = 1
    for i in range(1, r+1):
        mol = mol * (n-r+i) % mod
        deno = deno * i % mod
    ret = mol * pow(deno, mod-2, mod) % mod
    return ret

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

P = 10**9+7

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

ans = (pow(2,n,P) -1 - nCa - nCb + 2*P)%P
print(ans)

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

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

P = 10**9+7

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

ans = (pow(2,n,P) -1 - nCa - nCb + 2*P)%P
print(ans)

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

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

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

Solution (Python):
import math

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def combination(n,r,mod):
    r = min(r,n-r)

    res = 1
    for i in range(r):
        res = res * (n-i) * modinv(i+1,mod) % mod
    
    return res

mod = 10**9+7

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

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

ans -= combination(n,a,mod)
ans -= combination(n,b,mod)

print(ans % mod)

Solution (Python):
N, A, B = map(int, input().split())

MOD = 10 ** 9 + 7


def comb(n, r):
    if n - r < r:
        r = n - r

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


res = pow(2, N, MOD)

res -= comb(N, A) + comb(N, B)
res %= MOD
print(res - 1)

Solution (Python):
n, a, b = map(int, input().split())
mod = 1000000007
def inv(y, mod):
    return pow(y, mod - 2, mod)

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

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

class ModInt:
    def __init__(self, x):
        if isinstance(x, ModInt):
            self.x = x.x
        else:
            self.x = x % MOD
            if self.x < 0:
                self.x += MOD
    
    def get_mod(self):
        return MOD
    
    def inv(self, other):
        return ModInt(pow(ModInt(other).x, MOD - 2, MOD))
    
    
    def __str__(self):
        return str(self.x)
    
    def __int__(self):
        return self.x
    
    __index__ = __int__
    
    
    __repr__ = __str__

    
    def __add__(self, other):
        return ModInt(self.x + ModInt(other).x)
    
    def __sub__(self, other):
        return ModInt(self.x - ModInt(other).x)

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

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

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

    
    __radd__ = __add__

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

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

    def __rfloordiv__(self, other):
        return ModInt(other // self.x)
    
    
    def __rpow__(self, other):
        return ModInt(pow(other, self.x, MOD))
    
    
    def __lt__(self, other):
        return self.x < ModInt(other).x
    
    def __gt__(self, other):
        return self.x > ModInt(other).x

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

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

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

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

ans = 2 ** n

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

print(ans)

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

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

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

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

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

    return result%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
            K%=mod
        x *= x
        x%=mod
        n //= 2

    return K * x%mod

ans=pow_k(2,n)-1
ans=ans- cmb(n, min(a,n-a))-cmb(n, min(b,n-b))
print(ans%mod)

Solution (Python):



from operator import mul
from functools import reduce



def main():

    def modcmb(n, r, mod):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        if r == 0:
            return 1
        over = 1
        under = 1





        over = reduce(lambda v1, v2: (v1 * v2) % mod, range(n, n-r, -1))
        under = reduce(lambda v1, v2: (v1 * v2) % mod, range(1, r+1))
        return (over * pow(under, mod - 2, mod)) % mod

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

    count = pow(2, n, mod) - 1
    count -= modcmb(n, a, mod)
    count -= modcmb(n, b, mod)

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


main()

Solution (Python):



from operator import mul
from functools import reduce



def main():

    def modcmb(n, r, mod):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        over = 1
        under = 1
        for i in range(n, n-r, -1):
            over = over * i % mod
        for i in range(1, r+1):
            under = under * i % mod



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

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

    count = pow(2, n, mod) - 1
    count -= modcmb(n, a, mod)
    count -= modcmb(n, b, mod)

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


main()

Solution (Python):



from operator import mul
from functools import reduce



def main():

    def modcmb(n, r, mod):
        if r < 0 or r > n:
            return 0
        r = min(r, 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)) % mod

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

    count = pow(2, n, mod) - 1
    count -= modcmb(n, a, mod)
    count -= modcmb(n, b, mod)

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


main()

Solution (Python):
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
n,a,b = map(int,input().split())
mod=10**9+7
print((pow(2,n,mod)-1-cmb(n,a,mod)-cmb(n,b,mod))%mod)

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


m=10**9+7





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

def main():
	n,a,b=map(int,input().split())
	ans=pow(2,n,m)-1-comb(n,a,m)-comb(n,b,m)
	ans%=m
	print(ans)
	
if __name__ == "__main__":
	main()

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


m=10**9+7





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

def main():
	n,a,b=map(int,input().split())
	ans=pow(2,n,m)-1-comb(n,a,m)-comb(n,b,m)
	ans%=m
	print(ans)
	
if __name__ == "__main__":
	main()

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


def mod_pow(a, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        half_p = p // 2
        half = mod_pow(a, half_p)
        return half * half % mod
    else:
        return a * mod_pow(a, p - 1) % mod


def calc_comb(a, b):
    if b > a - b:
        return calc_comb(a, a - b)

    ans_mul = 1
    ans_div = 1
    for i in range(b):
        ans_mul *= (a - i)
        ans_div *= (i + 1)
        ans_mul %= mod
        ans_div %= mod

    ans = ans_mul * mod_pow(ans_div, mod - 2) % mod
    return ans


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

Solution (Python):
def ncr(n,r,z):
  x=1
  y=1
  for i in range(min(r,n-r)):
    x=(x*(n-i))%z
    y=(y*(i+1))%z
  y=pow(y,z-2,z)
  return x*y%z

n,a,b=map(int,input().split())
mod=10**9+7
A=ncr(n,a,mod)
B=ncr(n,b,mod)
ans=pow(2,n,mod)-1-A-B
while ans<0:
  ans+=mod
print(ans)

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

total = (pow(2, n, p) - 1) % p

def cmb(n, r):
    x = 1
    y = 1
    for i in range(r):
        x = (x * (n - i)) % p
        y = (y * (r - i)) % p
    ret = x * pow(y, p - 2, p) % p
    return ret

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

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


def inv(a, mod):
    b = mod
    p, q = 1, 0
    while b > 0:
        c = a // b
        a, b = b, a-c*b
        p, q = q, p-c*q
    return p + mod if p < 0 else p


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


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