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:
def main():
    n,a,b,c,d = [int(x) for x in input().split()]
    S = input()
    
    a -= 1
    b -= 1
    c -= 1
    d -= 1

    if a>b:
        a,b,c,d=b,a,d,c
    
    # move a to left
    while a>0:
        if a-2>=0 and S[a-2]=='.':
            a -= 2
        elif a-1>=0 and S[a-1]=='.':
            a -= 1
        else:
            break
    # move b to right
    while b<n:
        if b+2<n and S[b+2]=='.':
            b += 2
        elif b+1<n and S[b+1]=='.':
            b += 1
        else:
            break
    # goal cannot be reached
    if c<a or b<d:
        print 'No'
        sys.exit()

    # move a as much to right as possible
    found_special = False
    while 1:
        if a+1<n and a+1<b and S[a+1]=='.':
            a += 1
        elif a+2<n and a+2<b and S[a+2]=='.':
            a += 2
        else:
            break
        if a-1>=0 and a+1<n and S[a-1]==S[a]==S[a+1]=='.':
            found_special = True
    
    # if they need to jump over eachother, but no gap was found
    if c>d and not found_special:
        print 'No'
        sys.exit()
    
    while a<c:
        if a+1<n and S[a+1]=='.':
            a += 1
        elif a+2<n and S[a+2]=='.':
            a += 2
        else:
            print 'No'
            sys.exit()
            
    while a>c:
        if a-1>=0 and S[a-1]=='.':
            a -= 1
        elif a-2>=0 and S[a-2]=='.':
            a -= 2
        else:
            print 'No'
            sys.exit()
    while b>d:
        if b-1>=0 and S[b-1]=='.':
            b -= 1
        elif b-2>=0 and S[b-2]=='.':
            b -= 2
        else:
            print 'No'
            sys.exit()
    if a!=c or b!=d:
        print 'No'
    else:
        print 'Yes'


######## Python 2 and 3 footer by Pajenegod and c1729

# Note because cf runs old PyPy3 version which doesn't have the sped up
# unicode strings, PyPy3 strings will many times be slower than pypy2.
# There is a way to get around this by using binary strings in PyPy3
# but its syntax is different which makes it kind of a mess to use.

# So on cf, use PyPy2 for best string performance.

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

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

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

# Cout implemented in Python
import sys
class ostream:
    def __lshift__(self,a):
        sys.stdout.write(str(a))
        return self
cout = ostream()
endl = '\n'

# Read all remaining integers in stdin, type is given by optional argument, this is fast
def readnumbers(zero = 0):
    conv = ord if py2 else lambda x:x
    A = []; numb = zero; sign = 1; i = 0; s = sys.stdin.buffer.read()
    try:
        while True:
            if s[i] >= b'0' [0]:
                numb = 10 * numb + conv(s[i]) - 48
            elif s[i] == b'-' [0]: sign = -1
            elif s[i] != b'\r' [0]:
                A.append(sign*numb)
                numb = zero; sign = 1
            i += 1
    except:pass
    if s and s[-1] >= b'0' [0]:
        A.append(sign*numb)
    return A

if __name__== "__main__":
  main()

Submission status: Wrong Answer

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

moziretu = S  # 保持しておく

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-1] = '#'
    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
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-1] = '#'
    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:
import numpy as np
NABCD = list(map(int,input().split()))
N = NABCD[0]
A = NABCD[1]
B = NABCD[2]
C = NABCD[3]
D = NABCD[4]
S = input()

output = "No"

cous = 0
maxs = 0
cour = 0
maxr = 0
maxi = np.array([])
maxir = np.array([])

for i in range(N):
    p = S[i]
    if p == "#":
        cour += 1
        cous = 0
    elif p == ".":
        cous += 1
        cour = 0
    if cour > maxr:
        maxr = cour
    if cous > maxs:
        maxs = cous
    if cous > 2:
        maxi = np.append(maxi,i+1)
    if cour >= 2:
        maxir = np.append(maxir,i+1)

keysum = sum(maxi-1>=B)
if C > D:
    if (maxr < 2)and(maxs >2)and(keysum>0):
        output = "Yes"
    elif (maxr >= 2)and(maxir[len(maxir)-1]<A)and(maxs >2)and(keysum>0):
        output = "Yes"
elif D > C:
    if maxr < 2:
        output = "Yes"
    elif (maxr >= 2)and(maxir[len(maxir)-1]<A):
        output = "Yes"
print(output)

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = list(map(int, input().split()))
S = input()
X = [".", "#"]
Ans = ["Yes", "No"]

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

f = 0
if A < B:
  if B < C and D < C:
    f = 1

a, b = A, C
s = 0
for i in range(a, b + 1):
  if S[i] == X[1]:
    if s == 1:
      print(Ans[1])
      exit()
    s = 1
  else:
    s = 0

a, b = B, D
s = 0
for i in range(a, b + 1):
  if S[i] == X[1]:
    if s == 1:
      print(Ans[1])
      exit()
    s = 1
  else:
    s = 0

if f == 0:
  print(Ans[0])
  exit()

s = 0
for i in range(B - 1, min(D + 1, N)):
  if S[i] == X[1]:
    if s == 1:
      break
    else:
      s = 1
  else:
    if s == 1:
      s = -1
    else:
      s -= 1
      if s == -3:
        print(Ans[0])
        exit()

print(Ans[1])

Submission status: Wrong Answer

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

if Sp.find('##') != -1:
    print('No')
    exit()

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

if Sp[B-1] == '.' and Sp[B+1] == '.':
    print('Yes')
    exit()

if Sp[B:B+2] == '..':
    print('Yes')
    exit()

if Sp[B:C].find('...') >= 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
#n=int(input())
n,a,b,c,d=map(int,input().split())
#a=[int(i) for i in input().split()]
s='_'+input()
ai=0
ans=['Yes','No']

#print(s,n,a,b,c,d)

def CanGo(x,y):
    cnt=0
    root=s[x:y]
    for c in root:
        if c=='#':
            cnt+=1
        elif c=='.':
            if cnt>2:
                return False
            cnt=0
    return True


def CanPass(x,y):  #(b,d)
    root=s[x:y+1]
    q=s[x:x+4]
    #print(root,len(root)-4)
    for i in range(len(root)-4):
        if q=='..#.' or  q=='.#..' or q=='....' or q=='...#' or q=='#...':
            return True
        q=q[1:4]+s[x+4+i]
        
    '''
    root=s[x-1:x+2]
    if root=='...':
        return True
    
    if x-2>=0 and b-a>=2:
        root=s[x-2:x+2]
        if root=='.#..':
            return True
    ''' 
    return False
        


if c<d:
    if CanGo(b,d) and CanGo(a,c):
        ai=0
    else:
        ai=1
elif c>d:
    if CanGo(b,d) and CanGo(a,c) and CanPass(b,d):
        ai=0
    else:
        ai=1
    
    

print(ans[ai])

Submission status: Wrong Answer

Solution code:

N,A,B,C,D = map(int,input().split())
a= input()
f = 0
s = 0
d = 1
t = []
k = []

f1 = 0
s1 = 0
d1 = 1
t1 = []
k1 = []


for i in a[A-1:C]:
    if i == "." and f ==1:
        k.append(d)
        s = 1
        f = 0
    elif i == ".":s+=1
    
    elif i == "#" and f==0:
        t.append(s)
        d = 1
        f = 1
    elif i == "#":d+=1
else:
    if f==1:
        k.append(d)
    else:
        t.append(s)
for i in a[B-1:D]:
    if i == "." and f1 ==1:
        k1.append(d1)
        s1 = 1
        f1 = 0
    elif i == ".":s1+=1
    
    elif i == "#" and f1==0:
        t1.append(s1)
        d1 = 1
        f1 = 1
    elif i == "#":d1+=1
else:
    if f1==1:
        k1.append(d1)
    else:
        t1.append(s1)
# print(t,k)
# print(t1,k1)
if C < D :
    if len(k) == sum(k):
        print("Yes")
    else:
        print("No")
else:
    if len(k) == sum(k) and any([i > 2 for i in t1]) :
        print("Yes")
    elif t1[-1] >1:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

    if c < d:
        count = 0
        for i in range(a, d):
            if s[i] == '#':
                count += 1
                if count == 2:
                    print('No')
                    exit(0)
            else:
                count = 0
        print('Yes')
    else:
        flag = 0
        countr = 0
        countv = 0
        for i in range(a, c):
            if s[i] == '#':
                countr += 1
                countv = 0
                if countr == 2:
                    print('No')
            else:
                if b - 2 <= i <= d:
                    countv += 1
                else:
                    countv = 0
                countr = 0
                if countv == 3:
                    flag = 1
        print('Yes') if flag else print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if '##' in S[A:C] or '##' in S[B:D]:
  ng=True
if (not ng) and (B<C and D<C):
  if '...' in S[B-1:D+1]: pass
  elif S[A-1:A+2]=='...' and A==B-1: pass
  else: ng = True

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

Submission status: Wrong Answer

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

ans = "Yes"
tmpSpace = 0
tmpRock = 0
space = 0
for i in range(min(A, B), min(C, D) + 1):
    if s[i] == ".":
        if i >= max(A, B) - 1:
            tmpSpace += 1
        tmpRock = 0
    else:
        tmpRock += 1
        if tmpRock >= 2:
            ans = "No"
            break
        space = max(space, tmpSpace)
        tmpSpace = 0

space = max(space, tmpSpace)
if (A - B) * (C - D) < 0:
    if space <= 2:
        ans = "No"

print(ans)

Submission status: Wrong Answer

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

for i in range(A,D-1):
    if S[i] == '#':
        if S[i - 1] == '#':
            print('No')
            exit(0)
if C < D:
    print('Yes')
    exit(0)

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

Submission status: Wrong Answer

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

S = input()
nS = S[B-1:max(C,D)+1]
AB = S[A-1:B]

if C<D:
    if nS.find("##") != -1:
        print("No")
    else:
        print("Yes")

elif AB.find("##") != -1:
    print("No")
elif nS.find("...") == -1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

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

for i, k in enumerate(s):
  if k == '.':
    j += 1
  else:
    if j >= 3 and i - j + 1 < d and b < i:
      flag = True
    j = 0
    
if c > d and flag:
  print('Yes')
elif c < d:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

n,a,b,c,d = m();
ss = list(input())
if c < d:
	k = s(ss[b-1:d])
	for i in range(len(k)):
		if k[i][0] == "#" and k[i][1] >= 2:
			print("No")
			exit()
	k = s(ss[a-1:c])
	for i in range(len(k)):
		if k[i][0] == "#" and k[i][1] >= 2:
			print("No")
			exit()
	print("Yes")
	exit()
else:
	# c > d
	count = 0
	k = s(ss[b-1:d])
	for i in range(len(k)):
		if k[i][0] == "#" and k[i][1] >= 2:
			print("No")
			exit()
		if k[i][0] == "." and k[i][1] >= 3:
			count = 1
	if count == 1:
		k = s(ss[a-1:c])
		for i in range(len(k)):
			if k[i][0] == "#" and k[i][1] >= 2:
				print("No")
				exit()
		print("Yes")
		exit()
	else:
		ss[d-1] = "#"
		k = s(ss[a-1:c])
		for i in range(len(k)):
			if k[i][0] == "#" and k[i][1] >= 2:
				print("No")
				exit()
		print("Yes")
		exit()

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = map(int, input().split())
S = input()
if "##" in S[a-1:max(c,d)]:
  print('No')
elif c > d and "..." not in S[b-2:min(c,d)]:
  print('No')
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
import copy

def solve(n, a, b, c, d, s):
    if c < d:
        for i in range(a-1, d-1):
            if s[i] == "#" and s[i+1] == "#":
                return "No"
            else:
                return "Yes"
    else:
        for i in range(a-1, c-1):
            if s[i] == "#" and s[i+1] == "#":
                return "No"
            # until: d - 1, d, d + 1
            elif i < d - 1 and s[i] == "." and s[i+1] == "." and  s[i+2] == "." :
                return "Yes"
        return "No"


if __name__ == '__main__':

    n, a, b, c, d = map(int, sys.stdin.readline().strip().split(" "))
    s = sys.stdin.readline().strip()
    print solve(n, a, b, c, d, s)

Submission status: Wrong Answer

Solution code:
# from sys import exit
N, A, B, C, D = [int(n)-1 for n in input().split()]
# N = int(input())
# a = [int(input()) for _ in range(N)]
S = list(str(input()))
L = len(S)
# T = str(input())
# # exit()
# S[A] = "A"
# S[B] = "B"
# S[C] = "AG"
# S[D] = "BG"
# print(S)
# 連続岩チェック
for i in range(0, L-1):
    if S[i] == "#" and S[i+1] == "#":
        if i < C or i < D:
            print("No")
            exit()

# Bをこす必要があって越せるかチェック

if D < C:
    OK = False
    if S[B+1] == "." and (S[B-1] == "." or S[B-1] == "A"):
        print("Yes")
        exit()
    for i in range(0, L-2):
        if S[i] == "." and S[i+1] == "." and S[i+2] == ".":
            if B < i:
                print("Yes")
                exit()
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
n,a,b,c,d=map(int,input().split())
s=input()
if '##' in s[a:]:
    print('No')
    sys.exit()
if d<c:
    if s[b-2]==s[b]=='.':
        print('Yes')
        sys.exit()
    elif '...' in s[b-1:c]:
        print('Yes')
        sys.exit()
else:
    print('Yes')
    sys.exit()
print('No')

Submission status: Wrong Answer

Solution code:

n, a, b, c, d = map(int, input().split())
s = "#"+input()
#print(s)

if ("##" in s[a:c+1]) or ("##" in s[b:d+1]):
    print("No")
elif not("##" in s[a:c+1]) and not("##" in s[b:d+1]) and c < d:
    print("Yes")
else:
    if s[b-1] == "." and s[b+1] == ".":
        print("Yes")
    elif "..." in s[b:d+1]:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

if '##' in S:
    print('No')
elif C<D:
    print('Yes')
else:
    if '...' in S[B:]:
        print('Yes')
    elif '...' in S[A-1:]:
        if S[B] == '.':
            print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
def valid_check(n, a, b, c, d, s):
    if not two_rocks(s[b:d]):
        return 0
    # if not two_rocks()
    if c < d:
        return two_rocks(s[a:c])
    else:
        return (three_spaces(s[a:c+1]) and two_rocks(s[a:c]))
            


        # for possibility in enumerate_possibilities(b, d, s):
        #     if two_rocks(possibility[a:c]):
        #         return 1
        # return 0

def three_spaces(s):
    for i in range(len(s)-2):
        if s[i]=='.' and s[i+1]=='.' and s[i+2]=='.':
            return 1
    return 0

# def enumerate_possibilities(b, d, s):
#     possibilities = []
#     for i in range(d-b+1):
#         if s[b+i]=='.':
#             tmp = s.copy()
#             tmp[b+i] = '#'
#             possibilities.append(tmp)
#     return possibilities


def two_rocks(s):
    for i in range(len(s)-1):
        if s[i]=='#' and s[i+1]=='#':
            return 0
    return 1

n, a, b, c, d = map(int, input().split())
a -= 1
b -= 1
c -= 1
d -= 1
s = list(input())


if valid_check(n, a, b, c, d, s):
    print('Yes')
else:
    print('No')

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!=n:
        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!=n:

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

Submission status: Wrong Answer

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

if '##' in S :
    print("No")
    quit()

if C > D:
    if '...' not in S[B-1:C-1]:
        print("No")
        quit()


print("Yes")

Submission status: Wrong Answer

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

# 間に＃が連続していなければ通るはず



if not "##" in S[B-1:D-1]:
    S = list(S)
    S[D-1] = "#"
    S = ''.join(S)
    if not "##" in S[A-1:C-1] or "..." in S[B-2:C-1]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n , a0 , b0 , c0 , d0 = map(int,input().split())
s = input()

print('Yes')

Submission status: Wrong Answer

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

if "##" in S:
    print("NO")
else:
    S = S[min(A, B)-1:max(C, D)]
    if "..." in S:
        print("YES")
    else:
        if C < D:
            print("YES")
        else:
            print("NO")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N,A,B,C,D = map(int, input().split())
S = list(input())

A -= 1
B -= 1
C -= 1
D -= 1
S[A] = 'a'
S[B] = 'b'

ans_D = False
ans_C = False

b = B
a = A

if C <= D:
    while True:
        if b == D:
            ans_D = True
            break
        else:
            if S[b+1] == '.':
                S[b] = '.'
                S[b+1] = 'b'
                b += 1
            else:
                if S[b+2] == '.':
                    S[b] = '.'
                    S[b+2] = 'b'
                    b += 2
                else:
                    break
    if ans_D:
        while True:
            if a == C:
                ans_C = True
                break
            else:
                if S[a+1] == '.':
                    S[a] = '.'
                    S[a+1] = 'a'
                    a += 1
                else:
                    if S[a+2] == '.':
                        S[a] = '.'
                        S[a+2] = 'a'
                        a += 2
                    else:
                        break
    if ans_C and ans_D:
        print('YES')
    else:
        print('No')
else:
    swap_flag = False
    while b + 1 < N:
        if S[b-1] == '.' and S[b+1] == '.':
            swap_flag = True
            break
        else:
            if S[b+1] == '.':
                S[b] = '.'
                S[b+1] = 'b'
                b += 1
            else:
                if S[b+2] == '.':
                    S[b] = '.'
                    S[b+2] = 'b'
                    b += 2
                else:
                    break
    if swap_flag:
        while True:
            if a == C:
                ans_C = True
                break
            else:
                if S[a+1] == '.':
                    S[a] = '.'
                    S[a+1] = 'a'
                    a += 1
                else:
                    if S[a+2] == '.':
                        S[a] = '.'
                        S[a+2] = 'a'
                        a += 2
                    else:
                        break
        if ans_C:
            while True:
                if b == D:
                    ans_D = True
                    break
                else:
                    if S[b+1] == '.':
                        S[b] = '.'
                        S[b+1] = 'b'
                        b += 1
                    else:
                        if S[b+2] == '.':
                            S[b] = '.'
                            S[b+2] = 'b'
                            b += 2
                        else:
                            break
            if ans_C and ans_D:
                print('YES')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')

Submission status: Wrong Answer

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

if C<D or C<B:
    if "##" in S[A-1:C] or "##" in S[B-1:D]:
        print("No")
    else:
        print("Yes")
else:
    s = S.split("##")
    l=-2
    for ss in s:
        l += 2+len(ss)
        if l >= A:break
    if ("..." in ss) and (l >= C):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N,A,B,C,D = map(int,input().split())
S = list(input())
SB = deepcopy(S)
SB[D-1]="#"

bool=False
for i in range(B-1,D):
    if i >= N-1:
        break
    if S[i] == "." and S[i-1]=="." and S[i+1]=="." and i != C:
        bool = True
        break

if bool == True:
    print("Yes")
else:
    for i in range(A,C):
        if SB[i-1]=="#" and SB[i]=="#":
            print("No")
            exit()
    print("Yes")

Submission status: Wrong Answer

Solution code:
#A問題
N,A,B,C,D = map(int,input().split())
Slist = list(str(input()))
if C < D:
    now = B-1
    Rock = 0
    flag = 0
    for i in range(D-B):
        I = i+now
        if i == 0:
            pass
        else:
            if Slist[I] == "#":
                Rock+=1
                if Rock == 2:
                    flag = 1
                    break
            else:
                Rock = 0
    now = A-1
    Rock = 0
    for i in range(C-A):
        I = i+now
        if i == 0:
            pass
        else:
            if Slist[I] == "#":
                Rock+=1
                if Rock == 2:
                    flag = 1
                    break
            else:
                Rock = 0

    if flag == 1:
        print("No")
    else:
        print("Yes")
    
else:
    now = B-1
    Rock = 0
    flag = 0
    for i in range(D-B):
        I = i+now
        if i == 0:
            pass
        else:
            if Slist[I] == "#":
                Rock+=1
                if Rock == 2:
                    flag = 1
                    break
            else:
                Rock = 0
    now = A-1
    Rock = 0
    mass = 0
    Maxmass = 0
    aflag = 0
    for i in range(C-A):
        I = i+now
        if i == 0:
            pass
        else:
            if Slist[I] == "#":
                Rock+=1
                if Rock == 2:
                    flag = 1
                    break
            else:
                Rock = 0
                
    now = A-1
    for i in range(D-A+2):
        I = now + i
        if i == 0:
            mass+=1
        else:
            if Slist[I] == "#":
                Maxmass = max(Maxmass,mass)
                mass = 0
            else:
                mass+=1
    Maxmass = max(Maxmass,mass)

    if Maxmass <= 2:
        flag = 1
    
    if flag == 1:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
a = input()
k = A
found = True
ffond = False
b = 0
c = 0
if C <D :
    while  found == True and k < D:
        if a[k] == "#":
            b += 1
        else:
            b = 0
        if b == 2:
            found = False
        k += 1
    if found == False:
        print("No")
    else:
        print("Yes")
else:
    while  found == True and k < C:
        if a[k] == "#":
            b += 1
            if k > B-2 and k <= D:
                c = 0
        else:
            b = 0
            if k > B-2 and k <=D:
                c +=1
        if b == 2:
            found = False
        if c == 3:
            ffond = True
        k += 1
    if found == False or ffond == False:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
def inverse(a):
    return pow(a, mod - 2, mod)

def main():
    n,a,b,c,d = map(int, input().split())
    a -=1
    b -=1
    c -=1
    d -=1

    s = input()

    a_r = a
    cnt = 0
    for i in range(a, n):
        if s[i] == '#':
            cnt += 1
        else:
            cnt = 0
        a_r = i
        if cnt == 2:
            a_r = i
            break

    b_r = a
    cnt = 0
    for i in range(b, n):
        if s[i] == '#':
            cnt += 1
        else:
            cnt = 0
        b_r = i
        if cnt == 2:
            b_r = i - 2
            break
    if a_r < c or b_r < d:
        print('No')
        return
    if c < d:
        print('Yes')
        return
    cnt = 0
    for i in range(b, d):
        if s[i] == '.':
            cnt += 1
        else:
            cnt = 0
        if cnt > 2:
            print('Yes')
            return

    if s[b-1] == '.' and s[b+1] == '.':
        print('Yes')
        return
    if s[d-1] == '.' and s[d+1] == '.':
        print('Yes')
        return

    print('No')


main()

Submission status: Wrong Answer

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

Sstr=input()


if "##" in Sstr[A:C-1]:
    print("No")
elif "##" in Sstr[B:D-1]:
    print("No")
else:
    
    if C<D:
        print("Yes")
    else:
        if "..." in Sstr[B:D]:
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
def check(list,a,b,e,d):
    i,z,count,counter,c=a,True,0,0,0
    check1=0
    while i<b:
        if list[i]=='#':
            c+=1
        if list[i]=='.':
            c=0
        if c>=2:
            check1+=1
        i+=1
    if check1>0:
        return False
    c=0
    check1=0
    i=max(a,b)
    while i<max(e,d) and z:
        if list[i]=='#':
            counter=0
            c+=1
        if list[i]=='.':
            counter+=1
            c=0
        if counter>=3:
            count+=1
        if c>=2:
            check1+=1
        i+=1
    
    if check1>0:
        return False
    else:
        if d>e:
            return True
        elif d==e:
           
            return False
        else:
            if count>1:
                
                return True
m=list(map(int,input().strip().split()))
l=list(input())
if check(l,m[1],m[2],m[3],m[4]):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

rock=0
blank=0
for i in range(a,c):
    if path[i-1]=='#' and path[i]=='#':
        rock=1
for i in range(b,d):
    if path[i-1]=='#' and path[i]=='#':
        rock=1

for i in range(max(a,b),min(c,d)):
    if path[i-2]=='.' and path[i-1]=='.' and path[i]=='.':
        blank=1

if rock==0 and ((a-b)*(c-d)>0 or (blank==1 and (a-b)*(c-d)<0)):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

if d > c: #B君の方が目的地が遠い
    if S[b:d].count('##') != 0:
        ans = 'No'
    else:
        if S[a:c].count('##') != 0:
            ans = 'No'
else:
    if S[a:c].count('##') != 0:
         ans = 'No'
    else:
        if S[b-2:d].count('...') == 0:
            ans = 'No'

print(ans)