Problem p03013 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M = map(int, input().split())
    A = deque([int(input()) for i in range(M)])
    if N == 1:
        print(1)
    else:
        dp = [0]*N
        # 一段目と二段目への行き方
        if len(A) != 0:
            out = A.popleft() 
        else:
            out = 0

        if out != 1:
            dp[0] = 1
        else:
            dp[0] = 0
            if len(A) != 0:
                out = A.popleft()
        if out != 2:
            dp[1] = 1+dp[0]
        else:
            dp[1] = 0
            if len(A) != 0:
                out = A.popleft()

        for i in range(2,N):
            if i+1 == out:
                dp[i] = 0
                if len(A) != 0:
                    out = A.popleft()
            else:
                if dp[i-2] != 0 or dp[i-1] != 0:
                    dp[i] = dp[i-2] + dp[i-1]

        if dp[N-1] != 0:
            print(dp[N-1]%(10**9 + 7))
        else:
            print(0)
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M = map(int, input().split())
    A = deque([int(input()) for i in range(M)])
    dp = [0]*N
    # 一段目と二段目への行き方
    if len(A) != 0:
        out = A.popleft() 
    else:
        out = 0

    if out != 1:
        dp[0] = 1
    else:
        dp[0] = 0
        if len(A) != 0:
            out = A.popleft()
    if out != 2:
        dp[1] = 1+dp[0]
    else:
        dp[1] = 0
        if len(A) != 0:
            out = A.popleft()

    for i in range(2,N):
        if i+1 == out:
            dp[i] = 0
            if len(A) != 0:
                out = A.popleft()
        else:
            if dp[i-2] != 0 or dp[i-1] != 0:
                dp[i] = dp[i-2] + dp[i-1]

    if dp[N-1] != 0:
        print(dp[N-1]%(10**9 + 7))
    else:
        print(0)
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M = map(int, input().split())
    A = deque([int(input()) for i in range(M)])
    dp = [0]*N
    # 一段目と二段目への行き方
    if len(A) != 0:
        out = A.popleft 
    else:
        out = 0
        
    if out != 1:
        dp[0] = 1
    else:
        dp[0] = 0
        if len(A) != 0:
            out = A.popleft 
    if out != 2:
        dp[1] = 1+dp[0]
    else:
        dp[1] = 0
        if len(A) != 0:
            out = A.popleft 

    for i in range(2,N):
        if i+1 == out:
            dp[i] = 0
            if len(A) != 0:
                out = A.popleft()
        else:
            if dp[i-2] != 0 or dp[i-1] != 0:
                dp[i] = dp[i-2] + dp[i-1]

    if dp[N-1] != 0:
        print(dp[N-1]%(10**9 + 7))
    else:
        print(0)
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M = map(int, input().split())
    A = deque([int(input()) for i in range(M)])
    dp = [0]*N
    # 一段目と二段目への行き方
    dp[0] = 1
    dp[1] = 2
    out = A.popleft()
    for i in range(2,N):
        if i+1 == out:
            dp[i] = 0
            if len(A) != 0:
                out = A.popleft()
        else:
            if dp[i-2] != 0 or dp[i-1] != 0:
                dp[i] = dp[i-2] + dp[i-1]
    if dp[N-1] != 0:
        print(dp[N-1]%(10**9 + 7))
    else:
        print(0)
    
if __name__ == '__main__':
    main()