Problem:


Score : 400 points

Problem Statement

There are N squares arranged in a row, numbered 1, 2, ..., N from left to right.
You are given a string S of length N consisting of . and #. If the i-th character of S is #, Square i contains a rock; if the i-th character of S is ., Square i is empty.

In the beginning, Snuke stands on Square A, and Fnuke stands on Square B.

You can repeat the following operation any number of times:

Choose Snuke or Fnuke, and make him jump one or two squares to the right. The destination must be one of the squares, and it must not contain a rock or the other person.

You want to repeat this operation so that Snuke will stand on Square C and Fnuke will stand on Square D.

Determine whether this is possible.

Constraints

4 \leq N \leq 200\ 000

S is a string of length N consisting of . and #.

1 \leq A, B, C, D \leq N

Square A, B, C and D do not contain a rock.

A, B, C and D are all different.

A < B

A < C

B < D

Input

Input is given from Standard Input in the following format:

N A B C D
S

Output

Print Yes if the objective is achievable, and No if it is not.

Sample Input 1

7 1 3 6 7
.#..#..

Sample Output 1

Yes

The objective is achievable by, for example, moving the two persons as follows. (A and B represent Snuke and Fnuke, respectively.)

A#B.#..

A#.B#..

.#AB#..

.#A.#B.

.#.A#B.

.#.A#.B

.#..#AB

Sample Input 2

7 1 3 7 6
.#..#..

Sample Output 2

No

Sample Input 3

15 1 3 15 13
...#.#...#.#...

Sample Output 3

Yes



Sample input:
7 1 3 6 7
.#..#..


Sample output:
Yes

Submission status: Runtime Error

Solution code:
n, a, b, c, d = map(int, input().split())
s = list(input())

def check():
    for i in range(a-1, d):
        if s[i-1] == s[i] == '#':
            return False
    return True


def check_2():
    for i in range(b-1, c):
        if s[i-1] == s[i] == s[i+1] == ".":
            return True
    return False


if check() is True:
    if c < d:
        print('Yes')
        exit()
    else:
        if check_2() is True:
            print('Yes')
            exit()
print('No')

Submission status: Runtime Error

Solution code:
N, A, B, C, D = map(int, input().split())
S = list(input())
A -= 1
B -= 1
C -= 1
D -= 1

def check_one_people_can(start, end):
    s = S[start+1: end]
    for x in s:
        if x == "#":
            if before_sharp:
                return False
            before_sharp = True
        else:
            before_sharp = False
    return True

def check_triple_dots(start, end):
    s = S[start-1: end+1]
    continuous_dots = 0
    for x in s:
        if x == ".":
            continuous_dots += 1
            if continuous_dots == 3:
                return True
        else:
            continuous_dots = 0
    return False

if D > C:
    if check_one_people_can(A, C) and check_one_people_can(C, D):
        print("Yes")
    else:
        print("No")
else:
    if check_triple_dots(B, D) and check_one_people_can(A, C):
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
N,A,B,C,D = map(int, input().split())
S = [""] + list(input())

def can(start, end):
    for i in range(start, end):
        if S[i] == S[i + 1] == "#":
            return False
    return True

def main():
    if not (can(A, C) and can(B, D)):
        return False

    if C < D:
        flag = False
        for i in range(B, D + 1):
            if S[i - 1] == S[i] == S[i + 1] == ".":
                flag = True
        if not flag:
            return False
    
    return True

if __name__ == "__main__":
    if main():
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
S = list(input())[: -1]
dp = [0] * (N + 1)
dp[B] = 1
for i in range(B, N + 1):
  if dp[i] == 0: continue
  if i + 1 <= N:
    if S[i] == ".":
      dp[i + 1] = 1
  if i + 2 <= N:
    if S[i + 1] == ".":
      dp[i + 2] = 1
if dp[D] == 0:
  print("No")
  exit(0)
S[D] = "#"
dp = [0] * (N + 1)
dp[A] = 1
for i in range(A, N + 1):
  if dp[i] == 0: continue
  if i + 1 <= N:
    if S[i] == ".":
      dp[i + 1] = 1
  if i + 2 <= N:
    if S[i + 1] == ".":
      dp[i + 2] = 1
#print(dp)
if dp[C]:
  print("Yes")
else: print("No")

Submission status: Runtime Error

Solution code:
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  n, a, b, c, d = input_list()
  s = input()
  dp = []
  has_space = False
  if s[c-1] == '#':
    print('No')
    exit(0)
  if s[d-1] == '#':
    print('No')
    exit(0)
  if c > d:
    for i in range(a-1, c):
      if s[i] == '#' and s[i+1] == '#':
        print('No')
        exit(0)
    for i in range(b-1, d):
      if s[i] == '#' and s[i+1] == '#':
        print('No')
        exit(0)
  else:
    for i in range(a-1, c):
      if s[i] == '#' and s[i+1] == '#':
        print('No')
        exit(0)
     
    for i in range(b-1, d):
      if s[i] == '#' and s[i+1] == '#':
        print('No')
        exit(0)
      if s[i-1] == '.' and s[i+1] == '.' and s[i] == '.':
        has_space = True
    if has_space is False:
      print('No')
      exit(0)

  print('Yes')
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Runtime Error

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
S = "#" + S + "#"

# A -= 1
# B -= 1
# C -= 1
# D -= 1

def can_reach(start, end):
    for i in range(start, end + 2):
        if S[i] == '#' and S[i + 1] == '#':
            return False
    return True


if not can_reach(A, C) or not can_reach(B, D):
    print("No")
    exit()

if C > D:
    cover = False
    for i in range(B, D + 1):
        if S[i - 1] == '.' and S[i] == '.' and S[i + 1] == '.':
            cover = True
    if not cover:
        print("No")
        exit()


print("Yes")

Submission status: Runtime Error

Solution code:
from itertools import accumulate
n,x = map(int,input().split())
blr = [list(map(int,input().split())) for i in range(n)]
tad = []
for i in range(n):
  b,l,r = blr[i]
  tad.append(((x-b)*r+b*l,-b*l,(x-b)*r,i))
tad.sort(reverse=True)
t = list(zip(*tad))[2]
a = list(zip(*tad))[1]
a = [a[i]*(-1) for i in range(n)]
tacc = list(accumulate(t))
aacc = list(accumulate(a))
for i in range(n):
  if tacc[i]>=aacc[n-1]-aacc[i]:
    p = i
    break
if p == 0:
  tsum = 0
  asum = aacc[n-1]
else:
  tsum = tacc[p-1]
  asum = aacc[n-1]-aacc[p-1]
vis = [0]*n
for i in range(p):
  if tad[i][0] == tad[p][0]:
    continue
  v = tad[i][3]
  vis[v] = 1
ans = 10**18
for i in range(n):
  if vis[i]:
    continue
  b,l,r = blr[i]
  asumd = asum-b*l
  dif = tsum-asumd
  anstmp = p*x
  if dif >= 0:
    anstmp += b-dif//l
    print(2/0)
  else:
    anstmp += (-dif+r-1)//r+b
  if anstmp > (p+1)*x:
    continue
  ans = min(ans,anstmp)
print(ans)

Submission status: Runtime Error

Solution code:
N, A, B, C, D = map(int, input().split())
S = str(input())

Sarr = [True if s == '.' else False for s in S]
#print(Sarr)

def canmove(st):
  global N, Sarr
  can = [False] * N
  can[st-1] = True
  for i in range(st, N):
    if Sarr[i]:
      if can[i-1] or can[i-2]:
        can[i] = True
  return can

Acan = canmove(A)
Bcan = canmove(B)
#print(Acan)
#print(Bcan)

ans = Acan[C-1] and Bcan[D-1]
#print(ans)

def canpass(st, ed):
  global Sarr
  for i in range(st, ed-1):
    if Sarr[i] and Sarr[i+1] and Sarr[i+2]:
      return True
  return False

if C > D:
  ans = ans and canpass(B-1, D+1)
#print(ans)

if ans:
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
n, a, b, c, d = map(int, input().split())
s = [0 if i == "#" else 1 for i in input()]
cnt = 0
for si in range(a, max(c, d)):
    if si != 0:
        cnt = 0
    else:
        cnt += 1
        if cnt == 2:
            print("No")
            exit()
if c < d:
    print("Yes")
    exit()
idx = b - 1
cnt = 0
while idx < d:
    if s[idx] == s[idx+1] == s[idx+2] == 1:
        print("Yes")
        exit()
    else:
        idx += 1
print("No")

Submission status: Runtime Error

Solution code:
n, a, b, c, d = map(int, input().split())
s = [0 if i == "#" else 1 for i in input()]
if c < d:
    print("Yes")
    exit()
idx = b - 1
cnt = 0
while idx <= d + 1:
    if s[idx] == 0:
        cnt = 0
    else:
        cnt += 1
        if cnt == 3:
            print("Yes")
            exit()
    idx += 1
print("No")

Submission status: Runtime Error

Solution code:
n, a, b, c, d = input().split()
s = input()
flag = False
for i in range(n-1):
    if s[i] == s[i+1] == '#':
        print("No")
        exit()
if c < d:
    print("Yes")
else:
    for i in range(b+1, d):
        if s[i-1] == s[i+1] == s[i]:
            print("Yes")
            exit()
    print("No")

Submission status: Runtime Error

Solution code:
N,A,B,C,D = map(int,input().split())
S = str(input())
E = max(C,D)
AE = S[A:E+1]
BD = S[B-2:D+1]
check = 0
if "##" in AE:
  check = 1
  break
else:
  check = 0
if check == 0 and C > D:
  if "..." in BD:
    check = 0
  else:
    check = 1
    break
if check == 0
  print("OK")
else:
  print("MISS")

Submission status: Runtime Error

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,a,b,c,d = inpl()
s = input()
def chk(i):
    if s[i] == s[i+1] == '#':
        print('No')
        quit()
    return True
def cc(i):
    if s[i] == s[i+1] == s[i+2] == '.':
        return True
    return False

if c < d:
    for i in range(b-1,d-1):
        chk(i)
    for i in range(a-1,c-1):
        chk(i)
else:
    for i in range(b-1,d):
        if cc(i):
            break
    else:
        print('No')
        quit()
    for i in range(a-1,c-1):
        chk(i)
print('Yes')

Submission status: Runtime Error

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

if c < d:
    for i in range(b-1, d-1):
        if s[i] == '#' and s[i+1] == '#':
            print('No')
            exit()

    t = ''
    for i in range(len(s)):
        if i == d-1:
            t += '#'
        else:
            t += s[i]

    for i in range(a-1, c-1):
        if t[i] == '#' and t[i+1] == '#':
            print('No')
            exit()

    print('Yes')
elif c > d:
    for i in range(a-1, c-1):
        if s[i] == '#' and s[i+1] == '#':
            print('No')
            exit()

for bi in range(b-1,d):
    if s[bi-1] == s[bi] == s[bi+1] == '.':
        print('Yes')
        exit()

else:
    print('No')

Submission status: Runtime Error

Solution code:
N,A,B,C,D = map(int,input().split())
S = list(input())
ans = "Yes"
is_reversed = False
flag = False

if D < C:
  is_reversed = True

for i in range(A,max(C,D) -1):
  if S[i] == S[i + 1] == "#":
    ans = "No"
if is_reversed == True:
  for i in range(B - 2,D - 1):
    if S[i] == S[i + 1] == S[i + 2] == ".":
 
  if flag == False:
    ans = "No"
print(ans)

Submission status: Runtime Error

Solution code:
N,A,B,C,D = map(int,input().split())
S = list(input())
ans = "Yes"
is_reversed = False
flag = False
if D < C:
  is_reversed = True
for i in range(A,max(C,D) -1):
  if S[i] == S[i + 1] == "#":
    ans = "No"
for i in range(B - 2,D - 1):
  if S[i] == S[i + 1] == S[i + 2] == ".":
    flag = True

if is_reversed == True and flag == False:
  ans = "No"
print(ans)

Submission status: Runtime Error

Solution code:
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")

Submission status: Runtime Error

Solution code:
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")

Submission status: Runtime Error

Solution code:
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")

Submission status: Runtime Error

Solution code:
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")

Submission status: Runtime Error

Solution code:
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")

Submission status: Runtime Error

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, a, b, c, d = list(map(int, readline().split()))
    if s[c-1] == "#" or s[d-1] == "#":
        print("No")
    else:
        s = str(readline().rstrip().decode('utf-8'))
        wrc = 0
        brc = 0
        wc = 0
        bc = 0
        for i in range(n):
            if s[i] == "#":
                bc += 1
                wc = 0
            else:
                bc = 0
                wc += 1
            wrc = max(wrc, wc)
            brc = max(brc, bc)
        if c < d:
            if brc < 2:
                print("Yes")
            else:
                print("No")
        else:
            if brc >= 2 and wrc >= 3:
                print("Yes")
            else:
                print("No")


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
n,a,b,c,d=map(int,input().split())
res=list(input())
if c<d:
    for i in range(1,n):
        if res[i-1]=="#" and res[i]=="#":
            print("No")
            exit()
    print("Yes")
    exit()

print(res[n+6])

# for i in range(b,d+1):
#     if i==1:
#         continue
#     if res[i-2]=="." and res[i-1]=="." and res[i]==".":
#         print("Yes")
#         exit()
#     if res[i-1]=="#" and res[i]=="#":
#         print("No")
#         exit()
        
# print("No")
# exit()

Submission status: Runtime Error

Solution code:
n,a,b,c,d=map(int,input().split())
res=list(input())
if c<d:
    for i in range(1,n):
        if res[i-1]=="#" and res[i]=="#":
            print("No")
            exit()
    print("Yes")
    exit()

for i in range(b,d+1):
    if i==1:
        continue
    if res[i-2]=="." and res[i-1]=="." and res[i]==".":
        print("Yes")
        exit()
    if res[i-1]=="#" and res[i]=="#":
        print("No")
        exit()
        
if res[i-1]=="." and res[i]=="." and res[i+1]==".":
    print("Yes")
    exit()
print("No")
exit()

Submission status: Runtime Error

Solution code:
n,a,b,c,d=map(int,input().split())
res=list(input())
if c<d:
    for i in range(1,n):
        if res[i-1]=="#" and res[i]=="#":
            print("No")
            exit()
    print("Yes")
    exit()

for i in range(b,d+1):
    if i<=n-4:
        continue
    if res[i+2]=="." and res[i+1]=="." and res[i]==".":
        print("Yes")
        exit()
print("No")
exit()

Submission status: Runtime Error

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
a-=1
b-=1
c-=1
d-=1
x=[]
cnt=1
y=s[0]
g=[0,0,0,0]
for i in range(1,n):
    if s[i]==y:
        cnt+=1
    else:
        x.append([cnt,y])
        cnt=1
        y=s[i]
    if i==a:
        g[0]=len(x)
    if i==b:
        g[1]=len(x)
    if i==c:
        g[2]=len(x)
    if i==d:
        g[3]=len(x)
x.append([cnt,y])
for i in x:
    if i[0]>=2 and i[1]=='#':
        print("No")
        exit()
if a<b and c<d:
    print("Yes")
    exit()
for i in range(g[1],min(g[2]-1):
    if x[i][1]=="." and x[i][0]>=3:
        print("Yes")
        exit()
print("No")

Submission status: Runtime Error

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
a-=1
b-=1
c-=1
d-=1
x=[]
cnt=1
y=s[0]
g=[0,0,0,0]
for i in range(1,n):
    if s[i]==y:
        cnt+=1
    else:
        x.append([cnt,y])
        cnt=1
        y=s[i]
    if i==a:
        g[0]=len(x)
    if i==b:
        g[1]=len(x)
    if i==c:
        g[2]=len(x)
    if i==d:
        g[3]=len(x)
x.append([cnt,y])
for i in x:
    if i[0]>=2 and i[1]=='#':
        print("No")
        exit()
if a<b and c<d:
    print("Yes")
    exit()
for i in range(g[1],g[2]):
    if i[1]=="." and i[0]>=3:
        print("Yes")
        exit()
print("No")
#print(x)
#print(g)

Submission status: Runtime Error

Solution code:
def main():
    n,a,b,c,d = map(int,input().split()) 
    s=list(input())
    for i in range(max(c,d)-a-1):
        if s[a+i-1]=="#" and s[a+i]=="#":
            print("No")
            return
    if c<d:
        print("Yes")
        return
    else:
        for i in range(c-b+1):
            if s[b+i-2]==s[b+i-1] and s[b+i-1] == s[b+i] and s[b+i]==".":
                print("Yes")
                return
        print("No")
main()

Submission status: Runtime Error

Solution code:
def main():
    n,a,b,c,d = map(int,input().split()) 
    s=list(input())
    for i in range(max(c,d)-a-1):
        if s[a+i-1]=="#" and s[a+i]=="#":
            print("No")
            return
    if c<d:
        print("Yes")
        return
    else:
        for i in range(c-b-2):
            if s[b+i]==s[b+i+1] and s[b+i]==".":
                print("Yes")
                return
        if s[b]=="." and s[b-2]==".":
            print("Yes")
            return
        if s[d]=="." and s[d+2]==".":
            print("Yes")
            return
        print("No")
main()

Submission status: Runtime Error

Solution code:
def main():
    n,a,b,c,d = map(int,input().split()) 
    s=list(input())
    for i in range(max(c,d)-a-1):
        if s[a+i-1]=="#" and s[a+i]=="#":
            print("No")
            return
    if c<d:
        print("Yes")
        return
    else:
        for i in range(c-b-2):
            if s[b+i]==s[b+i+1] and s[b+i]==".":
                print("Yes")
                return
        if s[b]=="." and s[b-2]==".":
            print("Yes")
            return
        if s[c]=="." and s[c+2]==".":
            print("Yes")
            return
        print("No")
main()