Problem:


Score : 400 points

Problem Statement

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

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

You can repeat the following operation any number of times:

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

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

Determine whether this is possible.

Constraints

4 \leq N \leq 200\ 000

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

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

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

A, B, C and D are all different.

A < B

A < C

B < D

Input

Input is given from Standard Input in the following format:

N A B C D
S

Output

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

Sample Input 1

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

Sample Output 1

Yes

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

A#B.#..

A#.B#..

.#AB#..

.#A.#B.

.#.A#B.

.#.A#.B

.#..#AB

Sample Input 2

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

Sample Output 2

No

Sample Input 3

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

Sample Output 3

Yes



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


Sample output:
Yes

Submission status: Wrong Answer

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

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

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

if C < 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
    stone = 0
    road = 0
    for i in range(B + 1, D):
        if S[i] == '#':
            stone += 1
            road = 0
            if stone > 1:
                print("No")
                exit()
        else:
            road += 1
            stone = 0
    print("Yes")
    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 = 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:
                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
    if check:
        ans = True
    S = S[:D] + ['.'] + S[D + 1:]

if not ans:
    stone = 0
    road = 0
    if l[-1] >= 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

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

Submission status: Wrong Answer

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

temp=str(input())
maxim=max(a,b)
minim=min(a,b)
if temp[maxim:].count("...")!=0 or temp[maxim+1]==temp[maxim+2]=="." or temp[maxim+1]==temp[maxim-1]==".":
    flag=1
else:
    flag=0
    
s=list(temp)
s[a]="A"
s[b]="B"
s[c]="C"
s[d]="D"

mac=max(c,d)
ans=1

for i in range(minim,mac):
    if s[i]==s[i+1]=="#":
        ans=0

if c<b:
    ans=1
elif c<d and ans==1:
    ans=1
elif c>d and ans==1:
    if flag==1:
        ans=1
    elif s[d-1]=="#" or s[d+1]=="#":
        ans=0
    else:
        ans=1
                
if ans==1:
    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,C-1):
    if S[k] == S[k+1] == "#":
        print("No")
        exit(0)
for k in range(B-1,D-1):
    if S[k] == S[k+1] == "#":
        print("No")
        exit(0)

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

Submission status: Wrong Answer

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

if A < C < B < D:
    if not (S.find("##", A - 1) < C - 1 and S.find("##", A - 1) != -1) and not (
            S.find("##", B - 1) < D - 1 and S.find("##", B - 1) != -1):
        print("Yes")
    else:
        print("No")
elif C < D:
    if S.find("##", A - 1) > D - 1 or S.find("##", A - 1) == -1:
        print("Yes")
    else:
        print("No")
else:
    if S.find("...", B - 1) < D - 1 and S.find("...", B - 1) != -1:
        if S.find("##", A - 1) > C - 1 or S.find("##", A - 1) == -1:
            print("No")
        else:
            print("Yes")
    else:
        print("No")

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 not i[1]-1 == b]
# max_rock1 = [i for i in max_rock if (i[1] < d and i[1] < c and i[1] > a and i[1] > b) or (i[1])]
max_rock1 = [i for i in max_rock if (i[1] > a and i[1] < b) or (i[1] > b and i[1] < c) or (i[1] > c and i[1] < d)]
max_rock3 = [i for i in max_rock if (i[1] > a and i[1] < b) or (i[1] > b and i[1] < d) or (i[1] > d and i[1] < c)]
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_rock3) > 0:
        print('No')
    elif len(max_non1) > 0:
        print('Yes')
    else:
        print('No')
elif len(max_rock1) > 0:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = (int(_) for _ in input().split())
x = input()

ng = [i+1 for i in range(n) if x[i:i+2] == "##"]

ng1 = [a < i < c or b < i < d for i in ng]

x2 = x[b-1:d+1]
ex = [x2[i:i+3] == "..." for i in range(len(x2))]

if any(ng1):
    res = "No"
elif c > d:
    if any(ex):
        res = "Yes"
    else:
        res = "No"
else:
    res = "Yes"

print(res)

Submission status: Wrong Answer

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

S = list(input())
SS = tuple(S)

flag = 0

for i in range(N-2):
    if i > B:
        if C < D:
            if S[i] == '#' and S[i+1] == '#':
                flag += 1

        if C > D:
            tempS = list(SS)

            if tempS[i] == '.' and tempS[i+1] == '.' and tempS[i+2] == '.':
                tempS[i+1] = '#'
                tempS[B-1] = '.'

                if tempS[i] == '#' and tempS[i+i] == '#':
                    flag += 1

if flag == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
l = list(map(str, input().split()))
sss=input()

num = int(l[0])
ast = l[1]
bst = l[2]
afin=int(l[3])
bfin=int(l[4])




if(ast > bst):
    st=int(bst)
    fin=int(ast)
if(bst > ast):
    st=int(ast)
    fin=int(bst)


if(afin > bfin):
    fst=int(bfin)
    ffin=int(afin)
if(bfin > afin):
    fst=int(afin)
    ffin=int(bfin)


kiritorist= sss[st:num]
kiritorifin=sss[fin-1:fst]
if(afin !="#" or bfin !="#"):
    if(kiritorist.find('##')>0):
        print("No")
    
    if(kiritorist.find('##')<0):
        if((ast<bst and afin<bfin)or(bst<ast and bfin<afin)):
            print("Yes")
    
        if((ast<bst and bfin<afin)or(bst<ast and afin<bfin)):
            if(kiritorifin.find("..")>=0):
                print("Yes")
                
            else:
                print("No")
if(afin =="#" or bfin =="#"):
    print("Yes")

Submission status: Wrong Answer

Solution code:
number_of_masu, firstsunuke, firstfunuke, lastsunuke, lastfunuke = map(int, input().split())
s = str(input())
tobenaiflag = 0
nukaseruflag = 0
lastfunuke -= 1
lastsunuke -= 1
firstsunuke -= 1
firstfunuke -= 1
for i in range(firstsunuke, lastsunuke-1):
    if s[i] == '#' and s[i+1] == '#':
        tobenaiflag += 1
        break
for k in range(firstfunuke, lastfunuke-1):
    if s[k] == '#' and s[k+1] == '#':
        tobenaiflag += 1
        break
if lastfunuke < lastsunuke:
    for j in range(max(firstsunuke, firstfunuke), lastfunuke):
        if s[j] == '.' and s[j-1] == '.' and s[j+1] == '.':
            nukaseruflag += 1
            break
else:
    nukaseruflag += 1
if number_of_masu == 4:
    print('Yes')
elif tobenaiflag == 0 and nukaseruflag == 1:
    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):
            sf = (S[A-1:D].count('...'))
            if(sf == 0):
                print(NO)
            
            elif(sf == 1):
                tS = list(S)
                tS[B-1] = 'b'
                tS = ''.join(tS)
                if(tS[A-1:D].count('..b') == 1):
                    print(NO)
                else:
                    print(YES)
            ######### あとはここだけ考える ####
            elif(sf >= 2):
                # print('Im here!')
                tS = list(S)
                tS[B-1] = 'b'
                tS = ''.join(tS)
                ptS = tS.rfind('..b')
                if(ptS == -1):
                    print(YES)
                else:
                    if(tS[ptS+3:D].count('...') == 0):
                        # print(tS[ptS:D])
                        print(NO)
                    else:
                        # print(tS[ptS:D])
                        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 = input()
s_flag = False
can_flag = True
count = 0
max_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
    max_count = max(max_count, count)
    
if max_count <= 2:
  if c > d:
    can_flag = False
if can_flag:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

if C<B:
    if not '##' in s[A:C]:
        if not '##' in s[B:D]:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    if C<D:
        if '##' in s[A:D]:
            print('No')
        else:
            print('Yes')
    else:
        if '##' in s[A:C]:
            print('No')
        else:
            if '...' in s[B:D+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()

a_to_c = s[a-1:c-1]
b_to_d = s[b-1:d-1]
if (b-1)-1 >= 0:
    b_to_d2 = s[b-1-1:d-1]
else:
    b_to_d2 = s[b-1:d-1]

possibility = True

if a_to_c.find("##")!=-1 or b_to_d.find("##")!=-1:
    possibility = False
if c>d:
    if s[d-1]=='#':
        if not(s[b-3:d-1].find("...")!=-1):
            possibility = False
    if not(b_to_d2.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 = input()
t = s[b-1: d]
def f():
    if '##' in s:
        return 'No'
    elif c < d:
        return 'Yes'
    elif '...' in t:
        return 'Yes'
    else:
        return 'No'
print(f())

Submission status: Wrong Answer

Solution code:
l = list(map(str, input().split()))
sss=input()

num = int(l[0])
ast = l[1]
bst = l[2]
afin=int(l[3])
bfin=int(l[4])




if(ast > bst):
    st=int(bst)
    fin=int(ast)
if(bst > ast):
    st=int(ast)
    fin=int(bst)


if(afin > bfin):
    fst=int(bfin)
    ffin=int(afin)
if(bfin > afin):
    fst=int(afin)
    ffin=int(bfin)


kiritorist= sss[st:num]
kiritorifin=sss[fin-1:fst]
print(kiritorifin)
print(kiritorist)
if(afin !="#" or bfin !="#"):
    if(kiritorist.find('##')>0):
        print("No")
    
    if(kiritorist.find('##')<0):
        if((ast<bst and afin<bfin)or(bst<ast and bfin<afin)):
            print("Yes")
    
        if((ast<bst and bfin<afin)or(bst<ast and afin<bfin)):
            if(kiritorifin.find("..")>=0):
                print("Yes")
                
            else:
                print("No")
if(afin =="#" or bfin =="#"):
    print("Yes")

Submission status: Wrong Answer

Solution code:
from sys import stdin
def main():
    N,A,B,C,D = map(int, stdin.readline().rstrip().split())
    S = stdin.readline().rstrip()
    Slist = list(S)
    A = A-1
    B = B-1
    C = C-1
    D = D-1
    
    # 前提 A Bはゴールよりも右にいると不可能
    if (C < A or D < B):
      print("No")
      return
    
    # 連続岩チェック
    index = -1
    while True:
      index = S.find('##', index + 1)
      if (index == -1) or (C < index and D < index):
        break
      if (A < index and index < C) or (B < index and index < D):
        print('No')
        return
    
    # 初期位置チェック
    if D-B==2 and Slist[B+1] =='#' and A < B and D < C:
        print('No')
        return
    if C-A==2 and Slist[A+1] =='#' and B < A and C < D:
        print('No')
        return
    if (B < A) and (Slist[C-1] =='#' and (A == C-2 or (C >= 4 and A==C-3 and Slist[C-4]=="#") or (C >= 4 and A==C-5 and Slist[C-4]=="#"))):
        print("No")
        return
    if (A < B) and (Slist[D-1] =='#' and (B == D-2 or (D >= 4 and B==D-3 and Slist[D-4]=="#") or (D >= 4 and B==D-5 and Slist[D-4]=="#"))):
        print("No")
        return

    # 連続岩チェック
    index = -3
    indexPre = -3
    flgA=False
    flgB=False
    firstFlg=False
    while True:
      index = S.find('.#.', index + 3)
      if (index == -1) or (C < index and D < index):
        break

      if index - indexPre != 3:
        flgA=False
        flgB=False
        
      if (B < A and index <= A and A <= index+2 and C < D):
        flgA=True
      if (A < B and index <= B and B <= index+2 and D < C):
        flgB=True
      if (flgA and index <= C and C <= index+2 ):
        print("No")
        return
      if (flgB and index <= D and D <= index+2 ):
        print("No")
        return
      
      indexPre = index
    
    print('Yes')

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

Submission status: Wrong Answer

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

if A < C < B < D:
    if not (S.find("##", A - 1) < C - 1 and S.find("##", A - 1) != -1) and not (
            S.find("##", B - 1) < D - 1 and S.find("##", B - 1) != -1):
        print("Yes")
    else:
        print("No")
elif C < D:
    if S.find("##", A - 1) > D - 1 or S.find("##", A - 1) == -1:
        print("No")
    else:
        print("Yes")
else:
    if S.find("...", B - 1) < D - 1 and S.find("...", B - 1) != -1:
        if S.find("##", A - 1) > C - 1 or S.find("##", A - 1) == -1:
            print("Yes")
        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<B:
    if '##' in s[A:C]:
        if '##' in s[B:D]:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    if C<D:
        if '##' in s[A:D]:
            print('No')
        else:
            print('Yes')
    else:
        if '##' in s[A:C]:
            print('No')
        else:
            if '...' in s[B:D+1]:
                print('Yes')
            else:
                print('No')

Submission status: Wrong Answer

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

# In[43]:


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


# In[54]:


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
    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個以上並べば、入れ替えられる
    #print(1)
    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:
        #print(2)
        pass
    elif mdc < 3: # A~Cに dotが3個以上並んでいないとき、
        #print(2)
        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
            
        shc = 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
        
        #print(l, r)
        mdc = 0
        dc = 0
        shc = 0
        for i, s in enumerate(S[l:r]):
            #print('{}: {}'.format(i, dc))
            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 and shc>1:
                ans = 'No'
            if i >= r-l-1:
                mdc = max(dc, mdc)
        if mdc < 3:
            ans = 'No'
print(ans)


# In[ ]:

Submission status: Wrong Answer

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

# 初期位置
su = a-1
fu = b-1

# 動けるか判定
def is_move(u, not_u, step=1):
    u_next = u + step
    # だめパターン
    #print(u_next)
    #print(s)
    if (s[u_next] == '#') or u_next == not_u:
        return False
    
    return True

def is_goal(u, not_u, goal, s):
    exist_flag = False
    u_ = u

    for u_d in range(u, goal):
        #print('u_', u_)
        if u_ < len(s)-1:
            is_move_1 = is_move(u_, not_u, step=1)
            is_move_2 = False
        # 2歩行けるなら計算
        if u_ < len(s) - 2:
            is_move_2 = is_move(u_, not_u, step=2)
    #else:
    #    break
        
        if u_ <= goal:
            if (u_ + 1 == goal) and not(is_move_1):
                exist_flag = False
                break
            
            # 2つ進む方を優先
            if is_move_2:
                u_ += 2
            elif is_move_1:
                u_ += 1
            else:
                break
        
        if u_ == goal:
            exist_flag = True
    return exist_flag
  
  
if is_goal(fu, su, d, s) and is_goal(su, d, c, s):
    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")
    exit()

if C > D:
    if "..." in S[B-1:D]:
        print("Yes")
    else:
        print("No")
else:
    if B == A+1 and S[A+1] == "#":
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
import sys

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

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

for i in range(A, max(C,D)):
    if S[i] == '#' and S[i+1] == '#':
        print('No')
        exit()
if C > D:
    for i in range(A, min(C,D)-1):
        if S[i] == '.' and S[i+1] == '.' and S[i+2] == '.' and B <= i+1:
            print('Yes')
            exit()
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
l = list(map(str, input().split()))
sss=input()

num = int(l[0])
ast = l[1]
bst = l[2]
afin=int(l[3])
bfin=int(l[4])




if(ast > bst):
    st=int(bst)
    fin=int(ast)
if(bst > ast):
    st=int(ast)
    fin=int(bst)


if(afin > bfin):
    fst=int(bfin)
    ffin=int(afin)
if(bfin > afin):
    fst=int(afin)
    ffin=int(bfin)


kiritorist= sss[st:num]
kiritorifin=sss[fin-1:fst]
if(afin !="#" or bfin !="#"):
    if(kiritorist.find('##')>0):
        print("No")
    
    if(kiritorist.find('##')<0):
        if((ast<bst and afin<bfin)or(bst<ast and bfin<afin)):
            print("Yes")
    
        if((ast<bst and bfin<afin)or(bst<ast and afin<bfin)):
            if(kiritorifin.find("..")>=0):
                print("Yes")
                
            else:
                print("NN")
if(afin =="#" or bfin =="#"):
    print("Yes")

Submission status: Wrong Answer

Solution code:
import itertools
from sys import stdin
N,A,B,C,D=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
lst = [0] + [1 if i == "#" else 0 for i in list(S)]
cumsum = itertools.accumulate(lst)
cumsum = list(cumsum) 
 
flag = True
flag_oinuki = False
for i in range(0,(len(cumsum) - 2)):
    if ((cumsum[i+2] - cumsum[i]) == 2):
        flag = False
        break
for j in range(0,(len(cumsum) - 3)):
    if cumsum[j] == cumsum[j+3] and (j+1 <= D):
        flag_oinuki = True
 
if C > D:
    if flag_oinuki and flag:
        print("Yes")
    else:
        print("No")
else:
    if flag:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int, input().split())
S = input()
S =S+"#"
S =S+"#"
S =S+"#"
answer = 1
a = 1
distance = []
distance_2 = []
for n in range(A-1,max(C-1,D-1)):
  a += 1
  if S[n] == "#":
    distance.append(a)
    a = 0
if 1 in distance:
  answer = 0
if D < C and answer == 1:
  a = 1
  for n in range(B-2,D):
    a += 1
    if S[n] == "#":
      distance_2.append(a)
      a = 0
  if max(distance_2) < 4:
    answer = 0
if answer == 1:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
number_of_masu, firstsunuke, firstfunuke, lastsunuke, lastfunuke = map(int, input().split())
s = str(input())
tobenaiflag = 0
nukaseruflag = 0
lastfunuke -= 1
lastsunuke -= 1
firstsunuke -= 1
firstfunuke -= 1
for i in range(firstsunuke, lastsunuke-1):
    if s[i] == '#' and s[i+1] == '#':
        tobenaiflag += 1
        break
for k in range(firstfunuke, lastfunuke-1):
    if s[k] == '#' and s[k+1] == '#':
        tobenaiflag += 1
        break
if lastfunuke < lastsunuke:
    for j in range(max(firstsunuke, firstfunuke), lastfunuke):
        if s[j] == '.' and s[j-1] == '.' and s[j+1] == '.':
            nukaseruflag+=1
            break
else:
  nukaseruflag+=1
if tobenaiflag == 0 and nukaseruflag == 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

if A < C < B < D:
    if not (S.find("##", A - 1) < C - 1 and S.find("##", A - 1) != -1) and not (
            S.find("##", B - 1) < D - 1 and S.find("##", B - 1) != -1):
        print("No")
    else:
        print("Yes")
elif C < D:
    if S.find("##", A - 1) > D - 1 or S.find("##", A - 1) == -1:
        print("Yes")
    else:
        print("No")
else:
    if S.find("...", B - 1) < D - 1 and S.find("...", B - 1) != -1:
        if S.find("##", A - 1) > C - 1 or S.find("##", A - 1) == -1:
            print("Yes")
        else:
            print("No")
    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")

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

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 = b
    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
            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
    import random
    if random.randint(0, 5) == 1:
        print('Yes')
        return
    print('No')


main()

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
s = list(input())
s_a =s[A-1:C-1]
s_b = s[B-1:D-1]
count = 0
if C < D :

    for i in range(C-A-1):
        if s_a[i] == "#" and s_a[i+1] == "#" :
            count += 1
    for i in range(D-B-1) :
        if s_b[i] == "#" and s_b[i+1] == "#" : 
            count += 1

    if count == 0 : print("Yes")
    else: print("No")


else :
    p = 0
    for i in range(C-A-1):
        if s_a[i] == "#" and s_a[i+1] == "#" :
            count += 1
    for i in range(D-B-1) :
        if s_b[i] == "#" and s_b[i+1] == "#" : 
            count += 1
    
    for i in range(C-A-2):
        if s_a[i] == "." :
            if  s_a[i+1] == "." and s_a[i+2]=="." :
                p += 1
    if p >= 1 and count == 0:
        print("Yes")
    else: print("No")

Submission status: Wrong Answer

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

S=[]
S.append([0  if i=='#' else 1  for i in input()])

cout=0
cin=0
M=max(C,D)
m=min(C,D)
#first
if(M==C):
    S[0][B-1]=0
    for i in S[0][B:D-1]:
        if i==1:
            cin+=1
            if cin==3:
                print("Yes")
                sys.exit()
    for i in S[0][0:M-1]:
        #print(i)
        if i==0:
            #print(i)
            cout+=1
            if cout==2:
                print("No")
                sys.exit()
        else:
            #print("##")
            cout=0
cout=0
S[0][B-1]=1
if(M==D):
    for i in S[0][0:m-1]:
        #print(i)
        if i==0:
            #print(i)
            cout+=1
            if cout==2:
                print("No")
                sys.exit()
        else:
            #print("##")
            cout=0
print("Yes")

Submission status: Wrong Answer

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

'''
7 1 2 4 3
....

7 1 3 5 7
.#.#.#.#.#.#

7 1 3 5 7
.#.#.#.#.#.#

'''
#print(S)
iwa_cnt = 0
kusa_cnt = 0
result ='No'
for i,s in enumerate(S[A-1:max(C,D)-1]):
    #print(s)
    #print(i)
    #print(iwa_cnt)
    #print(kusa_cnt)
    if s =='#':
        iwa_cnt +=1
        kusa_cnt = 0
    else:
        #print(s)
        #print(i + A - 1)
        if i + A - 1 > B -1:
            kusa_cnt +=1
        iwa_cnt = 0
    if iwa_cnt == 2:
        break
    if kusa_cnt == 1 and C < D:
        result = 'Yes'
    #if kusa_cnt == 2:
    #    result = 'Yes'
    if kusa_cnt == 3:
        result = 'Yes'
    if D <C and S[B-2] =='.'and S[B] =='.' and kusa_cnt ==1:
        result = 'Yes'
    if D <C and S[B] =='.'and S[B+1] =='.' and kusa_cnt ==1:
        result = 'Yes'


print(result)



'''
Aの現在地からCまでに...が三つ続いていれば、
そこにCをおける
Cは##がない限り、さきに動かせばいいので、問題ない


'''
#print(N,M)
#print(target)
#print(P)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
cou = 0
ans = 0
cou2 = 0
ans2 = 0
if C < D:
    S = S[A: D-1]
    for i in S:
        if i == "#":
            cou += 1
        else:
            ans = max(ans, cou)
            cou = 0
    if ans >= 2:
        print("No")
    else:
        print("Yes")
else:
    S = S[A:C-1]
    for i in S:
        if i == "#":
            cou += 1
            ans2 = max(ans2, cou2)
            cou2 = 0
        else:
            cou2 += 1
            ans = max(ans, cou)
            cou = 0
    ans2 = max(ans2, cou2)
    if ans < 2 and ans2 >= 3:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

s_cnt = 0
max_s_cnt = 0
pre_s = ''

goal = max(C, D)

for i in range(A-1, goal):
  if pre_s == "#":
    if S[i] == "#":
      print("No")
      exit()
  if i > B -1 and i < D + 1:
    if S[i] == '.':
      s_cnt += 1
      if max_s_cnt < s_cnt:
        max_s_cnt = s_cnt
    else:
      s_cnt = 0
  pre_s = S[i]
#  print(max_s_cnt)
  
if C < D:
  print("Yes")
else:
  if max_s_cnt >= 3:
    print("Yes")
  else:
    print("No")