Problem p03013 (python)

Fixed submission:
N,M=map(int,input().split())
a=[]
b=[0]*N
for i in range(M):
    a.append(int(input()))
if M==0:
    j=-1
else:
    j=0
if N==1:
    b[0]=1
elif M>0 and a[0]==1:
    b[0]=0
    b[1]=1
elif M>0 and a[0]==2:
    b[0]=1
    b[1]=1
else:
    b[0]=1
    b[1]=2
for i in range(N-2):
    if j==M-1 or (j>=0 and (i+2)!=a[j] and (i+1)!=a[j]):
        b[i+2]=b[i+1]+b[i]
    if j>0 and a[j]==a[j-1]+1:
        b[N-1]=0
    if j+1<M and a[j+1]==a[j]+1:
        b[N-1]=0
    elif j>=0 and (i+2)==a[j]:
        b[i+2]=b[i]
    elif j>=0 and j+1<M and (i+1)==a[j]:
        j+=1
        b[i+2]=b[i+1]
    elif j>=0 and (i+1)==a[j]:
        b[i+2]=b[i+1]
print(b[N-1]%1000000007)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=[]
b=[0]*N
for i in range(M):
    a.append(int(input()))
if M==0:
    j=-1
else:
    j=0
if M>0 and a[0]==1:
    b[0]=0
    b[1]=1
elif M>0 and a[0]==2:
    b[0]=1
    b[1]=1
else:
    b[0]=1
    b[1]=2
for i in range(N-2):
    if j==M-1 or (j>=0 and (i+2)!=a[j] and (i+1)!=a[j]):
        b[i+2]=b[i+1]+b[i]
    if j>0 and a[j]==a[j-1]+1:
        b[N-1]=0
    if j+1<M and a[j+1]==a[j]+1:
        b[N-1]=0
    elif j>=0 and (i+2)==a[j]:
        b[i+2]=b[i]
    elif j>=0 and j+1<M and (i+1)==a[j]:
        j+=1
        b[i+2]=b[i+1]
    elif j>=0 and (i+1)==a[j]:
        b[i+2]=b[i+1]
print(b[N-1]%1000000007)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=[]
b=[0]*N
for i in range(M):
    a.append(int(input()))
j=0
if a[0]==1:
    b[0]=0
    b[1]=1
elif a[0]==2:
    b[0]=1
    b[1]=1
else:
    b[0]=1
    b[1]=2
for i in range(N-2):
    if j==M-1 or ((i+2)!=a[j] and (i+1)!=a[j]):
        b[i+2]=b[i+1]+b[i]
    if j>0 and a[j]==a[j-1]+1:
        b[N-1]=0
    if j+1<M and a[j+1]==a[j]+1:
        b[N-1]=0
    elif (i+2)==a[j]:
        b[i+2]=b[i]
    elif j+1<M and (i+1)==a[j]:
        j+=1
        b[i+2]=b[i+1]
    elif (i+1)==a[j]:
        b[i+2]=b[i+1]
print(b[N-1]%1000000007)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=[]
b=[0]*N
for i in range(M):
    a.append(int(input()))
j=0
if a[0]==1:
    b[0]=0
    b[1]=1
elif a[0]==2:
    b[0]=1
    b[1]=1
else:
    b[0]=1
    b[1]=2
for i in range(N-2):
    if j==M-1 or ((i+2)!=a[j] and (i+1)!=a[j]):
        b[i+2]=b[i+1]+b[i]
    if j>0 and a[j]==a[j-1]+1:
        b[N-1]=0
    if j+1<M and a[j+1]==a[j]+1:
        b[N-1]=0
    elif (i+2)==a[j]:
        b[i+2]=b[i]
    elif j+1<M and (i+1)==a[j]:
        j+=1
        b[i+2]=b[i+1]
    elif (i+1)==a[j]:
        b[i+2]=b[i+1]
print(b[N-1]%1000000007,b)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=[]
b=0 in range(N)
for i in range(M):
    a.append(int(input()))
j=M-1
if j>=0 and a[0]==1:
    f1=0
    f2=1
elif j>=0 and a[0]==2:
    f1=1
    f2=1
else:
    f1=1
    f2=2
def f(n,a,j):
    if n>2:
        if j==-1 or ((n-1)!=a[j] and (n-2)!=a[j]):
            return (f(n-1,a,j)+f(n-2,a,j))%100000007
        if j>0 and a[j]==a[j-1]+1:
            return 0
        if j+1<M and a[j+1]==a[j]+1:
            return 0
        elif j>0 and (n-1)==a[j]:
            return f(n-2,a,j-1)%100000007
        elif (n-1)==a[j]:
            return f(n-2,a,j)
        elif (n-2)==a[j]:
            return f(n-1,a,j)%100000007
    elif n==1:
        return f1
    else:
        return f2
print(f(N,a,j)%100000007)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=[]
b=0 in range(N)
for i in range(M):
    a.append(int(input()))
j=M-1
if j>=0 and a[0]==1:
    f1=0
    f2=1
elif j>=0 and a[0]==2:
    f1=1
    f2=1
else:
    f1=1
    f2=2
def f(n,a,j):
    if n>2:
        if j==-1 or ((n-1)!=a[j] and (n-2)!=a[j]):
            return (f(n-1,a,j)+f(n-2,a,j))%100000007
        if j>0 and a[j]==a[j-1]+1:
            return 0
        if j+1<M and a[j+1]==a[j]+1:
            return 0
        elif (n-1)==a[j]:
            return f(n-2,a,j-1)%100000007
        elif (n-2)==a[j]:
            return f(n-1,a,j)%100000007
    elif n==1:
        return f1
    else:
        return f2
print(f(N,a,j)%100000007)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=[]
b=0 in range(N)
for i in range(M):
    a.append(int(input()))
j=M-1
if j>=0 and a[0]==1:
    f1=0
    f2=1
elif j>=0 and a[0]==2:
    f1=1
    f2=1
else:
    f1=1
    f2=2
def f(n,a,j):
    if n>2:
        if j==-1 or ((n-1)!=a[j] and (n-2)!=a[j]):
            return f(n-1,a,j)+f(n-2,a,j)
        if j>0 and a[j]==a[j-1]+1:
            return 0
        if j+1<M and a[j+1]==a[j]+1:
            return 0
        elif (n-1)==a[j]:
            return f(n-2,a,j-1)
        elif (n-2)==a[j]:
            return f(n-1,a,j)
    elif n==1:
        return f1
    else:
        return f2
print(f(N,a,j))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=[]
b=0 in range(N)
for i in range(M):
    a.append(int(input()))
j=M-1
if a[0]==1:
    f1=0
    f2=1
elif a[0]==2:
    f1=1
    f2=1
else:
    f1=1
    f2=2
def f(n,a,j):
    if n>2:
        if (n-1)!=a[j] and (n-2)!=a[j]:
            return f(n-1,a,j)+f(n-2,a,j)
        if j>0 and a[j]==a[j-1]+1:
            return 0
        if j+1<M and a[j+1]==a[j]+1:
            return 0
        elif (n-1)==a[j]:
            return f(n-2,a,j-1)
        elif (n-2)==a[j]:
            return f(n-1,a,j)
    elif n==1:
        return f1
    else:
        return f2
print(f(N,a,j))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=[]
for i in range(M):
    a.append(int(input()))
j=M-1
if a[0]==1:
    f1=0
    f2=1
elif a[0]==2:
    f1=1
    f2=1
else:
    f1=1
    f2=2
def f(n,a,j):
    if n>2:
        if (n-1)!=a[j] and (n-2)!=a[j]:
            if n>3 and n-3==a[j]:
                return f(n-1,a,j)+f(n-2,a,j-1)
            else:
                return f(n-1,a,j)+f(n-2,a,j)
        if j>0 and a[j]==a[j-1]+1:
            return 0
        if j+1<M and a[j+1]==a[j]+1:
            return 0
        elif (n-1)==a[j]:
             if n>3 and j>0 and n-3==a[j-1]:
                return f(n-2,a,j-1)
             else:
                return f(n-2,a,j)
        elif (n-2)==a[j]:
            return f(n-1,a,j-1)
    elif n==1:
        return f1
    else:
        return f2
print(f(N,a,j))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=[]
for i in range(M):
    a.append(int(input()))
j=M-1
if a[0]==1:
    f1=0
    f2=1
elif a[0]==2:
    f1=1
    f2=1
else:
    f1=1
    f2=2
def f(n,a,j):
    print("a")
    if n>2:
        if (n-1)!=a[j] and (n-2)!=a[j]:
            if n>3 and n-3==a[j]:
                return f(n-1,a,j)+f(n-2,a,j-1)
            else:
                return f(n-1,a,j)+f(n-2,a,j)
        if j>0 and a[j]==a[j-1]+1:
            return 0
        if j+1<M and a[j+1]==a[j]+1:
            return 0
        elif (n-1)==a[j]:
             if n>3 and j>0 and n-3==a[j-1]:
                return f(n-2,a,j-1)
             else:
                return f(n-2,a,j)
        elif (n-2)==a[j]:
            return f(n-1,a,j-1)
    elif n==1:
        return f1
    else:
        return f2
print(f(N,a,j))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=[]
for i in range(M):
    a.append(int(input()))
j=M-1
if a[0]==1:
    f1=0
    f2=1
elif a[0]==2:
    f1=1
    f2=1
else:
    f1=1
    f2=2
def f(n,a,j):
    if n>2:
        if (n-1)!=a[j] and (n-2)!=a[j]:
            if n>3 and n-3==a[j]:
                return f(n-1,a,j)+f(n-2,a,j-1)
            else:
                return f(n-1,a,j)+f(n-2,a,j)
        elif (n-1)==a[j]:
             if n>3 and j>0 and n-3==a[j-1]:
                return f(n-2,a,j-1)
             else:
                return f(n-2,a,j)
        elif (n-2)==a[j]:
            return f(n-1,a,j-1)
    elif n==1:
        return f1
    else:
        return f2
print(f(N,a,j))