Problem p03013 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N ,M = cin.mapInt()
    A = [True] * (N + 1)
    for i in range(M):
        a = cin.int()
        A[a - 1] = False

    dp = [0] * (N + 1)
    dp[0] = 1
    for i in range(N):
        if A[i] == True:
            dp[i + 1] = dp[i] + dp[i - 1]
            dp[i + 1] %= MOD
    print(dp[N])
    return

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N ,M = cin.mapInt()
    A = cin.intColsList(M)

    p = 0
    dp = [0] * (N + 1)
    dp[0] = 1
    for i in range(N):
        if A[p] - 1 == i:
            p += 1
            if p == M:
                p = 0
        else:
            dp[i + 1] = dp[i] + dp[i - 1]
        dp[i + 1] %= MOD
    print(dp[N])
    return

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

@lru_cache(maxsize=None)
def fib(n):
    if n == 0:
        return 1
    if n == 1:
        return 1
    return (fib(n - 1) + fib(n - 2)) % MOD

def main():
    N ,M = cin.mapInt()
    A = cin.intColsList(M)

    for i in range(M - 1):
        if A[i + 1] - A[i] == 1:
            print(0)
            return
    if M == 0:
        print(fib(N))
        return
    A.insert(0,-1)
    A.append(N + 1)

    ans = 1
    for i in range(M + 1):
        n,m = A[i] + 1,A[i + 1] - 1,
        ans *= fib(m - n)
        ans %= MOD
    print(ans)
    return

if __name__ == "__main__":
    main()