Problem p03013 (python)

Fixed submission:
N, M = map(int, input().split())
a = [0]*N
for _ in range(M):
    idx = int(input()) - 1
    a[idx] = 1
    
dp = [0]*(N+1)
dp[0] = 1
dp[1] = 1
for i in range(N-1):
    if a[i] == 0:
        dp[i+1] += dp[i]
        dp[i+2] += dp[i]
print(dp[N-1] % 1000000007)

Buggy submission (verdict: Runtime Error):
def combination(n, r):
    r = min(r, n-r)
    nume = 1
    denomi = 1
    for i in range(1, r+1):
        denomi *= i
    for i in range(n-r+1, n+1):
        nume *= i
    return nume // denomi

N, M = map(int, input().split())

sl = []
cnt = -1
ng = 0
for i in range(M):
    a = int(input())
    b = (a - 1) - (cnt + 1)
    if b == -1:
        ng = 1
    sl.append(max(b, 1))
    cnt = a

if ng:
    print(0)
else:
    sl.append(max(N - (a + 1), 1))
    ans = 1
    for s in sl:
        p = 0
        for i in range(s):
            j = s - i
            if (i <= j):
                p += combination(j, i)
            else:
                break
        ans *= p
    print(ans % 1000000007)

Buggy submission (verdict: Runtime Error):
def combination(n, r):
    r = min(r, n-r)
    nume = 1
    denomi = 1
    for i in range(1, r+1):
        denomi *= i
    for i in range(n-r+1, n+1):
        nume *= i
    return nume // denomi

N, M = map(int, input().split())

sl = []
cnt = -1
for i in range(M):
    a = int(input())
    b = (a - 1) - (cnt + 1)
    if b == -1:
        print(0)
        break
    sl.append(max(b, 1))
    cnt = a
else:
    sl.append(max(N - (a + 1), 1))
    ans = 1
    for s in sl:
        p = 0
        for i in range(s):
            j = s - i
            if (i <= j):
                p += combination(j, i)
            else:
                break
        ans *= p
    print(ans % 1000000007)

Buggy submission (verdict: Runtime Error):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, M = map(int, input().split())

sl = []
cnt = -1
for i in range(M):
    a = int(input())
    b = (a - 1) - (cnt + 1)
    if b == -1:
        print(0)
        break
    sl.append(max(b, 1))
    cnt = a
else:
    sl.append(max(N - (a + 1), 1))
    ans = 1
    for s in sl:
        p = 0
        for i in range(s):
            j = s - i
            if (i <= j):
                p += combinations_count(j, i)
            else:
                break
        ans *= p
        ans = ans % 1000000007
    print(ans % 1000000007)

Buggy submission (verdict: Runtime Error):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, M = map(int, input().split())

sl = []
cnt = -1
for i in range(M):
    a = int(input())
    b = (a - 1) - (cnt + 1)
    if b == -1:
        print(0)
        break
    sl.append(max(b, 1))
    cnt = a
else:
    sl.append(max(N - (a + 1), 1))
    ans = 1
    for s in sl:
        p = 0
        for i in range(s):
            j = s - i
            if (i <= j):
                p += combinations_count(j, i)
            else:
                break
        ans *= p
    print(ans % 1000000007)

Buggy submission (verdict: Runtime Error):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, M = map(int, input().split())

sl = []
cnt = -1
for i in range(M):
    a = int(input())
    b = (a - 1) - (cnt + 1)
    if b == -1:
        print(0)
        break
    sl.append(max(b, 1))
    cnt = a
else:
    sl.append(max(N - (a + 1), 1))
    ans = 1
    for s in sl:
        p = 0
        for i in range(s):
            j = s - i
            if (i > j):
                break
            p += combinations_count(j, i)
        ans *= p
    print(ans % 1000000007)