Problem p03013 (python)

Fixed submission:
# coding: utf-8

n, m = map(int, input().split())
z = 10**9 + 7

ans = [1]
if m != 0:
    a_i = int(input())
else:
    a_i = 0
m_count = 1
if a_i == 1:
    ans.append(0)
    if m_count < m:
        a_i = int(input())
        m_count += 1
else:
    ans.append(1)
        
for i in range(2, n+1):
    if a_i == i:
        ans.append(0)
        if m_count < m:
            a_i = int(input())
            m_count += 1
    else:
        ans.append(ans[i-1]+ans[i-2])
        
# print(ans, ans[67])
print(int(ans[-1]%z))

Buggy submission (verdict: Runtime Error):
# coding: utf-8

n, m = map(int, input().split())
z = 10**9 + 7

ans = [1]
a_i = int(input())
m_count = 1
if a_i == 1:
    ans.append(0)
    if m_count < m:
        a_i = int(input())
        m_count += 1
else:
    ans.append(1)
        
for i in range(2, n+1):
    if a_i == i:
        ans.append(0)
        if m_count < m:
            a_i = int(input())
            m_count += 1
    else:
        ans.append(ans[i-1]+ans[i-2])
        
# print(ans, ans[67])
print(int(ans[-1]%z))

Buggy submission (verdict: Runtime Error):
import sys
n, m = map(int, input().split())
a_list = []
for i in range(m):
    a_i = int(input())
    a_list.append(a_i)
#print(n, m, a_list)
#print(a_list)
flag = 0

'''
def stepup(x):
    #x段
    ans = 0
    for i in range(x):
        if i==0:
            two_before=1
            ans=1
        elif i==1:
            one_before=2
            ans=2
        else:
            #print(two_before, one_before)
            ans = one_before+two_before
            two_before = one_before
            one_before = ans
    return(ans)
'''
def stepup(x):
    x += 1
    ans = ((1 + 5**0.5) / 2)**x / 5**0.5 + 0.5
    return(int(ans))

#print(stepup(1))
#print(a_list)
for i in range(m):
    if i==0:
        if a_list[i]==1:
            count = 1
            continue
        else:
            count = stepup(a_list[0]-1)
    else:
        if a_list[i]-a_list[i-1]==1:
            #print(a_list[i], a_list[i-1])
            flag = 1
            break
        elif a_list[i]-a_list[i-1]==2:
            pass
        else:
            #print(stepup(23))
            #print(i, stepup(a_list[i]-a_list[i-1]))
            count *= stepup(a_list[i]-a_list[i-1]-2)
    #print(count)
#print(len(a_list), m)
if n-a_list[m-1]==1:
    pass
else:
    count *= stepup(n-a_list[i]-1)
#print(count)

if flag==1:
    print(0)
else:
    print(count%1000000007)
#print((stepup(20)**4 * stepup(10))%1000000007)

Buggy submission (verdict: Runtime Error):
import sys
n, m = map(int, input().split())
a_list = []
for i in range(m):
    a_i = int(input())
    a_list.append(a_i)
    a_list = list(set(a_list))
#print(n, m, a_list)
#print(a_list)
m = len(a_list)
flag = 0

def stepup(x):
    #x段
    ans = 0
    for i in range(x):
        if i==0:
            two_before=1
            ans=1
        elif i==1:
            one_before=2
            ans=2
        else:
            #print(two_before, one_before)
            ans = one_before+two_before
            two_before = one_before
            one_before = ans
    return(ans)
        
a_list.sort()
#print(stepup(5))
#print(a_list)
for i in range(m):
    if i==0:
        if a_list[i]==1:
            count = 1
            continue
        else:
            count = stepup(a_list[0]-1)
    else:
        if a_list[i]-a_list[i-1]==1:
            #print(a_list[i], a_list[i-1])
            flag = 1
            break
        else:
            #print(stepup(23))
            #print(i, stepup(a_list[i]-a_list[i-1]))
            count *= stepup(a_list[i]-a_list[i-1]-2)
    #print(count)
if n-a_list[i]==1:
    pass
else:
    count *= stepup(n-a_list[i]-1)
#print(count)

if flag==1:
    print(0)
else:
    print(count%1000000007)
#print((stepup(20)**4 * stepup(10))%1000000007)