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: Runtime Error

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

def move(S, before_a, before_b, a_index, b_index, g_a, g_b):
    try:
        if len(S)<=a_index or len(S) <= b_index:
            return -1
    except:
        return -1
    if S[a_index]=='#' or S[a_index]=='B':
        return 0
    elif S[b_index]=='#' or S[b_index]=='A':
        return 0
    if a_index==g_a and b_index==g_b:
        return 100


    rr1 = 0
    rr2 = 0
    rr3 = 0
    rr4 = 0
    try:
        S[before_a] = '.'
        S[before_b] = '.'
        S[a_index] = 'A'
        S[b_index] = 'B'
    except:
        return 0
    try:
        rr1 = move(S, a_index, b_index, a_index+1, b_index, g_a, g_b)
    except:
        pass
    try:
        rr2 = move(S, a_index, b_index, a_index+2, b_index, g_a, g_b)
    except:
        pass
    try:
        rr3 = move(S, a_index, b_index, a_index, b_index+1, g_a, g_b)
    except:
        pass
    try:
        rr4 = move(S, a_index, b_index, a_index, b_index+2, g_a, g_b)
    except:
        pass
    return max([rr1,rr2,rr3,rr4])

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

S = list(input())

S[A-1] = 'A'
S[B-1] = 'B'

a_index = A-1
b_index = B-1

r1 = 0
r2 = 0
r3 = 0
r4 = 0

if len(S)-1>a_index:
    r1 = move(S, a_index, b_index, a_index+1, b_index, C-1, D-1)
    if r1==100:
        print('Yes')
        exit()
if len(S)-2>a_index:
    r2 = move(S, a_index, b_index, a_index+2, b_index, C-1, D-1)
    if r2==100:
        print('Yes')
        exit()
if len(S)-1>b_index:
    r3 = move(S, a_index, b_index, a_index, b_index+1, C-1, D-1)
    if r3==100:
        print('Yes')
        exit()
if len(S)-2>b_index:
    r4 = move(S, a_index, b_index, a_index, b_index+2, C-1, D-1)
    if r4==100:
        print('Yes')
        exit()


print('No')

Submission status: Runtime Error

Solution code:
N, A, B, C, D = map(int, input().split())
S = list(input())
S[A-1] = '#'; S[B-1] = '#'
S.extend(['#']*2)
def dfs(a = A, b = B):
    if a == C and b == D:
        return 'Yes'

    if S[a] == '.':
        S[a] = '#'; S[a-1] = '.'
        return dfs(a+1, b)
    if S[a+1] == '.':
        S[a+1] = '#'; S[a-1] = '.'
        return dfs(a+2, b)
    if S[b] == '.':
        S[b] = '#'; S[b-1] = '.'
        return dfs(a, b+1)
    if S[b+1] == '.':
        S[b+1] = '#'; S[b-1] = '.'
        return dfs(a, b+2)
    return 'No'
print(dfs())

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,A,B,C,D=map(int,input().split())
S=input()
print("No" if "##" in S else "No" if ((S[C-2])=="#" or (S[C])=="#") and C>D else "Yes")

Submission status: Runtime Error

Solution code:
# -*- 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")

Submission status: Runtime Error

Solution code:
n,a,b,c,d=map(int,input().split())
s=[0 if i=='.' else 1 for i in input()]
#print(s)
t=[0]*n
cst=0
ans=0
for j in range(n-1):
    if s[j]*s[j+1]==1:
        t[j]=2
        t[j+1]=2
    elif j+2 <= n:
        if s[j]+s[j+1]+s[j+2]==0:
            t[j]=3
            t[j+1]=3
            t[j+2]=3
if b>c:
    if (2 in t[a-1:c]) or (2 in t[b-1:d]):
        print('No')
    else:
        print('Yes')
elif b<c and c<d:
    if 2 in t[a-1:d]:
        print('No')
    else:
        print('Yes')
elif b<c and d<c:
    if not(2 in t[a-1:d]) and (3 in t[b-2:d]):
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

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

def move(S, before_a, before_b, a_index, b_index, g_a, g_b):
    if len(S)<=a_index or len(S) <= b_index:
        return -1
    if S[a_index]=='#' or S[a_index]=='B':
        return 0
    elif S[b_index]=='#' or S[b_index]=='A':
        return 0
    if a_index==g_a and b_index==g_b:
        return 100


    rr1 = 0
    rr2 = 0
    rr3 = 0
    rr4 = 0
    try:
        S[before_a] = '.'
        S[before_b] = '.'
        S[a_index] = 'A'
        S[b_index] = 'B'
    except:
        return 0
    try:
        rr1 = move(S, a_index, b_index, a_index+1, b_index, g_a, g_b)
    except:
        pass
    try:
        rr2 = move(S, a_index, b_index, a_index+2, b_index, g_a, g_b)
    except:
        pass
    try:
        rr3 = move(S, a_index, b_index, a_index, b_index+1, g_a, g_b)
    except:
        pass
    try:
        rr4 = move(S, a_index, b_index, a_index, b_index+2, g_a, g_b)
    except:
        pass
    return max([rr1,rr2,rr3,rr4])

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

S = list(input())

S[A-1] = 'A'
S[B-1] = 'B'

a_index = A-1
b_index = B-1

r1 = 0
r2 = 0
r3 = 0
r4 = 0

if len(S)-1>a_index:
    r1 = move(S, a_index, b_index, a_index+1, b_index, C-1, D-1)
    if r1==100:
        print('Yes')
        exit()
if len(S)-2>a_index:
    r2 = move(S, a_index, b_index, a_index+2, b_index, C-1, D-1)
    if r2==100:
        print('Yes')
        exit()
if len(S)-1>b_index:
    r3 = move(S, a_index, b_index, a_index, b_index+1, C-1, D-1)
    if r3==100:
        print('Yes')
        exit()
if len(S)-2>b_index:
    r4 = move(S, a_index, b_index, a_index, b_index+2, C-1, D-1)
    if r4==100:
        print('Yes')
        exit()


print('No')

Submission status: Runtime Error

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

def move(S, before_a, before_b, a_index, b_index, g_a, g_b):
    if len(S)<=a_index or len(S) <= b_index:
        return -1
    if S[a_index]=='#' or S[a_index]=='B':
        return 0
    elif S[b_index]=='#' or S[b_index]=='A':
        return 0
    if a_index==g_a and b_index==g_b:
        return 100


    rr1 = 0
    rr2 = 0
    rr3 = 0
    rr4 = 0
    S[before_a] = '.'
    S[before_b] = '.'
    S[a_index] = 'A'
    S[b_index] = 'B'
    try:
        rr1 = move(S, a_index, b_index, a_index+1, b_index, g_a, g_b)
    except:
        pass
    try:
        rr2 = move(S, a_index, b_index, a_index+2, b_index, g_a, g_b)
    except:
        pass
    try:
        rr3 = move(S, a_index, b_index, a_index, b_index+1, g_a, g_b)
    except:
        pass
    try:
        rr4 = move(S, a_index, b_index, a_index, b_index+2, g_a, g_b)
    except:
        pass
    return max([rr1,rr2,rr3,rr4])

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

S = list(input())

S[A-1] = 'A'
S[B-1] = 'B'

a_index = A-1
b_index = B-1

r1 = 0
r2 = 0
r3 = 0
r4 = 0

if len(S)-1>a_index:
    r1 = move(S, a_index, b_index, a_index+1, b_index, C-1, D-1)
    if r1==100:
        print('Yes')
        exit()
if len(S)-2>a_index:
    r2 = move(S, a_index, b_index, a_index+2, b_index, C-1, D-1)
    if r2==100:
        print('Yes')
        exit()
if len(S)-1>b_index:
    r3 = move(S, a_index, b_index, a_index, b_index+1, C-1, D-1)
    if r3==100:
        print('Yes')
        exit()
if len(S)-2>b_index:
    r4 = move(S, a_index, b_index, a_index, b_index+2, C-1, D-1)
    if r4==100:
        print('Yes')
        exit()


print('No')

Submission status: Runtime Error

Solution code:

  print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# -*- 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")

Submission status: Runtime Error

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: Runtime Error

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

reach = [1 if s == "." else 0 for s in S]
reach[A-1] = -1
reach[B-1] = -2

ans = "No"
for i in range(B-1, N):
  if reach[i] == 0 or reach[i] == -1:
    continue
  if reach[D-1] == -2:
    ans = "Yes"
    break
  if i+2 < N and reach[i+2] == 1:
    reach[i+2] = -2
    reach[i] = 1
  elif i+1 < N and reach[i+1] == 1:
    reach[i+1] = -2
    reach[i] = 1
  elif (reach[i+2] == 0 or reach[i+2] == -1) and (reach[i+1] == 0 or reach[i+1] == -1):
    ans = "No"
    break
  reach

for i in range(A-1, N):
  if reach[i] == 0 or reach[i] == -2:
    continue
  if reach[C-1] == -1:
    ans = "Yes"
    break
  if i+2 < N and reach[i+2] == 1:
    reach[i+2] = -1
    reach[i] = 1
  elif i+1 < N and reach[i+1] == 1:
    reach[i+1] = -1
    reach[i] = 1
  elif (reach[i+2] == 0 or reach[i+2] == -2) and (reach[i+1] == 0 or reach[i+1] == -2):
    ans = "No"
    break
  reach
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def move(S, before_a, before_b, a_index, b_index, g_a, g_b):
    if len(S)<=a_index or len(S) <= b_index:
        return -1
    if S[a_index]=='#' or S[a_index]=='B':
        return 0
    elif S[b_index]=='#' or S[b_index]=='A':
        return 0
    if a_index==g_a and b_index==g_b:
        return 100
    S[before_a] = '.'
    S[before_b] = '.'

    S[a_index] = 'A'
    S[b_index] = 'B'
    rr1 = 0
    rr2 = 0
    rr3 = 0
    rr4 = 0
    rr1 = move(S, a_index, b_index, a_index+1, b_index, g_a, g_b)
    rr2 = move(S, a_index, b_index, a_index+2, b_index, g_a, g_b)
    rr3 = move(S, a_index, b_index, a_index, b_index+1, g_a, g_b)
    rr4 = move(S, a_index, b_index, a_index, b_index+2, g_a, g_b)
    return max([rr1,rr2,rr3,rr4])

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

S = list(input())

S[A-1] = 'A'
S[B-1] = 'B'

a_index = A-1
b_index = B-1

r1 = 0
r2 = 0
r3 = 0
r4 = 0

if len(S)-1>a_index:
    r1 = move(S, a_index, b_index, a_index+1, b_index, C-1, D-1)
    if r1==100:
        print('Yes')
        exit()
if len(S)-2>a_index:
    r2 = move(S, a_index, b_index, a_index+2, b_index, C-1, D-1)
    if r2==100:
        print('Yes')
        exit()
if len(S)-1>b_index:
    r3 = move(S, a_index, b_index, a_index, b_index+1, C-1, D-1)
    if r3==100:
        print('Yes')
        exit()
if len(S)-2>b_index:
    r4 = move(S, a_index, b_index, a_index, b_index+2, C-1, D-1)
    if r4==100:
        print('Yes')
        exit()


print('No')

Submission status: Runtime Error

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

# 以下indexに変更
A-=1
B-=1
C-=1
D-=1

L = [1]*N
reversed_goal = C > D
# 0を岩、1を通路とする
for i in range(N):
    if S[i] == '#':
        L[i] =  0


def search(idx, g, reversed_goal):
    if idx > N-1:
        return False
        
    L[idx] =0
    if not reversed_goal:
        if idx+1 == g or idx+2 == g:
            return True

    else:
        if idx+2 == g and L[idx+1] and L[idx+3]:
            L[idx] = 1
            L[g] = 0
            return True

        if idx+1 == g and L[idx+2]:
            L[idx] = 1
            L[g] = 0
            return True

        if idx+1 == g or idx+2 == g:
            return False


    if reversed_goal:
        if L[idx+2] and L[idx+1]:
            L[idx] = 1
            L[idx+1] = 0
            return True


    if L[idx+2]:
        L[idx] = 1
        return search(idx+2, g, reversed_goal)
    
    if L[idx+1]:
        L[idx] = 1
        return search(idx+1, g, reversed_goal)
    
    return False

def main():
    if not reversed_goal:
        r_b = search(B,D,False)
        if r_b:
            r_a = search(A,C,False)
            if r_a:
                return 'Yes'        

    else:
        r_b = search(B,D,True)
        if r_b:
            r_a = search(A,C,False)
            if r_a:
                return 'Yes'

    return 'No'

ans = main()
print(ans)

Submission status: Runtime Error

Solution code:
import sys
N, X = map(int, input().split())
BLU = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
B, L, U = map(list, zip(*BLU))
C = [(u-l)*b for b, l, u in BLU]
D = [(X*u - c, u, c, l) for u, c, l in zip(U, C, L)]
D.sort(reverse = True)
SL = sum(l*b for l, b in zip(L, B))
SS = 0
for i, (d, _, _, _) in enumerate(D):
    SS += d
    if SS >= SL:
        break
SSb = SS - d
lans = i*X
m = 10**10
for _, u, c, l in D[i:]:
    m = min(m, -(-(c + SL - SSb)//u), -((SSb - SL)//l))
lans += m

ans = (i+1) * X
m = 0
for _, u, _, _ in D[:i+1]:
    m = max(m, -(-(SS - SL))//u)
print(min(lans, ans - m))

Submission status: Runtime Error

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

def move(S, before_a, before_b, a_index, b_index, g_a, g_b):
    if len(S)<=a_index or len(S) <= b_index:
        return -1
    if S[a_index]=='#' or S[a_index]=='B':
        return 0
    elif S[b_index]=='#' or S[b_index]=='A':
        return 0
    if a_index==g_a and b_index==g_b:
        return 100
    S[before_a] = '.'
    S[before_b] = '.'

    S[a_index] = 'A'
    S[b_index] = 'B'
    rr1 = 0
    rr2 = 0
    rr3 = 0
    rr4 = 0
    rr1 = move(S, a_index, b_index, a_index+1, b_index, g_a, g_b)
    rr2 = move(S, a_index, b_index, a_index+2, b_index, g_a, g_b)
    rr3 = move(S, a_index, b_index, a_index, b_index+1, g_a, g_b)
    rr4 = move(S, a_index, b_index, a_index, b_index+2, g_a, g_b)
    return max([rr1,rr2,rr3,rr4])
#    return 1

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

S = list(input())

S[A-1] = 'A'
S[B-1] = 'B'

a_index = A-1
b_index = B-1

r1 = 0
r2 = 0
r3 = 0
r4 = 0

if len(S)>a_index:
    r1 = move(S, a_index, b_index, a_index+1, b_index, C-1, D-1)
    if r1==100:
        print('Yes')
        exit()
if len(S)-1>a_index:
    r2 = move(S, a_index, b_index, a_index+2, b_index, C-1, D-1)
    if r2==100:
        print('Yes')
        exit()
if len(S)>b_index:
    r3 = move(S, a_index, b_index, a_index, b_index+1, C-1, D-1)
    if r3==100:
        print('Yes')
        exit()
if len(S)-1>b_index:
    r4 = move(S, a_index, b_index, a_index, b_index+2, C-1, D-1)
    if r4==100:
        print('Yes')
        exit()


print('No')

Submission status: Runtime Error

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 N[D] == "." and N[D-2] ==".":
    answer = 1
if answer == 1:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

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

# 以下indexに変更
A-=1
B-=1
C-=1
D-=1

L = [1]*N
reversed_goal = C > D
# 0を岩、1を通路とする
for i in range(N):
    if S[i] == '#':
        L[i] =  0


def search(idx, g, reversed_goal):
    L[idx] =0
    if not reversed_goal:
        if idx+1 == g or idx+2 == g:
            return True

    else:
        if idx+2 == g and L[idx+1] and L[idx+3]:
            L[idx] = 1
            L[g] = 0
            return True

        if idx+1 == g and L[idx+2]:
            L[idx] = 1
            L[g] = 0
            return True

        if idx+1 == g or idx+2 == g:
            return False


    if reversed_goal:
        if L[idx+2] and L[idx+1]:
            L[idx] = 1
            L[idx+1] = 0
            return True


    if L[idx+2]:
        L[idx] = 1
        return search(idx+2, g, reversed_goal)
    
    if L[idx+1]:
        L[idx] = 1
        return search(idx+1, g, reversed_goal)
    
    return False

def main():
    if not reversed_goal:
        r_b = search(B,D,False)
        if r_b:
            r_a = search(A,C,False)
            if r_a:
                return 'Yes'        

    else:
        r_b = search(B,D,True)
        if r_b:
            r_a = search(A,C,False)
            if r_a:
                return 'Yes'

    return 'No'

ans = main()
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def move(S, before_a, before_b, a_index, b_index, g_a, g_b):
    if len(S)<=a_index or len(S) <= b_index:
        return -1
    if S[a_index]=='#' or S[a_index]=='B':
        return 0
    elif S[b_index]=='#' or S[b_index]=='A':
        return 0
    if a_index==g_a and b_index==g_b:
        return 100
    S[before_a] = '.'
    S[before_b] = '.'

    S[a_index] = 'A'
    S[b_index] = 'B'
    rr1 = 0
    rr2 = 0
    rr3 = 0
    rr4 = 0
    rr1 = move(S, a_index, b_index, a_index+1, b_index, g_a, g_b)
    rr2 = move(S, a_index, b_index, a_index+2, b_index, g_a, g_b)
    rr3 = move(S, a_index, b_index, a_index, b_index+1, g_a, g_b)
    rr4 = move(S, a_index, b_index, a_index, b_index+2, g_a, g_b)
    return max([rr1,rr2,rr3,rr4])
#    return 1

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

S = list(input())

S[A-1] = 'A'
S[B-1] = 'B'

a_index = A-1
b_index = B-1

r1 = 0
r2 = 0
r3 = 0
r4 = 0

if len(S)>a_index:
    r1 = move(S, a_index, b_index, a_index+1, b_index, C-1, D-1)
    if r1==100:
        print('Yes')
        exit()
if len(S)-1>a_index:
    r2 = move(S, a_index, b_index, a_index+2, b_index, C-1, D-1)
    if r2==100:
        print('Yes')
        exit()
if len(S)>b_index:
    r3 = move(S, a_index, b_index, a_index, b_index+1, C-1, D-1)
    if r3==100:
        print('Yes')
        exit()
if len(S)-1>b_index:
    r4 = move(S, a_index, b_index, a_index, b_index+2, C-1, D-1)
    if r4==100:
        print('Yes')
        exit()
print('r1:{}, r2:{}, r3:{}, r4:{}'.format(r1,r2,r3,r4))


print('No')

Submission status: Runtime Error

Solution code:
#atcoder grand A
#2019/06/02

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

i = 0
judge1 = False
judge2 = False

if C > D:               #CがDより大きい場合
    i = A               #Aを先に動かす場合
    while True:
        if (S[i-1+1] == ".") & (i+1 != B):
            i = i + 1
            if i == C:
                judge1 = True
                break
        elif (S[i-1+2] == ".") & (i+1 != C) & (i+2 != B):
            i = i + 2
            if i == C:
                judge1 = True
                break
        else:
            break
    i = B
    while True:
        if S[i-1+1] == ".":
            i = i + 1
            if i == D:
                judge2 = True
                break
        elif (S[i-1+2] == ".") & (i+1 != D):
            i = i + 2
            if i == D:
                judge2 = True
                break
        else:
            break
    
    i = B               #Bを先に動かす場合
    while True:
        if S[i-1+1] == ".":
            i = i + 1
            if i == D:
                judge1 = True
                break
        elif (S[i-1+2] == ".") & (i+1 != D):
            i = i + 2
            if i == D:
                judge1 = True
                break
        else:
            break
    i = A
    while True:
        if (S[i-1+1] == ".") & (i+1 != D):
            i = i + 1
            if i == C:
                judge2 = True
                break
        elif (S[i-1+2] == ".") & (i+1 != C) & (i+2 != D):
            i = i + 2
            if i == C:
                judge2 = True
                break
        else:
            break

else:                   #DがCより大きい場合
    i = B
    while True:
        if S[i-1+1] == ".":
            i = i + 1
            if i == D:
                judge1 = True
                break
        elif (S[i-1+2] == ".") & (i+1 != D):
            i = i + 2
            if i == D:
                judge1 = True
                break
        else:
            break

    i = A
    while True:
        if (S[i-1+1] == ".") & (i+1 != D):
            i = i + 1
            if i == C:
                judge2 = True
                break
        elif (S[i-1+2] == ".") & (i+1 != C) & (i+2 != D):
            i = i + 2
            if i == C:
                judge2 = True
                break
        else:
            break
  
if judge1 & judge2:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
n , a , b , c , d = map(int,input().split())
mas = input()
tmp = ""
tmp2 = ""
a =a - 1
b = b - 1
c = c - 1
d = d - 1
han = 0
mas_len = len(mas)
while True :
    if mas[b+2] == "." and b+2 != mas_len:
        b = b+2
    elif mas[b+1] == '.' and b+1 != mas_len :
        b = b + 1
    elif b == d or b+1 == d:
        break
    if mas[b] == '#':
        han = 1
        break


while True :
    if mas[a+2] == '.' and a+2 != mas_len  :
        a = a+2
    elif mas[a+1] == '.' and a+1 != mas_len :
        a = a + 1
    elif a == c or a+1 == c:
        break

    if mas[a] == '#' or mas[a] == mas[d] :
        han += 1
        break

if han == 0:
    print("yes")
else :
    print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

l_s = []
for i in range(len(s)):
    l_s += [0 if s[i] == '.' else 1]

ans = 'Yes'
if i in range(len(s)-1):
    if sum(l_s[i:i+2])==2:
        ans = 'No'

if ans == 'Yes':
    if d>c:
        pass
    else:
        ans = 'No'
        for j in range(b-a,d-1-a):
            if sum(l_s[j:3+j]) == 0:
                ans = 'Yes'
            else:
                pass
        if ans == 'No':
            if sum(l_s[d-1-a,d-a])==0:
                ans = 'Yes'

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, a, b, c, d = map(int, input().split())
s = list(input())
for i in range(b, d - 1):
    if s[i] == '#' and s[i + 1] == '#':
        print('No')
        exit(0)
for i in range(a, c - 1):
    if s[i] == '#' and s[i + 1] == '#':
        print('No')
        exit(0)
if c < d:
    print('Yes')
else:
    l, r = a - 1, a
    while l >= 0 and (s[l] != '#' or s[l + 1] != '#'):
        l -= 1
    l += 2 - int(l == -1)
    while r < n and (s[r - 1] != '#' or s[r] != '#'):
        r += 1
    r -= 2 - int(r == n)
    for i in range(l, r - 1):
        if s[i] == '.' and s[i + 1] == '.' and s[i + 2] == '.':
            exit(1)
            break
    else:
        print('No')