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:
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:
            L[idx] = 1
            return True
        if idx+2 == g: 
            L[idx] = 1
            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:
        if search(B,D,False):
            if search(A,C,False):
                return 'Yes'        

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

    return 'No'

ans = main()
print(ans)

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:
    exit(1)
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] == '.':
            print('Yes')
            break
    else:
        print('No')

Submission status: Runtime Error

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

def candi_check(a,b):
    can=[]
    if (S[a-1+1]=='.') or (a+1!=b):
        can.append('a1')
    if (S[a-1+2]=='.') or (a+2!=b):
        can.append('a2')
    if (S[b-1+1]=='.') or (b+1!=a):
        can.append('b1')
    if (S[b-1+2]=='.') or (b+2!=a):
        can.append('b2')
    can.append('_')
    return(can)

 def move_smirate(move,a,b):
    if move=='_':
        a=A_before.pop(-1)
        b=B_before.pop(-1)
    if move=='a1':
        a+=1
    elif move=='a2':
        a+=2
    elif move=='b1':
        b+=1
    else:
        b+=2
    return (a,b)

 import copy

state="still"
ans='No'
move_queue=[]
S=S+'__'
move_queue.extend(candi_check(A,B))
A_before=[A]
B_before=[B]

while len(move_queue)!=0:
    #print(A,B)
    #print(move_queue)
    move=move_queue.pop(0)
    new_A,new_B=move_smirate(move,A,B)
    if new_A==C and new_B==D:
        ans='Yes'
        break
    if new_A>C or new_B>D or S[new_A-1]=='#' or S[new_B-1]=='#' or new_A==B or new_B==A:
        continue
    else:
        move_queue=(candi_check(new_A,new_B))+(move_queue)
        A_before.append(A)
        B_before.append(B)
        A=copy.copy(new_A)
        B=copy.copy(new_B)
        #print("add!!!")
        #print(move_queue)
        #print(A_before)
print(ans)

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:
            L[idx] = 1
            return True
        if idx+2 == g: 
            L[idx] = 1
            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:
        if search(B,D,False):
            if search(A,C,False):
                return 'Yes'
            
        return 'No'

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

        return 'No'

ans = main()
print(ans)

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
while True :
    if mas[b+2] == '.':
        b = b+2
    elif mas[b+1] == '.' :
        b = b + 1
    elif b == d or b+1 == d:
        break
    if mas[b] == '#':
        han = 1
        break


while True :
    if mas[a+2] == '.'  :
        a = a+2
    elif mas[a+1] == '.' :
        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
else:#c>d
    if '...' in s[a-1:]:
        flg = True
        if not('...' in s[:d-1]):
            flg = False
        elif (b>3):
            if '...' in s[:b]:
                flg = False
if '##' in s:
    flg = False
if flg:
    print('Yes')
else:
    print(aaaa)

Submission status: Runtime Error

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
for i in s:
  if i=='.':
    i=0
  else:
    i=1
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:
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
        elif cou2 != 0:
            ans2.append(cou2)
            cou2 = 0
    if ans1 < 2 and min(ans2) >= 3:
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
line = input().split()
object_ = input()

N = int(line[0])
A = int(line[1])-1
B = int(line[2])-1
C = int(line[3])-1
D = int(line[4])-1

placing_objects = [True if s == '#' else False for s in list(object_)]

def main():
    if (A < B and C < D) or (A > B and C > D):
        for i in range(N-1):
            if placing_objects[i] and placing_objects[i+1]:
                print('No')
                return
        print('Yes')
        return
    else:
        possible_trans = False
        trans_index = []
        for i in range(N-1):
            if placing_objects[i] and placing_objects[i+1]:
                print('No')
                return
            if i < N-1 and (not placing_objects[i]) and (not placing_objects[i+1]) and (not placing_objects[i+2]):
                possible_trans = True
                trans_index.append(i+1)
        if not possible_trans:
            if C < D:
                if placing_objects[C-1] or placing_objects[C+1]:
                    print('No')
                    return
            else:
                if placing_objects[D-1] or placing_objects[D+1]:
                    print('No')
                    return
        else:
            if A > B:
                if A > max(trans_index):
                    print('No')
                    return
            else:
                if B > max(trans_index) or D < min(trans_index):
                    print('No')
                    return
        print('Yes')
        
main()

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

# 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:
            L[idx] = 1
            return True
        if idx+2 == g: 
            L[idx] = 1
            return True

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

        if idx+1 == g and L[idx+2]:
            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():
    reversed_goal = C > D
    if not reversed_goal:
        if search(B,D,False):
            if search(A,C,False):
                return 'Yes'
            
        return 'No'

    else:
        if search(B,D,True):
            if search(A,C,False):
                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()

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

Submission status: Runtime Error

Solution code:
box_num, a_start, b_start, a_end, b_end = map(int, input().split())
box = input()
a_now = a_start
b_now = b_start

def a_one(a_now, b_now):
    a_now += 1

    if(a_now > a_end or b_now > b_end or a_now > box_num):
        return
    if(a_now == a_end and b_now == b_end):
        print("Yes")
        exit()
    if(box[a_now-1] == '#' or a_now == b_now):
        return

    a_one(a_now, b_now)
    a_two(a_now, b_now)
    b_one(a_now, b_now)
    b_two(a_now, b_now)

def a_two(a_now, b_now):
    a_now += 2

    if(a_now > a_end or b_now > b_end or a_now > box_num):
        return
    if(a_now == a_end and b_now == b_end):
        print("Yes")
        exit()
    if(box[a_now-1] == '#' or a_now == b_now):
        return

    a_one(a_now, b_now)
    a_two(a_now, b_now)
    b_one(a_now, b_now)
    b_two(a_now, b_now)

def b_one(a_now, b_now):
    b_now += 1

    if(a_now > a_end or b_now > b_end or b_now > box_num):
        return
    if(a_now == a_end and b_now == b_end):
        print("Yes")
        exit()
    if(box[b_now-1] == '#' or a_now == b_now):
        return

    a_one(a_now, b_now)
    a_two(a_now, b_now)
    b_one(a_now, b_now)
    b_two(a_now, b_now)

def b_two(a_now, b_now):
    b_now += 2

    if(a_now > a_end or b_now > b_end or b_now > box_num):
        return
    if(a_now == a_end and b_now == b_end):
        print("Yes")
        exit()
    if(box[b_now-1] == '#' or a_now == b_now):
        return

    a_one(a_now, b_now)
    a_two(a_now, b_now)
    b_one(a_now, b_now)
    b_two(a_now, b_now)

a_one(a_now, b_now)
a_two(a_now, b_now)
b_one(a_now, b_now)
b_two(a_now, b_now)

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
while True :
    if mas[b+2] == '.':
        b = b+2
    else if mas[b+1] == '.'
        b = b + 1
    elif b == d || b+1 == d:
        break
    if mas[b] == '#':
        han = 1
        break


while True :
    if mas[a+2] == '.' :
        a = a+2
    else if mas[a+1] == '.'
        a = a + 1
    elif a == c || a+1 == c:
        break
    if mas[a] == '#' || 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
else:#c>d
    if '...' in s[a-1:]:
        flg = True
        if not('...' in s[:d-1]):
            flg = False
        else 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:
a

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,D = map(int,input().split())
S=input()

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:
import sys
sys.setrecursionlimit(10**9)
W, A, B, C, D = map(int, input().split())
S = [i for i in input()]
judge = False
def dfs(x, y, field, judge):
    if C-1 == x and D-1 == y:
        return True
    for idx, n in enumerate([1,2,1,2]):
        if idx <= 1:
            n += x
            if n < W:
                if n == y:
                    continue
                elif field[n] == "#":
                    continue
                judge = dfs(n, y, field, judge)
        else:
            n += y
            if n < W:
                if n == x:
                    continue
                elif field[n] == "#":
                    continue
                judge = dfs(x, n, field, judge)
    if judge:
        return True
    else:
        return False

if dfs(A-1,B-1,S):
    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
else:#c>d
    if '...' in s[a-1:]:
        flg = True
        if not('...' in s[:d-1]):
            flg = False
        else if ('...' in s[a-1: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 = list(map(int, input().split()))

S = input()

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

L = [1]*N

# 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:
            L[idx] = 1
            L[g] = 0
            return True
        if idx+2 == g: 
            L[idx] = 1
            L[g] = 0
            return True

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

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

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


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


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

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

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

        return 'No'

ans = main()
print(ans)

Submission status: Runtime Error

Solution code:
print("Yes")n,a,b,c,d = [int(i) for i in input().split()]
s = input()


flag1 = False
block = 0
for i in range(b, len(s)):
    if block == 2:
        flag1 = False
        break
    elif i == d-1:
        flag1 = True
        break
    elif s[i] == ".":
        block = 0
    elif s[i] == "#":
        block += 1

if flag1 == True:
    s2 = s[:d-1]+'#'+s[d:]
    flag1 = False
    block = 0
    for i in range(a, len(s)):
        if block == 2:
            flag1 = False
            break
        elif i == c-1:
            flag1 = True
            break
        elif s2[i] == ".":
            block = 0
        elif s2[i] == "#":
            block += 1


flag2 = False
flag3 = False
temp = 0
block = 0
for i in range(b-2,c-1):
    if temp == 3:
        flag2 = True
        temp = i-1
        break
    elif s[i] == "#":
        temp = 0
    elif s[i] == ".":
        temp += 1

if flag2 == True:
    flag3 = False
    block = 0
    s1 = s[:temp-1]+'#'+s[temp:]
    for i in range(a, len(s)):
        if block == 2:
            flag3 = False
            break
        elif i == c-1:
            flag3 = True
            break
        elif s1[i] == ".":
            block = 0
        elif s1[i] == "#":
            block += 1

    if flag3 == True:
        s3 = s1[:c - 1] + '#' + s1[c:]
        flag3 = False
        block = 0
        for i in range(temp + 1, len(s)):
            if block == 2:
                flag3 = False
                break
            elif i == c-1:
                flag3 = True
                break
            elif s3[i] == ".":
                block = 0
            elif s3[i] == "#":
                block += 1

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

Submission status: Runtime Error

Solution code:
n, a, b, c, d = (map(int, input().split()))
S = input()
import re
if '##' in S:
  return 'No'
elif d>c and not '...' in S:
  return 'No'
elif c==d:
  return 'No'
else:
  return 'Yes'

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
while True :
    if mas[b+2] == '.':
        b = b+2
    else if mas[b+1] == '.'
        b = b + 1
    elif b == d || b+1 == d:
        break
print(mas)

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
    if len(S)-1>a_index:
        rr1 = move(S, a_index, b_index, a_index+1, b_index, g_a, g_b)
    if len(S)-2>a_index:
        rr2 =  move(S, a_index, b_index, a_index+2, b_index, g_a, g_b)
    if len(S)-1>b_index:
        rr3 = move(S, a_index, b_index, a_index, b_index+1, g_a, g_b)
    if len(S)-2>b_index:
        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 len(S)-1>a_index:
    r2 = move(S, a_index, b_index, a_index+2, b_index, C-1, D-1)
if len(S)>b_index:
    r3 = move(S, a_index, b_index, a_index, b_index+1, C-1, D-1)
if len(S)-1>b_index:
    r4 = move(S, a_index, b_index, a_index, b_index+2, C-1, D-1)


if r1==100 or r2==100 or r3==100 or r4==100:
    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

# 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:
            L[idx] = 1
            L[g] = 0
            return True
        if idx+2 == g: 
            L[idx] = 1
            L[g] = 0
            return True

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

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

        if L[idx+1] == g or L[idx+2] == g:
            return False


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


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

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

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

        return 'No'

ans = main()
print(ans)

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)-2 >= 0:
    b_to_d2 = s[b-1-2:d-1]
elif:
    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 not(b_to_d2.find('...')!=-1):
        possibility = False

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

Submission status: Runtime Error

Solution code:
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
    if len(S)>a_index:
        rr1 = move(S, a_index, b_index, a_index+1, b_index, g_a, g_b)
    if len(S)-1>a_index:
        rr2 =  move(S, a_index, b_index, a_index+2, b_index, g_a, g_b)
    if len(S)>b_index:
        rr3 = move(S, a_index, b_index, a_index, b_index+1, g_a, g_b)
    if len(S)-1>b_index:
        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 len(S)-1>a_index:
    r2 = move(S, a_index, b_index, a_index+2, b_index, C-1, D-1)
if len(S)>b_index:
    r3 = move(S, a_index, b_index, a_index, b_index+1, C-1, D-1)
if len(S)-1>b_index:
    r4 = move(S, a_index, b_index, a_index, b_index+2, C-1, D-1)


if r1==100 or r2==100 or r3==100 or r4==100:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
box_num, a_start, b_start, a_end, b_end = map(int, input().split())
box = input()
a_now = a_start
b_now = b_start

def a_one(a_now, b_now):
    a_now += 1

    if(a_now > a_end or b_now > b_end):
        return
    if(a_now == a_end and b_now == b_end):
        print("Yes")
        exit()
    if(box[a_now-1] == '#' or a_now == b_now):
        return

    a_one(a_now, b_now)
    a_two(a_now, b_now)
    b_one(a_now, b_now)
    b_two(a_now, b_now)

def a_two(a_now, b_now):
    a_now += 2

    if(a_now > a_end or b_now > b_end):
        return
    if(a_now == a_end and b_now == b_end):
        print("Yes")
        exit()
    if(box[a_now-1] == '#' or a_now == b_now):
        return

    a_one(a_now, b_now)
    a_two(a_now, b_now)
    b_one(a_now, b_now)
    b_two(a_now, b_now)

def b_one(a_now, b_now):
    b_now += 1

    if(a_now > a_end or b_now > b_end):
        return
    if(a_now == a_end and b_now == b_end):
        print("Yes")
        exit()
    if(box[b_now-1] == '#' or a_now == b_now):
        return

    a_one(a_now, b_now)
    a_two(a_now, b_now)
    b_one(a_now, b_now)
    b_two(a_now, b_now)

def b_two(a_now, b_now):
    b_now += 2

    if(a_now > a_end or b_now > b_end):
        return
    if(a_now == a_end and b_now == b_end):
        print("Yes")
        exit()
    if(box[b_now-1] == '#' or a_now == b_now):
        return

    a_one(a_now, b_now)
    a_two(a_now, b_now)
    b_one(a_now, b_now)
    b_two(a_now, b_now)

a_one(a_now, b_now)
a_two(a_now, b_now)
b_one(a_now, b_now)
b_two(a_now, b_now)

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)-2 < 0:
    b_to_d2 = s[b-1:d-1]
elif:
    b_to_d2 = s[b-1-2:d-1]

possibility = True

if a_to_c.find("##")!=-1 or b_to_d.find("##")!=-1:
    possibility = False
if c>d:
    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()
if c < d:
    #最後まで動かす
    flg = True
else:#c>d
    if '...' in s[a-1:]:
        flg = True
        if not(c-d==2 and '...' in s[:d-1]):
            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()
if c < d:
    #最後まで動かす
    flg = True
else:#c>d
    if '...' in s[a:]:
        flg = True
        if not(c-d==2 and '...' in s[:d]):
            flg = False
if '##' in s:
    flg = False
if flg:
    print('Yes')
else:
    print('No')