Problem p02768 (python)

Fixed submission:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n, a, b = MAP()

def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, int(y/2)) ** 2 % mod
    else:
        return power(x, int((y-1)/2)) ** 2 * x % mod
ans = power(2, n) - 1
    
a_max = 2 * 10 ** 5
# a, bの最大値+2
fact = [1] * (a_max + 2)
# 逆元
for i in range(1, a_max + 1):
    fact[i] = (fact[i-1] * i) % mod
# combination
def C(n, a):
    tmp = 1
    for i in range(n, n-a, -1):
        tmp = (tmp * i) % mod
    return tmp * power(fact[a], mod - 2)

print((ans - C(n, a) - C(n, b)) % mod)

Buggy submission (verdict: Runtime Error):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n, a, b = MAP()

def c(n,k): 
  return 1 if(k<=0 or n<=k) else ( c(n-1, k-1) + c(n-1, k) ) %4

def make_comb_dp(n):
    dp = [[0] * (n + 1) for i in range(n + 1)]
    for i in range(n + 1):
        dp[i][0] = 1
        dp[i][i] = 1
    for i in range(2, n + 1):
        for j in range(1, i):
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]
    return dp
    
dp = make_comb_dp(n)
soko = (sum(dp[n]))
ans = soko - 1 - dp[n][a] - dp[n][b]
print(ans % mod)






# def c(n,k): 
#   return 1 if(k<=0 or n<=k) else c(n-1, k-1) + c(n-1, k)

# for i in range(10):
#   print([c(i,j) for j in range(i+1)])


# MAX = 510000
# fac = [0] * MAX
# finv = [0] * MAX
# inv = [0] * MAX

# # // テーブルを作る前処理
# MOD = mod
# def COMinit():
#     fac[0] = fac[1] = 1
#     finv[0] = finv[1] = 1
#     inv[1] = 1
#     # for (i = 2; i < MAX; i++){
#     for i in range(2, MAX):
#         fac[i] = fac[i - 1] * i % MOD;
#         inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
#         finv[i] = finv[i - 1] * inv[i] % MOD

# # // 二項係数計算
# def C(n, k):
#     if (n < k):
#         return 0
#     if (n < 0 or k < 0):
#         return 0
#     else:
#         print(1)
#         return fac[n] * (finv[k] * finv[n - k] % mod) % mod
# print(C(173205, 141421))