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:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a, b, c, d = LI_()
    s = S()
    flg = False
    if a - b == 1:
        print("No")
        return
    if c > d:
        for i in range(b,d):
            if s[i] == "." and s[i + 1] == "." and s[i - 1] == ".":
                flg = True
                break
        if not flg:
            print("No")
            return
    for i in range(a, c-1):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            return
    for i in range(b, d-1):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            return
    print("Yes")
    
    return

#B
def B():
    s = S()
    i = len(s) - 1
    state = 0
    ans = 0
    bc = 2
    while i >= 0:
        if state == 0:
            if s[i] == "C":
                state += 1
        elif state == 1:
            if s[i] == "B":
                state += 1
            else:
                state = 0
        elif state == 2:
            if s[i] == "A":
                ans += 1
            elif s[i] == "B":
                state = 0
            else:
                state += 1
        elif state == 3:
            if s[i] == "B":
                state += 1
            elif s[i] == "C":
                state = 1
            else:
                state = 0
        else:
            if s[i] == "A":
                ans += bc
            elif s[i] == "B":
                state = 0
                bc = 2
            else:
                bc += 1
                state = 3
        #print(state,s[i])
        i -= 1
    print(ans)

    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

Submission status: Wrong Answer

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

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

if S[C] == '#' or S[D] == '#':
    print("No")
    exit()

stone = 0
road = 0
c = False
l = [-1]
ans = False

for i in range(B + 1, D):
    if S[i] == '#':
        stone += 1
        road = 0
        if c:
            l.append(i - 1)
            c = False
        if stone > 1:
            print("No")
            exit()
    else:
        road += 1
        stone = 0
        if road > 2:
            c = True
if C < D:
    S[B] == '.'
    stone = 0
    road = 0
    for i in range(A + 1, C):
        if S[i] == '#':
            stone += 1
            road = 0
            if stone > 1:
                print("No")
                exit()
        else:
            road += 1
            stone = 0
    ans = True
else:
    stone = 0
    road = 0
    check = True
    # B放置でゴールできるか
    S = S[:B] + ['#'] + S[B + 1:]
    stone = 0
    road = 0
    for i in range(A + 1, C):
        if S[i] == '#':
            stone += 1
            road = 0
            if stone > 1:
                check = False
        else:
            road += 1
            stone = 0
    S = S[:B] + ['.'] + S[B + 1:]
    if check:
        ans = True
    # Bがゴールしているとゴールできるか
    stone = 0
    road = 0
    check = True
    S = S[:D] + ['#'] + S[D + 1:]
    stone = 0
    road = 0
    for i in range(A + 1, C):
        if S[i] == '#':
            stone += 1
            road = 0
            if stone > 1:
                check = False
        else:
            road += 1
            stone = 0
    S[D] = '.'
    if check:
        ans = True

# Bが避難しているときBはAを通したあとゴールできるか
if not ans:
    if l[-1] > 0:
        ans = True

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

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = list(map(int, input().split()))
S = list(input())
A = A-1
B = B-1
C = C-1
D = D-1
a = A
b = B
flag = False
bflag = False
dflag = False
if A > B:
    B, A = (A, B)
    D, C = (C, D)

S[A] = 'a'
S[B] = 'b'
Atame = S.copy()
count_a = a
for i in range(N):
    if count_a > N-3:
        break
    if Atame[count_a+1] == '#' and Atame[count_a+2] == '#':
        dflag = True
    count_a += 1
    


if B > A and D > C:
    for i in range(N):
        if b == D:
            flag = True
            break
        if S[b+1]=='.':
            S[b+1] = 'b'
            S[b] = '.'
            b += 1
        elif S[b+2]=='.':
            S[b+2] = 'b'
            S[b] = '.'
            b += 2

elif B > A and C > D:
    for i in range(N):
        if b >= 1 and b+1 < N:
            if (S[b-1] == '.' or S[b-1] == 'a') and S[b+1] == '.':
                bflag = True
                break
        if b + 1 < N:
            if S[b+1] == '.':
                S[b+1] = 'b'
                S[b] = '.'
                b += 1
            elif b + 2 < N:
                if S[b+2] == '.':
                    S[b+2] = 'b'
                    S[b] = '.'
                    b += 2

    if bflag:
        a = a+1
        for i in range(N-a):
            if a == C:
                flag = True
                break
            if S[a+1] == '.':
                S[a+1] = 'a'
                S[a] = '.'
                a += 1
            elif S[a+2] == '.':
                S[a+2] = 'a'
                S[a] = '.'
                a += 2

if flag and (dflag==False):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = [int(i) for i in input().split()]
s = input()

if n[3] > n[4]:
    s1 = n[1]
    s2 = n[2]
    g1 = n[3]
    g2 = n[4]

    sss = s[n[1]: g2].find('##')
    if sss == -1:
        ssss = s[s2:g1+1].find('...')
        if ssss == -1:
            print('No')
        else:
            print('Yes')
    else:
        print('No')

else:
    s1 = n[2]
    s2 = n[1]
    g1 = n[4]
    g2 = n[3]

    sss = s[n[1]: g2].find('##')
    if sss == -1:
        print("Yes")
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = [int(i) for i in input().split()]
s = input()
t = s.split("#")
cnt = -1
if(s.count('##') > 0):
    frag = 0
elif(c<d):
    frag = 1
else:
    frag = 0
    frag1 = 0
    frag2 = 0
    frag3 = 0
    for i in range(len(t)): #cnt...(i個目の#までの文字数),cntがdより小さかったら
        if(cnt < d and i > 0):
                if(t[i].count('.') >= 3):
                    frag1 = 1
        cnt += len(t[i])+1
    cnt -= t[len(t)-1].count('.')
    if(s[b] == '.' or frag1 == 1):
        frag2 = 1
    if(s[d-2] == '.' or frag1 == 1):
        frag3 = 1
    if(frag1 == 1 and frag2 == 1 and frag3 == 1):
        frag = 1
if(frag == 1):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = [int(i) for i in input().split()]
s = input()


flag1 = False
block = 0
for i in range(b, len(s)):
    if block == 2:
        flag1 = False
        break
    elif i == d-1:
        flag1 = True
        break
    elif s[i] == ".":
        block = 0
    elif s[i] == "#":
        block += 1

if flag1 == True:
    s2 = s[:d-1]+'#'+s[d:]
    flag1 = False
    block = 0
    for i in range(a, len(s)):
        if block == 2:
            flag1 = False
            break
        elif i == c-1:
            flag1 = True
            break
        elif s2[i] == ".":
            block = 0
        elif s2[i] == "#":
            block += 1


flag2 = False
flag3 = False
temp = 0
block = 0
for i in range(b-2,c-2):
    if temp == 3:
        flag2 = True
        temp = i-1
        break
    elif s[i] == "#":
        temp = 0
    elif s[i] == ".":
        temp += 1

if flag2 == True:
    flag3 = False
    block = 0
    s1 = s[:temp-1]+'#'+s[temp:]
    for i in range(a, len(s)):
        if block == 2:
            flag3 = False
            break
        elif i == c-1:
            flag3 = True
            break
        elif s1[i] == ".":
            block = 0
        elif s1[i] == "#":
            block += 1

    if flag3 == True:
        s3 = s1[:c - 1] + '#' + s1[c:]
        flag3 = False
        block = 0
        for i in range(temp, len(s)):
            if block == 2:
                flag3 = False
                break
            elif i == c-1:
                flag3 = True
                break
            elif s3[i] == ".":
                block = 0
            elif s3[i] == "#":
                block += 1

if flag1 or flag3:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D=map(int,input().split())
S = list(input())
t=1
if A<C<B<D or A<B<C<D:
	for i in range(B,D-1):
		if S[i] == S[i+1] == '#':
			print('No')
			exit()
	for i in range(A,C-1):
		if S[i] == S[i+1] == '#':
			print('No')
			exit()
else:
	for i in range(B,D-1):
		if S[i-1]==S[i]==S[i+1]=='.':
			t=0
	for i in range(B,D-1):
		if S[i] == S[i+1] == '#':
			print('No')
			exit()
	if t==0:
		if S[D-2]==S[D]=='#':
			for i in range(B,D-4):
				if S[i-1]==S[i]==S[i+1]=='.':
					print('Yes')
					exit()
				else:
					print('No')
					exit()
	else:
		print('No')
		exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a, b, c, d = LI_()
    s = S()
    flg = False
    if a == 0:
        print("No")
        return
    if c > d:
        for i in range(b,d):
            if s[i] == "." and s[i + 1] == "." and s[i - 1] == ".":
                flg = True
                break
        if not flg:
            print("No")
            return
    for i in range(a, c-1):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            return
    for i in range(b, d-1):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            return
    print("Yes")
    
    return

#B
def B():
    s = S()
    i = len(s) - 1
    state = 0
    ans = 0
    bc = 2
    while i >= 0:
        if state == 0:
            if s[i] == "C":
                state += 1
        elif state == 1:
            if s[i] == "B":
                state += 1
            else:
                state = 0
        elif state == 2:
            if s[i] == "A":
                ans += 1
            elif s[i] == "B":
                state = 0
            else:
                state += 1
        elif state == 3:
            if s[i] == "B":
                state += 1
            elif s[i] == "C":
                state = 1
            else:
                state = 0
        else:
            if s[i] == "A":
                ans += bc
            elif s[i] == "B":
                state = 0
                bc = 2
            else:
                bc += 1
                state = 3
        #print(state,s[i])
        i -= 1
    print(ans)

    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input() + "##"
line = [0 for i in range(len(S))]
for i in range(len(S)):
    line[i] = 0 if S[i]=="." else 1
A -= 1
B -= 1
C -= 1
D -= 1
line[A] = "A"
line[B] = "B"

change = False if (C < D) else True

A_checkin = False
B_checkin = False

while True:
    if (line[A+1]=="B") and (line[A+2]==0) and (not A_checkin) and (not B_checkin) and (not change):
        line[B+1] = "B"
        line[B] = 0
        B += 1
    if (line[A+1] != 0) and (line[A+2] != 0) and(not A_checkin):
        if (line[D-1]=="B" or line[D-2]=="B"):
            B_checkin = True
            line[D] = "B"
            line[B] = 0
            B = D
        elif (line[B+1]==0 and not B_checkin):
            line[B+1] = "B"
            line[B] = 0
            B += 1
        elif (line[B+2]==0 and not B_checkin):
            line[B+2] = "B"
            line[B] = 0
            B += 2
        elif (S[B+1]=="C" and not B_checkin) :
            line[B+1] = "B"
            line[B] = 0
            B += 1
        elif (S[B+2]=="C" and not B_checkin) :
            line[B+2] = "B"
            line[B] = 0
            B += 2
        else:   
    
            break

    if (line[D-1]=="B" or line[D-2]=="B"):
        B_checkin = True
        line[D] = "B"
        line[B] = 0
        B = D
    
    if (line[C-1]=="A" or line[C-2]=="A"):
        line[C] = "A"
        A_checkin = True
        line[A] = 0
        A = C
    
    elif (line[A+2]==0) and (not A_checkin):
        line[A+2] = "A"
        line[A] = 0
        A += 2
    elif (line[A+1]==0) and (not A_checkin):
        line[A+1] = "A"
        line[A] = 0
        A += 1
    else:
        break


while True:
    if (not B_checkin):
        if (line[D-1]=="B" or line[D-2]=="B"):
            B_checkin = True
            line[D] = "B"
            line[B] = 0
            B = D
        elif (line[B+2]==0) and (not B_checkin):
            line[B+2] = "B"
            line[B] = 0
            B += 2
        elif (line[B+1]==0) and (not B_checkin):
            line[B+1] = "B"
            line[B] = 0
            B += 1
        else:
            break
    else:
        break

print("Yes" if (A_checkin and B_checkin) else "No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = map(int,input().split())
s = input()
flg = False
if c < d:
    #最後まで動かす
    flg = True
else:#c>d
    if '...' in s[a-1:]:
        flg = True
        if not('...' in s[:d-1]):
            flg = False
        elif (b>3):
            if '...' in s[:b]:
                flg = False
if '##' in s:
    flg = False
if flg:
    print('Yes')
else:
    print(a)

Submission status: Wrong Answer

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

rock = 0
max_rock = []
non = 0
max_non = []
k = 0
for i in s:
    if i == '#':
        rock += 1
        if non >= 3:
            max_non.append([non, k])
        non = 0
    else:
        non += 1
        if rock >= 2:
            max_rock.append([rock, k])
        rock = 0
    if k == n-1:
        k += 1
        if non >= 3:
            max_non.append([non, k])
        if rock >= 2:
            max_rock.append([rock, k])
    k += 1

# print(max_non)
max_non1 = [i for i in max_non if i[1]-i[0]+2 < d and i[1]-i[0]+2 < c and i[1]-2 >= a and i[1]-2 >= b and not i[1]-1 == b]
max_rock1 = [i for i in max_rock if i[1] < d or i[1] < c or i[1] > a or i[1] > b]
max_non2 = max_non
max_rock2 = [i for i in max_rock if (i[1] < d and i[1] > b) or (i[1] > a and i[1] < c)]
# print(max_non1)
# print(max_rock1)
if b > c:
    if len(max_rock2) > 0:
        print('No')
    else:
        print('Yes')
elif c > d:
    if len(max_rock1) > 0:
        print('No')
    elif len(max_non1) > 0:
        print('Yes')
elif len(max_rock1) > 0:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N, A, B, C, D=list(map(int, input().split()))
s=input()
S=[i == "#" for i in s]

can=True
CD = max(C,D)
for i in range(A,CD-1):
  if (S[i] & S[i+1]):
    can=False

if (C>D):
  safe=False
  for i in range(A,D-2):
    if not (S[i] | S[i+1] | S[i+2]):
      safe=True
      break
  can = can & safe

print("Yes" if can else "No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split())
s=str(input())
arr=[]
for i in range(len(s)):
	if(s[i]=='#'):
		arr.append(-1)
	elif(s[i]=='.'):
		arr.append(0)

a-=1
b-=1
c-=1
d-=1
flag=0
arr[a]=1
arr[b]=2

for i in range(max(c,d)):
	if(s[i]=='#' and s[i+1]=='#'):
		flag=1
		break
if(flag==0):
	if(c<d):
		print("Yes")
	else:
		pos1=a
		pos2=b
		temp=0
		while(pos2>pos1):
			if(pos1+1<n and arr[pos1+1]==0):
				arr[pos1]=0
				arr[pos1+1]=1
				pos1+=1
			else:
				if(pos1+2<n and arr[pos1+2]==0):
					pos1+=2
					arr[pos1-2]=0
					arr[pos1]=1
				else:
					if(pos2+1<n and arr[pos2+1]==0):
						pos2+=1
						arr[pos2-1]=0
						arr[pos2]=2
					else:
						if(pos2+2<n and arr[pos2+2]==0):
							pos2+=2
							arr[pos2-2]=0
							arr[pos2]=2
						else:
							flag=1
							break
			if(pos2==d):
				temp=1
				break
			#print(arr)
		if(flag==1):
			print("No")
		else:
			if(temp==0):
				print("Yes")
			else:
				while(pos2>pos1):
					if(pos1+1<n and arr[pos1+1]==0):
							pos1+=1
							arr[pos1-1]=0
							arr[pos1]=1
					
					else:
						if(pos1+2<n and arr[pos1+2]==0):
							pos1+=2
							arr[pos1-2]=0
							arr[pos1]=1
						else:
							flag=1
							break
				if(flag==1):
					print("No")
				else:
					print("Yes")
else:
	print("No")

Submission status: Wrong Answer

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


def solve(n, a, b, c, d, s):
    def check(sub):
        if '##' in sub:
            return False
        return True
    # check for a
    s_a = s[a-1:c]
    state_a = check(s_a)
    if not state_a:
        return 'No'
    s_b = s[b-1:d]
    state_b = check(s_b)
    if not state_b:
        return 'No'
    
    if c < b:
        return 'Yes'
    if c > d:
        if '...' in s_a:
            if '...' in s_b:
                return 'Yes'
        else:
            return 'No'

    return 'Yes'


def main():
    n, a, b, c, d, s = input_from_console()
    print(solve(n, a, b, c, d, s))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

Submission status: Wrong Answer

Solution code:
def main():
    n,a,b,c,d=map(int,input().split(' '))
    s=input()
    result = 'Yes'
    if a<b<d<c:
        tmp =0
        cnt=0
        for i in range(b-2,d+1):
            if s[i]=='#'and s[i+1]=='#':
                result = 'No'
                break
            if s[i]=='.':
                tmp +=1
            else:
                if cnt < tmp:
                    cnt = tmp
                    tmp =0

        if max(cnt,tmp) < 3:
                result = 'No'
        elif result =='Yes':
            for i in range(a,c-1):
                if s[i]=='#'and s[i+1]=='#':
                    result='No'
    else:
        for i in range(b,d-1):
            if s[i] =='#' and s[i+1]=='#':
                result ='No'
                break
        if result=='Yes':
            for i in range(a,c-1):
                if s[i] =='#' and s[i+1]=='#':
                    result = 'No'
                    break
    print(result)

main()

Submission status: Wrong Answer

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

if c<d:
    m=d
else:
    m=c

for i in range(a, m-3):
        if s[i] == '#' and s[i+1] == '#':
            ans=0

flag=0
if d<c:
    for i in range(b-2, d-2):
        if s[i] == '.' and s[i+1] == '.' and s[i+2] == '.':
            flag=1
    if flag == 0:
        ans=0
        
if ans == 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[38]:


N, A, B, C, D = map(int, input().split())
S = input()
"""
7 1 3 7 6
.#..#..
"""


# In[39]:


ans = 'Yes'
if C<D: # C < D のとき、A~C、B~Dに#が2連続じゃなければYes
    shc = 0
    for s in S[A-1:C]:
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
        if s == '.':
            shc = 0
    for s in S[B-1:D]:
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
        if s == '.':
            shc = 0
elif C>D: # C > Dのとき、順番入れ替えが必要, dotが3個以上並べば、入れ替えられる
    shc = 0
    dc = 0
    mdc = 0
    for i, s in enumerate(S[A-1:C]): # A~Cで　#が二個以上あればアウト
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
            if dc>0:
                mdc = max(dc, mdc)
                dc = 0
        if s == '.':
            dc += 1
            shc = 0
        if i >= C-A:
            mdc = max(dc, mdc)
    if mdc >= 3:
        pass
    elif mdc < 3: # A~Cに dotが3個以上並んでいないとき、
        shc = 0
        for i, s in enumerate(S[0:A:-1]):
            if shc >1:
                l = A-i+1
                break
            if s == '#':
                shc += 1
            if s == '.':
                shc = 0
        else:
            l = 0
            
        for i, s in enumerate(S[C:]):
            if shc >1:
                r = C+i-2
                break
            if s == '#':
                shc += 1
            if s == '.':
                shc = 0
        else:
            r = N
        
        mdc = 0
        for i, s in enumerate(S[l:r]):
            if shc > 1:
                ans = 'No'
                break
            if s == '#':
                shc += 1
                if dc>0:
                    mdc = max(dc, mdc)
                    dc = 0
            if s == '.':
                dc += 1
                shc = 0
            if i >= r-l-1:
                mdc = max(dc, mdc)
        if mdc < 3:
            ans = 'No'
print(ans)


# In[ ]:

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a, b, c, d = LI_()
    s = S()
    flg = False
    if a == 1:
        print("No")
        return
    if c > d:
        for i in range(b,d):
            if s[i] == "." and s[i + 1] == "." and s[i - 1] == ".":
                flg = True
                break
        if not flg:
            print("No")
            return
    for i in range(a, c-1):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            return
    for i in range(b, d-1):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            return
    print("Yes")
    
    return

#B
def B():
    s = S()
    i = len(s) - 1
    state = 0
    ans = 0
    bc = 2
    while i >= 0:
        if state == 0:
            if s[i] == "C":
                state += 1
        elif state == 1:
            if s[i] == "B":
                state += 1
            else:
                state = 0
        elif state == 2:
            if s[i] == "A":
                ans += 1
            elif s[i] == "B":
                state = 0
            else:
                state += 1
        elif state == 3:
            if s[i] == "B":
                state += 1
            elif s[i] == "C":
                state = 1
            else:
                state = 0
        else:
            if s[i] == "A":
                ans += bc
            elif s[i] == "B":
                state = 0
                bc = 2
            else:
                bc += 1
                state = 3
        #print(state,s[i])
        i -= 1
    print(ans)

    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

Submission status: Wrong Answer

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

print("Yes")
exit()

for i in range(N-1):
    if S[i] == "#" and S[i+1] == "#":
        print("No")
        exit()

if C < D:
    print("Yes")
    exit()

if S[B-2] != "#" and S[B] == ".":
    print("Yes")
    exit()
    
if S[B-2] == "#" and S[B] == "." and S[B+1] == ".":
    print("Yes")
    exit()

for i in range(N):
    
    if i+B+2 >= N:
        print("No")
        exit()
        break
    
    if i+B+2 > D:
        print("No")
        exit()
        break
        
    if S[i+B] == "." and S[i+B+1] == "." and S[i+B+2] == ".":
        print("Yes")
        exit()

print("No")

Submission status: Wrong Answer

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

index1 = s[a:c-a-1].find("##")
index2 = s[b:d-b-1].find("##")


if index1 != -1 or index2 != -1:
	print("No")
elif c < d :
	print("Yes")
elif s[d] != "#" and s[d-2] != "#" : # c > d のとき
	print("Yes")
elif s[b-2:b-d+2].find("...") != -1 : #s[d+1]またはs[d-1]が"#"のとき、つまり途中でsnukeがhnukeをこす
	print("Yes")
else :
	print("No")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = list(map(int, input().split()))
S = [0]+[0 if s=='.' else 1 for s in input()]
can_jump = [0] + [1-S[i]*S[i+1] for i in range(N-1)]
can_change = [0] + [(1-S[i])*(1-S[i+1])*(1-S[i+2]) for i in range(N-2)]

def Solution():
  if not all(can_jump[A:C]):
    return False
  if not all(can_jump[B:D]):
    return False
  
  if C<D:
    return True
  if C>D:
    if any(can_change[B-1:D-1]):
      return True
    else:
      return False

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

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = map(int,input().split())
s = input()
flg = False
if c < d:
    #最後まで動かす
    flg = True
else:#c>d
    if '...' in s[a-1:]:
        flg = True
        if not('...' in s[:d-1]):
            flg = False
        elif (b>3):
            if '...' in s[:b]:
                flg = False
if '##' in s:
    flg = False
if flg:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split())
s=str(input())
arr=[]
for i in range(len(s)):
	if(s[i]=='#'):
		arr.append(-1)
	elif(s[i]=='.'):
		arr.append(0)

a-=1
b-=1
c-=1
d-=1
flag=0
arr[a]=1
arr[b]=2

for i in range(n-1):
	if(s[i]=='#' and s[i+1]=='#'):
		flag=1
		break
if(flag==0):
	if(c<d):
		print("Yes")
	else:
		pos1=a
		pos2=b
		temp=0
		while(pos2>pos1):
			if(pos1+1<n and arr[pos1+1]==0):
				arr[pos1]=0
				arr[pos1+1]=1
				pos1+=1
			else:
				if(pos1+2<n and arr[pos1+2]==0):
					pos1+=2
					arr[pos1-2]=0
					arr[pos1]=1
				else:
					if(pos2+1<n and arr[pos2+1]==0):
						pos2+=1
						arr[pos2-1]=0
						arr[pos2]=2
					else:
						if(pos2+2<n and arr[pos2+2]==0):
							pos2+=2
							arr[pos2-2]=0
							arr[pos2]=2
						else:
							flag=1
							break
			if(pos2==d):
				temp=1
				break
			#print(arr)
		if(flag==1):
			print("No")
		else:
			if(temp==0):
				print("Yes")
			else:
				while(pos2>pos1):
					if(pos1+1<n and arr[pos1+1]==0):
							pos1+=1
							arr[pos1-1]=0
							arr[pos1]=1
					
					else:
						if(pos1+2<n and arr[pos1+2]==0):
							pos1+=2
							arr[pos1-2]=0
							arr[pos1]=1
						else:
							flag=1
							break
				if(flag==1):
					print("No")
				else:
					print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

    sunuke = S[A-1:C]
    funuke = S[B-1:D]
    if '##' in sunuke or '##' in funuke:
        print('No')
        return

    ans = 'No'
    if C < D:
        ans = 'Yes'
    else:
        if '...' in funuke:
            ans = 'Yes'
        else:
            sunuke = S[A-1:D-1] + '#' + S[D:C]
            if '##' not in sunuke:
                ans = 'Yes'
    print(ans)

input = lambda: stdin.readline()
main()