Problem p03017 (python)

Fixed submission:
n, a, b, c, d = map(int, input().split())
s = input()

if c < d:
    print("Yes" if s[a - 1:d].count("##") == 0 else "No")
    #aからd-1までで二個あるとあうと
else:
    print("Yes" if s[a - 1:c].count("##") ==
          0 and s[b - 2:d + 1].count("...") > 0 else "No")
          #b-1からd+1までで飛び越すの

Buggy submission (verdict: Runtime Error):
from copy import deepcopy
def deal(s):
    stin=[]
    for i in range(len(s)):
        if s[i]==".":
            stin.append(0)
        else:
            stin.append(1)
    return stin
def dp(start,goal,stin):
    if goal<start or stin[goal-1]==1:
     #   print(start,goal)
      #  print(stin[goal-1])
       # print(stin)
        return False
    if start==goal:
        return True
    return dp(start,goal-1,stin) or dp(start,goal-2,stin)

n,a,b,c,d=map(int,input().split())
s=deal(input())
#print(s)
root=[]
if c<d:
    if dp(b,d,s):
       # print("ceh")
        if dp(a,c,s):
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif d<c:
    for i in range(b-1,d):
        if s[i]==0:
            q=deepcopy(s)
            q[i]=1
            root.append(q)
    #    print(root)
   # print("DAME")
    if dp(b,d,s):
        for x in root:
            if dp(a,c,x):
                print("Yes")
                exit()
        print("No")  
    else:
        print("No")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
from copy import deepcopy
def deal(s):
    stin=[]
    for i in range(len(s)):
        if s[i]==".":
            stin.append(0)
        else:
            stin.append(1)
    return stin
def dp(start,goal,stin):
    if goal<start or stin[goal-1]==1:
     #   print(start,goal)
      #  print(stin[goal-1])
       # print(stin)
        return False
    if start==goal:
        return True
    return dp(start,goal-1,stin) or dp(start,goal-2,stin)

n,a,b,c,d=map(int,input().split())
s=deal(input())
#print(s)
root=[]
if c<d:
    if dp(b,d,s):
       # print("ceh")
        if dp(a,c,s):
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif d<c:
    for i in range(b-1,d):
        if s[i]==0:
            q=deepcopy(s)
            q[i]=1
            root.append(q)
    #    print(root)
   # print("DAME")
    if dp(b,d,s):
        for x in root:
            if dp(a,c,x):
                print("Yes")
                exit()
        print("No")  
    else:
        print("aa")
        print("No")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
from copy import deepcopy
def deal(s):
    stin=[]
    for i in range(len(s)):
        if s[i]==".":
            stin.append(0)
        else:
            stin.append(1)
    return stin
def dp(start,goal,stin):
    if goal<start or stin[goal-1]==1:
     #   print(start,goal)
      #  print(stin[goal-1])
       # print(stin)
        return False
    if start==goal:
        return True
    return dp(start,goal-1,stin) or dp(start,goal-2,stin)

n,a,b,c,d=map(int,input().split())
s=deal(input())
#print(s)
root=[]
if c<d:
    if dp(b,d,s):
        print("ceh")
        if dp(a,c,s):
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif d<c:
    for i in range(b-1,d):
        if s[i]==0:
            q=deepcopy(s)
            q[i]=1
            root.append(q)
    #    print(root)
   # print("DAME")
    if dp(b,d,s):
        for x in root:
            if dp(a,c,x):
                print("Yes")
                exit()
        print("No")  
    else:
        print("aa")
        print("No")
else:
    print("No")