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 = (int(i) for i in input().split())  
s = input()
if c<d:
  if s[a:c+1].count("##")>0 and s[b:d+1].count("##")>0:
    print("No")
  else:
    print("Yes")
else:
  if s[a:c+1].count("##")==0 and s[b:d+1].count("##")==0 and (s[b-1:d+1].count("...")>0 or s[b-1:B+2]):
    print("Yes")
  else:
    print("No")

Submission status: Runtime Error

Solution code:
def available(start, end, S, step=None):
    if step is not None:    #   追い越し処理
        S = S[:step] + "#" + S[step+1:]
    for i in range(start-1, end-2):
        if S[i] == "#" and S[i+1] == "#":
            return False
    return True, S
    
def overtake(start, end, S):
    fixed_end = min(end, len(S)-1)
    for i in range(start, fixed_end-1):
        if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
            step = i
            return True, step
    return False, None

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

if D > C:   #   追い越しが不要な時
    judge1, S = available(A, C, S)
    judge2, S = available(B, D, S)
    if judge1 and judge2:
        print("Yes")
    else:
        print("No")
else:   #   追い越しが必要な時
    overtakable, step = overtake(B, D, S)
    if overtakable:   #   追い越しが可能な時
        judge1, S = available(B, D, S)
        judge2, S = available(A, C, S, step=step)
        if judge1 and judge2:
            print("Yes")
        else:
            print("No")
    else:   #   追い越しができない時
        print("No")

Submission status: Runtime Error

Solution code:
N,A,B,C,D = map(int,input().split())
S = str(input())
dp = list(S)
dp[A-1] = "A"
dp[B-1] = "B"
flag_A = 0
flag_B = 0
print(dp)
for i in range(N-2):
    if dp[i] == "B" and flag_B != 1:
        dp[i] = "."
        if dp[i+3] == dp[D-1] and dp[i+3] == ".":
            dp[D-1] = "B"
            flag_B = 1
            dp[i] = "."
        elif dp[i+2] == dp[D-1] and dp[i+2] == ".":
            dp[D-1] == "B"
            flag_B = 1
            dp[i] = "."
        elif dp[i+3] == ".":
            dp[i+3] = "B"
            dp[i+1] = "."
        elif dp[i+2] == ".":
            dp[i+2] = "B"
            dp[i] = "."
for i in range(N-2):
    if dp[i] == "A" and flag_A != 1:
        dp[i] = "."
        if dp[i+3] == dp[C-1] and dp[i+3] == ".":
            dp[C-1] = "A"
            flag_A = 1
            dp[i] = "."
        elif dp[i+2] == dp[C-1] and dp[i+2] == ".":
            dp[C-1] == "A"
            flag_A = 1
            dp[i] = "."
        elif dp[i+3] == ".":
            dp[i+3] = "A"
            dp[i+1] = "."
        elif dp[i+2] == ".":
            dp[i+2] = "A"
            dp[i] = "."
    print(dp)
if dp[D-1] == "B" and dp[C-1] == "A":
    if dp.index(dp[D-1]) > dp.index(dp[C-1]):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N,A,B,C,D = [int(x) for x in input().split(' ')]

S = []
S.append(-1)
p2 = -1
p = -1
err = False
pathway = []
for idx, s in enumerate(input()):
  if s == '.':
    S.append(0)
    if p2 == 0 and p == 0:
      pathway.append(idx-2)
    p2 = p
    p = 0
  else:
    S.append(1)
    if p == 1:
      err = True
    p2 = p
    p = 1
    
 res = err
if err == False:
  if (S[A] == 0) and (S[B] == 0) and (S[C] == 0) or (S[D] == 0):
    if C > D:
      if D in pathway:
        res = False
      else:
        res = True

    else:
      res = True
    
if res == True:
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
import sys
N, A, B, C, D = map(int, input().split())
S = input()
skip = 0
for i in range(max(C,D)):
	if S[i]==S[i+1]=="#":
		print('No')
		sys.exit()
	if B-1 <= i < max(C,D)-2 and S[i]==S[i+1]==S[i+2]==".":
		skip += 1
	if i == B-1 and S[i-1]==S[i+1]==".":
		skip += 1

if C<D:
	print('Yes')

elif skip > 0:
	print("Yes")
else:
	print('No')

Submission status: Runtime Error

Solution code:
print(No)

Submission status: Runtime Error

Solution code:
def main():
    n,a,b,c,d=map(int,input().split(' '))
    s=input()
    result = 'Yes'
    if a<b<d<c:
        tmp =0
        cnt=0
        for i in range(b-2,d+1):
            if s[i]=='#'and s[i+1]=='#':
                result='No'
                break
            if s[i]=='.':
                tmp +=1
            else:
                if cnt < tmp:
                    cnt = tmp
                    tmp =0

        if max(cnt,tmp) < 3:
                raise NameError
        if result =='Yes':
            for i in range(a,c-1):
                if s[i]=='#'and s[i+1]=='#':
                    result='No'
    else:
        for i in range(b,d-1):
            if s[i] =='#' and s[i+1]=='#':
                result ='No'
                break
        if result=='Yes':
            for i in range(a,c-1):
                if s[i] =='#' and s[i+1]=='#':
                    result = 'No'
    print(result)

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 reversed_goal:
        if idx == g:
            if idx+1 <= g and L[idx-1] and L[idx+1]:
                return True
                
            return False
    else:
        if idx == g:
            return True 

    if reversed_goal and idx+2 <= g 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:
N, A, B, C, D = map(int, input().split())

S = list(input().split()[0])

result = "Yes"

if C < D:
    for i in range(B, D - 1):
        if S[i] == "#" and S[i + 1] == "#":
                result = "No"
                print(result)
                break
else:
    for i in range(B, C - 1):
        if S[i] == "#" and S[i + 1] == "#":
                result = "No"
                print(result)
                flag = True
                break
    if not flag:
        for i in range(B - 1, C - 2):
            if S[i] == "." and S[i + 1] == "." and S[i + 2] == ".":
                print("Yes")
                break

Submission status: Runtime Error

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

s = input()

flagA = True
flagB = True

for i in range(d - b):
    if s[b + i] == "#" and s[b + i + 1] == "#":
        flagB = False

for i in range(c - a):
    if ((s[a + i] == "#") or (a + i == d - 1)) and ((s[a + i + 1] == "#") or (a + i + 1 == d - 1)):
        flagA = False
        for j in range(c - a):
            if (s[a + j] == "." and s[a + j + 1] == "." and s[a + j + 2] == "."):
                flagA = True

if flagA and flagB:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
def main():
    n,a,b,c,d=map(int,input().split(' '))
    s=input()
    result = 'Yes'
    if a<b<d<c:
        tmp =0
        cnt=0
        for i in range(b-2,d+1):
            if s[i]=='#'and s[i+1]=='#':
                result='No'
                break
            if s[i]=='.':
                tmp +=1
            else:
                if cnt < tmp:
                    cnt = tmp
                    tmp =0

        if max(cnt,tmp) < 3:
                return raise(NameError)
        if result =='Yes':
            for i in range(a,c-1):
                if s[i]=='#'and s[i+1]=='#':
                    result='No'
    else:
        for i in range(b,d-1):
            if s[i] =='#' and s[i+1]=='#':
                result ='No'
                break
        if result=='Yes':
            for i in range(a,c-1):
                if s[i] =='#' and s[i+1]=='#':
                    result = 'No'
    print(result)

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 reversed_goal:
        if idx == g:
            if L[idx-1] and L[idx+1]:
                return True
                
            return False
    else:
        if idx == g:
            return True 

    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:
def available(start, end, S, step=None):
    if step is not None:    #   追い越し処理
        S = S[:step] + "#" + S[step+1:]
    for i in range(start-1, end-1):
        if S[i] == "#" and S[i+1] == "#":
            return False
    return True, S
    
def overtake(start, end, S):
    fixed_end = min(end-1, len(S)-2)
    fixed_start = max(start-1, 1)
    for i in range(fixed_start, fixed_end):
        if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
            step = i
            return True, step
    return False, None

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

if D > C:   #   追い越しが不要な時
    judge1, S = available(A, C, S)
    judge2, S = available(B, D, S)
    if judge1 and judge2:
        print("Yes")
    else:
        print("No")
else:   #   追い越しが必要な時
    overtakable, step = overtake(B, D, S)
    if overtakable:   #   追い越しが可能な時
        judge1, S = available(B, D, S)
        judge2, S = available(A, C, S, step=step)
        if judge1 and judge2:
            print("Yes")
        else:
            print("No")
    else:   #   追い越しができない時
        print("No")

Submission status: Runtime Error

Solution code:
if "##" in S[A-1:C]:
	print("No")
elif "##" in S[B-1:D]:
	print("No")
elif D < C:	# A jumps over B
	if not "..." in S[B-1:C]:
		print("No")
	elif S[B-1:D].count("...") < 2:
		if S[D-2:D+1] == "#..":
			print("No")
		else:
			print("Yes")
	else:
		print("Yes")
else:
	print("Yes")

Submission status: Runtime Error

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

def ken(s, a, b, c, d, dp):
    global ret

    if a == c and b == d:
        ret = True
        return True
    if a == b:                  return False
    if s[a-1] == "#":           return False
    if s[b-1] == "#":           return False
    if a > len(s):              return False
    if b > len(s):              return False

    dp = dp + 1
    r = False
    if a < len(s) and s[a] == ".":
        r = ken(s, a+1, b, c, d, dp)
        if r == True: return r
    if a < len(s) - 1 and s[a+1] == ".":
        r = ken(s, a+2, b, c, d, dp)
        if r == True: return r
    if b < len(s) and s[b] == ".":
        r = ken(s, a, b+1, c, d, dp)
        if r == True: return r
    if b < len(s) - 1 and s[b+1] == ".":
        r = ken(s, a, b+2, c, d, dp)
        if r == True: return r
    return False


dp = 0
ken(s, a, b, c, d, dp)
if ret is True:print("Yes")
else: print("No")

Submission status: Runtime Error

Solution code:
m = max([c, d])
if n>m:
    n = m
    s = s[:n]
    
if '##' in s:
    print('No')
else:
    if c>d:
        if '...' in s[:d]:
            print('Yes')
        else:
            print('No')
    else:
        print('Yes')

Submission status: Runtime Error

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

# In[2]:


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


# In[26]:


#print(A, B, C, D)


# In[37]:


k = []
try:
    st = S.index(".")+1
except:
    print("No")
for i in range(N):
    
    if i==0:
        m = S[i]
        count = 1
    else:
        if S[i] == m:
            count += 1
        else:
            k.append(count)
            m = S[i]
            count = 1
        
    if i == A-1:
        wa = len(k)
    if i == B-1:
        wb = len(k)
    if i == C-1:
        wc = len(k)
    if i == D-1:
        wd = len(k)
    if i == N-1:
        k.append(count)

if S[i] == '.':
    dot = k[::2]
    sharp = k[1::2]
else:
    dot = k[1::2]
    sharp = k[2::2]
    wa -= 1
    wb -= 1
    wc -= 1
    wd -= 1
#print(k)
#print(dot)
#print(sharp)
#print(wa, wb, wc, wd)

if C<D:
    for s in sharp[wa//2:wc//2]:
        if s>1:
            print("No")
            sys.exit()
    for s in sharp[wb//2:wd//2]:
        if s>1:
            print("No")
            sys.exit()
    print("Yes")
elif C>D:
    for s in sharp[wa//2:wc//2]:
        if s>1:
            print("No")
            sys.exit()
    for s in sharp[wb//2:wd//2]:
        if s>1:
            print("No")
            sys.exit()
    if C<B:
        print("Yes")
        sys.exit()
    elif C>B:
        l = 0
        for i, s in enumerate(sharp[0:wa//2:-1]):
            if s>2:
                l = wa//2-i
        r = len(dot)
        for i, s in enumerate(sharp[wc//2:]):
            if s>2:
                r = wc//2+i
        for d in dot[l:r+1]:
            if d>2:
                print("Yes")
                sys.exit()
        else:
            print("No")


# In[ ]:

Submission status: Runtime Error

Solution code:


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


if x == OK:
  print('Yes')
 
if x == NO:
  print('No')

Submission status: Runtime Error

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

@author: hisaki
"""

#at coder 2019年6月2日日曜日　A問題
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 ] != '#' and A_pos + 1 != B_pos:#操作A
        func(A_pos+1,B_pos)
    if A_pos <= N-3 and S[ A_pos + 2 ] != '#' and A_pos + 2 != B_pos:#操作A
        func(A_pos+2,B_pos)
    if B_pos <= N-2 and S[ B_pos + 1 ] != '#' and B_pos + 1 != A_pos:#操作A
        func(A_pos,B_pos+1)
    if B_pos <= N-3 and S[ B_pos + 2 ] != '#' and B_pos + 2 != A_pos:#操作A
        func(A_pos,B_pos+2)
    
    return

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

Submission status: Runtime Error

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

# In[2]:


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


# In[25]:


S = input()


# In[26]:


#print(A, B, C, D)


# In[37]:


k = []
try:
    st = S.index(".")+1
except:
    print("No")
for i in range(N):
    
    if i==0:
        m = S[i]
        count = 1
    else:
        if S[i] == m:
            count += 1
        else:
            k.append(count)
            m = S[i]
            count = 1
        
    if i == A-1:
        wa = len(k)
    if i == B-1:
        wb = len(k)
    if i == C-1:
        wc = len(k)
    if i == D-1:
        wd = len(k)
    if i == N-1:
        k.append(count)

if S[i] == '.':
    dot = k[::2]
    sharp = k[1::2]
else:
    dot = k[1::2]
    sharp = k[2::2]
    wa -= 1
    wb -= 1
    wc -= 1
    wd -= 1
#print(k)
#print(dot)
#print(sharp)
#print(wa, wb, wc, wd)

if C<D:
    for s in sharp[wa//2:wc//2]:
        if s>1:
            print("No")
            sys.exit()
    for s in sharp[wb//2:wd//2]:
        if s>1:
            print("No")
            sys.exit()
    print("Yes")
elif C>D:
    for s in sharp[wa//2:wc//2]:
        if s>1:
            print("No")
            sys.exit()
    for s in sharp[wb//2:wd//2]:
        if s>1:
            print("No")
            sys.exit()
    if C<B:
        print("Yes")
        sys.exit()
    elif C>B:
        l = 0
        for i, s in enumerate(sharp[0:wa//2:-1]):
            if s>2:
                l = wa//2-i
        r = len(dot)
        for i, s in enumerate(sharp[wc//2:]):
            if s>2:
                r = wc//2+i
        for d in dot[l:r+1]:
            if d>2:
                print("Yes")
                sys.exit()
        else:
            print("No")


# In[ ]:

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n, a, b, c, d = map(int, input().split())
s = input()
grid = []
for rock in s:
    grid.append(rock == '#')

if grid[c-1] or grid[d-1]:
    print('No')

max_none_count = 0
max_rock_count = 0
none_count = 0
rock_count = 0
if c < d:
    for i in range(a-1, d):
        if grid[i]:
            none_count = 0
            rock_count += 1
        else:
            rock_count = 0

        max_none_count = max(max_none_count, none_count)
        max_rock_count = max(max_rock_count, rock_count)

    if max_rock_count >= 2:
        print('No')
    else:
        print('Yes')
elif c > d:
    max_rock_count = 0
    rock_count = 0
    # Dの位置は岩として考える
    grid[d-1] = True
    canSkip = False
    for i in range(a-1, c):
        if grid[i]:
            rock_count += 1
        else:
            if b - 1 <= i and c - 2 <= i and not grid[i-1] and not grid[i] and not grid[i+1]:
                canSkip = True
            rock_count = 0

        max_rock_count = max(max_rock_count, rock_count)

    if max_rock_count <= 1 and canSkip:
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:
s = input()
check = [[0]*(n+1) for _ in range(n+1)]
check[a][b] = 1

for i in range(a,n+1):
    for j in range(b, n+1):
        # A, Bは同じ場所に入れない
        if i == j:
            continue
        # 岩がある場所には入れない
        if s[i-1] == '#' and s[j-1] == '#':
            continue
        # 遷移元があればtrue
        if check[i-1][j] or check[i-2][j] or check[i][j-1] or check[i][j-2]:
            check[i][j] = 1
print('YES' if check[c][d]==1 else 'NO')

Submission status: Runtime Error

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()

stone = 0
road = 0
c = False
l = []

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

stone = 0
road = 0

count = 0

# B放置でゴールできるか
if S[B - 1] == '#' or S[B + 1] == '#':
    count += 1
# Bがゴールしているとゴールできるか
if D < C:
    if S[D - 1] == '#' or S[D + 1] == '#':
        count += 1

if count > 1:
    if len(l) == 0:
        print("No")
        exit()

# Bが避難しているときBはAを通したあとゴールできるか
if C < D:
    if l[-1] < C:
        if S[C - 1] == '#' or S[C + 1] == '#':
            count += 1

if count > 2:
    print("No")
    exit()

print("Yes")

Submission status: Runtime Error

Solution code:
m = max([c, d])
if n>m:
    n = m
    s = s[:n]
    
if '##' in s:
    print('No')
else:
    if c>d:
        if '...' in s:
            print('Yes')
        else:
            print('No')
    else:
        print('Yes')

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import sys

n, a, b, c, d = map(int, input().split())
s = [ s for s in input()]
a = a-1
b = b-1
s[a] = "a"
s[b] = "b"

result = True
cnt = 0

if c > d and a < b:
    while True:
        if b+1 < n and (s[b+1] != "a" and s[b+1] != "#"):
            s[b+1] = "b"
            s[b] = "."
            b += 1
        elif b+2 < n and (s[b+2] != "a" and s[b+2] != "#"):
            s[b+2] = "b"
            s[b] = "."
            b += 2
        else:
            cnt = 1
        if b+1 > n:
            resut = False
            break
        elif s[b-1] == "." and s[b+1] == ".":
            break
        if cnt == 1:
            result = False
            break
    while a < b:
        if a+2 < n and (s[a+2] != "b" and s[a+2] != "#"):
            s[a+2] = "a"
            s[a] = "."
            a += 2
        elif a+1 < n and (s[a+1] != "b" and s[a+1] != "#"):
            s[a+1] = "a"
            s[a] = "."
            a += 1
        else:
            reult = False
            break
if not result:
    print("NO")
    sys.exit(0)

while True:
    if a != c-1:
        if a+2 < n and (s[a+2] != "b" and s[a+2] != "#"):
            s[a+2] = "a"
            s[a] = "."
            a += 2
        elif a+1 < n and (s[a+1] != "b" and s[a+1] != "#"):
            s[a+1] = "a"
            s[a] = "."
            a += 1
        else:
            cnt += 1
    if b != d-1:
        if b+2 < n and (s[b+2] != "a" and s[b+2] != "#"):
            s[b+2] = "b"
            s[b] = "."
            b += 2
        elif b+1 < n and (s[b+1] != "a" and s[b+1] != "#"):
            s[b+1] = "b"
            s[b] = "."
            b += 1
        else:
            cnt += 1
    if cnt == 2:
        result = False
        break
    if a == c-1 and b == d-1:
        break
if result:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
from sys import stdin
N, A, B, C, D = (int(i) for i in input().rstrip().split())
S = stdin.readline().rstrip()
A -= 1
B -= 1
C -= 1
D -= 1
swap_flag = False
swap_able = -1
for itr in range(len(S)):
    if itr < (len(S) - 1) and S[itr] == '#' and S[itr+1] == '#':
        print('No')
        exit()
    if swap_flag == False and 2 < itr and S[itr] == '.' and S[itr-1] == '.' and S[itr-2] == '.':
        swap_able = itr
        swap_flag = True 
# print(swap_able)
# print(A, B, C, D)
if A > B and S[C-1] == '#' and C <= swap_able:
    print('No')
elif A > B and C != N and S[C+1] == '#' and C <= swap_able:
    print('No')
elif A < B and S[D-1] == '#' and D <= swap_able:
    print('No')
elif A < B and D != N and S[D+1] == '#' and D <= swap_able:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n,a,b,c,d=map(int,input().split())
s=list(input())
if c<d:
  f=0
  for i in range(b,d-1):
    if s[i]=='#' and s[i+1]=='#':
      f==1
      break
  if f==0:
    for i in range(a,c-1):
      if s[i]=='#' and s[i+1]=='#':
        f=1
  if f==1:print('No')
  else:print('Yes')
else:
  f=0
  for i in range(b,d-1):
    if s[i]=='#' and s[i+1]=='#':
      f=1
      break
  if f==1:
    print('No')
  else:
    for i in range(a,c-1):
      if s[i]=='#' and s[i+1]=='#':
        f=1
        break
    if f==1:
      print('No')
    else:
      if s[d-2]=='#' or s[d]=='#':
        ct=0
        for i in range(b,d-2):
          if s[i]=='.' and s[i+1]=='.' and s[i+2]=='.':
            ct=1
            break
        if ct==0:
          if s[b-2]=='#' or s[b]=='#':
          print('No')
        else:
          print('Yes')
      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 c < d:
    print('Yes')
else:
    p = []
    while True:
        i = s.find('...', i + 1)
        if b <= i < d:
            print('Yes')
            break
     
    print('No')

Submission status: Runtime Error

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

@author: hisaki
"""

#at coder 2019年6月2日日曜日　A問題
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 ] != '#' and A_pos + 1 != B_pos:#操作A
        func(A_pos+1,B_pos)
    if A_pos <= N-3 and S[ A_pos + 2 ] != '#' and A_pos + 2 != B_pos:#操作A
        func(A_pos+2,B_pos)
    if B_pos <= N-2 and S[ B_pos + 1 ] != '#' and B_pos + 1 != A_pos:#操作A
        func(A_pos,B_pos+1)
    if B_pos <= N-3 and S[ B_pos + 2 ] != '#' and B_pos + 2 != A_pos:#操作A
        func(A_pos,B_pos+2)
    
    return

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

Submission status: Runtime Error

Solution code:
N,A,B,C,D = map(int, input().split())
S = input()
S.split()
S.append("#")
S.append("#")
S.append("#")
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+2):
    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: Runtime Error

Solution code:
import sys

move_store = [[2,2], [1,2], [2,1], [1,1], [0,1],[0,2],[1,0],[2,0]]


def check(A, B, C, D, N, move_a, move_b):
  new_A = A + move_a
  new_B = B + move_b
  if new_A>N or new_B>N or new_A>C or new_B>D or new_A==new_B:
    return False
  else:
    return True


def answer(N, A, B, C, D, S):
  move_a, move_b = None, None
  for ma, mb in move_store:
    if check(A, B, C, D, N, ma, mb):
      move_a, move_b = ma, mb

  if any([move_a is None, move_b is None]):
    print('No')
    return
  
  A += move_a
  B += move_b
  if A==C and B==D:
    print('Yes')
    return
  answer(N, A, B, C, D, S)

    
_input = sys.stdin.readline
N, A, B, C, D = (int(n) for n in _input().split())
S = sys.stdin.readline().strip()
answer(N, A, B, C, D, S)

Submission status: Runtime Error

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
if (c<d):
	if not '##' in s[a:d]: print('Yes')
	else: print('No')
elif (d<c):
	if (not '##' in s[a:c])&(s[d+1]!='#'):print('Yes')
	else: print('No')

Submission status: Runtime Error

Solution code:
nya-n,mya-n=map(int,input().split())
nya-n=[[] for i in range(n)]
    a,b=map(int,input().split())
    st[a-1].append(i)
    en[b-1].append(i)
ans=0
co=0
now=[]
while(co<n):
    if len(now)!=0 and len(en[co])!=0:
        ch=False
        for i in en[co]:
            if ju[i]==1:
                ch=True
        if ch:       
            for i in now:
                ju[i]=-1
            ans+=1
            now=[]
    for i in st[co]:
        ju[i]=1
        now.append(i)
for i in range(10):
	x=r*x-d
	print(x)

Submission status: Runtime Error

Solution code:
N, A, B, C, D = map(int, input().split())
 
S = input()
 
S = S + '#'
 
def continuous_rock_search(S, A, B, C, D):
    begin = min(A, B)
    target = max(C, D)
    for i in range(begin - 1, target - 1):
        if S[i] == '#' and S[i+1] == '#':
            return True
    return False
  
def validation_funuke_move(S, B, D):
    '''
    ふぬけ君が両隣に岩がなくなるまで移動したとき、Dより向こうにはイカないことを確認する。
    True/False and ふぬけの移動後の位置
    '''
    funuke_position = B
    while (B <= D):
        if (S[B-2] == '#' or S[B] == '#'):
            if S[B] == '.' :
                B = B + 1
            else:
                B = B + 2
        elif (S[B-2] == '.' and S[B] == '.'):
            return True, B
    
    return False, -1
  
def KenKenRace(S, A, B, C, D):
    if continuous_rock_search(S,A, B C, D):
        return False
    
    if C < D:
        return True
    
    if D < C:
        valid , _ = validation_funuke_move(S, B, D)
        if valid:
            return True
        else:
            return False
          
if KenKenRace(S, A, B, C, D):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import re

n,a,b,c,d = input().split()
li = input()

pat1 = '##'
pat2 = r'\.\.\.'

sm = int(c) if int(c) < int(d) else int(d)
lg = int(c) if int(c) > int(d) else int(d)

sh = li[:sm]
sh = [int(b) - 1:]
lo = li[:lg]
ret = ''

if re.match(pat1, lo):
    ret = 'No'
else:
    if c > d:
        if re.match(pat2, sh):
            ret = 'Yes'
        else:
            ret = 'No'
    else:
        ret = 'Yes'
    

print(ret)