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: Runtime Error

Solution code:
import sys
import math
import itertools
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()


def inv_mod(a, N):
    """
    ユークリッドの互除法より
    aの逆元 ax = 1 (mod N)を満たすxを返す。
    O(log a)
    """

    def extgcd(a, b):
        """
        Extended Great Common Divisor
        ax + by = gcd(a, b) = dを満たすx, y, dを返す。
        """
        d = math.gcd(a, b)
        if b == 0:
            return 1, 0, a
        else:
            q, r = divmod(a, b)
            x, y, d = extgcd(b, r)
            s, t = y, x - q * y
            return s, t, d

    return extgcd(a, N)[0]


def bpm(x, y, N):
    """
     Bisection power method : 二分累乗法
     O(log y)でx^(y) mod N を求める。
    """
    ans = 1
    x %= MOD
    digit = int((math.log2(y) // 1 + 1))  # yの２進数表示の桁数
    for i in range(digit):
        if (y >> i) & 1 == 1:
            ans *= x
            ans %= MOD
        x **= 2
        x %= MOD
    return ans


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

nCa = 1
nCb = 1

inv_list = []

for i in range(max(a, b)):
    inv_list.append(inv_mod(i + 1, MOD))

for i in range(a):
    nCa *= inv_list[i]
    nCa %= MOD
    nCa *= n - i
    nCa %= MOD

for i in range(b):
    nCb *= inv_list[i]
    nCb %= MOD
    nCb *= n - i
    nCb %= MOD

print((bpm(2, n, MOD) -1 - nCa - nCb) % MOD)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
S = []
n, a, b = map(int, input().split())
for i in range(1, n+1):
    c = comb(n, i, exact=True)
    S.append(c)
d = sum(S)
e = comb(n, a, exact=True)
f = comb(n, b, exact=True)
g = comb(n, 0, exact=True)
h = d - (e + f + g)
print(h//10**9+7)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
S = []
n, a, b = map(int, input().split())
for i in range(1, n+1):
    c = comb(n, i, exact=True)
    S.append(c)
print(S)
d = sum(S)
e = comb(n, a, exact=True)
f = comb(n, b, exact=True)
g = comb(n, 0, exact=True)
h = d - (e + f + g)
print(h//10**9+7)

Submission status: Runtime Error

Solution code:
n,a,b = map(int,input().split())
inf = 10**9 +7
ans = pow(2,n,inf)-1
def conbi(n,k):
  if n-k < k:
    k = n-k
  x = 1
  y = 1
  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  -= conbi(n,a) + conbi(n,b)
ans = ans%inf
print(ans)

Submission status: Runtime Error

Solution code:
n,a,b = map(int,input().split())
inf = 10**9 +7
ans = pow(2,n,inf)-1
def conbi(n,k):
  if n-k < k:
    k = n-k
  x = 1
  y = 1
  for i in range(k):
    x *= n-i
    x = x%inf
    y *= i+1
    y = y%inf
    ans1 = x* pow(y,inf-2,inf)%inf
  return ans1
sol = ans - conbi(n,a)- conbi(n,b)
print(sol%inf)

Submission status: Runtime Error

Solution code:
n,a,b = map(int,input().split())
inf = 10**9 +7
ans = pow(2,n,inf)-1
def conbi(n,k):
  if n-k < k:
    k = n-k
  x = 1
  y = 1
  for i in range(k):
    x *= n-i
    x = x%inf
    y *= i+1
    y = y%inf
    ans1 = x* pow(y,inf-2,inf)%inf
  return ans1
print(conbi(n,a))
sol = ans - conbi(n,a)- conbi(n,b)
print(sol)

Submission status: Runtime Error

Solution code:
n,a,b=map(int, input().split())
 
def comb(n, r,MOD):
  	r=min(r,n-r)
    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)

Submission status: Runtime Error

Solution code:
    def solve():
     
        n, a, b = map(int, input().split())
        mod = 10**9 + 7
     
        # 繰り返し二乗法 使ってない
        def modPow(a, n, mod):
            if n == 1:
                return a
            elif n%2 == 1:
                return a * modPow(a, n-1, mod) % mod
            else:
                t = modPow(a, n/2, mod)
                return (t * t) % mod
     
        def combination(n, a, mod):
            x = 1
            y = 1
            for i in range(a):
                x = x * (n-i)%mod
                y = y * (a-i)%mod
                #遅い
                #x *= (n-i)%mod
                #y *= (a-i)%mod
            return x * pow(y, mod-2, mod)%mod
     
        #全ての選び方
        sigma_nCi = pow(2, n, mod)
        # nCa, nCb
        nCa = combination(n, a, mod)
        nCb = combination(n, b, mod)
     
        ans = sigma_nCi - 1 - nCa - nCb
     
        #print(Sigma_nCi, nCa, nCb)
        print(ans%mod)
     
    if __name__ == '__main__':
        solve()

Submission status: Runtime Error

Solution code:
# coding: utf-8
def modcomb(n, r, mod):
    "nCr = X/Yとおく"
    r = min(r, n - r)
    X, Y = 1, 1
    # a, b, c = 1, 1, 1
    for i in range(1, n + 1):
        X = X * (n + 1 - i) % mod
        Y = Y * i % mod
        a = a * i % mod
    for i in range(1, r + 1):
        b = b * i % mod
        c = c * (n - i + 1) % mod
    return a * pow((b * c) % mod, mod-2, mod) % 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)
# ans %= mod
b = modcomb(N, B, mod)
ans -= a + b
print(ans % mod)

Submission status: Runtime Error

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

MOD = 10**9 + 7
m = 2*10**5
mm = 2** m

ans = 1
for _ in range(n // m):
  ans = (ans * mm) % MOD

ans = (ans * 2**(n % m)) % MOD  
    
ans = (ans - 1) % MOD

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

print(ans)

Submission status: Runtime Error

Solution code:
def cmb(n, r, p):
	if (r < 0) or (n < r):
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % p


def cmb(n, r, p):
	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  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

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)


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

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)

N, A, B = map(int, input().split())
mo = 10 ** 9 + 7
def hanaya(n, x):
    if x == 1:
        return n
    else:
        return ((hanaya(n, x-1))*((n-x+1)/x))%mo
    
ans = (pow(2, N, mo) - 1 - hanaya(N, A)- hanaya(N, B)) % mo
print(int(ans))

Submission status: Runtime Error

Solution code:
N, A, B = map(int, input().split())
mo = 10 ** 9 + 7
def hanaya(n, x):
    if x == 1:
        return n
    else:
        return ((int((hanaya(n, x-1))*((n-x+1)/x))%mo))

ans = (pow(2, N, mo) - 1 - hanaya(N, A)- hanaya(N, B)) % mo
print(int(ans))

Submission status: Runtime Error

Solution code:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#include <conio.h>
using namespace std;

typedef long long int ll;
typedef pair<ll,ll> pll;

#define rep(i,n)	for(ll i=0;i<(n);i++)
#define SZ(x) ((ll)x.size())
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define F first
#define S second
#define int ll
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll MOD = INT_MAX;
const double PI = acos(-1);

void openfile(){
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
}

const int mod = 1e9+7;
int mul(int a,int b){
	return a * b % mod;
}
int add(int a,int b){
	a += b;
	if(a >= mod)	a -= mod;
	if(a < 0)		a += mod;
	return a;
}
int exp_pow(int n, int expo){
	int res = 1,base = n,cur_exp = 1;
	while(cur_exp <= expo){
		if(cur_exp & expo)	res = mul(res, base);
		base = mul(base, base);
		cur_exp <<= 1;
	}
	return res;
}
int C(int n,int m){
	int res = 1;
	if(n == m)	return res;
	if(n-m < m)	m = n-m;
	int res2 = 1;
	rep(i,m)	res = mul(res, n-i);
	rep(i,m)	res2 = mul(res2, i+1);
	res2 = exp_pow(res2, mod-2);

	return mul(res, res2);
}

signed main(){
	IOS
	int n,a,b;	cin >> n >> a >> b;

	// ans : (2^n - C(n,a) - C(n,b) - 1) % mod

	int comb = exp_pow(2,n) - 1;
	comb = add(comb, -C(n,a));
	comb = add(comb, -C(n,b));
	cout << comb << endl;


}

Submission status: Runtime Error

Solution code:
def ten_to_n(X, n):
    i = int(X / n)
    s = str(X % n)
    if (i):
        return ten_to_n(i, n) + s
    return s

def solve():
    N, M = map(int, input().split())
    n = ten_to_n(N, M)
    return len(n)
 
print(solve())

Submission status: Runtime Error

Solution code:
def cmb(n, r, p):
	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  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

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)


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

Submission status: Runtime Error

Solution code:
from scipy.misc import comb
MOD = 10 ** 9 + 7
N, a, b = map(int, input().split())
ans = pow(2, N) - 1 - comb(N, a) - comb(N, b)
print(ans % MOD)

Submission status: Runtime Error

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

#output
mod = pow(10, 9) + 7

n_ = pow(10, 9) + 1
fun = [1]*(n_+1)
for i in range(1,n_+1):
    fun[i] = fun[i-1]*i%mod
rev = [1]*(n_+1)
rev[n_] = pow(fun[n_],mod-2,mod)
for i in range(n_-1,0,-1):
    rev[i] = rev[i+1]*(i+1)%mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod

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

Submission status: Runtime Error

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

#output
mod = 10**9 + 7

n_ = 10**9 + 1
fun = [1]*(n_+1)
for i in range(1,n_+1):
    fun[i] = fun[i-1]*i%mod
rev = [1]*(n_+1)
rev[n_] = pow(fun[n_],mod-2,mod)
for i in range(n_-1,0,-1):
    rev[i] = rev[i+1]*(i+1)%mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod

answer = 2**n - 1 - cmb(n, a) - cmb(n, b)
print(answer % mod)

Submission status: Runtime Error

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

count=0
mod=10**9+7

def C(n,a):
    x=1
    y=1
    for i in range(a):
        x*=n-i
        y*=i+1
    return x/y

count+=pow(2,n,mod)
#print(count)
count-=1
count-=C(n,a)
#print(count)
count-=C(n,b)

print(int(count%mod))

Submission status: Runtime Error

Solution code:
#include<iostream>
#define int long long int
using namespace std;
const int N = 1e5;
const int mod = 1e9+7;

int bigMod(int b, int p){
    if(p==1) return b%mod;
    else if(p%2==0){
        int e = bigMod(b,p/2);
        return (e*e)%mod;
    }
    else{
        int o = b%mod;
        int aa = bigMod(b,p-1);
        return (aa*o)%mod;
    }
}

int nCr(int n, int r){
    int curr = 1;
    for(int i=1; i<=r; i++){
        curr = (curr*(n+1-i))%mod;
        curr = (curr*bigMod(i, mod-2))%mod;
    }
    return curr;
}

int32_t main(){
    int n,a,b;
    cin>>n>>a>>b;
    int curr = bigMod(2,n)-1;
    if(curr<0)
        curr += mod;
    int x = nCr(n,a), y = nCr(n,b);

    curr = (curr - x)%mod;
    if(curr<0)
        curr += mod;

    curr = (curr - y)%mod;
    if(curr<0)
        curr += mod;
    cout<<curr<<"\n";
    return 0;
}

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def calc(x):
    return x % (10**9+7)

X = list(map(int, input().split()))

N = X[0]
X.remove(N)

numList = list(range(1,N+1))
for i in X:
    numList.remove(i)

result = 0

for i in numList:
    result += cmb(N,i)

print(result % (10**9+7))

Submission status: Runtime Error

Solution code:
n,a,b=map(int,input().split())
mod=10**9+7
def comb(n,a,b):
    temp=1
    a=min(a,n-a)
    b=min(b,n-b)
    A=a if a<b else b
    B=a+b-A
    for i in range(B):
        temp*=pow(i+1,mod-2,mod)*(n-i)%mod
        if i+1==A:
            ComA=temp

    return (ComA+temp)%mod
#二分累乗法を勉強する
ans=pow(2,n,mod)-1-comb(n,a,b)
print(ans%mod)

Submission status: Runtime Error

Solution code:
n, a, b = map(int, input().split())
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**4
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 )
"""    
sum = 0
for i in range(n):
    cm = cmb(n,i+1,mod)
    sum += cm
"""

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

Submission status: Runtime Error

Solution code:
from functools import reduce

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

def nCr(N,R,DIV):
  f=lambda x,y:x*y%DIV
  if R>N-R:
    R=N-R
  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)-1
ans-=nCr(n,a,DIV)
ans-=nCr(n,b,DIV)
print(ans%DIV)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
#coding:utf-8
import math

def combination(n, r):
    return (math.factorial(n) // (math.factorial(n - r) * math.factorial(r)))


if __name__ == "__main__":
    n, a, b = map(int, input().split())
    num_list = list(range(1, n+1))
    num_list.remove(a)
    num_list.remove(b)
    print(num_list)
    ans = 0

    for i in range(0, n-2):
        ans += int(combination(n, int(num_list[i])))


    print(ans % (7 + 10**9))

Submission status: Runtime Error

Solution code:
n, a, b = map(int, input().split())
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**4
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 )
    
sum = 0
for i in range(n):
    cm = cmb(n,i+1,mod)
    sum += cm

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

Submission status: Runtime Error

Solution code:
from scipy.special import comb

n,a,b=map(int,input().split())
m=10**9+7
def mod_m(x):
    return (x+m)%m

def power_a(n,m,a=2):
    ret=1
    while n>0:
        if n%2==1:
            ret=ret*a%m
        a=a*a%m
        n>>=1
    return ret  


def comb_m(a):
    X=1
    Y=1
    for i in range(a):
        X*=(n-i)%m
        Y*=(i+1)%m
    return X*power_a(m-2,m,Y)%m   


varie=mod_m(power_a(n,m)-comb_m(a)-comb_m(b)-1)
          
    
print(int(varie))

Submission status: Runtime Error

Solution code:
def comb(n r):
    #if n < 0 or r < 0 or r > n:
    #    return -1
    if (n - r) < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    num = []
    den = []
    res = 1

    for k in range(0, r):
        num.append(n - r + k + 1)
        den.append(k + 1)

    for p in range(2, r + 1):
        piv = den[p - 1]
        if piv > 1:
            off = (n - r) % p
            for k in range((p - 1), r, p):
                num[k - off] /= piv
                den[k] /= piv

    for k in range(0, r):
        if num[k] > 1: res *= num[k]

    return res

nab = input().split()
n = int(nab[0])
a = int(nab[1])
b = int(nab[2])

ans = 0
for i in range(1, n + 1):
    if i == a or j == b:
        continue
    ans += comb(n, i)

print(ans)

Submission status: Runtime Error

Solution code:
def comb(n r):
    #if n < 0 or r < 0 or r > n:
    #    return -1
    if (n - r) < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    num = []
    den = []
    res = 1

    for k in range(0, r):
        num.append(n - r + k + 1)
        den.append(k + 1)

    for p in range(2, r + 1):
        piv = den[p - 1]
        if piv > 1:
            off = (n - r) % p
            for k in range((p - 1), r, p):
                num[k - off] /= piv
                den[k] /= piv

    for k in range(0, r):
        if num[k] > 1: res *= num[k]

    return res

nab = input().split()
n = int(nab[0])
a = int(nab[1])
b = int(nab[2])

ans = 0
for i in range(0, n + 1):
    if i == a or j == b:
        continue
    ans += comb(n, i)

print(ans)

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     


def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

comb = [0 for _ in range(2*10**5 + 2)]
comb[0] = 1

for i in range(2*10**5+1):
    comb[i]

def NCMMod(n, a):
    cur = n
    for i in range(2, a+1):
        cur = cur * (n-i+1) // i
    return cur % mod


fac = [-1] * (10**7+1)
finv = [-1] * (10**7+1)
inv = [-1] * (10**7+1)

fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1

def initNCMMod(limit):
    for i in range(2, limit):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod
initNCMMod(2*10**5 + 1)

def main():
    n, a, b = LI()
    comb[1] = n
    if n == 2:
        print(0)
        return
    n_pow = power_fun(2, n, mod)
    for i in range(2, 2*10**5+1):
        comb[i] = comb[i-1] * (n-i+1) * inv[i] % mod
    ans = n_pow - 1
    ans %= mod
    ans = ans - comb[a] - comb[b]
    ans %= mod
    print(ans)

main()

Submission status: Runtime Error

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

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

fac = [0]*(10**9+10)
fac[0] = 1
fac[1] = 1
for i in range(2,10**9+1):
    fac[i] = fac[i-1] * i % mod

c = pow(2,n,mod)
c -= 1
c -= ( fac[n] * modinv(fac[a]) )%mod * modinv(fac[n-a]) % mod
c -= ( fac[n] * modinv(fac[b])) % mod * modinv(fac[n-b]) % mod
print(c%mod)

Submission status: Runtime Error

Solution code:
def prepare(N, MOD):
    fac = [None] * (N+2)
    finv = [None] * (N+2)
    inv = [None] * (N+2)
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, N+1):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD
    return fac, finv

def combination(N, K, fac, finv, MOD):
    if N < K:
        return 0
    if N < 0 or K < 0:
        return 0
    else:
        return fac[N] * (finv[K] * finv[N - K] % MOD) % MOD

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

MOD = 10 ** 9 + 7
fac, finv = prepare(n, MOD)
ans = 2**n-1 - combination(n, a, fac, finv, MOD) - combination(n, b, fac, finv, MOD)
print(ans)

Submission status: Runtime Error

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

pattern = list(range(1,n+1))
pattern.remove(a)
pattern.remove(b)

result=0

for i in pattern:
  temp=1
  for j in range(i):
    temp*=n-j
  
  t=1
  for j in range(i,0,-1):
    t*=j
    
  result+=temp//t
    
    
print(result)