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 = map(int,input().split())

def power(x, n, mod):
    """
    x**n mod in  O(log n)
    """
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K = K * x % mod
            x = x ** 2 % mod
            n = (n - 1) // 2
        else:
            x = x ** 2 % mod
            n = n // 2
    return K * x % mod
 
def nCrMOD(a,b,m):
    c = 1
    for i in range(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = egcd(a, m)
    return inv % m

m=10**9+7

ans = power(2,n,m) -1 - nCrMOD(n,a,m) -nCrMOD(n,b,m)
print(ans%m)

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

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

bunbo = 1
bunsi = 1
for i in range(1,a+1):
    bunbo *= i
    bunbo = bunbo%1000000007
    bunsi *= (n+1-i)
    bunsi = bunsi%1000000007
bunbo = pow(bunbo,1000000005,1000000007)
nca = (bunsi*bunbo)%1000000007

bunbo = 1
bunsi = 1
for i in range(1,b+1):
    bunbo *= i
    bunbo = bunbo%1000000007
    bunsi *= (n+1-i)
    bunsi = bunsi%1000000007
bunbo = pow(bunbo,1000000005,1000000007)
ncb = (bunsi*bunbo)%1000000007

ans = (ans-1-nca-ncb)%1000000007
print(ans)

Solution (Python):
def combnk_mod(n, k, p):
    
    
    
    

    if  2 * k > n:
        k = n - k
    x = 1 
    y = 1 
    for i in range(1, k + 1):
        x *= pow(i, p - 2, p)
        y *= n - i + 1
        x %= p
        y %= p
    return (x * y) % p

if __name__ == '__main__':
    MOD = 10 ** 9 + 7
    n, a, b = map(int, input().split())
    ans = pow(2, n, MOD) - 1
    ans %= MOD
    for k in [a, b]:
        ans -= combnk_mod(n, k, MOD)
        ans %= MOD
    print(ans)

Solution (Python):
import math
n,c,d= map(int, input().split())
mod = pow(10,9)+7

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


ans=(pow(2,n,mod)-1-comb(n,c)-comb(n,d))%mod
print(ans)

Solution (Python):
import itertools

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


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

sumc = pow(2, n, mod)-1
ac = ncr(n, a, mod)
bc = ncr(n, b, mod)

print((sumc - ac - bc)% mod)

Solution (Python):
def nCr(n, r, mod):
    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

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

print(ans%MOD)

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

MOD = 10**9 + 7
fact_inv, inv = [0]*10**6, [0]*10**6

def init_nCk():
    fact_inv[0] = fact_inv[1] = 1
    inv[1] = 1
    for i in range(2,10**6):
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        fact_inv[i] = fact_inv[i-1] * inv[i] % MOD

def nCk(n,k):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    ans = 1
    for i in range(n, n-k+1 - 1, -1):
        ans *= i
        ans %= MOD
    return ans * fact_inv[k] % MOD


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

Solution (Python):
def solve():
    n, a, b = list(map(int, input().split()))
    MOD = 10 ** 9 + 7
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    
    for i in range(2, max(a, b)+1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)
    
    def ncr(n, r):
        ret = factinv[r]
        for i in range(n, n-r, -1):
            ret = ret * i % MOD
        return ret
        
    ans = pow(2, n, MOD)
    ans = (ans-ncr(n, a)-ncr(n, b)-1) % MOD
    return ans


print(solve())

Solution (Python):
def solve():
    n, a, b = list(map(int, input().split()))
    MOD = 10 ** 9 + 7
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    
    for i in range(2, max(a, b)+1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)
    
    def ncr(n, r):
        ret = factinv[r]
        for i in range(n, n-r, -1):
            ret = ret * i % MOD
        return ret
        
    ans = pow(2, n, MOD)
    ans = (ans-ncr(n, a)-ncr(n, b)-1) % MOD
    return ans


print(solve())

Solution (Python):

from functools import reduce

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


    bunsi = reduce(lambda x, y: (x * y) % mod, range(n, n-r, -1))
    bunbo = reduce(lambda x, y: (x * y) % mod, range(r, 1, -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):
n, a, b = map(int, input().split())
MOD = 10 ** 9 + 7


def comb(n, a):
	ret = 1
	
	for i in range(n - a + 1, n + 1):
		ret *= i
		ret %= MOD
	
	for i in range(1, a + 1):
		ret *= pow(i, MOD - 2, MOD)
		ret %= MOD
	return ret
	
ans = pow(2, n, MOD) - 1
ans -= comb(n, a)
ans -= comb(n, b)
print(ans % MOD)

Solution (Python):
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


















def comb(n, k, mod):
    a = factmod(n, n - k + 1, mod)
    b = factmod(k, 1, mod)

    div = pow(b % mod, mod - 2, mod)  

    return a * div % mod


def factmod(n, start, mod):
    val = 1
    for i in range(start, n + 1):
        val *= i
        val %= mod
    return val


def resolve():
    global dp

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

    
    
    
    

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


if __name__ == "__main__":
    resolve()





import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4 1 3"""
        output = """7"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """1000000000 141421 173205"""
        output = """34076506"""
        self.assertIO(input, output)

Solution (Python):
MOD = 1000000007
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

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

    __repr__ = __str__

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

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

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

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

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

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

    __radd__ = __add__

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

    __rmul__ = __mul__

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

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

    def __isub__(self,other):
        self.x += ModInt(MOD - other.x) if isinstance(other, ModInt) else ModInt(MOD - other)
        return self

    def __imul__(self, other):
        self.x *= other.x if isinstance(other, ModInt) else other
        self.x %= MOD
        return self
    
    def factorical(self,n):
        tmp = ModInt(1)
        for i in range(n):
            tmp *= (i+1)
        return tmp
    
    
    def modinv(self,a,m=MOD):
        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
        return ModInt(u)

    def comb(self,n,r):
        n = int(n)
        r = int(r)
        if r > n or n < 0 or r < 0:
            return 0
        m = n+1
        nterms = min(r, n-r)
        numerator = ModInt(1)
        denominator = ModInt(1)
        for j in range(1, nterms + 1):
            numerator *= m - j
            denominator *= j
        return numerator * self.modinv(denominator.x)
        
if __name__ == "__main__":
    n,a,b = map(int,input().split())
    c = ModInt(2)
    c = c ** n
    ans = ModInt(c-1)
    ans -= ans.comb(n,a)
    ans -= ans.comb(n,b)
    print(ans)

Solution (Python):
MOD = 1000000007
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

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

    __repr__ = __str__

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

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

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

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

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

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

    __radd__ = __add__

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

    __rmul__ = __mul__

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

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

    def __isub__(self,other):
        self.x += ModInt(MOD - other.x) if isinstance(other, ModInt) else ModInt(MOD - other)
        return self

    def __imul__(self, other):
        self.x *= other.x if isinstance(other, ModInt) else other
        self.x %= MOD
        return self
    
    def factorical(self,n):
        tmp = ModInt(1)
        for i in range(n):
            tmp *= (i+1)
        return tmp
    
    
    def modinv(self,a,m=MOD):
        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
        return ModInt(u)

    def comb(self,n,r):
        n = int(n)
        r = int(r)
        if r > n or n < 0 or r < 0:
            return 0
        m = n+1
        nterms = min(r, n-r)
        numerator = ModInt(1)
        denominator = ModInt(1)
        for j in range(1, nterms + 1):
            numerator *= m - j
            denominator *= j
        return numerator * self.modinv(denominator.x)
        
if __name__ == "__main__":
    n,a,b = map(int,input().split())
    c = ModInt(2)
    c = c ** n
    ans = ModInt(int(c-1))
    ans -= ans.comb(n,a)
    ans -= ans.comb(n,b)
    print(ans)

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


fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
com = [0 for i in range(MAX)]
power = [2 for i in range(32)]

for i in range(1, 32) :
  power[i] = power[i-1] * power[i-1] % MOD

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


def two_n_mod(n) :
  ans = 1
  temp_i = 0
  temp = [0 for i in range(32)]
    
  for i in range(32) :
    temp[i] += n%2
    n = int(n/2)
  ans = (2**n) % MOD
  for i in range(32) :
    ans = ans * (power[i] ** temp[i]) % MOD
  return ans

temp = cominit()


print((two_n_mod(n) - 1 - com[a] - com[b]) % MOD)

Solution (Python):
def main():
    n,a,b=map(int,input().split())
    mod=(10**9)+7
    ans=pow(2,n,mod)-1
    comb=1
    for i in range(n-a+1,n+1):
        comb*=i
        comb%=mod
    for i in range(1,a+1):
        comb*=pow(i,mod-2,mod)
        comb%=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=ans-comb-comb2
    ans%=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
comb=1
for i in range(n-a+1,n+1):
    comb*=i
    comb%=mod
for i in range(1,a+1):
    comb*=pow(i,mod-2,mod)
    comb%=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=ans-comb-comb2
ans%=mod
print(ans)

Solution (Python):
p = 10 ** 9 + 7
n,a,b = map(int,input().split())
k=max(a,b)
def nCr(n, r, mod):
  ret = [1]*(r+1)
  for i in range(1, r+1):
    ret[i] = (ret[i-1] * (n-i+1) * pow(i,mod-2,mod)) % mod
  return ret
nCrl = nCr(n, k, p)
print((pow(2,n,p)-1-nCrl[a]-nCrl[b])%p)

Solution (Python):
import math

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


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

sumComb= pow(2, n, mod) 

aComb = calcCombination(n, a, mod)

bComb = calcCombination(n, b, mod)

ans = ( sumComb - 1 - aComb - bComb ) % mod

print(int(ans))

Solution (Python):
from functools import reduce

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


def cmb(N, 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


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

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

from functools import reduce
 
def nCr(n,r,DIV):
  f=lambda x,y:x*y%DIV
  X=reduce(f,range(n-r+1,n+1))
  Y=reduce(f,range(1,r+1))
  return X*pow(Y,DIV-2,DIV)%DIV

DIV = 10**9+7

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

print(ans%DIV)

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

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

Solution (Python):
M = 10**9 + 7
n, a, b = map(int, input().split())
r = pow(2, n, M) - 1
f = c = 1
for i in range(b):
  f = f * (i + 1) % M
  c = c * (n - i) % M
  if i + 1 == a:
    a = b
    r -= c * pow(f, M - 2, M)
print(r % M)

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

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

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

ans -= p
ans -= q
ans %= mod
print(ans-1)

Solution (Python):
import math

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

 
def comb(n,k,mod):
    """power_funcを用いて(nCk) mod p を求める"""
    if n<0 or k<0 or n<k: return 0
    if n==0 or k==0: return 1
    k=min(n-k,k)
    
    deno=1
    
    mole=1

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

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


def power_func(a,b,p):
    """a^b mod p を求める"""
    if b==0: return 1
    if b%2==0:
        d=power_func(a,b//2,p)
    return d*d %p
    
    if b%2==1:
        return (a*power_func(a,b-1,p ))%p

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

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

def nCr(n,r,m):
    a = b = 1
    for i in range(r):
        a = a * (n-i) % m
        b = b * (r-i) % m
    return a * pow(b, m-2, m) % m

ans = pow(2,n,M) - 1
ans -= nCr(n,a,M)
ans -= nCr(n,b,M)
ans %= M
if ans<0: ans += M
print(ans)

Solution (Python):
def comb_mod(a: int, b: int, mod: int = 10**9+7) -> int:
    """Returns Comb(a, b) % mod
    Precondition: mod is prime
    Complexity: O(min(a-b, b))
    :param a:
    :param b:
    :param mod: a prime number
    :return:
    """
    b = min(b, a-b)

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

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

    return res


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


if __name__ == '__main__':
    main()

Solution (Python):
def cmb(n, r, mod):
    if r < 0 or n < r:
        return 0
    r = min(r, n - r)
    numerator, denominator = 1, 1
    for i in range(1, r + 1):
        numerator = (numerator * (n + 1 - i)) % mod
        denominator = (denominator * i) % mod
    return numerator * pow(denominator, mod - 2, mod) % mod


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


if __name__ == '__main__':
    solve()

Solution (Python):
def choose(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        

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


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

ans = ans % MOD
print(int(ans))

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

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

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, 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

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

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n, a, b = map(int, input().split())
    ans = pow(2, n, MOD)

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

    print((ans-1)%MOD)
resolve()

Solution (Python):
import time
from math import factorial

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

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

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

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

fn=2*10**5
fac=[0]*fn
fac[1]=n

print((power(2, n, mo)-1-comb(n,a,mo)-comb(n,b,mo))%mo)

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

ans=pow(2,n,mod_num)

def get_combi_mod(n, k, MOD):
    if n < k:
        return 0
    if n-k < k:
        k = n-k
    comb = 1
    for x in range(n-k+1, n+1):
        comb = (comb * x) % MOD
    d = 1
    for x in range(1, k+1):
        d = (d * x) % MOD
    comb *= pow(d, MOD-2, MOD)
    return comb % MOD

ans-=1
ans-=get_combi_mod(n,a,mod_num)
ans-=get_combi_mod(n,b,mod_num)
print(ans%mod_num)

Solution (Python):
import time



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

M = 10**9+7


twon = pow(2,n,M)












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





nCa = comb_mod(n,a,M)


nCb = comb_mod(n,b,M)

ans = twon - 1 - nCa - nCb

elapsed_time = time.time() - start 

print(ans % M)

Solution (Python):

mod = 1000000007


def sub(a, b):
    return (a - b + mod) % mod


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


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


def comb(n, r):
    """ nCr % mod
    Equivalent to comb(n, r) in Python 3.8
    """
    num = 1
    den = 1
    for i in range(r):
        num = mul(num, n - i)
        den = mul(den, i + 1)
    return div(num, den)


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

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

Solution (Python):

import sys,math
import numpy as np


n,a,b=map(int,sys.stdin.readline().split())


p=10**9+7
to=pow(2,n,p)-1


def C(N,K):
    if N<K:
        return 0
    else:
        c=1
        d=1
        for i in range(1,K+1):
            c=c*(n-i+1)%p
            d=d*i%p
        return c*pow(d,p-2,p)%p
print((to-C(n,a)-C(n,b))%p)

Solution (Python):
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

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

MOD = 10 ** 9 + 7

def myPow(x, n, MOD):
    if n == 0:
        return 1

    res = 1
    while(n > 0):
        if n & 1 == 1:
            res = res * x % MOD

        x = x * x % MOD
        n = n >> 1

    return res


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

def cumprod(arr, MOD):
    L = len(arr)
    Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]
        arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]
        arr[n] %= MOD
    return arr.ravel()[:L]


def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64)
    x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64)
    x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv


fact, fact_inv = make_fact(B + 10, MOD)

arr = cumprod(list(range(N, N-B, -1)), MOD)

a = arr[A - 1] * fact_inv[A]
a %= MOD
b = arr[B-1] * fact_inv[B]
b %= MOD




'''
a = ma * fact_inv[A]
a %= MOD

b = mb * fact_inv[B]
b %= MOD
'''

ans -= (a + b)
ans %= MOD

print(ans)

Solution (Python):






import math
import statistics
import numpy as np
import queue
import itertools
import functools 


TBMod = int(1e+9 + 7)


def nCr(n, r, mod):
	f = lambda x, y : x * y % mod
	x, y = functools.reduce(f, range(n - r + 1, n + 1)), \
		functools.reduce(f, range(1, r + 1))
	return x * pow(y, mod - 2, mod) % mod

n,a,b = map(int, input().split())
print((pow(2, n, TBMod) - (nCr(n, a, TBMod) + nCr(n, b, TBMod)) - 1) % TBMod)

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 calc_mod_comb(x, y):
  numerator = 1
  for i in range(y):
    numerator = (numerator * (x-i))%modval
  denominator = 1
  for i in range(1, y+1):
    denominator = (denominator * i)%modval
  denominator = pow(denominator, modval-2, modval)
  return (numerator * denominator)%modval

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

a_combs = calc_mod_comb(n, a)
b_combs = calc_mod_comb(n, b)

ans = (pow(2, n, modval) - 1 - a_combs - b_combs)%modval

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
n, a, b = [int(x) for x in input().strip().split()]
mod = 10 ** 9 + 7
ans = pow(2, n, mod) - 1

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

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

print(ans)

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

M = 10**9+7


twon = pow(2,n,M)







L = [0] * (2*(10**5) + 1)
L[0] = 1
for i in range(len(L)-1):
    L[i+1] = ( L[i] * (n-i) * pow(i+1,M-2,M) ) % M

nCa = L[a]


nCb = L[b]

ans = twon - 1 - nCa - nCb

print(ans % M)

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

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

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

mod = 1000000007

def modpow(a,n,m):
    x = 1
    while n:
        if n%2: x *= a
        a *= a
        a %= m
        n //= 2
    return x

def nCr(n,r,m):
    a = b = 1
    for i in range(r):
        a *= n - i
        b *= r - i
        a %= m
        b %= m
    return a * modpow(b, m-2, m) % m

ans = modpow(2,n,mod) - 1
ans -= nCr(n,a,mod)
ans -= nCr(n,b,mod)
ans %= mod
if ans<0: ans += mod
print(ans)

Solution (Python):
n, a, b = map(int, input().split())
mod = 10**9+7
s = 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:
        s -= x*pow(y, mod-2, mod)

print(s%mod)

Solution (Python):
def main():
    n, a, b = map(int, input().split())
    mod = 10**9+7
    s = 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:
            s -= x*pow(y, mod-2, mod)

    print(s%mod)

main()

Solution (Python):
n, a, b = map(int, input().split())
mod = 10**9+7
"""
def factorial_mod(x, y, mod):
    factorial = 1
    for i in range(x,y+1):
        factorial *= i
        factorial %= mod
    return factorial



def n_C_k(n,k,mod):
    factorial_nk = factorial_mod(n-k+1, n, mod)
    factorial_k = factorial_mod(1,k,mod)
    conbi=factorial_nk*pow(factorial_k, mod-2, mod)
    return conbi%mod

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


def factorial_mod(n, mod):
    x = 1
    for i in range(1, n+1):
        x *= i
        x %= mod
    return x


def permutation_mod(n, k, mod):
    x = 1
    for i in range(n-k+1, n+1): 
        x *= i
        x %= mod
    return x


def n_C_k(n, k, mod): 
    k = min(k, n-k)
    n_P_k = permutation_mod(n, k, mod)
    factorial_k = factorial_mod(k, mod)
    conbi=n_P_k * pow(factorial_k, mod-2, mod)
    return conbi % mod

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

Solution (Python):
mod = 10**9+7
n,a,b = [int(i) for i in input().split()]
k = min(n,2*(10**5))
import sys
sys.setrecursionlimit(100000000)
def pow_k(a,n,mod):
    if n == 0:
        return 1
    if n % 2 ==0:
        return pow_k(a*a % mod,n//2,mod)
    else:
        return a * pow_k(a,n-1,mod) % mod
def modinv(a, mod):
    return pow(a, mod-2, mod)
def combination_list(n, mod):
    lst = [1]
    for i in range(1, k+1):
        lst.append(lst[-1] * (n+1-i) % mod * modinv(i, mod) % mod)
    return lst
ans = pow_k(2,n,mod)
cmb = combination_list(n,mod)
ans -=1
ans -= cmb[a]
if ans < 0:
    ans += mod
ans -= cmb[b]
if ans <0:
    ans += mod
print(ans)