Problem p03017 (python)

Fixed submission:
N,A,B,C,D = map(int,input().split())
S = input().strip()
S = "."+S
flag=0
if C<B:
    for i in range(A,C):
        if S[i:i+2]=="##":
            flag=1
            break
    for i in range(B,D):
        if S[i:i+2]=="##":
            flag=1
            break
    if flag==1:
        print("No")
    else:
        print("Yes")
elif B<C<D:
    for i in range(A,D):
        if S[i:i+2]=="##":
            flag=1
            break
    if flag==1:
        print("No")
    else:
        print("Yes")
else:
    for i in range(A,C):
        if S[i:i+2]=="##":
            flag = 1
            break
    if flag==1:
        print("No")
    else:
        flag = 1
        for i in range(B+1,D):
            if S[i]=="#":continue
            if (S[i-1]=="#" and S[i+1]=="#") or (S[i-2:i]=="#." and S[i+1]=="#") or (S[i-1]=="#" and S[i+1:i+3]==".#"):continue
            else:
                flag=0
                break
        if flag==1:
            if S[B+1]=="#" or (S[B-1]=="#" and S[B+1:B+3]==".#"):
                flag=1
            else:
                flag=0
        if flag==1:
            print("No")
        else:
            print("Yes")

Buggy submission (verdict: Runtime Error):
import heapq
INFTY = 10**6
N,A,B,C,D = map(int,input().split())
S = input().strip()
S = "0"+S
G = {i:[] for i in range(1,N+1)}
for i in range(1,N-1):
    if S[i]==".":
        if S[i+1]==".":
            G[i].append(i+1)
        if S[i+2]==".":
            G[i].append(i+2)
if S[N-1]==".":
    if S[N]==".":
        G[N-1].append(N)
if D>C:
    d = [INFTY for _ in range(N+1)]
    heap = [(0,B)]
    d[B] = 0
    while heap:
        cur = heapq.heappop(heap)
        if cur[0]>d[cur[1]]:continue
        for x in G[cur[1]]:
            if d[x]>cur[0]+1:
                d[x] = cur[0]+1
                heapq.heappush(heap,(d[x],x))
    if d[D]>=INFTY:
        flagB = 0
    else:
        flagB = 1
    d = [INFTY for _ in range(N+1)]
    heap = [(0,A)]
    while heap:
        cur = heapq.heappop(heap)
        if cur[0]>d[cur[1]]:continue
        for x in G[cur[1]]:
            if d[x]>cur[0]+1:
                d[x] = cur[0]+1
                heapq.heappush(heap,(d[x],x))
    if d[C]>=INFTY:
        flagA = 0
    else:
        flagA = 1
else:
    b = B
    flag = 0
    while b+1<=D and (S[b-1]=="#" or S[b+1]=="#"):
        if S[b+1]==".":
            b += 1
        elif b+2<=D and S[b+2]==".":
            b += 2
        else:
            flag = 1
            break
    if S[b-1]==".":
        if b+1<=D and S[b+1]==".":
            flag = 0
        elif b==D:
            flag = 0
        else:
            flag = 1
    else:
        if S[D-1]=="." and S[D]==".":
            b = D
            flag = 0
        else:
            flag = 1
    if flag==1:
        flagB = 0
    else:
        B = b
        if b in G[b-1]:
            G[b-1].remove(b)
        if b-2>=1 and b in G[b-2]:
            G[b-2].remove(b)
        d = [INFTY for _ in range(N+1)]
        heap = [(0,A)]
        while heap:
            cur = heapq.heappop(heap)
            if cur[0]>d[cur[1]]:continue
            for x in G[cur[1]]:
                if d[x]>cur[0]+1:
                    d[x] = cur[0]+1
                    heapq.heappush(heap,(d[x],x))
        if d[C]>=INFTY:
            flagA = 0
        else:
            flagA = 1
            if C in G[C-1]:
                G[C-1].remove(C)
            if C-2>=1 and C in G[C-2]:
                G[C-2].remove(C)
        d = [INFTY for _ in range(N+1)]
        heap = [(0,B)]
        while heap:
            cur = heapq.heappop(heap)
            if cur[0]>d[cur[1]]:continue
            for x in G[cur[1]]:
                if d[x]>cur[0]+1:
                    d[x] = cur[0]+1
                    heapq.heappush(heap,(d[x],x))
        if d[D]>=INFTY:
            flagB = 0
        else:
            flagB = 1
if flagA==1 and flagB==1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import heapq
INFTY = 10**6
N,A,B,C,D = map(int,input().split())
S = input().strip()
S = "0"+S
G = {i:[] for i in range(1,N+1)}
for i in range(1,N-1):
    if S[i]==".":
        if S[i+1]==".":
            G[i].append(i+1)
        if S[i+2]==".":
            G[i].append(i+2)
if S[N-1]==".":
    if S[N]==".":
        G[N-1].append(N)
if D>C:
    d = [INFTY for _ in range(N+1)]
    heap = [(0,B)]
    d[B] = 0
    while heap:
        cur = heapq.heappop(heap)
        if cur[0]>d[cur[1]]:continue
        for x in G[cur[1]]:
            if d[x]>cur[0]+1:
                d[x] = cur[0]+1
                heapq.heappush(heap,(d[x],x))
    if d[D]>=INFTY:
        flagB = 0
    else:
        flagB = 1
    d = [INFTY for _ in range(N+1)]
    heap = [(0,A)]
    while heap:
        cur = heapq.heappop(heap)
        if cur[0]>d[cur[1]]:continue
        for x in G[cur[1]]:
            if d[x]>cur[0]+1:
                d[x] = cur[0]+1
                heapq.heappush(heap,(d[x],x))
    if d[C]>=INFTY:
        flagA = 0
    else:
        flagA = 1
else:
    b = B
    flag = 0
    while b+1<=D and (S[b-1]=="#" or S[b+1]=="#"):
        if S[b+1]==".":
            b += 1
        elif b+2<=D and S[b+2]==".":
            b += 2
        else:
            flag = 1
            break
    if S[b-1]==".":
        if b+1<=D and S[b+1]==".":
            flag = 0
        elif b==D:
            flag = 0
        else:
            flag = 1
    else:
        if S[D-1]=="." and S[D]==".":
            b = D
            flag = 0
        else:
            flag = 1
    if flag==1:
        flagB = 0
    else:
        B = b
        if b in G[b-1]:
            G[b-1].remove(b)
        if b-2>=1 and b in G[b-2]:
            G[b-2].remove(b)
        d = [INFTY for _ in range(N+1)]
        heap = [(0,A)]
        while heap:
            cur = heapq.heappop(heap)
            if cur[0]>d[cur[1]]:continue
            for x in G[cur[1]]:
                if d[x]>cur[0]+1:
                    d[x] = cur[0]+1
                    heapq.heappush(heap,(d[x],x))
        if d[C]>=INFTY:
            flagA = 0
        else:
            flagA = 1
            if C in G[C-1]>0:
                G[C-1].remove(C)
            if C-2>=1 and C in G[C-2]:
                G[C-2].remove(C)
        d = [INFTY for _ in range(N+1)]
        heap = [(0,B)]
        while heap:
            cur = heapq.heappop(heap)
            if cur[0]>d[cur[1]]:continue
            for x in G[cur[1]]:
                if d[x]>cur[0]+1:
                    d[x] = cur[0]+1
                    heapq.heappush(heap,(d[x],x))
        if d[D]>=INFTY:
            flagB = 0
        else:
            flagB = 1
if flagA==1 and flagB==1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import heapq
INFTY = 10**6
N,A,B,C,D = map(int,input().split())
S = input().strip()
S = "0"+S
G = {i:[] for i in range(1,N+1)}
for i in range(1,N-1):
    if S[i]==".":
        if S[i+1]==".":
            G[i].append(i+1)
        if S[i+2]==".":
            G[i].append(i+2)
if S[N-1]==".":
    if S[N]==".":
        G[N-1].append(N)
if D>C:
    d = [INFTY for _ in range(N+1)]
    heap = [(0,B)]
    d[B] = 0
    while heap:
        cur = heapq.heappop(heap)
        if cur[0]>d[cur[1]]:continue
        for x in G[cur[1]]:
            if d[x]>cur[0]+1:
                d[x] = cur[0]+1
                heapq.heappush(heap,(d[x],x))
    if d[D]>=INFTY:
        flagB = 0
    else:
        flagB = 1
    d = [INFTY for _ in range(N+1)]
    heap = [(0,A)]
    while heap:
        cur = heapq.heappop(heap)
        if cur[0]>d[cur[1]]:continue
        for x in G[cur[1]]:
            if d[x]>cur[0]+1:
                d[x] = cur[0]+1
                heapq.heappush(heap,(d[x],x))
    if d[C]>=INFTY:
        flagA = 0
    else:
        flagA = 1
else:
    b = B
    flag = 0
    while b+1<=D and (S[b-1]=="#" or S[b+1]=="#"):
        if S[b+1]==".":
            b += 1
        elif b+2<=D and S[b+2]==".":
            b += 2
        else:
            flag = 1
            break
    if S[b-1]==".":
        if b+1<=D and S[b+1]==".":
            flag = 0
        elif b==D:
            flag = 0
        else:
            flag = 1
    else:
        if S[D-1]==".":
            b = D
            flag = 0
        else:
            flag = 1
    if flag==1:
        flagB = 0
    else:
        B = b
        if len(G[b-1])>0:
            G[b-1].remove(b)
        if b-2>=1 and len(G[b-2])>0:
            G[b-2].remove(b)
        d = [INFTY for _ in range(N+1)]
        heap = [(0,A)]
        while heap:
            cur = heapq.heappop(heap)
            if cur[0]>d[cur[1]]:continue
            for x in G[cur[1]]:
                if d[x]>cur[0]+1:
                    d[x] = cur[0]+1
                    heapq.heappush(heap,(d[x],x))
        if d[C]>=INFTY:
            flagA = 0
        else:
            flagA = 1
            if len(G[C-1])>0:
                G[C-1].remove(C)
            if C-2>=1 and len(G[C-2])>0:
                G[C-2].remove(C)
        d = [INFTY for _ in range(N+1)]
        heap = [(0,B)]
        while heap:
            cur = heapq.heappop(heap)
            if cur[0]>d[cur[1]]:continue
            for x in G[cur[1]]:
                if d[x]>cur[0]+1:
                    d[x] = cur[0]+1
                    heapq.heappush(heap,(d[x],x))
        if d[D]>=INFTY:
            flagB = 0
        else:
            flagB = 1
if flagA==1 and flagB==1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import heapq
INFTY = 10**6
N,A,B,C,D = map(int,input().split())
S = input().strip()
S = "0"+S
G = {i:[] for i in range(1,N+1)}
for i in range(1,N-1):
    if S[i]==".":
        if S[i+1]==".":
            G[i].append(i+1)
        if S[i+2]==".":
            G[i].append(i+2)
if S[N-1]==".":
    if S[N]==".":
        G[N-1].append(N)
if D>C:
    d = [INFTY for _ in range(N+1)]
    heap = [(0,B)]
    d[B] = 0
    while heap:
        cur = heapq.heappop(heap)
        if cur[0]>d[cur[1]]:continue
        for x in G[cur[1]]:
            if d[x]>cur[0]+1:
                d[x] = cur[0]+1
                heapq.heappush(heap,(d[x],x))
    if d[D]>=INFTY:
        flagB = 0
    else:
        flagB = 1
    d = [INFTY for _ in range(N+1)]
    heap = [(0,A)]
    while heap:
        cur = heapq.heappop(heap)
        if cur[0]>d[cur[1]]:continue
        for x in G[cur[1]]:
            if d[x]>cur[0]+1:
                d[x] = cur[0]+1
                heapq.heappush(heap,(d[x],x))
    if d[C]>=INFTY:
        flagA = 0
    else:
        flagA = 1
else:
    b = B
    flag = 0
    while b+1<=D and (S[b-1]=="#" or S[b+1]=="#"):
        if S[b+1]==".":
            b += 1
        elif S[b+2]==".":
            b += 2
        else:
            flag = 1
            break
    if S[b-1]==".":
        if b+1<=D and S[b+1]==".":
            flag = 0
        elif b==D:
            flag = 0
        else:
            flag = 1
    else:
        if S[D-1]==".":
            b = D
            flag = 0
        else:
            flag = 1
    if flag==1:
        flagB = 0
    else:
        B = b
        if len(G[b-1])>0:
            G[b-1].remove(b)
        if b-2>=1 and len(G[b-2])>0:
            G[b-2].remove(b)
        d = [INFTY for _ in range(N+1)]
        heap = [(0,A)]
        while heap:
            cur = heapq.heappop(heap)
            if cur[0]>d[cur[1]]:continue
            for x in G[cur[1]]:
                if d[x]>cur[0]+1:
                    d[x] = cur[0]+1
                    heapq.heappush(heap,(d[x],x))
        if d[C]>=INFTY:
            flagA = 0
        else:
            flagA = 1
            if len(G[C-1])>0:
                G[C-1].remove(C)
            if C-2>=1 and len(G[C-2])>0:
                G[C-2].remove(C)
        d = [INFTY for _ in range(N+1)]
        heap = [(0,B)]
        while heap:
            cur = heapq.heappop(heap)
            if cur[0]>d[cur[1]]:continue
            for x in G[cur[1]]:
                if d[x]>cur[0]+1:
                    d[x] = cur[0]+1
                    heapq.heappush(heap,(d[x],x))
        if d[D]>=INFTY:
            flagB = 0
        else:
            flagB = 1
if flagA==1 and flagB==1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import heapq
INFTY = 10**6
N,A,B,C,D = map(int,input().split())
S = input().strip()
S = "0"+S
G = {i:[] for i in range(1,N+1)}
for i in range(1,N-1):
    if S[i]==".":
        if S[i+1]==".":
            G[i].append(i+1)
        if S[i+2]==".":
            G[i].append(i+2)
if S[N-1]==".":
    if S[N]==".":
        G[N-1].append(N)
if D>C:
    d = [INFTY for _ in range(N+1)]
    heap = [(0,B)]
    d[B] = 0
    while heap:
        cur = heapq.heappop(heap)
        if cur[0]>d[cur[1]]:continue
        for x in G[cur[1]]:
            if d[x]>cur[0]+1:
                d[x] = cur[0]+1
                heapq.heappush(heap,(d[x],x))
    if d[D]>=INFTY:
        flagB = 0
    else:
        flagB = 1
    d = [INFTY for _ in range(N+1)]
    heap = [(0,A)]
    while heap:
        cur = heapq.heappop(heap)
        if cur[0]>d[cur[1]]:continue
        for x in G[cur[1]]:
            if d[x]>cur[0]+1:
                d[x] = cur[0]+1
                heapq.heappush(heap,(d[x],x))
    if d[C]>=INFTY:
        flagA = 0
    else:
        flagA = 1
else:
    b = B
    flag = 0
    while b+1<=D and (S[b-1]=="#" or S[b+1]=="#"):
        if S[b+1]==".":
            b += 1
        elif S[b+2]==".":
            b += 2
        else:
            flag = 1
            break
    if S[b-1]==".":
        if S[b+1]==".":
            flag = 0
        else:
            flag = 1
    else:
        if S[D-1]==".":
            b = D
            flag = 0
        else:
            flag = 1
    if flag==1:
        flagB = 0
    else:
        B = b
        if len(G[b-1])>0:
            G[b-1].remove(b)
        if b-2>=1 and len(G[b-2])>0:
            G[b-2].remove(b)
        d = [INFTY for _ in range(N+1)]
        heap = [(0,A)]
        while heap:
            cur = heapq.heappop(heap)
            if cur[0]>d[cur[1]]:continue
            for x in G[cur[1]]:
                if d[x]>cur[0]+1:
                    d[x] = cur[0]+1
                    heapq.heappush(heap,(d[x],x))
        if d[C]>=INFTY:
            flagA = 0
        else:
            flagA = 1
            if len(G[C-1])>0:
                G[C-1].remove(C)
            if C-2>=1 and len(G[C-2])>0:
                G[C-2].remove(C)
        d = [INFTY for _ in range(N+1)]
        heap = [(0,B)]
        while heap:
            cur = heapq.heappop(heap)
            if cur[0]>d[cur[1]]:continue
            for x in G[cur[1]]:
                if d[x]>cur[0]+1:
                    d[x] = cur[0]+1
                    heapq.heappush(heap,(d[x],x))
        if d[D]>=INFTY:
            flagB = 0
        else:
            flagB = 1
if flagA==1 and flagB==1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import heapq
INFTY = 10**6
N,A,B,C,D = map(int,input().split())
S = input().strip()
S = "0"+S
G = {i:[] for i in range(1,N+1)}
for i in range(1,N-1):
    if S[i]==".":
        if S[i+1]==".":
            G[i].append(i+1)
        if S[i+2]==".":
            G[i].append(i+2)
if S[N-1]==".":
    if S[N]==".":
        G[N-1].append(N)
if D>C:
    d = [INFTY for _ in range(N+1)]
    heap = [(0,B)]
    d[B] = 0
    while heap:
        cur = heapq.heappop(heap)
        if cur[0]>d[cur[1]]:continue
        for x in G[cur[1]]:
            if d[x]>cur[0]+1:
                d[x] = cur[0]+1
                heapq.heappush(heap,(d[x],x))
    if d[D]>=INFTY:
        flagB = 0
    else:
        flagB = 1
    d = [INFTY for _ in range(N+1)]
    heap = [(0,A)]
    while heap:
        cur = heapq.heappop(heap)
        if cur[0]>d[cur[1]]:continue
        for x in G[cur[1]]:
            if d[x]>cur[0]+1:
                d[x] = cur[0]+1
                heapq.heappush(heap,(d[x],x))
    if d[C]>=INFTY:
        flagA = 0
    else:
        flagA = 1
else:
    b = B
    flag = 0
    while b+1<=D and (S[b-1]=="#" or S[b+1]=="#"):
        if S[b+1]==".":
            b += 1
        elif S[b+2]==".":
            b += 2
        else:
            flag = 1
            break
    if S[b-1]==".":
        if S[b+1]==".":
            flag = 0
        else:
            flag = 1
    else:
        if S[D-1]==".":
            b = D
            flag = 0
        else:
            flag = 1
    if flag==1:
        flagB = 0
    else:
        B = b
        if len(G[b-1])>0:
            G[b-1].remove(b)
        if b-2>=1 and len(G[b-2])>0:
            G[b-2].remove(b)
        d = [INFTY for _ in range(N+1)]
        heap = [(0,A)]
        while heap:
            cur = heapq.heappop(heap)
            if cur[0]>d[cur[1]]:continue
            for x in G[cur[1]]:
                if d[x]>cur[0]+1:
                    d[x] = cur[0]+1
                    heapq.heappush(heap,(d[x],x))
        if d[C]>=INFTY:
            flagA = 0
        else:
            flagA = 1
            if len(G[C-1])>0:
                G[C-1].remove(C)
            if C-2>=1 and len(G[C-2])>0:
                G[C-2].remove(C)
        d = [INFTY for _ in range(N+1)]
        heap = [(0,B)]
        while heap:
            cur = heapq.heappop(heap)
            if cur[0]>d[cur[1]]:continue
            for x in G[cur[1]]:
                if d[x]>cur[0]+1:
                    d[x] = cur[0]+1
                    heapq.heappush(heap,(d[x],x))
        if d[D]>=INFTY:
            flagB = 0
        else:
            flagB = 1
if flagA==1 and flagB==1:
    print("Yes")
else:
    print("No")