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):
class cmbs(object):
    def __init__(self, mod):
        self.mod = mod
        self.g1 = [1, 1]
        
        self.g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, 10 ** 6 + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)
    def cmb(self, n, r):
        if n > 10 ** 6:
            return self.cmbl(n, r)
        return self.cmbr(n, r)
    def cmbr(self, n, r):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.mod
    def cmbl(self, n, r):
        t = 1
        r = min(r, n-r)
        mod = self.mod
        for i in range(n - r + 1, n + 1):
            t = t * i % mod
        return t * self.g2[r] % mod
def pown(n, m, mod):
    r = 1
    while n:
        if n & 1:
            r = r * m
            r %= mod
        m *= m
        m %= mod
        n >>= 1
    return r

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

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

"""繰り返し二乗法"""
def s_pow(x,n):
    ans = 1
    while n>0:
        if(bin(n&1) == bin(1)):
            ans *= x
        x *= x
        n = n>>1
    return ans

"""コンビネーション"""
def cmb(n,r):
    if n-r<r:
        r = n - r
    x,y = 1,1
    for i in range(r):
        x = x*(n-i)%MOD
        y = y*(i+1)%MOD
    return x*pow(y,MOD-2,MOD)


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

Solution (Python):
def combination(n, r, p):
    """
    nCr mod p の組み合わせ数を求める関数
    n: 総数
    r: 取り出す個数
    p: 法
    """
    r = min(n - r, r)
    if r == 0:
        return 1
    over = 1
    for i in range(n, n - r, -1):
        over = over * i % p
    under = 1
    for i in range(1, r + 1):
        under = under * i % p
    inv = pow(under, p - 2, p)
    return over * inv % p

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

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

_n = modpow(2, n, p)
_a = combination(n, a, p)
_b = combination(n, b, p)

ans = _n - _a - _b - 1

print(ans%p)

Solution (Python):
def choose(n, r, M):
    x = 1
    y = 1
 
    for i in range(r):
        x = x * (n - i) % M
        y = y * (i + 1) % M
    res = x * pow(y, M-2, M) % M
    return res
 
n, a, b = map(int, input().split())
M = 10 ** 9 + 7
 
print((pow(2, n, M) - 1 - choose(n, a, M) - choose(n, b, M)) % M)

Solution (Python):
def main():
    MOD = 10**9 + 7
    n, a, b = map(int, input().split())
    
    def cmb(n, r):
        if n-r<r:
            r = n-r
        
        X, Y = (1, 1)
        for i in range(r):
            X = X*(n-i)%MOD
            Y = Y*(i+1)%MOD
        return X*pow(Y, MOD-2, MOD)
    
    base = pow(2, n, MOD)-1
    base -= cmb(n, a)
    base -= cmb(n, b)
    base %= MOD
    print(base)
if __name__ == '__main__':
    main()

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

mod = 10**9+7

total = pow(2,n,mod)
total += mod*3


c = [pow(x,mod-2,mod) for x in range(2*10**5+1)]

nCa = 1
for i in range(1,a+1):
    nCa *= n-i+1
    nCa *= c[i]
    nCa %= mod

nCb = 1
for i in range(1,b+1):
    nCb *= n-i+1
    nCb *= c[i]
    nCb %= mod


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

Solution (Python):
def choose(n, r, M):
    x = 1
    y = 1

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

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

print((pow(2, n, M) - 1 - choose(n, a, M) - choose(n, b, M)) % M)

Solution (Python):

from functools import reduce

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

def nCr(n, r):
    r = min(n-r, r)
    if r == 0: return 1
    numer = reduce(lambda x, y: x * y % mod, range(n, n - r, -1))
    denom = reduce(lambda x, y: x * y % mod, range(1, r + 1))
    return numer * pow(denom, mod - 2, mod) % mod

mod = 10 ** 9 + 7

tnmo = pow(2, n, mod) - 1
an = nCr(n, a)
bn = nCr(n, b)
ans = (tnmo - an - bn) % mod

print(ans)

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

mod = 10**9+7


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


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

Solution (Python):

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

inf = 10**9+7
def comb2(n,k): 
    x,y = 1,1
    if n-k < k:
        k = n-k
    for i in range(k):
        x *= n-i
        x = x%inf
        y *= i+1
        y = y%inf
    ans = x* pow(y,inf-2,inf) %inf
    return ans

ans -= comb2(n,a) + comb2(n,b)
ans = ans%inf
print(ans)

Solution (Python):
def cmb(n, r, p):
    
    nume, deno = 1, 1
    for i in range(r):
        nume = nume * (n - i) % p
        deno = deno * (i + 1) % p
    return nume * pow(deno, p - 2, p) % p


if __name__ == "__main__":
    n, a, b = map(int, input().split())
    p = 10 ** 9 + 7

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

Solution (Python):
n, a, b = map(int, input().split())
 
 
mod = 1000000007
 
inv = [1] * 222222
 




for i in range(2, 222222):
    inv[i] = -inv[mod % i] * (mod // i)
    inv[i] %= mod
    
def comb(n, a):
    res = 1
    for i in range(a):
        res *= n-i
        res *= inv[i+1]
        res %= mod
    return res
 
ans = pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)
 
ans %= mod
if ans < 0:
    ans += mod
 
print(ans)

Solution (Python):

def comb(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
c_n=pow(2,n,mod)-1
c_a=comb(n,a,mod)
c_b=comb(n,b,mod)
print((c_n-c_a-c_b)%mod)

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


def comb_mod(n, a, p):
  X = 1
  for num in range(n, n-a, -1):
    X *= num
    X %= p
  Y = math.factorial(a) % p
  return (X * (pow(Y, p-2, p))) % p

print((pow(2, n, mod_num) - (comb_mod(n, a, mod_num) + comb_mod(n, b, mod_num) + 1)) % mod_num)

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

_sum = pow(2, n, mod)-1
x = 1
y = 1

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

print(_sum%mod)

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


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


def mod_inv(a, m):
    b = m
    u = 1
    v = 0
    while b:
        t = a // b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= m
    if u < 0:
        u += m
    return u


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

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

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

inv=[0]*(2*10**5+100)
inv[1]=1
for i in range(2,2*10**5+100):
    inv[i]=-(mod//i)*inv[mod%i]%mod

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

ans=(pow(2,N,mod)-1)%mod
num=1
for i in range(1,a+1):
    num=num*(N-i+1)*inv[i]%mod
ans=(ans-num)%mod

num=1
for i in range(1,b+1):
    num=num*(N-i+1)*inv[i]%mod
ans=(ans-num)%mod

print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

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

    def comb_c(n, r):
        if r > n - r:
            r = n - r
        a, b = 1, 1
        for i in range(r):
            a = a * (n - i) % MOD
            b = b * (i + 1) % MOD
        return a * pow(b, MOD-2, MOD)

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

if __name__ == '__main__':
    main()

Solution (Python):


mo = 10**9+7

def C(n,a):
  d = 1
  u = 1
  for i in range(n-a+1,n+1):
    d *= i
    d %= mo
  for j in range(1,a+1):
    u *= j
    u %= mo
  return d*(pow(u,mo-2,mo))

n,a,b = map(int,input().split())
p = pow(2,n,mo) - 1

print((p-C(n,a)-C(n,b))%mo)

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

def com(n,k,mod):
    res=1
    tmp=1
    for i in range(1,k+1):
        res=res*(n-i+1)%mod
        tmp=tmp*i%mod
    a=modpow(tmp,1000000005,mod)
    return res*a%mod

MOD=1000000007
n,a,b=map(int,input().split())
ans=modpow(2,n,MOD)-1
t=com(n,a,MOD)
m=com(n,b,MOD)
ans=ans-t
if(ans<0):
    ans+=MOD
ans=ans-m
if(ans<0):
    ans+=MOD
print(ans)

Solution (Python):
def ore_comb(n,r,mod):
    '''
    return nCr
    O(min{n-r, r})
    '''
    bunsi=1 
    bunbo=1 
    r = min(r,n-r)
    for i in range(r):
      bunsi = bunsi*(n-i)%mod
      bunbo = bunbo*(i+1)%mod

    ans = (bunsi*pow(bunbo,mod-2,mod))%mod
    return ans

[N,a,b] = list(map(int,input().split()))

mod = 10**9+7

ans = pow(2, N, mod) -1
ans -= ore_comb(N,a,mod)
if ans<0:
    ans += mod
ans -= ore_comb(N,b,mod)
if ans<0:
    ans += mod

print(ans)

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

MOD = 10**9 + 7
x = 1
y = 1
ans = pow(2, n, MOD) - 1

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

print(ans%MOD)

Solution (Python):
def modcmb(n,r,mod=10**9+7):
    res=1
    div=min(r,n-r)
    for i in range(div):
        res=res*(n-i)*pow(div-i,mod-2,mod)%mod
    return res%mod

n,a,b=[int(i) for i in input().split()]
mod=10**9+7
ans=pow(2,n,mod)-1
ans-=modcmb(n,a)
ans%=mod
ans-=modcmb(n,b)
ans%=mod
print(ans)

Solution (Python):

def modcomb(n, r, mod):
    "nCr = X/Yとおく"
    r = min(r, n - r)
    X, Y = 1, 1
    for i in range(1, r + 1):
        X = X * (n + 1 - i) % mod
        Y = Y * i % mod
    
    return X * pow(Y, mod-2, mod) % mod

N, A, B = map(int, input().split())
mod = 10 ** 9 + 7
ans = pow(2, N, mod) - 1
a = modcomb(N, A, mod)

b = modcomb(N, B, mod)
ans -= a + b
print(ans % mod)

Solution (Python):
import math

counter = 0

def new_way(n, a, b, mod, nCa, nCb):
    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 = new_cmb(n, a, mod, g1, g2)
    print("a")
    nCb = new_cmb(n, b, mod, g1, g2)
    print("b")

def new_cmb(n, r, mod, g1, g2):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    ans = g1[n] * g2[r] % mod
    ans = ans * g2[n-r] % mod
    return ans


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    bunshi = 1
    bunbo = 1
    for i in range(r):
        bunshi = bunshi * (n-i) % mod

        bunbo = bunbo * (i+1) % mod
    
    bunbo_inv = my_pow(bunbo, mod-2, mod)

    return bunshi * bunbo_inv % mod

def my_pow(x, n, mod):
    global counter
    
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K = K * x % mod
        x = x * x % mod
        n //= 2

    return K * x % mod

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


mod = 10**9+7 

sum_nCr = my_pow(2, n, mod)

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




ans = sum_nCr - (1 + nCa + nCb)
ans %= mod
print(ans)

Solution (Python):
n, a, b = map(int, input().split())
mod = 10**9+7
c = pow(2,n,mod)
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
c -= 1
aa = nCr(n,a,mod)
bb = nCr(n,b,mod)
c -= (aa+bb)
print (c%mod)

Solution (Python):
n, a, b = map(int, input().split())
mod = 10**9+7
c = pow(2,n,mod)
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
c -= 1
aa = nCr(n,a,mod)
bb = nCr(n,b,mod)
c -= (aa+bb)
print (c%mod)

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


def prm(n, k, p=10**9+7):
    res = 1
    for i in range(k):
        res = res * (n-i) % p
    return res


def cmb(n, k, p=10**9+7):
    k = min(k, n - k)
    return prm( n, k ) * pow( prm(k, k), p-2, p ) % p

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


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

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

mod = 10**9+7

total = pow(2,n,mod)
total += mod*3

def factorials(n,m):
    
    f = [1,1]
    for i in range(2,n+1):
        f.append(f[-1]*i%m)

    
    g = [1]
    for i in range(n):
        g.append(pow(f[i+1],m-2,m))

    return f,g

f,g = factorials(2*10**5+1,mod)

nCa = g[a]
for i in range(1,a+1):
    nCa *= n-i+1
    nCa %= mod

nCb = g[b]
for i in range(1,b+1):
    nCb *= n-i+1
    nCb %= mod

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

Solution (Python):
def modpow(a,n,mod=10**9+7):
    res=1
    while n>0:
        if n&1:
            res=res*a%mod
        a=a*a%mod
        n>>=1
    return res%mod

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

n,a,b=[int(i) for i in input().split()]
ans=modpow(2,n)-1
ans-=modcmb(n,a)
ans%=10**9+7
ans-=modcmb(n,b)
ans%=10**9+7
print(ans)

Solution (Python):
import math

def modpow(x, n, mod):
    ans = 1
    while n:
        if n % 2:
            ans = ans * x % mod
        x = x * x % mod
        n >>= 1
    return ans

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


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

sum2 = modpow(2, n, mod)
ca = modcomb(a, n, mod)
cb = modcomb(b, n, mod)
ans = (sum2 - ca -cb -1) % mod

print(ans)

Solution (Python):
def mpow(a,b,M):
	r = 1
	while(b >= 1):
		if(b%2 == 1):
			r=r*a%M
		b//=2
		a=a*a%M
	return r

def minv(a,M):
	return mpow(a,M-2,M)

def mcomb(a,b,M):
	A = 1
	for i in reversed(range(a-b+1,a+1)):
		A = A * i % M
	A = A * minv(mfact(b,M),M) % M
	return A
def mfact(a,M):
	res = 1
	for i in range(1,a+1):
		res = res * i % M
	return res
def main():
	n,a,b  = [int(n) for n in input().split()]
	M=10**9+7
	A = mpow(2,n,M)-1
	A = ((A - mcomb(n,a,M))%M - mcomb(n,b,M))%M
	print(A)
main()

Solution (Python):
from functools import reduce
mod=10**9+7
def nCk(n,k):
  c=reduce(lambda x,y: x*y%mod, range(n,n-k,-1))
  m=reduce(lambda x,y: x*y%mod, range(1,k+1))
  return c*pow(m,mod-2,mod)%mod

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

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

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


class ModInt:

    def __init__(self, x):
        self.x = x.x if isinstance(x, ModInt) else x % MOD

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

    def __int__(self): return self.x
    __index__ = __int__

    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 __pow__(self, other): return ModInt(pow(self.x, ModInt(other).x, MOD))

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

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

    def __radd__(self, other): return ModInt(other + self.x)

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

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

    def __rmul__(self, other): return ModInt(other * self.x)

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

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

    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 cmb(n, r):  
    retVal = ModInt(1)
    for i in range(n-r+1, n+1):
        retVal *= i
    for i in range(2, r+1):
        retVal /= i
    return retVal


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


def twopow(p):
    if p == 0:
        return ModInt(1)
    if p % 2 == 0:
        t = twopow(p // 2)
        return t * t
    return 2 * twopow(p - 1)


nC = [ModInt(1)]
for i in range(1, 200005):
    nC.append(nC[-1] * (n - i + 1) / i)

print((twopow(n) - nC[a] - nC[b] - 1))

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

MOD = 10**9+7

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

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

ans = (ans - cmb(n,a,MOD))%MOD
ans = (ans - cmb(n,b,MOD))%MOD

print(ans)

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

mod=10**9+7

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

x=1
for i in range(n-a+1,n+1):
  x *= i
  x %= mod

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

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

ans = ans - x - y
ans %= mod

print(ans)

Solution (Python):
def combination(n, r, p):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = 1
    for i in range(n, n - r, -1):
        over = over * i % p
    under = 1
    for i in range(1, r + 1):
        under = under * i % p
    inv = pow(under, p - 2, p)
    return over * inv % p

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

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

Solution (Python):
def cmb(n,r,mod):
    if r<0 or r>n:return 0
    return g1[r]*g2[r]%mod


mod=10**9+7
n,a,b=map(int,input().split())
k=max(a,b)
g1=[1,n]
g2=[1,1]
inverse=[0,1]

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

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

Solution (Python):
def cmb(n,r,mod):
    if r<0 or r>n:return 0
    return g1[r]*g2[r]%mod


mod=10**9+7
n,a,b=map(int,input().split())
k=max(a,b)
g1=[1,n]
g2=[1,1]
inverse=[0,1]

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

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

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

ans1, ans2 = 1, 1
N = 3 * 10 ** 5
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  
p = MOD
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(a):
    ans1 = ans1 * (n-i) * inv[1+i] %MOD 
for i in range(b):
    ans2 = ans2 * (n-i) * inv[1+i] %MOD 

print((pow(2, n, MOD) + 2*MOD - 1 - ans1 - ans2)%MOD)

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

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 = list(map(int, input().split()))
mod = 10**9 + 7

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

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

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

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

const = 10**9 +7

ans = pow(2, n, const)
acmb = cmbmod(n, a, const)
bcmb = cmbmod(n, b, const)
ans = (ans-acmb-bcmb-1) %const

print(ans)

Solution (Python):
import sys






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

n, a, b = map(int, sys.stdin.readline().split())
MOD = 10 ** 9 + 7
ans = pow(2, n, MOD) - 1
ans = (ans - nCr(n, a, MOD) - nCr(n, b, MOD)) % MOD
print(ans)

Solution (Python):
import sys






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

n, a, b = map(int, sys.stdin.readline().split())
MOD = 10 ** 9 + 7
ans = pow(2, n, MOD) - 1
ans = (ans - nCr(n, a, MOD) - nCr(n, b, MOD)) % MOD
print(ans)

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


def prm(n, k, p=10**9+7):
    res = 1
    for i in range(k):
        res = res * (n-i) % p
    return res


def cmb(n, k, p=10**9+7):
    return prm( n, k ) * pow( prm(k, k), p-2, p ) % p

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


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

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


def prm(n,k,mod=10**9+7):
    res = 1
    for i in range(k):
        res = res * (n-i) % mod
    return res

def cmb(n,k,mod=10**9+7):
    return prm(n,k) * pow(prm(k,k),mod-2,mod) % mod

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


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

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


def prm(n,k,mod=10**9+7):
    res = 1
    for i in range(k):
        res = res * (n-i) % mod
    return res

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

ans = pow(2,n,mod) - 1 
ans = (ans - prm(n,a)*pow(prm(a,a),mod-2,mod)) % mod
ans = (ans - prm(n,b)*pow(prm(b,b),mod-2,mod)) % mod

print(ans)

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

def f(A):
    num = reduce(lambda x, y: x * y % MOD, range(N, N - A, -1))
    den = reduce(lambda x, y: x * y % MOD, range(1, A + 1))
    return num * pow(den, MOD - 2, MOD) % MOD
  
answer = pow(2, N, MOD) - f(A) - f(B) - 1
answer %= MOD
print(answer)

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

def fact(n,k,mod):
    res = 1
    for i in range(k):
        res = res * (n-i) % mod
    return res % mod

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

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

ans = (ans - fact(n,a,mod)*pow(fact(a,a,mod),mod-2,mod)) % mod
ans = (ans - fact(n,b,mod)*pow(fact(b,b,mod),mod-2,mod)) % mod

print(ans)

Solution (Python):

 

MOD = (10**9) + 7
 















 



 




 
def cmb(n, r, p):
    if r > n - r:
        r = n - r
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
 
p = 10 ** 9 + 7
N = 10 ** 6  
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
 
def f(t,k,mod):
    res = 1
    for i in range(k):
        res = res * t % mod
        t -= 1
    return res

def nCk(n,r):
    if r > n - r:
        r = n - r
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    res = 1
    for i in range(r):
      res *= n - i
      res /= i + 1
    return int(res)
    
def fact(n,k,mod):
    res = 1
    for i in range(k):
        res = res * (n-i) % mod
    return res % mod

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

 
mod = 10 ** 9 + 7



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















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







ans = (ans - fact(n,a,mod)*pow(fact(a,a,mod),mod-2,mod)) % mod
ans = (ans - fact(n,b,mod)*pow(fact(b,b,mod),mod-2,mod)) % mod





 
print(ans)

Solution (Python):
import heapq
import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

import functools
@functools.lru_cache(maxsize=None)
def tami(n, x):
	if x == 1:
		return n
	elif x%2 == 0:
		return tami(n, x//2)**2 %mod
	else:
		return tami(n, x-1)*n %mod

def nCr(n, r):
	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 = IL()

n = tami(2, N) -1
aa = nCr(N, a)
bb = nCr(N, b)
ans = n-aa-bb
while ans < 0:
	ans += mod
print(ans)

Solution (Python):
from sys import stdin

MOD = 10**9+7
def modcmb(n, r, mod):
    x = 1
    y = n
    for i in range(2,r+1):
        x *= i
        x %= mod
        y *= n-i+1
        y %= mod
    return y * pow(x, mod-2, mod) % mod

n, a, b = [int(x) for x in stdin.readline().rstrip().split()]

DIV = 10**9+7

_n = pow(2, n, MOD)
_a = modcmb(n, a, MOD)
_b = modcmb(n, b, MOD)
ans = _n - _a - _b - 1
print(ans % MOD)

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

def main():
    N,a,b = map(int,input().split())
    MOD = 10**9+7

    fac = [0 for _ in range(2*10**5+1)]
    fac[0],fac[1] = 1,1
    inv = copy.deepcopy(fac)
    invfac = copy.deepcopy(fac)
    
    for i in range(2,2*10**5+1):
        fac[i] = (fac[i-1]*i)%MOD
        inv[i] = MOD-(MOD//i)*inv[MOD%i]%MOD
        invfac[i] = (invfac[i-1]*inv[i])%MOD
        
    def coef(x,y):
        num = (((fac[x]*invfac[y])%MOD)*invfac[x-y]%MOD)
        return num

    def nume(N, r, mod):
        x = 1
        for i in range(1, r + 1):
            x = x * (N-i+1) % mod 
        return x

    s = pow(2,N,MOD) 
    a = nume(N,a,MOD)*invfac[a]
    b = nume(N,b,MOD)*invfac[b]
    ans = (s-1-a-b) % MOD

    print(int(ans))
    
if __name__ == "__main__":
    main()

Solution (Python):
MOD=10**9+7
n,a,b=map(int,input().split())
s=pow(2,n,MOD)-1
comba=1
combb=1
a=min(a,n-a)
b=min(b,n-b)
for i in range(1,a+1):
    comba*=(n-i+1)*(pow(i,MOD-2,MOD))
    comba=comba%MOD
comba=comba%MOD
for i in range(1,b+1):
    combb*=(n-i+1)*(pow(i,MOD-2,MOD))
    combb=combb%MOD
combb=combb%MOD
print((s-comba-combb)%MOD)

Solution (Python):

from functools import reduce
from operator import mul

MOD = 1000000007

def power_func(a, b, mod):
    if b == 0: return 1
    if b % 2 == 0:
        d = power_func(a, b // 2, mod)
        return d * d % mod
    if b % 2 == 1:
        return (a * power_func(a, b - 1, mod)) % mod

def nCr(n, r, mod):

    min_r = min(r, n-r)

    if min_r == 1: return n
    if min_r == 0: return 1

    bunsi = reduce(lambda x, y: (x * y) % mod, range(n, n-min_r, -1))
    bunbo = reduce(lambda x, y: (x * y) % mod, range(1, min_r + 1))

    return bunsi * power_func(bunbo, mod - 2, mod) % mod


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

print(((power_func(2, n, MOD) -1) - nCr(n, a, MOD)- nCr(n, b, MOD)) % MOD)

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

def main():
    N,a,b = map(int,input().split())
    MOD = 10**9+7
    
    def Comb(N, r, mod):
        x = 1
        y = 1
        for i in range(1, r + 1):
            x = x * (N-i+1) % mod 
            y = y * i % mod
        return (x*pow(y, mod-2, mod)) % mod

    s = pow(2,N,MOD) 
    a = Comb(N,a,MOD)
    b = Comb(N,b,MOD)
    ans = (s-1-a-b) % MOD

    print(int(ans))
    
if __name__ == "__main__":
    main()

Solution (Python):



MOD = 10**9 + 7

def getModInv(a, b):
    return 1 if (a == 1) else (1-b*getModInv(b%a, a))//a%b


def modPow(a, b):
    x = 1
    
    while b > 0:
        if b & 1:
            x = (x*a)%MOD

        a = (a**2)%MOD
        b //= 2

    return x


def modComb(n, r):
    p = 1
    q = 1

    for i in range(r):
        p = p*(n-i)%MOD
        q = q*(i+1)%MOD

    return p*getModInv(q, MOD)%MOD



N,A,B = map(int, input().split())
print((modPow(2,N) - modComb(N,A) - modComb(N,B) - 1)%MOD)

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

Solution (Python):
def comb(n,r,mod=10**9+7):
    cnt = 1
    for i in range(1, r+1): 
        cnt *= (n-i+1)*pow(i,mod-2,mod) 
        cnt %= mod 
    return cnt

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

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

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

def mod_combination(n, k, mod = 10 ** 9 + 7):
    def extended_gcd(a, b):
        if b == 0:
            return (a, 1, 0)
        d, x, y = extended_gcd(b, a % b)
        return (d, y, x - (a // b) * y)
    p, q = 1, 1
    for i in range(n - k + 1, n + 1):
        p = (p * i) % mod
    for i in range(2, k + 1):
        q = (q * i) % mod
    return p * (extended_gcd(q, mod)[1] % mod) % mod

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

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

print(ans % mod)

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

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