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: Wrong Answer

Solution code:
N,A,B,C,D=map(int,input().split())
S=input()
for i in range(N-1):
    if S[i]==S[i+1] and S[i]=='#':
        print('No')
        exit()

if C<D:
    print('Yes')
else:
    cnt=0
    for i in range(B-1,D):
        if S[i-1]==S[i] and S[i]==S[i+1] and S[i]=='.':
            print('Yes')
            exit()
    print('No')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D=map(int,input().split())
S=input()
for i in range(N-1):
    if S[i]==S[i+1] and S[i]=='#':
        print('No')
        exit()

if C<D:
    print('Yes')
else:
    cnt=0
    for i in range(B-1,D):
        if D<N:
            if S[i-1]==S[i] and S[i]==S[i+1]:
                print('Yes')
                exit()
        else:
            if i<D-1:
                if S[i-1]==S[i] and S[i]==S[i+1]:
                    print('Yes')
                    exit()
            else:
                break
    print('No')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D=map(int,input().split())
S=input()
for i in range(N-1):
    if S[i]==S[i+1] and S[i]=='#':
        print('No')
        exit()

if C<D:
    print('Yes')
else:
    cnt=0
    for i in range(B-1,D):
        if S[i]=='.':
            cnt+=1
        else:
            cnt=0
        if cnt==3:
            print('Yes')
            exit()
    print('No')

Submission status: Wrong Answer

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

if C<D:
    for i in range(N-1):
        if S[i]==S[i+1] and S[i]=='#':
            print('No')
            exit()
    print('Yes')
else:
    for i in range(N-1):
        if S[i]==S[i+1] and S[i]=='#':
            print('No')
            exit()
    cnt=0
    for i in range(B,D):
        if S[i]=='.':
            cnt+=1
        else:
            cnt=0
        if cnt==3:
            print('Yes')
            exit()
    print('No')

Submission status: Wrong Answer

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

if C<D:
    for i in range(N-1):
        if S[i]==S[i+1] and S[i]=='#':
            print('No')
            exit()
    print('Yes')
else:
    cnt=0
    for i in range(B,D):
        if S[i]=='.':
            cnt+=1
        else:
            cnt=0
        if cnt==3:
            print('Yes')
            exit()
    print('No')

Submission status: Wrong Answer

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

for i in range(A, C-1):
    if S[i] == "#" and S[i+1] == "#":
        print("No")
        exit()
for i in range(B, D-1):
    if S[i] == "#" and S[i+1] == "#":
        print("No")
        exit()

if A < B and C < D:
    print("Yes")
elif A > B and C < D:
    flag = False
    for i in range(A-2, C-2):
        if S[i] == "." and S[i+1] == "." and S[i+2] == ".":
            flag = True
    if flag:
        print("Yes")
    else:
        print("No")
elif A < B and C > D:
    flag = False
    for i in range(B-2, D-2):
        if S[i] == "." and S[i+1] == "." and S[i+2] == ".":
            flag = True
    if flag:
        print("Yes")
    else:
        print("No")   
else:
    print("Yes")

Submission status: Wrong Answer

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

for i in range(A, C-1):
    if S[i] == "#" and S[i+1] == "#":
        print("No")
        exit()
for i in range(B, D-1):
    if S[i] == "#" and S[i+1] == "#":
        print("No")
        exit()

if A < B and C < D:
    print("Yes")
elif A > B and C < D:
    flag = False
    for i in range(A-1, C-2):
        if S[i] == "." and S[i+1] == "." and S[i+2] == ".":
            flag = True
    if flag:
        print("Yes")
    else:
        print("No")
elif A < B and C > D:
    flag = False
    for i in range(B-1, D-2):
        if S[i] == "." and S[i+1] == "." and S[i+2] == ".":
            flag = True
    if flag:
        print("Yes")
    else:
        print("No")   
else:
    print("Yes")

Submission status: Wrong Answer

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

for i in range(A, C-2):
    if S[i] == "#" and S[i+1] == "#":
        print("No")
        exit()
for i in range(B, D-2):
    if S[i] == "#" and S[i+1] == "#":
        print("No")
        exit()

if A < B and C < D:
    print("Yes")
elif A > B and C < D:
    flag = False
    for i in range(B, C-3):
        if S[i] == "." and S[i+1] == "." and S[i+2] == ".":
            flag = True
    if flag:
        print("Yes")
    else:
        print("No")
elif A < B and C > D:
    flag = False
    for i in range(A, D-3):
        if S[i] == "." and S[i+1] == "." and S[i+2] == ".":
            flag = True
    if flag:
        print("Yes")
    else:
        print("No")   
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
canCross = False
for i, s in enumerate(S, start=1):
  if A < i < max(C, D) and s == '#' and (S[i-2] == '#' or S[i] == '#'):
    print('No')
    exit()
  if B < i < min(C, D) and s == '.' and S[i-2] == '.' and S[i] == '.':
    canCross = True
if C < D:
  print('Yes')
else:
  if canCross:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

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

kabe = S.find("##")
if kabe != -1:
    if kabe < C or kabe < D:
        print('No')
        exit()
if C < D:
    print('Yes')
else:
    irekae = S.find("...")
    if irekae == -1:
        print('No')
        exit()
    if irekae + 2 <= C:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import sys, math
from functools import lru_cache
from itertools import accumulate
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

N, A, B, C, D = mi()
S = input()
f = (not '##' in S[A-1:C]) and (not '##' in S[B-1:D])
if C > D:
    f = f and ('...' in S[B-1:D])

print('Yes' if f else 'No')

Submission status: Wrong Answer

Solution code:
import sys, math
from functools import lru_cache
from itertools import accumulate
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

N, A, B, C, D = mi()
S = input()

if C < D:
    bl = (not '##' in S[A-1:C]) and (not '##' in S[B-1:D])

else:
    bl = (not '##' in S[A-1:C]) and ('...' in S[B-1:D])

print('Yes' if bl else 'No')

Submission status: Wrong Answer

Solution code:
import sys, math
from functools import lru_cache
from itertools import accumulate
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

N, A, B, C, D = mi()
S = input()

if C < D:
    bl = (not '##' in S[A-1:C]) and (not '##' in S[B-1:D])

else:
    bl = (not '##' in S[A-1:C]) and ('...' in S[A-1:D])

print('Yes' if bl else 'No')

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N, A, B, C, D = map(int, input().split())
S = 'x' + input()
if '##' in S:
    print('No')
    exit()
if C > D:
    if '...' in S[B-1:D+2]:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
if '##' in S:
    print('No')
    exit()
if C > D:
    if '...' in S[B-2:D + 2]:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
if '##' in S:
    print('No')
    exit()
if C > D:
    if '...' in S[B-2:D + 1]:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
if '##' in S:
    print('No')
    exit()
if C > D:
    if '...' in S[B-2:]:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
if '##' in S:
    print('No')
    exit()
if C > D:
    if '...' in S[B:C]:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
if '##' in S:
    print('No')
    exit()
if C > D:
    if '...' in S[:C]:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
if '##' in S:
    print('No')
    exit()
if C > D:
    if S[D - 2] == S[D - 1] == S[D]:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
if '##' in S:
    print('No')
    exit()
if C > D:
    if '...' in S:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
if '##' in S[A:C]:
    print('No')
elif '##' in S[B:D]:
    print('No')
elif A<B and C>D:
    if not '...' in S[B-1:D+1]:
        print('No')
    else:
        print('Yes')
elif B<A and D>C:
    if not '...' in S[A-1:C+1]:
        print('No')
    else:
        print('Yes')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
#print(S[A:B])
if '##' in S[A:C]:
    print('No')
elif '##' in S[B:D]:
    print('No')
elif A<B and C>D:
    #print(S[B:D+1])
    if not '...' in S[B-1:D+1]:
        print('No')
    else:
        print('Yes')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
#print(S[A:B])
if '##' in S[A:C]:
    print('No')
elif '##' in S[B:D]:
    print('No')
elif A<B and C>D:
    #print(S[B:D])
    if not '...' in S[B-1:D]:
        print('No')
    else:
        print('Yes')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
#print(S[A:B])
if '##' in S[A:C]:
    print('No')
elif '##' in S[B:D]:
    print('No')
elif A<B and C>D:
    if not '...' in S[B:D-1]:
        print('No')
    else:
        print('Yes')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
#print(S[A:B])
if '##' in S[A:C]:
    print('No')
elif '##' in S[B:D]:
    print('No')
elif A<B and C>D:
    if not '...' in S[B:D]:
        print('No')
    else:
        print('Yes')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(lambda x:int(x)-1,input().split())
n += 1
S = input()

ok = True
overtake = False

if c < d:
    overtake = True
    
for i in range(a,d):
    if S[i] == "#" and S[i+1] == "#":
        ok = False

for i in range(b,d):
    if S[i] == "." and S[i-1] == "." and S[i+1] == ".":
        overtake = True
        
if ok and overtake:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(lambda x:int(x)-1,input().split())
n += 1
S = input()

ok = True
overtake = False

if c < d:
    overtake = True
    
for i in range(a,d):
    if S[i] == "#" and S[i+1] == "#":
        ok = False

for i in range(b,n-1):
    if S[i] == "." and S[i-1] == "." and S[i+1] == ".":
        overtake = True
        
if ok and overtake:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(lambda x:int(x)-1,input().split())
n += 1
S = [1 if s == "." else 0 for s in input()]

ok = True
overtake = False

if a<b and c<d:
    overtake= True
if b<a and d<c:
    overtake = True
    
groups = []
tmp = 0
zeros = 0
for n in S:
    if n == 1:
        if zeros != 0:#直前まで０だったとき
            groups.append(zeros)
            zeros = 0#リセット
        tmp += 1
    elif n == 0:
        if tmp != 0:#直前まで１だったとき
            groups.append(tmp)
            tmp = 0#リセット
        zeros -= 1
if tmp != 0:
    groups.append(tmp)
if zeros != 0:
    groups.append(zeros)

now = 0
for i in range(len(groups)):
    if now+abs(groups[i]) >= max(a,b):
        ind = i
        break
    now += abs(groups[i])

for i in range(ind+1,len(groups)):
    if groups[i] >= 3:
        overtake = True
    if groups[i] <= -2:
        ok = False

if now+groups[ind]-max(a,b) >= 2:
    overtake= True
if now+groups[ind]-max(a,b) >= 1 and max(a,b)-now >= 1:
    overtake = True

if overtake and ok:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(int, input().split())
a -= 1
b -= 1
c -= 1
d -= 1
s = input()
if "##" in s[a:c+1] or "##" in s[b:d+1]:
    print("No")
    exit()
if c > d:
    if "##" in s[a:c+1] :
        print("No")
        exit()
    print("Yes" if "..." in s[b-1:d+2] else "No")

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(int, input().split())
a -= 1
b -= 1
c -= 1
d -= 1
s = input()+".."
can = True
if "##" in s[a:c+1] or "##" in s[b:d+1]:
    print("No")
    exit()
if c >= d:
    can = False
    if "..." in s[b:d+2]:##?
        can = True
print("Yes" if can else "No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int, input().split())
a-=1;b-=1;c-=1;d-=1
s=input()
can=True
if "##" in s[a:c+1] or "##" in s[b:d+1]:
    print("No");exit()
if c>=d:
    can=False
    if "..." in s[b:d+1]:
        can=True
print("Yes" if can else "No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int, input().split())
a-=1;b-=1;c-=1;d-=1
s=input()+".."
can=True
for i in range(a,c):
    if s[i:i+2]=="##":
        print("No")
        exit()
for i in range(b,d):
    if s[i:i+2]=="##":
        print("No")
        exit()
if c>=d:#?
    can=False
    for i in range(b,d):
        if s[i:i+3]=="...":
            can=True
            break
print("Yes" if can else "No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int, input().split())
a-=1;b-=1;c-=1;d-=1
s=input()+".."
can=True
for i in range(a,c):
    if s[i:i+2]=="##":
        print("No")
        exit()
for i in range(b,d):
    if s[i:i+2]=="##":
        print("No")
        exit()
if c>d:
    can=False
    for i in range(b,d):
        if s[i:i+3]=="...":
            can=True
            break
print("Yes" if can else "No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int, input().split())
a-=1;b-=1;c-=1;d-=1
s=input()+".."
can=True
for i in range(a,c):
    if s[i:i+2]=="##":
        print("No")
        exit()
for i in range(b,d):
    if s[i:i+2]=="##":
        print("No")
        exit()
if c>d:
    can=False
    for i in range(b,d-1):
        if s[i:i+3]=="...":
            can=True
            break
print("Yes" if can else "No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int, input().split())
a-=1;b-=1;c-=1;d-=1
s=input()+".."
can=True
for i in range(a,c+1):
    if s[i:i+2]=="##":
        print("No")
        exit()
for i in range(b,d+1):
    if s[i:i+2]=="##":
        print("No")
        exit()
if c>d:
    can=False
    for i in range(b,d+1):
        if s[i:i+3]=="...":
            can=True
            break
print("Yes" if can else "No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int, input().split())
a-=1;b-=1;c-=1;d-=1
s=input()+".."
can=True

for i in range(a,c+1):
    if s[i:i+2]=="##":
        can=False
        break
for i in range(b,d+1):
    if s[i:i+2]=="##":
        can=False
        break
if c>d:
    can=False
    for i in range(b,d-1):
        if s[i:i+3]=="...":
            can=True
            break
print("Yes" if can else "No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int, input().split())
a-=1;b-=1;c-=1;d-=1
s=input()+".."
can=True
if c<d:
    for i in range(a,c):
        if s[i:i+2]=="##":
            can=False
            break
    for i in range(b,d):
        if s[i:i+2]=="##":
            can=False
            break
else:
    can=False
    for i in range(b,d-1):
        if s[i:i+3]=="...":
            can=True
            break
print("Yes" if can else "No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int, input().split())
a-=1;b-=1;c-=1;d-=1
s=input()+".."
can=True
if c<d:
    for i in range(a,c):
        if s[i:i+2]=="##":
            can=False
            break
    for i in range(b,d):
        if s[i:i+2]=="##":
            can=False
            break
else:
    can=False
    for i in range(b,d):
        if s[i:i+3]=="...":
            can=True
            break
print("Yes" if can else "No")

Submission status: Wrong Answer

Solution code:
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n,a,b,c,d = (int(x) for x in input().split())
s = input()

ok1 = True
cnt = 0
for i in xrange(b,d):
    if s[i-1] == "#":
        cnt += 1
        if cnt == 2:
            ok1 = False
            break
    else:
        cnt = 0

ok2 = True
cnt = 0
for i in xrange(a,c):
    if s[i-1] == "#":
        cnt += 1
        if cnt == 2:
            ok2 = False
            break
    else:
        cnt = 0
if d > c: # a->c and b->d
    ok3 = True
else:
    cnt = 0
    ok3 = False
    for i in xrange(b-1,d+1):
        if s[i-1] == ".":
            cnt += 1
            if cnt == 3:
                ok3 = True
                break
        else:
            cnt = 0
if ok1 and ok2 and ok3:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n,a,b,c,d = (int(x) for x in input().split())
s = input()

ok1 = True
cnt = 0
for i in xrange(b,d):
    if s[i-1] == "#":
        cnt += 1
        if cnt == 2:
            ok1 = False
            break
    else:
        cnt = 0

ok2 = True
cnt = 0
for i in xrange(a,c):
    if s[i-1] == "#":
        cnt += 1
        if cnt == 2:
            ok2 = False
            break
    else:
        cnt = 0
if d > c: # a->c and b->d
    ok3 = True
else:
    cnt = 0
    ok3 = False
    for i in xrange(b-1,d):
        if s[i-1] == ".":
            cnt += 1
            if cnt == 3:
                ok3 = True
                break
        else:
            cnt = 0
if ok1 and ok2 and ok3:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n,a,b,c,d = (int(x) for x in input().split())
s = input()

ok1 = True
cnt = 0
for i in xrange(b,d):
    if s[i-1] == "#":
        cnt += 1
        if cnt == 2:
            ok1 = False
            break
    else:
        cnt = 0

ok2 = True
cnt = 0
for i in xrange(a,c):
    if s[i-1] == "#":
        cnt += 1
        if cnt == 2:
            ok2 = False
            break
    else:
        cnt = 0
if d > c: # a->c and b->d
    ok3 = True
else:
    cnt = 0
    ok3 = False
    for i in xrange(b-1,c+1):
        if s[i-1] == ".":
            cnt += 1
            if cnt == 3:
                ok3 = True
                break
        else:
            cnt = 0
if ok1 and ok2 and ok3:
    print("Yes")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n,a,b,c,d = (int(x) for x in input().split())
s = input()

ok1 = True
cnt = 0
for i in xrange(b,d):
    if s[i-1] == "#":
        cnt += 1
        if cnt == 2:
            ok1 = False
            break
    else:
        cnt = 0

ok2 = True
cnt = 0
for i in xrange(a,c):
    if s[i-1] == "#":
        cnt += 1
        if cnt == 2:
            ok2 = False
            break
    else:
        cnt = 0
if d > c: # a->c and b->d
    ok3 = True
else:
    cnt = 0
    ok3 = False
    for i in xrange(b-1,c+1):
        if s[i-1] == ".":
            cnt += 1
            if cnt == 3:
                ok3 = True
                break
        else:
            cnt = 0
if ok1 and ok2 and ok3:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n,a,b,c,d = (int(x) for x in input().split())
s = input()

ok1 = True
cnt = 0
for i in xrange(b,d):
    if s[i-1] == "#":
        cnt += 1
        if cnt == 2:
            ok1 = False
            break
    else:
        cnt = 0

ok2 = True
cnt = 0
for i in xrange(a,c):
    if s[i-1] == "#":
        cnt += 1
        if cnt == 2:
            ok2 = False
            break
    else:
        cnt = 0
if d > c: # a->c and b->d
    ok3 = True
else:
    cnt = 0
    ok3 = False
    for i in xrange(b-1,c):
        if s[i-1] == ".":
            cnt += 1
            if cnt == 3:
                ok3 = True
                break
        else:
            cnt = 0
if ok1 and ok2 and ok3:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N,A,B,C,D = mint()
S = input()

def f(m,n):
    block2 = space3 = False
    b = s = 0
    for i in range(m-1,n):
        (b,s) = (b+1,0) if S[i]=='#' else (0,s+1)
        if not block2 and b==2:
            block2 = True
        if not space3 and s==3:
            space3 = True
    return block2, space3

if D<C:
    judge(not f(A,C)[0] and f(B,D)[1])
else:
    judge(not f(A,C)[0] and not f(B,D)[0])

Submission status: Wrong Answer

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

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

ok = []
ng = []

for i in range(1, N - 1):
    if S[i] == S[i + 1] and S[i] == "#":
        ng.append(i)
    elif S[i - 1] == S[i] and S[i] == S[i + 1] and S[i] == ".":
        ok.append(i)

for ngi in ng:
    if (A < ngi and ngi < C) or (B < ngi and ngi < D):
        print("No")
        exit()

if C < D:
    print("Yes")

else:
    for oki in ok:
        if B < oki and oki < D:
            print("Yes")
            exit()

    print("No")

Submission status: Wrong Answer

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

ok = []
ng = []

for i in range(1, N - 1):
    if S[i] == S[i + 1] and S[i] == "#":
        ng.append(i + 1)
    elif S[i - 1] == S[i] and S[i] == S[i + 1] and S[i] == ".":
        ok.append(i + 1)

for ngi in ng:
    if (A < ngi and ngi < C) or (B < ngi and ngi < D):
        print("No")
        exit()

if C < D:
    print("Yes")

else:
    for oki in ok:
        if B < oki and oki < D:
            print("Yes")
            exit()

    print("No")

Submission status: Wrong Answer

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

ok = []
ng = []

for i in range(1, N - 1):
    if S[i] == S[i + 1] and S[i] == "#":
        ng.append(i)
    elif S[i - 1] == S[i] and S[i] == S[i + 1] and S[i] == ".":
        ok.append(i)

for ngi in ng:
    if (A < ngi and ngi < C) or (B < ngi and ngi < D):
        print("No")
        exit()

if C < D:
    print("Yes")

else:
    for oki in ok:
        if B < oki and oki < D:
            print("Yes")
            exit()

    print("No")

Submission status: Wrong Answer

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

S=input()
jump=False
n=0
R=0

for i in range(A-1,D):
    if S[i]=="#":
        R+=1
        n=0
        if R>=2:
            print("No")
            exit()
    else:
        n+=1
        R=0
        if n>=3 and i-1>=B-1 and i-1<=D-1:
            jump=True

if C<D:
    print("Yes")
else:
    if jump==True:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

S=input()
jump=False
n=0
R=0

for i in range(A-1,D):
    if S[i]=="#":
        R+=1
        n=0
        if R>=2:
            print("No")
            exit()
    else:
        n+=1
        R=0
        if n>=3 and i>=B-2 and i<=D-2:
            jump=True

if C<D:
    print("Yes")
else:
    if jump==True:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
def main():
    N, A, B, C, D = map(int, input().split())
    S = list(input())
    E = max(C, D)
    cnt = 0
    for i in range(A-1, E):
        if S[i] == '#':
            cnt += 1
        else:
            cnt = 0
        if cnt >= 2:
            print('No')
            return
    cnt = 0; E = min(C, D)
    for i in range(B-1, min(E+2, len(S))):
        if S[i] == '.':
            cnt += 1
        else:
            cnt = 0
        if cnt >= 3:
            break
    if cnt <= 2 and D < C:
        print('No')
        return
    print('Yes')
        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, A, B, C, D = map(int, input().split())
    S = list(input())
    E = max(C, D)
    cnt = 0
    for i in range(A-1, E):
        if S[i] == '#':
            cnt += 1
        else:
            cnt = 0
        if cnt >= 2:
            print('No')
            return
    cnt = 0; E = min(C, D)
    for i in range(B-1, E):
        if S[i] == '.':
            cnt += 1
        else:
            cnt = 0
        if cnt >= 3:
            break
    if cnt <= 2 and D < C:
        print('No')
        return
    print('Yes')
        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(250000)


def read():
    N, A, B, C, D = map(int, input().strip().split())
    S = input().strip()
    return N, A-1, B-1, C-1, D-1, S


def check_reachable(N, S, start):
    reachable = [False for s in S]
    reachable[start] = True
    
    def _bfs(x):
        for d in [1, 2]:
            nx = x + d
            if 0 <= nx < N and not reachable[nx] and S[nx] == ".":
                reachable[nx] = True
                _bfs(nx)
    
    _bfs(start)
    return reachable


def solve(N, A, B, C, D, S):
    r1 = check_reachable(N, S, A)
    r2 = check_reachable(N, S, B)
    if C < D:
        if r1[B] and r2[D]:
            return "Yes"
    else:
        max_seq = 0
        seq = 0
        for x1, x2 in zip(r1, r2):
            if x1 and x2:
                seq += 1
            else:
                max_seq = max(max_seq, seq)
                seq = 0
        if max_seq >= 3:
            return "Yes"
    return "No"
        


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(250000)


def read():
    N, A, B, C, D = map(int, input().strip().split())
    S = input().strip()
    return N, A-1, B-1, C-1, D-1, S


def check_reachable(N, S, start):
    reachable = [False for s in S]
    
    def _bfs(x):
        for d in [1, 2]:
            nx = x + d
            if 0 <= nx < N and not reachable[nx] and S[nx] == ".":
                reachable[nx] = True
                _bfs(nx)
    
    _bfs(start)
    return reachable


def solve(N, A, B, C, D, S):
    r1 = check_reachable(N, S, A)
    r2 = check_reachable(N, S, B)
    if C < D:
        if r1[B] and r2[D]:
            return "Yes"
    else:
        max_seq = 0
        seq = 0
        for x1, x2 in zip(r1, r2):
            if x1 and x2:
                seq += 1
            else:
                max_seq = max(max_seq, seq)
                seq = 0
        if max_seq >= 3:
            return "Yes"
    return "No"
        


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))