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



Sample input:
4 1 3


Sample output:
7

Submission status: Accepted

Solution code:
K = 10**9 + 7

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

# 組み合わせ計算
# 約分してから計算するアルゴリズム
# 10^9 + 7 で割ったあまりを返すバージョン
MOD = 1000000007

def combination(n, r):
    # n >= 0, r >= 0, r <= n を仮定
    if n < 0 or r < 0 or n < r:
        return -1

    # r <= n - r を仮定
    if n - r < r:
        r = n - r

    # r < 2 の場合
    if r == 0:
        return 1
    if r == 1:
        return n

    # nCr の分子
    # [n - r + 1, n - r + 2, ... , n - 1, n]
    numerator = [n - r + 1 + i for i in range(r)]


    # nCr の分母
    # [1, 2, ... , r - 1, r]
    denominator = [i + 1 for i in range(r)]

    # nCr を約分する
    for i in range(r):
        # i番目の分母で約分する
        # 0番目は1なので省略

        # 元の（今までの約分を行う前の）i番目の分母の値
        original_denominator = i + 1

        # 今までの約分を行った後の、i番目の分母の値
        # 今回の約分で割る数
        divisor = denominator[i]

        # divisorが1（全て約分済み）の場合は無視する
        if divisor == 1:
            continue

        # 約分する相手の分子を決める
        # 0～i番目の分子（約分前）の中で、
        # original_denominatorで割り切れる数
        # （一つしかない）を選ぶ
        # remainder = i番目の分子 % original_denominator
        # とするとき、
        # (i - remainder)番目の分子 = i番目の分子 - remainder
        # (i - remainder)番目の分子 % original_denominator
        #  = (i番目の分子 - remainder) % original_denominator
        #  = 0
        # なので、(i - remainder)番目の分子を選べばよい。

        # remainder = i番目の分子 % original_denominator
        #           = (n - r + i + 1) % (i + 1)
        #           = (n - r) % (i + 1)
        remainder = (n - r) % original_denominator

        # divisor で約分できるペアをすべて約分する
        for j in range(i, r, original_denominator):
            numerator[j - remainder] = numerator[j - remainder] // divisor
            denominator[j] = denominator[j] // divisor

    ans = 1
    for i in numerator:
        ans = (ans * i) % MOD
    return ans

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

Submission status: Accepted

Solution code:
def mod_com(n, k, mod):
    def ext_gcd(a, b):
        if b == 0:
            return a, 1, 0
        else:
            d, x, y = ext_gcd(b, a % b)
            x -= (a // b)*y
        return d, y, x
    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 int(p * (ext_gcd(q, mod)[1] % mod) % mod)


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

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


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

    MOD = 10 ** 9 + 7
    factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
    inv = [0, 1]  # for factinv calcuration
    for i in range(2, B + 1):
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)

    res = 2 ** N - 1
    res %= MOD

    a = 1
    r = min(N - A, A)
    for i in range(N, N - r, -1):
        a *= i
        a %= MOD
    a = a * factinv[r] % MOD

    b = 1
    r = min(N - B, B)
    for i in range(N, N - r, -1):
        b *= i
        b %= MOD
    b = b * factinv[r] % MOD

    res -= a
    res -= b
    res %= MOD
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
MOD = 10**9 + 7
ans = pow(2, n, MOD)
ans -= 1 # select no flowers

def ncr(n, r, MOD):
  res = 1
  for i in range(r):
    res = res*(n-i)%MOD
  
  f = [1]*(r+1)
  inv = [1]*(r+1)

  for i in range(r):
    f[i+1] = f[i]*(i+1)%MOD
  
  inv[r] = pow(f[r], MOD-2, MOD)
  
  for i in range(r, 0, -1):
    inv[i-1] = inv[i]*i%MOD
    
  return res*inv[r]%MOD
    
ans -= ncr(n, a, MOD)
ans -= ncr(n, b, MOD)

print(ans%MOD)

Submission status: Accepted

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

nCa = 1
for i in range(n - a + 1, n + 1): #n*(n-1)*…*(n-a+1)
    nCa *= i
    nCa %= mod
for i in range(1, a + 1): #1/a
    nCa *= pow(i, mod - 2, mod)
    nCa %= mod

nCb = 1
for i in range(n - b + 1, n + 1): #n*(n-1)*…*(n-b+1)
    nCb *= i
    nCb %= mod
for i in range(1, b + 1): #1/b
    nCb *= pow(i, mod - 2, mod)
    nCb %= mod

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

Submission status: Accepted

Solution code:
MOD = 1000000007
def mod(n):         
  return n % MOD
def multiply(a, b): #mod(a*b)を求める
  return mod(mod(a)*mod(b))
def divide(a, b):   #mod(a / b)を求める
  ans = mod(a) * inverse(b)
  return mod(ans)
def modpow(a, n):   #mod(a**n)を高速で求める
    res = 1  
    digit = len(str(bin(n))) - 2
    for i in range(digit):
      if (n >> i) & 1:
        res *= mod(a)
        res = mod(res)
      a = mod(a**2)
    return mod(res)
def inverse(a):     #aの逆元を求める
  return modpow(a, MOD-2)
def comb(n, k):
  res = 1
  for i in range(k):
    res = multiply(res, n - i) 
  for i in range(k):
    res = divide(res, i + 1)
  return mod(res)

n, a, b = map(int, input().split())
ans = modpow(2, n) - 1
resa = comb(n, a)
resb = comb(n, b)
print(mod(ans - resa - resb))

Submission status: Accepted

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

# 全通りーa本の通りーb本の通り
# 全通り→ 2**n-1
p = 10**9+7
ansAll = pow(2,n,p)
ansAll -= 1

# a本の通り→X*Y**p-2, X=n*n-1*...をa回, Y=a*a-1*...をa回
X = 1
Y = 1
for i in range(a):
    X = X*(n-i)%p
    Y = Y*(a-i)%p
ansA = pow(Y,p-2,p)
ansA = (ansA*X)%p

# bも同様
X = 1
Y = 1
for i in range(b):
    X = X*(n-i)%p
    Y = Y*(b-i)%p
ansB = pow(Y,p-2,p)
ansB = (ansB*X)%p

ans = (ansAll - ansA - ansB)%p

print(ans)

Submission status: Accepted

Solution code:
import math


n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
x_b = 1
y_b = 1
for i in range(b):
    x_b = x_b * (n - i) % mod
    y_b = y_b * (i + 1) % mod
    if i == a - 1:
        x_a = x_b
        y_a = y_b
z_a = x_a * pow(y_a, mod - 2, mod)
z_b = x_b * pow(y_b, mod - 2, mod)
print((pow(2, n, mod) - 1 - z_a - z_b) % mod)

Submission status: Accepted

Solution code:
from functools import reduce

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

def combi_mod(n, r, mod):
    numerator = reduce(lambda x, y: x * y % mod, [n-i for i in range(r)])
    denominater = reduce(lambda x, y: x * y % mod, [i+1 for i in range(r)])
    return numerator * pow(denominater, mod - 2, mod) % mod

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

# 強化版cmb
def cmb(x,y):
    r=1
    for i in range(1,y+1):
        # 5C3なら
        # 5 * 4 * 3 / 3 * 2 * 1
        # = 5(mod m) * 1 / 3(mod m) * 4 (mod m) * 1 / 2(mod m) * 3(mod m) * 1 / 1(mod m)
        # (x- i + 1): 5 - 1 + 1...
        # pow(i,m-2,m):
        # フェルマーの小定理 a ** (m - 2) (mod m) = 1 / a (mod d)
        # 1 / a (mod m) はaで掛けると1 (mod m)になる数
        # 1 / 2なら500000004
        r=(r*(x-i+1)*pow(i,m-2,m))%m
    return r
# powでmod累乗を楽にできる
print((pow(2,n,m)-1-cmb(n,a)-cmb(n,b))%m)

Submission status: Accepted

Solution code:
n,a,b = [int(x) for x in input().split()]
mod = 10**9 + 7
def comb(x,y):
    child = 1
    mother = 1
    for i in range(y):
        child = child * (x-i)%mod
        mother = mother * (i+1)%mod
    return child * pow(mother,mod-2,mod) % mod
ans = pow(2,n,mod) - 1 - comb(n,a) - comb(n,b)
print(ans%mod)

Submission status: Accepted

Solution code:
n,a,b = [int(x) for x in input().split()]
mod = 10**9 + 7
def comb(x,y):
    child = 1
    mother = 1
    for i in range(y):
        child = child * (x-i)%mod
        mother = mother * (i+1)%mod
    return child * pow(mother,mod-2,mod) % mod
ans = pow(2,n,mod) - 1 - comb(n,a) - comb(n,b)
print(ans%mod)

Submission status: Accepted

Solution code:
n,a,b = [int(x) for x in input().split()]
mod = 10**9 + 7
def comb(x,y):
    child = 1
    mother = 1
    for i in range(y):
        child = child * (x-i)%mod
        mother = mother * (i+1)%mod
    return child * pow(mother,mod-2,mod) % mod
ans = pow(2,n,mod) - 1
ans -= comb(n,a)
ans %= mod
ans -= comb(n,b)
ans %= mod
print(ans)

Submission status: Accepted

Solution code:
import math
from functools import reduce
MOD = 10**9+7
N, A, B = [int(i) for i in input().split(' ')]


def combination_mod(n,r):
    a = reduce(lambda x, y : x * y % MOD, range(n, n-r, -1))
    b = reduce(lambda x, y: x * y % MOD, range(1,r+1))
    return a * pow(b, MOD-2 ,MOD) % MOD

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

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
M=10**9+7
sum=pow(2,n,M)-1
def inverse(number,mod):
    m=mod-2
    mod2=""
    while m!=0:
        if m%2==0:
            mod2="0"+mod2
        else:
            mod2="1"+mod2
        m=m//2
    two=[]
    for i in range(len(mod2)):
        if mod2[len(mod2)-1-i]=="1":
            two.append(i)
    ret=1
    for i in two:
        v=i
        retsub=number
        while v>0:
            retsub=retsub**2
            retsub=retsub%mod
            v-=1
        ret*=retsub
    ret=ret%mod
    return ret
def cal(num,r,mod):
    ret1=1
    for i in range(0,r):
        ret1*=(num-i)
        ret1%=mod
    r_factorial=1
    for i in range(1,r+1):
        r_factorial*=i
        r_factorial%=M
    ret2=inverse(r_factorial,mod)
    ret=(ret1*ret2)%mod
    return ret

ans=sum-cal(n,a,M)-cal(n,b,M)
print(ans%M)

Submission status: Accepted

Solution code:
def combi_mod(n, r, mod):
    child = 1
    mother = 1
    for i in range(r):
        child = child * (n-i) % mod
        mother = mother * (i+1) % mod
    return child * pow(mother, mod-2, mod) % mod

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

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

Submission status: Accepted

Solution code:
mod = 10**9+7

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

# 全ての場合の数
ans = pow(2,n,mod)-1

# a本の場合の数(nCa = a1/a2)
# a1 = n*(n-1)*...*(n-(a-1))の計算
a1 = 1
for i in range(a) :
  a1 = a1*(n-i)%mod
# 1/a2 = (1/a)*(1/(a-1))*...*(1/1)の計算
a2 = 1
for i in range(a) :
  a2 = a2*pow(a-i,mod-2,mod)%mod
  
# b本の場合の数(nCb = b1/b2)
# b1 = n*(n-1)*...*(n-(b-1))の計算
b1 = 1
for i in range(b) :
  b1 = b1*(n-i)%mod
# 1/b2 = (1/b)*(1/(b-1))*...*(1/1)の計算
b2 = 1
for i in range(b) :
  b2 = b2*pow(b-i,mod-2,mod)%mod

print((ans-a1*a2-b1*b2)%mod)

Submission status: Accepted

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

def cmb(x,y):

    r=1

    for i in range(1,y+1):

        r=(r*(x-i+1)*pow(i,m-2,m))%m
        
    return r
print((pow(2,n,m)-1-cmb(n,a)-cmb(n,b))%m)

Submission status: Accepted

Solution code:
N,A,B = list(map(int,input().split()))
mod = 10** 9+7
pattern_all = pow(2,N,mod)-1
def C(N,A,mod):
    high = N
    low =  A
    for i in range(1,A):
        high = high * (N-i) % mod
        low = low * (A-i) % mod
    return (high * pow(low,mod-2,mod))%mod
af_a = C(N,A,mod)
af_b = C(N,B,mod)
print((pattern_all-af_a-af_b)%mod)

Submission status: Accepted

Solution code:
def mod_c(n, r, m):
    num, den = 1, 1
    for i in range(1, r + 1):
        num = num * (n - i + 1) % m
        den = den * i % m
    return (num * pow(den, m - 2, m)) % m

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

Submission status: Accepted

Solution code:
MOD = 1000000007
NCK_MAX = 510000

fac = [0 for _ in range(NCK_MAX)]; finv = [0 for _ in range(NCK_MAX)]
inv = [0 for _ in range(NCK_MAX)]; facn = [0 for _ in range(NCK_MAX)]

def myPow(x,n,MOD=MOD):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return myPow(x*x%MOD,n//2)
    else:
        return x*myPow(x,n-1)%MOD

def COMinit(n):
    fac[0] = 1; fac[1] = 1
    facn[1] = n
    finv[0] = 1; finv[1]=1
    inv[1]=1
    for i in range(2,NCK_MAX):
        fac[i] = fac[i-1]*i%MOD
        facn[i] = facn[i-1]*(n-i+1)%MOD
        inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
        finv[i] = finv[i-1]*inv[i]%MOD

def modinv(a,MOD=MOD):
    return myPow(a,MOD-2)

def COM(n,k):
    if n<k:
         return 0
    elif n<0 and k<0:
         return 0
    return facn[k] * finv[k]%MOD

n,a,b = map(int,input().split())
COMinit(n)
ans = (myPow(2,n)-1+MOD)%MOD
ans = (ans-COM(n,a)+MOD)%MOD
ans = (ans-COM(n,b)+MOD)%MOD
print(ans)

Submission status: Accepted

Solution code:
mod=10**9+7
l,a,b=map(int,input().split())
def C(n,k,m):
  g=k
  f=n
  for i in range(1,k):
    n=n*(f-i)%m
    k=k*(g-i)%m
  return (n*pow(k,m-2,m))%m
ans=pow(2,l,mod)-1
ca=C(l,a,mod)
cb=C(l,b,mod)
print((ans-ca-cb)%mod)

Submission status: Accepted

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

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

print((pow(2, N, P) - 1 - C(N, A) - C(N, B)) % P)

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
mod=int(1e9+7)
def nCr(a,b):
  global mod
  res = 1
  for i in range(1,b+1):
    res = res * (n-i+1) % mod * pow(i,mod-2,mod) % mod
  return res%mod
print((pow(2,n,mod) - 1 - nCr(n,a) - nCr(n,b) + 2*mod ) % mod)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
mod = 1000000007

def cmb(n, r, mod):
    n_1 = 1
    n_2 = 1

    r = min(r, n-r)
    for i in range(1, r+1):
        n_1 = n_1 * i % mod
        n_2 = n_2 * (n - i + 1) % mod

    return (n_2 * pow(n_1, mod - 2, mod))%mod

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

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

Submission status: Accepted

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

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

    return res

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

def cmb(n,r,m):
    X = Y = 1
    r = min(r,n-r)
    for i in range(1,r+1):
        Y = Y*i%m
        X = X*(n-i+1)%m
    Y = pow(Y,m-2,m)
    return X*Y
print((pow(2,n,m)-1-cmb(n,a,m)-cmb(n,b,m))%m)

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
mod = 1000000007
all_comb = pow(2, n, mod)

def inv(k):
    return pow(k, mod - 2, mod)

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

ans = all_comb - 1 - comb(a) - comb(b)
print(ans % mod)

Submission status: Accepted

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

def combn(n, r, m):
    X = Y = 1
    if n-r < r:
        r = n-r
    for i in range(1, r+1):
        Y = Y*i % m
        X = X*(n-i+1) % m
    Y = pow(Y, m-2, m)
    return X*Y
  
print((pow(2, n, m) - 1 - combn(n, a, m) - combn(n ,b, m)) % m)

Submission status: Accepted

Solution code:
import math
n,a,b=map(int,input().split())
m=10**9+7
ans=pow(2,n,m)

# X=for i in range
s=1
ss=1
for i in range(a):
    s*=(n-i)
    if(s>m):s=s%m
    ss*=(a-i)
    if(ss>m):ss=ss%m
X=s
Y=ss
Y=pow(Y,m-2,m)
ans-=X*Y%m
s= 1
ss=1
for i in range(b):
    s*=(n-i)
    if(s>m):s=s%m
    ss*=(b-i)
    if(ss>m):ss=ss%m
X=s
Y=ss
Y=pow(Y,m-2,m)
ans-=X*Y%m

print(ans%m-1)

Submission status: Accepted

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

def func(n, i):
    x = 1
    y = 1
    for j in range(1, i+1):
        x = (x * (n - (j - 1))) % m
        y = (y * j) % m
    return (x * pow(y, m-2, m)) % m

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

Submission status: Accepted

Solution code:
def input_multiple_number():
    return map(int, input().split())

def cmb_mod(n,r,mod):
    x=1
    y=1
    if n/2<r:
        r=n-r
    for i in range(r):
        x*=n-i
        if x>mod:
            x%=mod
        y*=r-i
        if y>mod:
            y%=mod
    val=x*pow(y,mod-2,mod)%mod #pow(y,mod-2,mod)モジュラ逆数
    return val

def modulo(a,mod):
    return (a % mod + mod) % mod


n_given,a_given,b_given = input_multiple_number()

MOD = 10 ** 9 + 7
mod = MOD
ans = pow(2,n_given,MOD)

ans -= cmb_mod(n_given,a_given,mod)
ans -= cmb_mod(n_given,b_given,mod)


ans = modulo(ans,mod) - 1
print(ans)

Submission status: Accepted

Solution code:
mod=10**9+7
import math

def co(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
    
n,a,b=map(int,input().split())
ans=pow(2,n,mod)-1-co(n,a,mod)-co(n,b,mod)
print(ans%mod)#ansにmod取らないと無理

Submission status: Accepted

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

def cmb(n, r, p):
    up = 1
    down = 1
    count = r
    for i in range(n + 1):
        if count <= 0:
            break
        else:
            up = up * (n - i) % p
            down = factinv[i + 1]
            count -= 1
    return ((up * down) % p)

def pow(a, n, p):
    bi = str(format(n, 'b'))
    res = 1
    for i in range(len(bi)):
        res = (res * res) % p
        if bi[i] == '1':
            res = (res * a) % p
    return res
                      
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, 2 * 10**5 + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

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

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
mod = 10 **9 +7
fac = [1] * 200001
inv = [1] * 200001
for i in range(1,len(fac)):
    fac[i] = fac[i-1] * i % mod
    inv[i] = pow(fac[i], mod-2, mod)

facna = 1
facnb = 1
for i in range(n-a+1,n+1):
    facna = facna * i %mod
for i in range(n-b+1,n+1):
    facnb = facnb * i %mod
ret = pow(2,n,mod) - 1 - facna * inv[a] - facnb * inv[b]
ret = ret%mod
print(ret)

Submission status: Accepted

Solution code:
import math

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

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

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

    fact = [0 for i in range(NMAX+5)]
    fact[0] = 1
    invfact = [0 for i in range(NMAX+5)]
    invfact[0] = 1

    for i in range(NMAX):
        fact[i+1] = (fact[i]*(i+1))%(MOD)

    invfact[NMAX] = pow(fact[NMAX], MOD-2, MOD)
    for i in range(NMAX-1,0,-1):
        invfact[i] = (invfact[i+1] * (i+1)) % MOD

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

    pa = calcp(n,a,MOD)*invfact[a]%MOD
    pb = calcp(n,b,MOD)*invfact[b]%MOD
    ans = ans - pa - pb;
    while ans < 0:
        ans += MOD
    print(ans)

        

main()

Submission status: Accepted

Solution code:
n,a,b = map(int,input().split())
mod = 10**9 + 7
aue,bue = 1,1
for i in range(a):
    aue = aue * (n-i) % mod
for i in range(b):
    bue = bue * (n-i) % mod
asita,bsita = 1,1
for i in range(1,a+1):
    asita = asita*i %mod
for i in range(1,b+1):
    bsita = bsita*i %mod
at = aue * pow(asita,mod-2,mod)
bt = bue * pow(bsita,mod-2,mod)

ans = (pow(2,n,mod) - 1 -at -bt)%mod
print(ans)

Submission status: Accepted

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

def comb(n, k):
    bunshi = 1
    bunbo = 1
    for i in range(k):
        bunshi = bunshi * (n - i) % mod
        bunbo = bunbo * (i + 1) % mod
    return bunshi * inv(bunbo) % mod


all_num = pow(2, n, mod)

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

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
mod = 1000000007
def inv(y, mod):
    return pow(y, mod - 2, mod)
 
def comb(n, a, mod):
    x = 1
    y = 1
    for i in range(a):
        x = x * (n - i) % mod
        y = y * (i + 1) % mod
    return (x * inv(y, mod)) % mod
    
print((pow(2, n, mod) - 1 - comb(n, a, mod) - comb(n, b, mod)) % mod)

Submission status: Accepted

Solution code:
import math

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

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

def mod_inv_table(k):
    table = [-1] * (k+1)
    for i in range(1,k+1):
        table[i] = mod_inv(i,10**9+7)
    return table

def binomial(n,k,table):
    ret = 1
    for i in range(k):
        ret *= n-i
        ret *=table[i+1]
        ret %= 10**9+7
    return ret
    

tablea = mod_inv_table(a)
tableb = mod_inv_table(b)
ka = binomial(n,a,tablea)
kb = binomial(n,b,tableb)
alla = pow(2,n,10**9+7)
z = alla - ka -kb -1
print(z%(10**9+7))

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
MOD = 10**9+7
ans = pow(2, n, MOD)-1
X = Y = 1
for i in range(1, b+1):
    Y = Y*i % MOD
    X = X*(n-i+1) % MOD
    if i == a or i == b:
        ans -= X*pow(Y, MOD-2, MOD)

print(ans % MOD)

Submission status: Accepted

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

def comb(n, k, p):
    if k > n-k:
        return comb(n, n-k, p)
    num, den = 1, 1
    for i in range(k):
        num = num * (n-i) % p
        den = den * (i+1) % p
    return num * pow(den, p-2, p) % p

print((total - 1 - comb(n,a,M) - comb(n,b,M)) % M)

Submission status: Accepted

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

def comb(n, k, p):
    if k > n-k:
        return comb(n, n-k, p)
    num, den = 1, 1
    for i in range(k):
        num = num * (n-i) % p
        den = den * (i+1) % p
    return num * pow(den, p-2, p) % p

print((total - 1 + (M - comb(n,a,M)) + (M - comb(n,b,M))) % M)

Submission status: Accepted

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


def COM(n, r):
    X = Y = 1
    if n-r < r:
        r = n-r
    for i in range(1, r+1):
        Y = Y*i % MOD
        X = X*(n-i+1) % MOD
    Y = pow(Y, MOD-2, MOD)
    return X*Y

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

print(ans)

Submission status: Accepted

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


def COM(n, r):
    X = Y = 1
    if n-r < r:
        r = n-r
    for i in range(1, r+1):
        Y = Y*i % MOD
    Y = pow(Y, MOD-2, MOD)
    while 0 < r:
        X = X*n % MOD
        n -= 1
        r -= 1
    return X*Y


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

print(ans)

Submission status: Accepted

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

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

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

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

n,a,b=map(int,input().split())
mod=1000000007
print((pow(2,n,mod)-1-binomial_coefficients(n, a)-binomial_coefficients(n, b))%mod)

Submission status: Accepted

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

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

# 全く分からん
for i in range(1, b+1):
    product = product * (n-i+1) % mod
    div = div*i % mod
    if i == a or i == b:
        ans -= product * pow(div, mod-2, mod)

print(ans % mod)