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())
mod = 10**9 + 7


def nCr(n, r, mod):
    r = min(r, n-r)
    x = 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) - nCr(n, a, mod) - nCr(n, b, mod) - 1
ans += mod if ans < 0 else 0
ans += mod if ans < 0 else 0
print(ans)

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

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

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

mod = 10**9 + 7
res = pow(2, n, mod)

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


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

print((res - A - B - 1) % mod)

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


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

mod = 10**9+7


def pow(n, p): 
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod


case_all = pow(2,n) -1 
case_a_n = 1
for i in range(n-a+1,n+1):
    case_a_n *= i
    case_a_n %= mod
case_a_r = 1
for i in range(1,a+1):
    case_a_r *= i
    case_a_r %= mod
case_a = case_a_n*pow(case_a_r,mod-2)%mod

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

case_all-=case_a+case_b
while case_all<0:
    case_all += mod
print(case_all)

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())
    MOD = 10**9 + 7
    COMB_a = modint(1)
    COMB_b = modint(1)
    for k in range(a):
        COMB_a *= n - k
    for k in range(1, a+1):
        COMB_a /= k
    for k in range(b):
        COMB_b *= n - k
    for k in range(1, b+1):
        COMB_b /= k
    ans = (pow(2, n, MOD) - 1 - COMB_a - COMB_b)
    print(ans)


if __name__ == '__main__':
    main()

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


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

Solution (Python):
n,a,b=map(int,input().split())
mod = 10**9 + 7
N = 10**6 
inv = [0] + [1] 
finv = [1] + [1] 
fac = [1] + [1] 
for i in range(2,N):
  inv += [inv[mod % i] * (mod - int(mod / i)) % mod]
  fac += [(fac[i-1] * i) % mod]
  finv += [(finv[i-1] * inv[i]) % mod]
t=(pow(2,n,mod)-1+mod)%mod
sa1,sa2,sb1,sb2=1,1,1,1
for i in range(1,a+1):
  sa1*=(n-i+1)
  sa1%=mod
sa=sa1*finv[a]%mod
for i in range(1,b+1):
  sb1*=(n-i+1)
  sb1%=mod
sb=(sb1*finv[b])%mod
print((t-sa-sb+mod)%mod)

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

X, Y = 1, 1
for i in range(min(a, b)):
    X *= n - i
    X %= t
    Y *= i + 1
    Y %= t
ans -= (X * pow(Y, t-2, t)) % t
if ans < 0:
    ans += t
for i in range(min(a, b), max(a, b)):
    X *= n - i
    X %= t
    Y *= i + 1
    Y %= t
ans -= (X * pow(Y, t-2, t)) % t
if ans < 0:
    ans += t

print(ans)

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

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

def main():
    n, a, b = map( int, input().split())
    print( (pow(2,n,Q) - cmb(n,a) - cmb(n,b)-1)%Q)
if __name__ == '__main__':
    main()

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

Solution (Python):
n,a,b = map(int,input().split())
mod = 10**9+7
ans = pow(2,n,mod)-1
fact = [1]*(2*10**5+1)
for i in range(2,2*10**5+1):
  tmp = fact[i-1]*i
  tmp %= mod
  fact[i]=tmp
  
def comb(n,k):
  k = min(k,n-k)
  fa = 1
  for i in range(n,n-k,-1):
    fa*=i
    fa%=mod
  return fa*pow(fact[k],mod-2,mod)
mi = comb(n,a)+comb(n,b)
mi%=mod
ans-=mi
ans%=mod
print(ans)

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

Solution (Python):
def ncr(n, r, p):
    
    
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den,
                      p - 2, p)) % p


def power(x, y, p):
    res = 1  

    
    
    x = x % p

    while (y > 0):

        
        
        if ((y & 1) == 1):
            res = (res * x) % p

            
        y = y >> 1  
        x = (x * x) % p

    return res
p=1000000007
n,a,b=map(int,input().split())
t=pow(2,n,p)-1-ncr(n,a,p)-ncr(n,b,p)
print(t%p)

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

Solution (Python):
import math

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


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


mod = 10**9+7

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

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

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp


def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp



def main():
    n,a,b=mis()
    print((pow(2, n, N1097) - comb(n, a, N1097) - comb(n, b, N1097) - 1) % N1097)

main()

Solution (Python):
n, a, b= [int(i) for i in input().split()]
m = 10**9 + 7

def nCk(N, K, m):
  ret = 1  
  for k in range(K):
    ret = (ret *(n - k)) %m
    
  inv = [1 for _ in range(K+1)]
  finv = [1 for _ in range(K+1)]
  for i in range(2, K+1):
    inv[i] = m - inv[m%i]*(m//i)%m
    finv[i] =finv[i-1] * inv[i]%m
    
  return (ret*finv[K])%m


print((pow(2,n,m)-nCk(n,a,m)-nCk(n,b,m)-1)%m)

Solution (Python):
n,a,b=map(int,input().split())
mod = 10**9 + 7
N = 10**6 
inv = [0] + [1] 
finv = [1] + [1] 
fac = [1] + [1] 
for i in range(2,N):
  inv += [inv[mod % i] * (mod - int(mod / i)) % mod]
  fac += [(fac[i-1] * i) % mod]
  finv += [(finv[i-1] * inv[i]) % mod]
def pow(x, n):
  ans = 1
  while(n > 0):
    if(bin(n & 1) == bin(1)):
      ans = ans*x%mod
    x = x*x%mod
    n = n >> 1 
  return ans
t=(pow(2,n)-1+mod)%mod
sa1,sa2,sb1,sb2=1,1,1,1
for i in range(1,a+1):
  sa1*=(n-i+1)
  sa1%=mod
sa=sa1*finv[a]%mod
for i in range(1,b+1):
  sb1*=(n-i+1)
  sb1%=mod
sb=(sb1*finv[b])%mod
print((t-sa-sb+mod)%mod)

Solution (Python):
import sys
from functools import reduce

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
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
print(answer % MOD)

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

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

def conv(n, k):
  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

ans = (ans - conv(n, a) - conv(n, b)) % MOD
print(ans)

Solution (Python):
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
k = 200010
fact = [0] * k
fact[0] = 1

for i in range(k-1):
  fact[i+1] = (fact[i] * (n - i) * pow((i+1), mod -2 , mod))% mod


ans = pow(2, n, mod) - fact[a] - fact[b] - 1
ans = ans % mod
print(ans)

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

mod = 10**9 + 7


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


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

print((pow(2, n, mod) - A - B - 1) % mod)

Solution (Python):
n,a,b=map(int, input().split())
 
def comb(n, r,MOD):
    p, q = 1, 1
    for i in range(r):
        p = p * (n-i) % MOD
        q = q * (i+1) % MOD
    return p * pow(q, MOD-2, MOD) % MOD

mod=10**9+7

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

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


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


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

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

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

mod = 1000000007

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

def modcombi(x, y):
  if x < y:
    return 0
  elif y == 0:
    return 1
  elif y > x-y:
    return modcombi(x, x-y)
  
  num = 1
  denom = 1
  
  for i in range(y):
    num *= (x-i)
    num %= mod
    denom *= (i+1)
    denom %= mod
  
  ans = num * modpow(denom, mod-2)
  return ans % mod

print( ( 2 * mod + modpow(2,n) - modcombi(n, a) - modcombi(n, b) ) % mod - 1)

Solution (Python):
n,a,b=map(int, input().split())
 
def comb(n, r,MOD):
    p, q = 1, 1
    for i in range(r):
        p = p * (n-i) % MOD
        q = q * (i+1) % MOD
    return p * pow(q, MOD-2, MOD) % MOD

mod=10**9+7
    
A=comb(n,a,mod)
B=comb(n,b,mod)  
C=pow(2,n,mod)

if n==2:
    print(0)
else:
    print((C-1-A-B)%mod)

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

def nck(n,r,mod):
    r=min(n,r)
    if r==0:
        return 1
    num,inv_num=1,1
    for i in range(1,r+1):
        num=num*(n-i+1)%mod
        inv_num=inv_num*i%mod
    return num*pow(inv_num,mod-2,mod)%mod

ans=pow(2,n,mod)
t=nck(n,a,mod)
s=nck(n,b,mod)
ans-=t+s+1
while ans<0:
  ans+=mod
print(ans)

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

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

a = min(a,n-a)
b = min(b,n-b)
if a > b:
    a,b = b,a

for i in range(n-a+1,n+1):
    x1 = x1 * i % MOD
x11 = 1
for i in range(1,a+1):
    x11 = x11 * i % MOD
x1 = x1 * pow(x11,MOD-2,MOD) % MOD

x2 = x1
for i in range(n-b+1,n-a+1):
    x2 = x2 * i % MOD
x21 = 1
for i in range(a+1,b+1):
    x21 = x21 * i % MOD
x2 = x2 * pow(x21,MOD-2,MOD) % MOD

t = []
nn = n
while nn > 0:
    t.append(nn % 2)
    nn //= 2
x0 = 1
for i in range(len(t)):
    x0 = x0 ** 2
    x0 = x0 % MOD
    if t[len(t)-i-1] == 1:
        x0 *= 2
        x0 = x0 % MOD
print ((x0 - x1 - x2 - 1) % MOD)

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

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

s, l = min(a, b), max(a, b)
s_factorial_inv = s_factorial_upper = l_factorial_inv = l_factorial_upper = m = 1

while True:
    if m <= s:
        s_factorial_inv *= m
        s_factorial_inv %= LARGE
        s_factorial_upper *= n - s + m
        s_factorial_upper %= LARGE
    if m <= l:
        l_factorial_inv *= m
        l_factorial_inv %= LARGE
        l_factorial_upper *= n - l + m
        l_factorial_upper %= LARGE
    else:
        break
    m += 1

nCs = pow(s_factorial_inv, LARGE - 2, LARGE) * s_factorial_upper
nCl = pow(l_factorial_inv, LARGE - 2, LARGE) * l_factorial_upper

print((pow(2, n, LARGE) - nCs - nCl - 1 + LARGE) % LARGE)

Solution (Python):
class Combination:
    '''MOD上の
    計算量：階乗・逆元テーブルの作成O(N)
    nCkを求めるO(1)'''

    def __init__(self, n, MOD):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % MOD)
        self.inv_fact = [pow(self.fact[i], MOD - 2, MOD) for i in range(n + 1)]
        self.MOD = MOD

    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]

    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]

    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[r]) % self.MOD

    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD

    def combination2(self, k, r):
        """kCrを求める O(r)
        kが大きいときに使える
        """
        if k < r:
            return 0
        res = 1
        for l in range(r):
            res *= (k - l)
            res %= self.MOD
        return (res * self.inv_fact[r]) % self.MOD

n, a, b = list(map(int, input().split()))
MOD = 10 ** 9 + 7
comb = Combination(2 * 10 ** 5 + 10, MOD)

ptn_a = comb.combination2(n, a)
ptn_b = comb.combination2(n, b)
ptn_n = pow(2, n, MOD) - 1

print((ptn_n - ptn_a - ptn_b) % MOD)

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

Solution (Python):
def cmb(n, r):
	if n - r < r:
		r = n - r
	if r == 0:
		return 1
	if r == 1:
		return n
	
	num = [n - r + k + 1 for k in range(r)] 
	den = [k + 1 for k in range(r)] 
	
	for p in range(2, r + 1):
		pivot = den[p - 1]
		if pivot > 1:
			offset = (n - r) % p
			for k in range(p - 1, r, p):
				num[k - offset] /= pivot
				den[k] /= pivot
	
	result = 1
	for k in range(r):
		if num[k] > 1:
			result *= int(num[k])
			result = result % mod
	
	return result

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

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

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

INF = (10**9 + 7)

def c(n,r,p):
    r = min(r,n-r)
    numer = 1
    denom = 1
    for i in range(1,r+1):
        numer = numer * (n+1-i) % p
        denom = denom * i % p
    return numer * pow(denom,p-2,p) % p

ans = pow(2,n,INF) - 1 - c(n,a,INF) - c(n,b,INF)

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

Solution (Python):

N, a, b=(int(i) for i in input().split())
import math
p = 10 ** 9 + 7
def binary(n):
    return bin(n)[2:]


def pow_by_binary_exponentiation(k, x, n): 
    x = [int(l) for l in binary(x)]
    y = k
    for i in range(1, len(x)):
        y = (y**2) % n
        if x[i] == 1:
            y = (y * k) % n
    return y

ans=(pow_by_binary_exponentiation(2,N,p)-1)
combA=1
combB=1
for i in range(a):
    combA*=(N-i)
    combA%=p
for i in range(b):
    combB*=(N-i)
    combB%=p

print((ans - combA*pow_by_binary_exponentiation(math.factorial(a), p-2, p) - combB*pow_by_binary_exponentiation(math.factorial(b), p-2,p))%p)

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


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



def pow_by_binary_exponentiation(a, x, n):
    x = [int(b) for b in binary(x)]
    y = a
    for i in range(1, len(x)):
        y = (y**2) % n
        if x[i] == 1:
            y = (y * a) % n
    return y


def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod


ac = combination(n, a, mod)
bc = combination(n, b, mod)
ans = pow_by_binary_exponentiation(2, n, mod)
print(((ans - ac - bc - 1) % mod)//1)

Solution (Python):
def comb(a, b, p=10 ** 9 + 7):
    if (b > a - b):
        return comb(a, a - b, p)
    c = d = 1
    for i in range(b):
        c *= (a - i)
        d *= (b - i)
        c %= p
        d %= p
    return c * modpow(d, p - 2, p) % p


def modpow(n, p, m=10 ** 9 + 7):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (modpow(n, p // 2, m) ** 2) % m
    return (modpow(n, p - 1, m) * n) % m


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


if __name__ == '__main__':
    resolve()

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def cmb(n, r, p):
  a=1
  for i in range(r):
    a*=n
    a%=mod
    n-=1
  b=1
  for i in range(1,r+1):
    b*=i
    b%=mod

  inv_b=mod_inv(b,mod)
  
  return a*inv_b

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

    return (K * x)%mod

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    
    return [w[0],w[1]]

def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def main():
  n,a,b=LI()
  if n==2:
    if a!=b:
      return 0
    else:
      return 1

  ans=pow_k(2,n)

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

  ans-=1
  ans%=mod

  if ans<0:
    ans+=mod

  return ans


print(main())

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy


from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) 

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

def main():
    n,a,b = inpm()
    ans = pow(2,n,mod) - 1
    ans += mod
    ans -= combination(n,a,b)
    print(ans%mod)
    
if __name__ == "__main__":
    main()

Solution (Python):
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):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    k=min(n-k,k)
    ans=1
    inv=[1]*(k+1)
    if k>=1:
        ans*=(n-k+1)%mod
    for i in range(2,k+1):
        inv[i]=mod-inv[mod%i]*(mod//i)%mod
        ans=ans*(n-k+i)*inv[i]%mod
    return ans

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

ans = power(2, n, MOD) - 1 - comb(n, a, MOD) - comb(n, b, MOD)

print(ans % MOD)

Solution (Python):
def pow2(n, mod):
    p = 2
    r = 1
    while n:
        if n % 2:
            r = r * p % mod
        p = (p * p) % mod
        n //= 2
    return r

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

def nCr(n, r, mod):
    t = 1
    r = min(r, n - r)
    for i in range(n - r + 1, n + 1):
        t = t * i % mod
    return t * g2[r] % mod



def prep(n, mod):
    for i in range(2, n):
        g1.append((g1[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod // i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)

def main():
    n, a, b = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    prep(2 * (10 ** 5) + 1, mod)
    print((pow2(n, mod) - 1 - nCr(n, a, mod) - nCr(n, b, mod))% mod)


main()

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

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    
    return [w[0],w[1]]

def mod_inv(a):
    x = extgcd(a,MOD)[0]
    return (MOD+x%MOD)%MOD

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

a = min(a,n-a)
b = min(b,n-b)
if a > b:
    a,b = b,a

for i in range(n-a+1,n+1):
    x1 = x1 * i % MOD
x11 = 1
for i in range(1,a+1):
    x11 = x11 * i % MOD
x1 = x1 * mod_inv(x11) % MOD

x2 = x1
for i in range(n-b+1,n-a+1):
    x2 = x2 * i % MOD
x21 = 1
for i in range(a+1,b+1):
    x21 = x21 * i % MOD
x2 = x2 * mod_inv(x21) % MOD

t = []
nn = n
while nn > 0:
    t.append(nn % 2)
    nn //= 2
x0 = 1
for i in range(len(t)):
    x0 = x0 ** 2
    x0 = x0 % MOD
    if t[len(t)-i-1] == 1:
        x0 *= 2
        x0 = x0 % MOD
print ((x0 - x1 - x2 - 1) % MOD)

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

bb = ncr(n,a,p)+ncr(n,b,p)+1
print((pow(2,n,p)-(bb%p))%p)

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

def mod_combination(n, r, mod):
    numerator = 1
    for i in range(n-r+1, n+1):
        numerator = (i * numerator) % mod
    denominator = 1
    for i in range(1, r+1):
        denominator = (i * denominator) % mod
    fermat = pow(denominator, mod-2, mod)
    return (numerator * fermat) % mod

def solve(n, a, b):
    k = pow(2, n, M)
    ac = mod_combination(n, a, M)
    ab = mod_combination(n, b, M)

    ans = k - ac - ab - 1
    while ans < 0:
        ans += M
    return ans

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

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

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

inv = [1] * (b + 1)
inv[-1] = pow(fact[-1], mod-2, mod)
for i in range(1, b):
    inv[-1-i] = (inv[-1-i+1] * (b-(i-1))) % mod

def nCr(n, r):
    ret = 1
    for i in range(r):
        ret = (ret * (n - i) % mod) % mod
    return (ret * inv[r]) % mod

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

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

class remainder():
    def __init__(self, mod=(10**9 + 7)):
        self.mod = mod
    
    def sub(self, a, b):

        return (a + self.mod - b) % self.mod
    
    def mul(self, a, b):

        return ((a % self.mod) * (b % self.mod)) % self.mod

    def pow(self, a, b):
        bp = []
        
        bp.append(a)

        n = len(bin(b)) - 2
        for x in range(n):
            bp.append(bp[x]**2 % self.mod)

        res = 1
        for x in range(n):
            if b >> x & 1:
                
                res = (res * bp[x]) % self.mod
        
        return res

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

com = [0] * (B + 1)
com[0] = 1

re = remainder()

ans = re.pow(2, N) - 1
for x in range(1, B + 1):
    s = re.sub(N, x) + 1
    d = re.div(s, x)
    com[x] = re.mul(com[x - 1], d)


subA = com[A]
subB = com[B]

ans = re.sub(ans, subA)
ans = re.sub(ans, subB)

print(ans)

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

 
def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = (numer*(n1-i)) % mod
        denom = (denom*i) % mod
    return numer * pow(denom, mod-2, mod) % mod

mod=10**9+7

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

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

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

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


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

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

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

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


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

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

if __name__ == "__main__":
    main()

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)

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

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