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:
    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)] #numerator(分子)
    	den = [k + 1 for k in range(r)] #denominator(分母)
    	
    	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])
    	
    	return result
     
    n,a,b = map(int,input().split())
     
    print((2**n - 1 - cmb(n,a) - cmb(n,b)) % (10**9 + 7))

Submission status: Runtime Error

Solution code:
N, a, b = map(int, input().split())
M = 1000000007

m = N//2 + 1
fact_list = [1] * (N+1)
fact_inv = [1] * (N+1)

for i in range(1, N+1):
    fact_list[i] = fact_list[i-1] * i % M

for i in range(1, N+1):
    fact_inv[i] = pow(int(fact_list[i]), M-2, M)

def mod_comb_k(n,k,M):
    return int(fact_list[n]) * int(fact_inv[k]) % M * int(fact_inv[n-k]) % M

ans = 0
for i in range(1, N+1):
    if i == a or i == b:
        continue
    ans += mod_comb_k(N, i, M) % M
    # print(ans)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(1000000)
def P(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
n,a,b=map(int,input().split())
a,b=min(a,n-a),min(b,n-b)
m=10**9+7
N=min(n,2*10**5)
inv=[0 for _ in range(max(a,b))]
inv[1]=1
if max(a,b)>1:
  for i in range(2,max(a,b)):
    inv[i]=m-inv[m%i]*(m//i)%m
def C(n,r,a):
  for i in range(r):
    a=a*(n-i)*inv[r-i-1]%m
  return a
A,B=C(n,a,1),C(n,b,1)
print((P(2,n,m)-int(A)-int(B)-1+m)%m)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
(n, a, b) = list(map(int, input().split()))

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

result = 0
result = 2**n - 1

minus_v = 0
for i in (a, b):
    minus_v += comb(n, i)
#    minus_v += math.factorial(n) //(math.factorial(n - i) * math.factorial(i))

result -= minus_v
print(int(result % (10**9 + 7)))

Submission status: Runtime Error

Solution code:
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

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

p = 10 ** 9 + 7

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

Submission status: Runtime Error

Solution code:
    n,a,b = map(int,input().split())
    mod = 10**9+7
     
    from math import factorial
    cmb_a = factorial(n) / factorial(a) / factorial(n-a)
    cmb_b = factorial(n) / factorial(b) / factorial(n-b)
     
    print(int((2**n - 1 - cmb_a - cmb_b) % 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 #出力の制限
X = 2 * 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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

ax = cmb(N, a, mod)
bx = cmb(N, b, mod)

print((pow(2, N) - ax - bx - 1)%(10**9 + 7))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(9**9)
def P(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
n,a,b=map(int,input().split())
a,b=min(a,n-a),min(b,n-b)
m=10**9+7
N=min(n,2*10**5)
inv=[0 for _ in range(max(a,b))]
inv[1]=1
if max(a,b)>1:
  for i in range(2,max(a,b)):
    inv[i]=m-inv[m%i]*(m//i)%m
def C(n,r,a):
  for i in range(r):
    a=a*(n-i)*inv[r-i-1]%m
  return a
A,B=C(n,a,1),C(n,b,1)
print((P(2,n,m)-int(A)-int(B)-1+m)%m)

Submission status: Runtime Error

Solution code:
mod = 1000000007

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

def power(s, t):
    if   t == 0     : return 1
    elif t == 1     : return x % mod
    elif t % 2 == 0 : return power(s, t/2)**2 % mod
    else            : return power(s, t/2)**2 * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))
    
def cmb(a,b):
    p = 1
    q = 1
    for i in range(1,b+1):
        p = mul(p,a-i)
    for j in range(1,b+1):
        q = mul(q,j)
    return div(p,q)

x,y,z = map(int,input().split(" "))
ans = 0

for i in range(1,x+1):
    if i == y or i == z:
        continue
    else:
        ans += cmb(x,i)

print(ans)

Submission status: Runtime Error

Solution code:
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
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

n, a, b = map(int, input().split())
nCa= 1
nCb= 1
for i in range(b):
    nCb = (nCb%p * (n-i)%p)%p
    nCb = nCb * mod_inv(i+1, p)
    if i+1 == a:
        nCa = nCb

ans = 2**n - 1- nCa%p - nCb%p
if ans < 0:
    print(0)
else:
    print(int(ans%p))

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
	long long val;
	constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
		if (val < 0) val += MOD;
	}
	constexpr int getmod() { return MOD; }
	constexpr Fp operator - () const noexcept {
		return val ? MOD - val : 0;
	}
	constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
	constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
	constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
	constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
	constexpr Fp& operator += (const Fp& r) noexcept {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	constexpr Fp& operator -= (const Fp& r) noexcept {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr Fp& operator *= (const Fp& r) noexcept {
		val = val * r.val % MOD;
		return *this;
	}
	constexpr Fp& operator /= (const Fp& r) noexcept {
		long long a = r.val, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr bool operator == (const Fp& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Fp& r) const noexcept {
		return this->val != r.val;
	}
	friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
		return os << x.val;
	}
	friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
		if (n == 0) return 1;
		auto t = modpow(a, n / 2);
		t = t * t;
		if (n & 1) t = t * a;
		return t;
	}
};
using mint = Fp<1000000007>;

long long MOD = 1000000007;

using ll = long long;
int main() {
	int n, a, b;
	cin >> n >> a >> b;
	mint ns = 1;
	for (ll i = 1; i < n + 1; ++i) {
		ns *= i;
	}
	mint rr = ns / n;
	mint r = 1;
	mint ans = 0;
	for (ll k = 1; k < n + 1; ++k) {
		if (k != a && k != b) {
 			ans += ns / r / rr;
		}
		r *= (k + 1);
		rr /= (n - k);
	}
	cout << ans.val << endl;
}

Submission status: Runtime Error

Solution code:
import math
from operator import mul
from functools import reduce

def comb(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

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

if (n==2 and a==1 and b==2) or (n==2 and a==2 and b==1):
    print(0)
else:
    ans = 2**n-1-comb(n,a)-comb(n,b)
if ans < 10**9+7:
    print(ans)
else:
    print(ans%(10**9+7))

Submission status: Runtime Error

Solution code:
import itertools
from math import factorial
from scipy.misc.import comb
"""
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
"""


n, a, b = map(int, input().split())
"""
counter = 0
UpperLimit = n//2
if n%2 == 0:
    for r in range(UpperLimit):
        counter += cmb(n,r)#comb(n, r, exact = True)
    counter *= 2
    counter += cmb(n,UpperLimit)#comb(n, UpperLimit, exact = True)
    counter -= 1
else:
    for r in range(UpperLimit+1):
        counter += cmb(n,r)#comb(n, r, exact = True)
    counter *= 2
    counter -= 1

counter -= cmb(n,a)#comb(n, a, exact = True)
counter -= cmb(n,b)#comb(n, b, exact = True)

print(counter%(10**9+7))
"""

numerator = n
denominator = 1
counter = 0
for i in range(1,n+1):
    counter += numerator//denominator
    numerator *= (n-i)
    denominator *= (1+i)

counter -= comb(n, a, exact = True)
counter -= comb(n, b, exact = True)
int(counter)
print(counter%(10**9+7))

Submission status: Runtime Error

Solution code:
import numpy as np
N, a, b = map(int, input().split())
M = 1000000007

m = N//2 + 1
fact_list = np.ones(N+1, dtype='int32')
fact_inv = np.ones(N+1, dtype='int32')

for i in range(1, N+1):
    fact_list[i] = fact_list[i-1] * i % M

for i in range(1, N+1):
    fact_inv[i] = pow(int(fact_list[i]), M-2, M)

def mod_comb_k(n,k,M):
    return int(fact_list[n]) * int(fact_inv[k]) % M * int(fact_inv[n-k]) % M

ans = 0
for i in range(1, N+1):
    if i == a or i == b:
        continue
    ans += mod_comb_k(N, i, M) % M
    # print(ans)
print(ans)

Submission status: Runtime Error

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

up = 1
down = 1
ans = 0
mod = 10 ** 9 + 7

for i, o in zip(range(1, n//2 + 1), range(n, 0, -1)):
    up *= o
    down *= i
    if (i != a) and (i != b):
        ans += up/down
        ans %= mod
 
    if i != (n - i):
        if ((n - i) != a) and ((n - i) != b):
            ans += up/down
            ans %= mod
  

if (n != a) and (n != b):
    ans += 1
print(ans%mod)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

p = 10 ** 9 + 7

print((2 ** n - comb(n, a, exact=True) - comb(n, b, exact=True)) % p - 1)

Submission status: Runtime Error

Solution code:
#abc156 d
n,a,b=map(int,input().split())
ans=[1]*(n+1)

for i in range(1,n+1):
    ans[i]=int(ans[i-1]*(n+1-i)/i)
if a<=n and b<=n:
    x=sum(ans)-ans[a]-ans[b]-1
else:
    x=sum(ans)-1
print(x)

Submission status: Runtime Error

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

class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod

    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod


mod = 10 ** 9 + 7
mc = ModComb(1000000, mod=mod) 

minus = (mc.nCk(n, a) % mod) + (mc.nCk(n, b) % mod)

print(((2 ** (n) - 1) - minus) % mod)

Submission status: Runtime Error

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

from scipy.special import comb
"""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 )
"""
mod = 10**9 + 7 
r = 0
ans = 2 ** n 
ans = ans - (comb(n,a,exact=True)+comb(n,a,exact=True)+1)
ans %= mod
print(ans)

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**5
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 )

def pos(x, n, m):
    res = pos(x*x%m, n//2, m)
    if n%2 == 1:
        res = res*x%m
    return res
    
if n==2:
    print(0)
else:
    ans=pos(2,n,mod)-1-cmb(n,a,mod)-cmb(n,b,mod)
    print(ans%mod)

Submission status: Runtime Error

Solution code:
import itertools
from math import factorial
from scipy.special import comb
"""
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
"""


n, a, b = map(int, input().split())
"""
counter = 0
UpperLimit = n//2
if n%2 == 0:
    for r in range(UpperLimit):
        counter += cmb(n,r)#comb(n, r, exact = True)
    counter *= 2
    counter += cmb(n,UpperLimit)#comb(n, UpperLimit, exact = True)
    counter -= 1
else:
    for r in range(UpperLimit+1):
        counter += cmb(n,r)#comb(n, r, exact = True)
    counter *= 2
    counter -= 1

counter -= cmb(n,a)#comb(n, a, exact = True)
counter -= cmb(n,b)#comb(n, b, exact = True)

print(counter%(10**9+7))
"""

numerator = n
denominator = 1
counter = 0
for i in range(1,n+1):
    counter += numerator//denominator
    numerator *= (n-i)
    denominator *= (1+i)

counter -= comb(n, a, exact = True)
counter -= comb(n, b, exact = True)
int(counter)
print(counter%(10**9+7))

Submission status: Runtime Error

Solution code:
from scipy.special import comb
a = comb(n, r, exact=True)

import numpy as np
n, a, b = map(int, input().split())

p = 10 ** 9 + 7

print((2**n-comb(n, a, exact=True)-comb(n, b, exact=True))%p-1)

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 #出力の制限
X = 2 * 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
 
for i in range( 2, X + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
 
ax = cmb(N, a, mod)
bx = cmb(N, b, mod)
 
print((pow(2, N) - ax - bx - 1))

Submission status: Runtime Error

Solution code:
n,a,b = list(map(int, input().split()))
m = (10 ** 9) + 7
dp = [-1] * (n+1)
total = 0

for i in range(0, n+1):
    if(i > 0):
        x = i * dp[i - 1]

        if(x <= m):
            dp[i] = x
        else:
            dp[i] = x % m
    else:
        dp[0] = 1

if n > 2:
    for i in range(1, n+1):
        if(i != a and i != b):
            total += int(dp[n] / (dp[i] * dp[n-i]))
    
print(total % m)

Submission status: Runtime Error

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

# def remove_specified_values(arr, value):
#     while value in arr:
#         arr.remove(value)

n2=int(n/2)

for i in range(1,n2+1):
    if i==a:
        continue
    if i==b:
        continue

    if i==1:
        ans+=n
    elif i==n:
        ans+=1
    else:
        ans+=len(list(itertools.combinations(list(range(0,n)), i)))

if n%2==1:
    if not n2+1==a and not n2*1==b:
        ans+=len(list(itertools.combinations(list(range(0,n)), n2+1)))

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

Submission status: Runtime Error

Solution code:
import sys
from operator import mul
from functools import reduce
sys.setrecursionlimit(9**9)
def P(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
n,a,b=map(int,input().split())
a,b=min(a,n-a),min(b,n-b)
m=10**9+7
N=min(n,2*10**5)
inv=[0 for _ in range(max(a,b))]
inv[1]=1
if max(a,b)>1:
  for i in range(2,max(a,b)):
    inv[i]=m-inv[m%i]*(m//i)%m
def C(n,r,a):
  for i in range(r):
    a=a*(n-i)*inv[r-i-1]%m
  return a
A,B=C(n,a,1),C(n,b,1)
print((P(2,n,m)-int(A)-int(B)-1+m)%m)

Submission status: Runtime Error

Solution code:
n,a,b = list(map(int, input().split()))
m = (10 ** 9) + 7
dp = [-1] * (n+1)
total = 0

for i in range(0, n+1):
    if(i > 0):
        x = i * dp[i - 1]

        if(x <= m):
            dp[i] = x
        else:
            dp[i] = x % m
    else:
        dp[0] = 1

if n > 2:
    for i in range(1, n+1):
        if(i != a and i != b):
            total += int(dp[n] / (dp[i] * dp[n-i]))
            total = total % m
    
print(total)

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 = 2*10**5
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 )

def pos(x, n, m):
    res = pos(x*x%m, n//2, m)
    if n%2 == 1:
        res = res*x%m
    return res
    
if n==2:
    print(0)
else:
    ans=pos(2,n,mod)-1-cmb(n,a,mod)-cmb(n,b,mod)
    print(ans%mod)

Submission status: Runtime Error

Solution code:
n , a , b = map(int,input().split())
p = 10**9 +7
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]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)


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


print(pow(2,n,p) -A - B-1)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

n, a, b = map(int, input().split())
print((2**n -1 -comb(n, a, exact=True)- comb(n, b, exact=True))%(10**9+7))

Submission status: Runtime Error

Solution code:
from math import factorial

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

choice = list(range(1, n+1))

choice.remove(a)
choice.remove(b)

combinations = 0

for i in range(len(choice)):
    combinations += factorial(n) / factorial(choice[i]) / factorial(n - choice[i])

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

Submission status: Runtime Error

Solution code:
import sys
from scipy.special import comb


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

big = 1000000007

sum = pow(2,n,1000000007)
#print(sum)
sum1 = sum -comb(n,a)-comb(n,b)-1

#print(sum1)

#sum = sum
ans = sum1 % 1000000007

##ans = (2**n-1-comb(n,a)-comb(n,b))%big


print(int(ans))

Submission status: Runtime Error

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

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 )


for i in range(n):
    s += cmb(n,i,mod)

s -= cmb(n,a,mod)
s -= cmb(n,b,mod)
print(s)

Submission status: Runtime Error

Solution code:
import numpy as np

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

n = np.asarray(n)

c = np.zeros(n)
c[0] =  n
c[n-1] = 1
c[n-2] = n
for i in range((n-1) // 2) :
    tmp = c[i] * (n - i - 1)
    tmp = tmp // (i + 2) % (10 ** 9 + 7)

    c[i+1] = c[n-i-3] = tmp
print(c)

print(int(sum(c) - c[a-1] - c[b-1]))

Submission status: Runtime Error

Solution code:
import scipy
n,a,b=map(int,input().split())
l1=[]
l2=[]
l3=[]
for i in range(1,a):
  x=scipy.misc.comb(n,i)
  l1.append(x)
for i in range(a+1,b):
  y=scipy.misc.comb(n,i)
  l2.append(y)
for i in range(b+1,n):
  z=scipy.misc.comb(n,i)
  l3.append(z)
L=sum(l1)+sum(l2)+sum(l3)
print((int(L)+1)%(10**9 + 7))

Submission status: Runtime Error

Solution code:
import numpy as np
MOD = 10**9+7
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
 
def prepare(n, MOD):
    nrt = int(n ** 0.5) + 1
    nsq = nrt * nrt
    facts = np.arange(nsq, dtype=np.int64).reshape(nrt, nrt)
    facts[0, 0] = 1
    for i in range(1, nrt):
        facts[:, i] = facts[:, i] * facts[:, i - 1] % MOD
    for i in range(1, nrt):
        facts[i] = facts[i] * facts[i - 1, -1] % MOD
    facts = facts.ravel().tolist()
 
    invs = np.arange(1, nsq + 1, dtype=np.int64).reshape(nrt, nrt)
    invs[-1, -1] = pow(facts[-1], MOD - 2, MOD)
    for i in range(nrt - 2, -1, -1):
        invs[:, i] = invs[:, i] * invs[:, i + 1] % MOD
    for i in range(nrt - 2, -1, -1):
        invs[i] = invs[i] * invs[i + 1, 0] % MOD
    invs = invs.ravel().tolist()
 
    return facts, invs

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

n,a,b=list(map(int,input().split()))
fact,factinv=prepare(n,MOD)

# 2**n-1
total = power_func(2,n,MOD)-1
print(total-cmb(n,a,MOD)-cmb(n,b,MOD))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)

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

nCr = {}
def cmb(n,r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1, r-1)
    return nCr[(n,r)]

combi = 0
combisum = 0


for romeo in range(0,n):
    if(romeo == a or romeo == b):
        pass
    else:
        combi = cmb(n,romeo)
        combisum += combi

if (combisum>= 1000000007):
    combisum = combisum % 1000000007
else:
    pass

print(combisum)

#nC(1~)を足し合わせて、a,bを飛ばせばいい

Submission status: Runtime Error

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

#ここから

mod = 10**9+7
MAX_N = 10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%mod)

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

def mod_comb_k(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

#ここまでパクリ
#https://juppy.hatenablog.com/entry/2018/11/12/%E8%9F%BB%E6%9C%AC_python_nCk_mod_p_%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0

ans = 2**n % mod - mod_comb_k(n,a,mod) - mod_comb_k(n,b,mod)
print(ans-1)

Submission status: Runtime Error

Solution code:
n=list(map(int, input().split()))
import math
#(math.factorial(5))
a=list(range(n[0]))
a.remove(n[1])
a.remove(n[2])
B=[math.factorial(n[0])/math.factorial(i)/math.factorial(n[0]-i) for i in a]
C=sum(B)
D=C%(10**9+7)
print(int(C))

Submission status: Runtime Error

Solution code:
n,a,b = map(int,input().split())
count = 0
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 #出力の制限
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 )
for j in range(2,n + 1):
  if j == a or i == b:
    pass
  else:
    count += cmb(n, j, p)
print(count)

Submission status: Runtime Error

Solution code:
import scipy
n,a,b=map(int,input().split())
l1=[]
l2=[]
l3=[]
for i in range(1,a):
  x=scipy.special.comb(n,i)
  l1.append(x)
for i in range(a+1,b):
  y=scipy.special.comb(n,i)
  l2.append(y)
for i in range(b+1,n):
  z=scipy.special.comb(n,i)
  l3.append(z)
L=sum(l1)+sum(l2)+sum(l3)
print((int(L)+1)%(10**9 + 7))

Submission status: Runtime Error

Solution code:
def nCrModpDP(n, r, p): 
    C = [0] * (n + 1); 
    C[0] = 1;  
    for i in range(1, (n + 1)): 
        j = min(i, r);  
        while(j > 0): 
            C[j] = (C[j] + C[j - 1]) % p; 
            j -= 1; 
    return C[r]; 
def nCrModpLucas(n, r, p): 
    if (r == 0): 
        return 1; 
    ni = int(n % p); 
    ri = int(r % p); 
    return (nCrModpLucas(int(n / p), int(r / p), p) * 
            nCrModpDP(ni, ri, p)) % p; # Remaining digits 
n,a,b= map(int,input().split())
if a>n/2:
    a=n-a
if b>n/2:
    b=n-b
nca = nCrModpLucas(n,a)
ncb = nCrModpLucas(n,b)
print(int(2**n - 1 - nca - ncb)%(10**9+7))

Submission status: Runtime Error

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

class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod

    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod


mod = 10 ** 9 + 7
mc = ModComb(1000000, mod=mod) 

minus = (mc.nCk(n, a) % mod) + (mc.nCk(n, b) % mod)

print((2 ** (n) - 1) - minus)

Submission status: Runtime Error

Solution code:
j=list(map(int, input().split()))
	
from scipy.special import comb
s=0
for i in range(1,j[0]+1):
	s=s+comb(j[0],i,exact=True)

s=s-comb(j[0],j[1])
s=s-comb(j[0],j[2])
print(s)

Submission status: Runtime Error

Solution code:
n,a,b = list(map(int, input().split()))
m = (10 ** 9) + 7
dp = [-1] * (n+1)
total = 0

for i in range(0, n+1):
    if(i > 0):
        x = i * dp[i - 1]

        if(x <= m):
            dp[i] = x
        else:
            dp[i] = x % m
    else:
        dp[0] = 1

if n > 2:
    for i in range(1, n+1):
        if(i != a and i != b):
            total += int(dp[n] / (dp[i] * dp[n-i]))


print(total)

Submission status: Runtime Error

Solution code:
import math
rom scipy.special import comb
t = comb(n, a, exact=True)
k = comb(n, b, exact=True)
n, a, b = map(int,input().split())
if n == 2:
  print(0)
else:
  total = 2 ** n -1
  total  = total - t - k
  print(total % (10 ** 9 + 7))

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]*(n+1)
fac[0] = 1
fac[1] = 1
for i in range(2,n+1):
    fac[i] = fac[i-1] * i % mod

c = 0
if n % 2 == 0:
    for i in range(1,n//2 ):
        c += ( fac[n] * modinv(fac[i]) )%mod * modinv(fac[n-i]) % mod
        c = c%mod
    c *= 2
    c += ( fac[n] * modinv(fac[n//2]) )%mod * modinv(fac[n-n//2]) % mod
    c += mod
    c -= ( fac[n] * modinv(fac[a]) )%mod * modinv(fac[n-a]) % mod
    c -= (fac[n] * modinv(fac[b])) % mod * modinv(fac[n-b]) % mod
    c += 1

else:
    for i in range(1, n // 2 + 1):
        c += (fac[n] * modinv(fac[i])) % mod * modinv(fac[n - i]) % mod
    c *= 2
    c += mod
    c -= (fac[n] * modinv(fac[a])) % mod * modinv(fac[n - a]) % mod
    c -= (fac[n] * modinv(fac[b])) % mod * modinv(fac[n - b]) % mod
    c += 1

print(c%mod)

Submission status: Runtime Error

Solution code:
from numba import jit

@jit
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**9 + 1 
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

@jit
def tmp():
    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 )

tmp()
s = list(map(int, input().split()))
n = s[0]
a = s[1]
b = s[2]
ans = 0
for i in range(n):
    if i+1 == a or i+1 ==b:
        continue
    else:
        ans += cmb(n, i+1 ,mod)
print(ans)

Submission status: Runtime Error

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

n, a, b = map(int, input().split())
counter = 0
for i in range(1,n+1):
    if ((i != a) and (i != b)):
        counter += cmb(n,i,mod)
print(counter)

Submission status: Runtime Error

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

comb = []
for k in range(1,n+1):
    if k == a:
        continue
    elif k == b:
        continue
    comb += list((itertools.combinations(range(n),k)))
print(len(comb))

Submission status: Runtime Error

Solution code:
n,a,b=map(int,input().split())
l=[0]*n
d=[0]*n
e=[0]*n

d[0]=n
e[0]=1
l[0]=n

for i in range(1,n):
  d[i]=d[i-1]*(n-i)
  e[i]=e[i-1]*(i+1)
  l[i]=d[i]//e[i]
del l[a-1]
del l[b-2]
k=sum(l)
print(k%(10**9 +7))

Submission status: Runtime Error

Solution code:
from scipy import special

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

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

for i in range(n):
    if a == i or b == i:
        continue
    else:
        ans += cmb(n,i)
print(ans % (10 ** 9 + 7))

Submission status: Runtime Error

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

dp = [[0, 0]] * (n + 1)
dp[0][0] = 0
dp[0][1] = 0

for i in range(n+1):
    if i == 1:
        dp[1][0] = n
    elif i >= 2: 
        dp[i][0] = int(dp[i-1][0] * (((n - i + 1) / i) % mod) % mod)
    
    if (i != a) and (i != b):
        dp[i][1] = (dp[i-1][1] + dp[i][0]) % mod
        
print(dp[-1][1])