Problem p03013 (python)

Fixed submission:
import sys
N,M=map(int,input().split())
dp=[1]*N
listA=[]
for i in range(M):
  a=int(input())
  listA+=[a]
  dp[a-1]=0
for i in range(1,M):
  if listA[i]==listA[i-1]:
    print(0)
    sys.exit()
setA=set(listA)    
if (1 not in setA) and (2 not in setA) and N!=1:
  dp[1]=2
for i in range(2,N):
  if i+1 not in setA:
    dp[i]=dp[i-1]+dp[i-2]
ans=dp[-1]%(10**9+7)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
N,M=map(int,input().split())
dp=[1]*N
listA=[]
for i in range(M):
  a=int(input())
  listA+=[a]
  dp[a-1]=0
for i in range(1,M):
  if listA[i]==listA[i-1]:
    print(0)
    sys.exit()
setA=set(listA)    
if (1 not in setA) and (2 not in setA):
  dp[1]=2
for i in range(2,N):
  if i+1 not in setA:
    dp[i]=dp[i-1]+dp[i-2]
ans=dp[-1]%(10**9+7)
print(ans)

Buggy submission (verdict: Runtime Error):
from math import factorial
import sys
N,M=map(int,input().split())
ANS1=1
ANS2=1
ANS3=1
A=int(input())
list1=[A]
DAN=A
B=DAN-DAN//2
for k in range(B):
  a = factorial(B) / factorial(k+1) / factorial(B - (k+1))
  ANS1+=a
for i in range(1,M):
  ans2=1
  A=int(input())
  list1+=[A]
  DAN=A-list1[i-1]-1
  B=DAN-DAN//2
  if A==list1[i-1] or A==list1[i-1]+1 and M!=1:
    print(0)
    sys.exit()
  for k in range(B):
    a = factorial(B) / factorial(k+1) / factorial(B - (k+1))
    ANS2+=a
  ANS3*=ANS2
DAN=N-A-1
B=DAN-DAN//2
for t in range(B):
  a = factorial(B) / factorial(t+1) / factorial(B - (t+1))
  ANS3+=a
ANS=ANS1*ANS2*ANS3  
print(int(ANS)%1000000007)

Buggy submission (verdict: Runtime Error):
from math import factorial
import sys
N,M=map(int,input().split())
ANS=0
A=int(input())
list1=[A]
DAN=A
B=DAN-DAN//2
for k in range(B):
  a = factorial(B) / factorial(k) / factorial(B - k)
  ANS+=a
for i in range(1,M):
  A=int(input())
  list1+=[A]
  DAN=A-list1[i-1]-1
  B=DAN-DAN//2
  if A==list1[i-1] or A==list1[i-1]+1:
    print(0)
    sys.exit()
  for k in range(B):
    a = factorial(B) / factorial(k) / factorial(B - k)
    ANS+=a
DAN=N-A-1
B=DAN-DAN//2
for t in range(B):
  a = factorial(B) / factorial(t) / factorial(B - t)
  ANS+=a
print(int(ANS)%1000000007)

Buggy submission (verdict: Runtime Error):
from math import factorial
N,M=map(int,input().split())
list1=[]
ANS=0
A=int(input())
DAN=A
B=DAN-DAN//2
for k in range(B):
  a = factorial(B) / factorial(k) / factorial(B - k)
  ANS+=a
for i in range(1,M):
  A=int(input())
  list1+=[A]
  DAN=A-list1[i-1]-1
  B=DAN-DAN//2
  if A==list1[i-1] or A==list1[i-1]+1:
    print(0)
    break  
  for k in range(B):
    a = factorial(B) / factorial(k) / factorial(B - k)
    ANS+=a
DAN=N-A-1
B=DAN-DAN//2
for t in range(B):
  a = factorial(B) / factorial(t) / factorial(B - t)
  ANS+=a
print(int(ANS)%1000000007)

Buggy submission (verdict: Runtime Error):
from math import factorial
N,M=map(int,input().split())
list1=[]
ANS=0
for i in range(M):
  A=int(input())
  list1+=[A]
  if i>=1:
    DAN=A-list1[i-1]-1
    B=DAN-DAN//2
    if A==list1[i-1] or A==list1[i-1]+1:
      print(0)
      break
    for k in range(B):
      a = factorial(B) / factorial(k) / factorial(B - k)
      ANS+=a
  else:
    DAN=A
    B=DAN-DAN//2
    for k in range(B):
      a = factorial(B) / factorial(k) / factorial(B - k)
      ANS+=a
DAN=N-A-1
B=DAN-DAN//2
for t in range(B):
  a = factorial(B) / factorial(t) / factorial(B - t)
  ANS+=a
print(int(ANS)%1000000007)