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 python
"""<https://github.com/cheran-senthil/PyRival>"""
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()


def solve(s, a, b, c, d):
    if s[d] == '#' or s[c] == '#' or c == d:
        return False
    else:
        def move_a():
            nonlocal a, b
            if s[a + 1] == 46 and b != a + 1:
                a += 1
            elif s[a + 2] == 46 and b != a + 2:
                a += 2
            elif a + 1 == b:
                if move_b():
                    a += 1
                else:
                    return False
            elif a + 2 == b:
                if move_b():
                    a += 2
                else:
                    return False
            else:
                return False
            return True

        def move_b():
            nonlocal a, b
            if s[b + 1] == 46:
                b += 1
                return True
            if s[b + 2] == 46:
                b += 2
                return True
            return False

        if c < d:
            while b < d:
                if not move_b():
                    return False
            if b != d:
                return False
            while a < c:
                if not move_a():
                    return False
            return True
        else:
            while a < c:
                if not move_a():
                    return False
            if b > d:
                return False
            while b < d:
                if not move_b():
                    return False
            return True


def solve_slow(s, a, b, c, d):
    if a == c and b == d:
        return True
    if a > c or b > d:
        return False
    if s[a + 1] == 46 and a + 1 != b:
        if solve_slow(s, a+1, b, c, d):
            return True
    if s[a + 2] == 46 and a + 2 != b:
        if solve_slow(s, a+2, b, c, d):
            return True
    if s[b + 1] == 46 and b + 1 != a:
        if solve_slow(s, a, b + 1, c, d):
            return True
    if s[b + 2] == 46 and b + 2 != a:
        if solve_slow(s, a, b + 2, c, d):
            return True
    return False


def main():
    n, a, b, c, d = read_int_array()
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    s = read() + b'###'
    if solve(s, a, b, c, d):
        print("YES")
    else:
        print("NO")
    # sl, fst = solve_slow(s, a, b, c, d), solve(s, a, b, c, d)
    # print(sl, fst)



# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        if self.buffer.tell():
            return self.buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")


def read():
    return input()


def read_array(sep=None, maxsplit=-1):
    return read().split(sep, maxsplit)


def read_int():
    return int(read())


def read_int_array(sep=None, maxsplit=-1):
    return [int(a) for a in read_array(sep, maxsplit)]

# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(int, input().split())
s = input()
j = 0
flag = False
fflag = False

if '#' not in s:
  flag = True

for i, k in enumerate(s):
  if k == '.':
    j += 1
  else:
    if j >= 3 and i - j + 1 < d and b < i:
      flag = True
    if s[i-1] == '#' and i-1 < max(c, d):
      fflag = True
    j = 0

if j >= 3 and len(s) - j + 1 < d:
  flag = True
    
if fflag:
  print('No')
else:
  if c > d and flag:
    print('Yes')
  elif c < d:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int, input().split())
s = input()
index = [(n+1) for n, v in enumerate(s) if s[n:n+3] == "..."]

if s.count("##")>=1:
    print("No")
    exit()

if C < D:
    print("Yes")

elif C > D:
    if len(index)>=1:
        for i in index:
            if A <= i and B <= i+1 and i+2<C:
                print("Yes")
                exit()
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
x = input().split()
s = input()
n = int(x[0])
a = int(x[1])
b = int(x[2])
c = int(x[3])
d = int(x[4])


kome_flag = False
santen_flag = False

b_s = s[b:]

if '...' in b_s:
  santen_flag = True
if not '##' in b_s:
  kome_flag = True
    
    
if kome_flag:
  if c < d:
    print('Yes')
  elif d < c:
    if santen_flag:
      print('Yes')

else:
  print('No')

Submission status: Wrong Answer

Solution code:
import math
import numpy as np


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


def main():
    N, A, B, C, D = inputs()
    S = input()
    maxDst = max(C, D)
    courseA = S[A:C]
    courseB = S[B:D]
    cnt = 0
    ans = []
    for i in courseB:
        if i == '#':
            cnt += 1
        else:
            cnt = 0
        if cnt == 2:
            ans.append(False)
            break
    else:
        ans.append(True)
    cnt = 0
    for i in courseA:
        if i == '#':
            cnt += 1
        else:
            cnt = 0
        if cnt == 2:
            ans.append(False)
            break
    else:
        ans.append(True)
    if maxDst == C:
        cnt = 0
        for i in courseB:
            if i == '.':
                cnt += 1
            else:
                cnt = 0
            if cnt == 3:
                ans.append(True)
                break
        else:
            ans.append(False)

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
cou1 = 0
ans1 = 0
cou2 = 0
ans2 = 0
S2 = S[A:]
if C < D:
    S1 = S[A: D-1]
    for i in S1:
        if i == "#":
            cou1 += 1
        else:
            ans1 = max(ans1, cou1)
            cou1 = 0
    if ans1 < 2:
        print("Yes")
    else:
        print("No")
else:
    for i in range(len(S2)):
        if S2[i] == "#":
            cou1 += 1
            ans2 = max(ans2, cou2)
            cou2 = 0
        else:
            cou2 += 1
            ans1 = max(ans1, cou1)
            cou1 = 0
        if (ans2 == 3 and ans1 < 2 and i > C - A) or (ans2 >= 3 and ans1 < 2 and i <= C-A):
            print("Yes")
            break
    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 = str(input())

moziretu = S  # 保持しておく

# Bの人から動かす
zenhann = True
hoge = S[B+1]
for i in range(B+2, D):
    if hoge == S[i] and hoge == '#':
        zenhann = False
        break
    else:
        hoge = S[i]


if zenhann:
    str_list = list(S)
    str_list[D] = '#'
    S = "".join(str_list)

    hoge = S[A+1]
    for i in range(A+2, C):
        if hoge == S[i] and hoge == '#':
            zenhann = False
            break
        else:
            hoge = S[i]


kouhann = True
# Aの人から動かす
str_list = list(moziretu)
str_list[B] = '#'
moziretu = "".join(str_list)

hantei = moziretu[B+1]
for i in range(B+2, C):
    if hantei == moziretu[i] and hantei == '#':
        kouhann = False
        break
    else:
        hantei = moziretu[i]

if kouhann:
    fuga = moziretu[A+1]
    for i in range(A+2, C):
        if fuga == moziretu[i] and fuga == '#':
            kouhann = False
            break
        else:
            fuga = S[i]
    if kouhann:
        str_list = list(moziretu)
        str_list[C] = '#'
        moziretu = "".join(str_list)

        fuga = moziretu[B+1]
        for i in range(B+2, D):
            if fuga == moziretu[i] and fuga == '#':
                kouhann = False
                break
            else:
                fuga = moziretu[i]

if zenhann or kouhann:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

for k in range(A-1,max(C,D)-1):
    if S[k] == S[k+1] == "#":
        print("No")
        exit(0)

if C < D:
    print("Yes")
    exit(0)
for k in range(B-1,D-1):
    if S[k] == S[k+1] == S[k+2] == ".":
        if k+2 <= D and k+3 <= C:
            print("Yes")
            exit(0)
print("No")
exit(0)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

listA=list(map(int,input().split()))

kenken_map = input()

A_init = listA[1]-1
B_init = listA[2]-1
A_goal = listA[3]-1
B_goal = listA[4]-1

kenken_temp_b = kenken_map[B_init:B_goal+1]
kenken_temp_b_goal = kenken_map[:B_goal] + '#' + kenken_map[B_goal+1:]
kenken_temp = kenken_temp_b_goal[A_init:A_goal]


if '##' in kenken_temp_b:
    print('No')
elif not '##' in kenken_temp:
    print('Yes')
elif '...' in kenken_temp_b:
    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
arr[c]=3
arr[d]=4

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+2<n and arr[pos1+2]==0):
				arr[pos1]=0
				arr[pos1+2]=1
				pos1+=2
			else:
				if(pos1+1<n and arr[pos1+1]==0):
					pos1+=1
					arr[pos1-1]=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(arr[pos2]==4):
				temp=1
				break
			#print(arr)
		if(flag==1):
			print("No")
		else:
			if(temp==0):
				print("Yes")
			else:
				while(pos2>pos1):
					if(pos1+2<n and arr[pos1+2]==0):
						pos1+=2
						arr[pos1-2]=0
						arr[pos1]=1
					else:
						if(pos1+1<n and arr[pos1+1]==0):
							pos1+=1
							arr[pos1-1]=0
							arr[pos1]=1
						else:
							flag=1
							break
				if(flag==1):
					print("No")
				else:
					print("Yes")

Submission status: Wrong Answer

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

i=0
j=0
gg=0
nnt=0
if c<d:
    i=a-1
    while i!=d:
        if s[i]=="#":
            j=j+1
        else:
            j=0
        if j==2:
            nnt=1
            break
        i=i+1

else:
    i=a-1
    nnt=1
    while i!=c-1:

        if s[i]==".":
            gg=gg+1
        else:
            gg=0
        if gg>=3:
            if i>=b:
                if i<=c:
                    nnt=0




        if s[i]=="#":
            j=j+1
        else:
            j=0
        if j==2:
            nnt=1
            break

        i=i+1
if nnt==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(int, input().split())
s = input()
s_flag = False
can_flag = True
count = 0

for i in range(n):
  if s[i] == '#':
    count = 0
    if s_flag:
      can_flag = False
      break
    s_flag = True

  else:
    s_flag = False
    count += 1
if count > 0 and count <= 2:
  if c > d:
    can_flag = False

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, A: int, B: int, C: int, D: int, S: str): 
    if(S[A-1] == '#' or S[B-1] == '#' or  S[C-1] == '#' or S[D-1] == '#'):
        print(NO)
        sys.exit()

    if(S[A-1:C].count('##') == 0 and S[B-1:D].count('##') == 0):
        if(D < C):
            if(S[B-1:D].count('...') == 0):
                print(NO)
            else:
                tS = list(S)
                tS[B-1] = '#'
                tS = ''.join(tS)
                if(tS[B-1:D].count('...') == 0 and B-1 == S[B-1:D].rfind('...')+2):
                    print(NO)
                else:
                    print(YES)
        else: # D > Cの場合
            print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

sunuke = ""
hunuke = ""


if C > D:
    k = ''.join(s[B-1:D])
    result = "..." in k
    if result == 0:
        print("No")
        exit()

while B <= D:
    if s[B] == ".":
        B += 1
        if B == D:
            hunuke = "ok"
            break
    elif s[B+1] == ".":
        B += 2
        if B == D:
            hunuke = "ok"
            break
        elif B > D:
            print("No")
            exit()
    else:
        print("No")
        exit()

while A <= C:
    if s[A] == ".":
        A += 1
        if A == C:
            sunuke = "ok"
            break
    elif s[A+1] == ".":
        A += 2
        if A == C:
            sunuke = "ok"
            break
        elif A > C:
            print("No")
            exit()
    else:
        print("No")
        exit()

if sunuke == "ok" and hunuke == "ok":
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = [int(x) for x in input().split()]
S = input()
cross = False
minG = C
maxG = D

if C > D:
    minG = D
    maxG = C
    cross = True

wall = S.find("##") + 1
even = S.rfind("...") + 1

if cross == False:
    if wall == -1:
        print("Yes")
    elif wall < A or maxG < wall:
        print("Yes")
    elif B < wall and wall < minG:
        print("Yes")
    else:
        print("No")
else:
    if even == -1:
        print("No")
    elif even + 1 < B:
        print("No")
    elif minG < even + 1:
        print("No")
    elif A < wall and wall < maxG:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
N, A, B, C, D = map(int, input().split())
S = input()
skip = 0
for i in range(max(C,D)-1):
	if S[i]==S[i+1]=="#":
		print('No')
		sys.exit()
	if B-1 <= i < max(C,D)-3 and S[i]==S[i+1]==S[i+2]==".":
		skip += 1
	if i == B-1 and S[i-1]==S[i+1]==".":
		skip += 1

if C<D:
	print('Yes')

elif skip > 0:
	print("Yes")
else:
	print('No')

Submission status: Wrong Answer

Solution code:
## AからＣ　ＢからＤに移動させたい
## C<D なら簡単

N,A,B,C,D = map(int,input().split())
S = input()
flag = 0
obs = []
esc = []
ans = 1

#ＡとＢで小さいほうを low
if A<B:
    low = A
    mid1 = B
else:
    low = B
    mid1 = A
#ＣとＤで大きいほうをhigh
if C<D:
    high = D
    mid2 = C
else:
    high = C
    mid2 = D



for i in range(low,high):
     if S[i]=="#" and flag == 1:
         obs.append(i)
         flag = 0
     elif S[i] == "#":
         flag = 1
     else: flag = 0

 # obsに通れない位置を入力
flag = 0
for i in range(mid1,mid2):
      if S[i]=="." and flag == 2:
          esc.append(i)
          flag = 0
      elif S[i] == ".":
          flag += 1
      else:
          flag = 0

if len(obs)!=0:
    ans = 0

if D<C :
    flag = 0
    for i in range(len(esc)):
        if mid1< esc[i] <= mid2:
            flag = 1
    if flag == 0:
        ans = 0


if ans==1:
    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
    if C < D:
        ans = 'Yes'
    else:
        sunuke = S[A-1:D-1] + '#' + S[D:C]
        if '...' in funuke or '##' not in sunuke:
            ans = 'Yes'
        else:
            ans = 'No'
    print(ans)

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

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
s = input()
if C<D:
    ans = 'Yes'
else:
    if s[B-2:D].count('...')>0:
        ans = 'Yes'
        if D-B == 1:
            ans = 'No'
        elif D-B == 2: 
            if s[B-2]== '#' or s[D]== '#':
                ans = 'No'
    else:
        ans = 'No'
if s[A:C-2].count('##')!=0 or s[B:D-2].count('##')!=0:
    ans = 'No'
print(ans)

Submission status: Wrong Answer

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

curval = "x"
cnt = 0
initidx = 0
ngarea = [-1]
triarea = [-1]

for idx,val in enumerate(S):
    if val == curval:
        cnt += 1
    else:
        if cnt >= 2 and curval == '#':
            ngarea.append(initidx + 1)
        elif cnt >= 3 and curval == '.':
            triarea.append(initidx + 1)
        initidx = idx
        cnt = 1
    curval = val
else:
    if cnt >= 2 and curval == '#':
        ngarea.append(initidx + 1)
    elif cnt >= 3 and curval == '.':
        triarea.append(initidx + 1)

if C < D:
    isBflg = True
    isABflg = True
    for ngp in ngarea:
        if ngp > B and ngp < D:
            isBflg = False
        if ngp > A and ngp < B:
            isABflg = False
    if isBflg and isABflg:
        print('Yes')
        exit()
    else:
        print('No')
        exit()
else:
    isChangeFlg = False
    Changepoint = -1
    for trp in triarea:
        if trp > A and trp + 1 >= B:
            Changepoint = trp
            isChangeFlg = True
            break
    if isChangeFlg == False:
        print('No')
        exit()
    else:
        isBflg = True
        isABflg = True
        isChange2DFlg = True
        for ngp in ngarea:
            if ngp > B and ngp < Changepoint:
                isBflg = False
            if ngp > A and ngp < B:
                isABflg = False
            if ngp > Changepoint and ngp < D:
                isChange2DFlg = False
        if isBflg and isABflg and isChange2DFlg:
            print('Yes')
            exit()
        else:
            print('No')
            exit()

Submission status: Wrong Answer

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

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

S = str(input())

moziretu = S  # 保持しておく

# Bの人から動かす
zenhann = True
hoge = S[B+1]
for i in range(B+2, D):
    if hoge == S[i] and hoge == '#':
        zenhann = False
        break
    else:
        hoge = S[i]


if zenhann:
    str_list = list(S)
    str_list[D] = '#'
    S = "".join(str_list)

    hoge = S[A+1]
    for i in range(A+2, C):
        if hoge == S[i] and hoge == '#':
            zenhann = False
            break
        else:
            hoge = S[i]


kouhann = True
# Aの人から動かす
str_list = list(moziretu)
str_list[B] = '#'
moziretu = "".join(str_list)

hantei = moziretu[B+1]
for i in range(B+2, C+1):
    if hantei == moziretu[i] and hantei == '#':
        kouhann = False
        break
    else:
        hantei = moziretu[i]

if kouhann:
    fuga = moziretu[A+1]
    for i in range(A+2, C):
        if fuga == moziretu[i] and fuga == '#':
            kouhann = False
            break
        else:
            fuga = S[i]
    if kouhann:
        str_list = list(moziretu)
        str_list[C] = '#'
        moziretu = "".join(str_list)

        fuga = moziretu[B+1]
        for i in range(B+2, D):
            if fuga == moziretu[i] and fuga == '#':
                kouhann = False
                break
            else:
                fuga = moziretu[i]

if zenhann or kouhann:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

if c < d:
    if ('##' in s[a-1:c]) or ('##' in s[b-1:d]):
        print('No')
    else:
        print('Yes')

else:
    if '##' in s[a-1:c]:
        print('No')
    elif '...' in s[b-2:d]:
        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()

if d > c:
    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, c + 1):
            if block == 2:
                flag1 = False
                break
            elif i == c-1:
                flag1 = True
                break
            elif s2[i] == ".":
                block = 0
            elif s2[i] == "#":
                block += 1

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



else:
    flag2 = False
    flag3 = False
    if s[b-2]==".":
        temp = 1
    else:
        temp = 0
    block = 0
    for i in range(b-1,c-1):
        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 + 1, 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 flag3:
        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()

a_to_c = s[a-1:c-1] if a<c else s[c-1:a-1]
b_to_d = s[b-1:d-1] if b<d else s[d-1:b-1]

possibility = True

if a_to_c.find("##")!=-1 or b_to_d.find("##")!=-1:
    possibility = False
if (a>b and c<d) or (a<b and c>d):
    if not(a_to_c.find('...')!=-1 and b_to_d.find('...')!=-1):
        possibility = False

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if "##" in S[A-1:C]:
	print("No")
elif "##" in S[B-1:D]:
	print("No")
elif D < C:	# A jumps over B
	if not "..." in S[B-2:D+1]:
		print("No")
	elif S[B-2:D+1].count("...") == 1:
		if S[D-2:D+1] == "#..":
			print("No")
		else:
			print("Yes")
	else:
		print("Yes")
else:
	print("Yes")

Submission status: Wrong Answer

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

rock = "#"
S = list()
three_empty = []
two_rocks = []
rock_cnt, empty_cnt = 0, 0

# 通れない２連続岩の場所とABが交差できる３emptyの場所取得
for i, s in enumerate(input().strip(), start=1):
  is_rock = s == rock
  if is_rock:
    if empty_cnt >= 3:
      three_empty.append(i - 1)
    rock_cnt += 1
    empty_cnt = 0
  else:
    if rock_cnt >= 2:
      two_rocks.append(i - 1)
    rock_cnt = 0
    empty_cnt += 1
if rock_cnt >= 2:
  two_rocks.append(i)
if empty_cnt >= 3:
  three_empty.append(i)

flag = True
left = A if A < B else B
right = B if A > B else A
left_rock = 0
right_rock = 200001


for i in two_rocks:
  # 目標の間に岩があるか確認
  if A > i > C or B > i > D:
    flag = False
    break
  # 左と右にいる人から一番近い岩の位置
  if i < left:
    left_rock = i
  elif right_rock != 200001 and right < i:
    right_rock = i

# print(two_rocks, three_empty)
# print(left_rock, right_rock)
# print(A, "->", B)
# print(C, "->", D)

if not flag:
  # 目標との間に2岩があるとき
  print("No")
elif (A > B and C > D) or (A < B and C < D):
  # 木彫との間に2岩がなく、交差が発生しない場合。
  print("Yes")
elif not three_empty:
  # 交差点となる3emptyがない場合
  print("No")
else:
  # 双方の一番近い岩との間に3emptyがあるかどうか 
  flag = False
  for i in three_empty:
    if left_rock < i < right_rock:
      flag = True
      break
  if flag:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
argN, argA, argB, argC, argD = list(map(int,input().split()))
argS = input()

if argA < argB and argC < argD:
  flgOIKOSI = False
elif argB < argA and argD < argC:
  flgOIKOSI = False
else:
  flgOIKOSI = True
#print(flgOIKOSI)
  
if "##" in argS[argA - 1:argC]:
  #print(argS[argA - 1:argC])
  print("NO")
elif "##" in argS[argB - 1:argD]:
  #print(argS[argB - 1:argD])
  print("NO")
elif flgOIKOSI == False:
  print("YES")
else:
  aryS = list(argS.split("#"))
  #print(aryS)
  #print(len(max(aryS)))
  if len(max(aryS)) > 2:
    print("YES")
  else:
    print("NO")

Submission status: Wrong Answer

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

switch = 0

S_before_a = S.copy()
S_before_a[B-1] ='#'
A_list = S_before_a[A:C-1]
count1 = 0
for i in range (len(A_list)-1):
    if ''.join(A_list[i:i+2])=='##':
        count1+=1

S_after_a = S.copy()
S_after_a[C-1]='#'

count2 = 0
B_list = S_after_a[B:D-1]
for i in range (len(B_list)-1):
    if ''.join(B_list[i:i+2])=='##':
        count2+=1
    
#count逆
S_before_b = S.copy()
S_before_b[A-1] ='#'
B_list = S_before_b[B:D-1]
count3 = 0
for i in range (len(B_list)-1):
    if ''.join(B_list[i:i+2])=='##':
        count3+=1

S_after_b = S.copy()
S_after_b[D-1]='#'

count4 = 0
A_list = S_after_b[A:C-1]
for i in range (len(A_list)-1):
    if ''.join(A_list[i:i+2])=='##':
        count4+=1
        
change_counter =0
changer = S[max(A,B):min(C,D)-1]
for i in range(len(changer)-2):
    if ''.join(changer[i:i+3])=='...':
        change_counter+=1
        
if (count1+count2) == 0 or (count3+count4) ==0:
    print('Yes')
elif (count1 == 1 and change_counter>0 ) or (count2 == 1 and change_counter>0 ) or (count3 == 1 and change_counter>0 ) or (count4 == 1 and change_counter>0 ):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

ans = "Yes"
if any(map(lambda i: s[i] == s[i + 1] == '#', range(a - 1, c - 1))):
    ans = "No"
if any(map(lambda i: s[i] == s[i + 1] == '#', range(b - 1, d - 1))):
    ans = "No"
if d < c and not any(map(lambda i: b < i + 1 < d, list(filter(lambda i: s[i - 1] == s[i] == s[i + 1] == '.', range(1, n - 1))))):
    ans = "No"

print(ans)

Submission status: Wrong Answer

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

pres = 'x'          # S[i-1]
cntx, cnty = 0, 0   # x:'.'の連続数, y:'#'の連続数
mxx, mxy = 1, 1     # mxx:'.'の連続数max, mxy:'#'の連続数max

for i in range(A-1, max(C, D)): # base=0
    if S[i] == pres:
        if S[i] == '.':
            cntx += 1
            if i >= B-1 and i < D:  # .のチェックは B-Dだけ
                mxx = max(cntx, mxx)
        elif S[i] == '#':
            cnty += 1
            if C > B or (i < C and i >= B-1):   # C < B の場合は、C-Bでは#の数は不問
                mxy = max(cnty, mxy)
    else:
        pres = S[i]
        if S[i] == '.':
            cntx = 1
        elif S[i] == '#':
            cnty = 1

if C < D:
    if mxy < 2:
        print("Yes")
    else:
        print("No")
else:
    if mxy < 2 and mxx >= 3:
        print("Yes")
    else:
        print("No")