Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
"""
Created on Sun Jun  2 22:01:55 2019

@author: hisaki
"""

import sys
N, A, B, C, D = map(int, input().split())
S = input()
A_start = A -1
B_start = B -1
A_goal = C -1
B_goal = D -1

A_pos = A_start
B_pos = B_start

flag = True
for i in range(A_goal):
    if i< A_goal-1 and S[i] == '#':
        if S[i+1] == '#':
            flag = False

for i in range(B_goal):
    if i< B_goal-1 and S[i] == '#':
        if S[i+1] == '#':
            flag = False
if flag == False:
    print ("No")
    sys.exit()
  


if A_pos < B_pos and A_goal < B_goal:
    print ("Yes")
    sys.exit()

if B_pos < A_pos and B_goal < A_goal:
    print ("Yes")
    sys.exit()


if A_pos < B_pos and B_goal < A_goal :
    for i in range(A_goal-2):
        if (S[i] == '.' or i == A_pos or i == B_pos) and (S[i+1]== '.' or i+1 == A_pos or i+1 == B_pos ) and (S[i+2] == '.' or i+2 == A_pos or i+2 == B_pos):
            print ("Yes")
            sys.exit()

if B_pos < A_pos and A_goal < B_goal :
    for i in range(B_goal-2):
        if (S[i] == '.' or i == B_pos or i == A_pos) and (S[i+1]== '.' or i+1 == B_pos or i+1 == A_pos ) and (S[i+2] == '.' or i+2 == B_pos or i+2 = A_pos):
            print ("Yes")
            sys.exit()
            
print ("No")
        


# -*- coding: utf-8 -*-
"""
Created on Sun Jun  2 22:01:55 2019

@author: hisaki
"""

import sys
N, A, B, C, D = map(int, input().split())
S = input()
A_start = A -1
B_start = B -1
A_goal = C -1
B_goal = D -1

A_pos = A_start
B_pos = B_start

flag = True
for i in range(A_goal):
    if i< A_goal-1 and (S[i] == '
        if S[i+1] == '#' or i+1 == B_pos:
            flag = False

for i in range(B_goal):
    if i< B_goal-1 and S[i] == '
        if S[i+1] == '#' or i+1 == A_pos:
            flag = False
            
if flag == False:
    print ("No")
    sys.exit()
  


if A_pos < B_pos and A_goal < B_goal:
    print ("Yes")
    sys.exit()

if B_pos < A_pos and B_goal < A_goal:
    print ("Yes")
    sys.exit()


if A_pos < B_pos and B_goal < A_goal :
    for i in range(A_goal-2):
        if (S[i] == '.' or i == A_pos or i == B_pos) and (S[i+1]== '.' or i+1 == A_pos or i+1 == B_pos ) and (S[i+2] == '.' or i+2 == A_pos or i+2 == B_pos):
            print ("Yes")
            sys.exit()

if B_pos < A_pos and A_goal < B_goal :
    for i in range(B_goal-2):
        if (S[i] == '.' or i == B_pos or i == A_pos) and (S[i+1]== '.' or i+1 == B_pos or i+1 == A_pos ) and (S[i+2] == '.' or i+2 == B_pos or i+2 == A_pos):
            print ("Yes")
            sys.exit()
            
print ("No")
        


# -*- coding: utf-8 -*-
"""
Created on Sun Jun  2 21:00:38 2019

@author: hisaki
"""


import sys
N, A, B, C, D = map(int, input().split())
S = input()
A_start = A -1
B_start = B -1
A_goal = C -1
B_goal = D -1

A_pos = A_start
B_pos = B_start

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

def func(A_pos, B_pos):
    global N
    global A_goal
    global B_goal
    
    if A_pos == A_goal and B_pos == B_goal:
        print ("Yes")
        sys.exit()
    
    if A_pos <= N-2 and S[ A_pos + 1 ] != '
        func(A_pos+1,B_pos)
    if A_pos <= N-3 and S[ A_pos + 2 ] != '
        func(A_pos+2,B_pos)
    if B_pos <= N-2 and S[ B_pos + 1 ] != '
        func(A_pos,B_pos+1)
    if B_pos <= N-3 and S[ B_pos + 2 ] != '
        func(A_pos,B_pos+2)
    
    return

func(A_pos,B_pos)
print ("No")


    
                   





            




# -*- coding: utf-8 -*-
"""
Created on Sun Jun  2 21:00:38 2019

@author: hisaki
"""


import sys
N, A, B, C, D = map(int, input().split())
S = input()
A_start = A -1
B_start = B -1
A_goal = C -1
B_goal = D -1

A_pos = A_start
B_pos = B_start

def func(A_pos, B_pos):
    global N
    global A_goal
    global B_goal
    
    if A_pos == A_goal and B_pos == B_goal:
        print ("Yes")
        sys.exit()
    
    if A_pos <= N-2 and S[ A_pos + 1 ] != '
        func(A_pos+1,B_pos)
    if A_pos <= N-3 and S[ A_pos + 2 ] != '
        func(A_pos+2,B_pos)
    if B_pos <= N-2 and S[ B_pos + 1 ] != '
        func(A_pos,B_pos+1)
    if B_pos <= N-3 and S[ B_pos + 2 ] != '
        func(A_pos,B_pos+2)
    
    return

func(A_pos,B_pos)
print ("No")


    
                   





            




# -*- coding: utf-8 -*-
"""
Created on Sun Jun  2 21:00:38 2019

@author: hisaki
"""


import sys
N, A, B, C, D = map(int, input().split())
S = input()
A_start = A -1
B_start = B -1
A_goal = C -1
B_goal = D -1

A_pos = A_start
B_pos = B_start

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

def func(A_pos, B_pos):
    global N
    global A_goal
    global B_goal
    
    if A_pos == A_goal and B_pos == B_goal:
        print ("Yes")
        sys.exit()
    
    if A_pos != N-1 and S[ A_pos + 1 ] != '
        func(A_pos+1,B_pos)
    if A_pos != N-1 and A_pos != N-2 and S[ A_pos + 2 ] != '
        func(A_pos+2,B_pos)
    if B_pos != N-1 and S[ B_pos + 1 ] != '
        func(A_pos,B_pos+1)
    if B_pos != N-1 and B_pos != N-2 and S[ B_pos + 2 ] != '
        func(A_pos,B_pos+2)
    
    return

func(A_pos,B_pos)
print ("No")


    
                   





            




# -*- coding: utf-8 -*-
"""
Created on Sun Jun  2 22:01:55 2019

@author: hisaki
"""

import sys
N, A, B, C, D = map(int, input().split())
S = input()
A_start = A -1
B_start = B -1
A_goal = C -1
B_goal = D -1

A_pos = A_start
B_pos = B_start

flag = True
for i in range(A_goal):
    if i< A_goal-1 and S[i] == '#':
        if S[i+1] == '#':
            flag = False

for i in range(B_goal):
    if i< B_goal-1 and S[i] == '#':
        if S[i+1] == '#':
            flag = False
if flag == False:
    print ("No")
    sys.exit()
  


if A_pos < B_pos and A_goal < B_goal:
    print ("Yes")
    sys.exit()

if B_pos < A_pos and B_goal < A_goal:
    print ("Yes")
    sys.exit()


if A_pos < B_pos and B_goal < A_goal :
    for i in range(A_goal-2):
        if (S[i] == '.' or i == A_pos or i == B_pos) and (S[i+1]== '.' or i+1 == A_pos or i+1 = B_pos ) and (S[i+2] == '.' or i+2 == A_pos or i+2 == B_pos):
            print ("Yes")
            sys.exit()

if B_pos < A_pos and A_goal < B_goal :
    for i in range(B_goal-2):
        if (S[i] == '.' or i == B_pos or i == A_pos) and (S[i+1]== '.' or i+1 == B_pos or i+1 == A_pos ) and (S[i+2] == '.' or i+2 == B_pos or i+2 = A_pos):
            print ("Yes")
            sys.exit()
            
print ("No")
        


# -*- coding: utf-8 -*-
"""
Created on Sun Jun  2 22:01:55 2019

@author: hisaki
"""

import sys
N, A, B, C, D = map(int, input().split())
S = input()
A_start = A -1
B_start = B -1
A_goal = C -1
B_goal = D -1

A_pos = A_start
B_pos = B_start

flag = True
for i in range(A_pos, A_goal):
    if S[i] == '#':
        if S[i+1] == '#':
            flag = False

for i in range(B_pos, B_goal):
    if S[i] == '#':
        if S[i+1] == '#':
            flag = False
            
if flag == False:
    print ("No")
    sys.exit()
  


if A_goal < B_goal:
    print ("Yes")
    sys.exit()


if B_goal < A_goal :
    for i in range(B_pos , B_goal+1):
        if (S[i-1] == '.' or i-1 == A_pos) and (S[i]== '.') and (S[i+1] == '.'):
            print ("Yes")
            sys.exit()

            
print ("No")
        


Verdicts: Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted