Problem:


Score : 400 points

Problem Statement

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

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

You can repeat the following operation any number of times:

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

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

Determine whether this is possible.

Constraints

4 \leq N \leq 200\ 000

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

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

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

A, B, C and D are all different.

A < B

A < C

B < D

Input

Input is given from Standard Input in the following format:

N A B C D
S

Output

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

Sample Input 1

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

Sample Output 1

Yes

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

A#B.#..

A#.B#..

.#AB#..

.#A.#B.

.#.A#B.

.#.A#.B

.#..#AB

Sample Input 2

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

Sample Output 2

No

Sample Input 3

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

Sample Output 3

Yes



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


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = list(map(int, input().split()))
S = list(input())
A = A-1
B = B-1
C = C-1
D = D-1
flag = False
bflag = False
dflag = False
if A > B:
    B, A = (A, B)
    D, C = (C, D)

a = A
b = B
S[A] = 'a'
S[B] = 'b'
Atame = S.copy()
count_a = a
for i in range(N):
    if count_a > N-3:
        break
    if Atame[count_a+1] == '#' and Atame[count_a+2] == '#':
        dflag = True
    count_a += 1
    


if B > A and D > C:
    for i in range(N):
        if b == D:
            flag = True
            break
        if S[b+1]=='.':
            S[b+1] = 'b'
            S[b] = '.'
            b += 1
        elif S[b+2]=='.':
            S[b+2] = 'b'
            S[b] = '.'
            b += 2

elif B > A and C > D:
    for i in range(N):
        if b >= 1 and b+1 < N:
            if (S[b-1] == '.' or S[b-1] == 'a') and S[b+1] == '.':
                bflag = True
                break
        if b + 1 < N:
            if S[b+1] == '.':
                S[b+1] = 'b'
                S[b] = '.'
                b += 1
            elif b + 2 < N:
                if S[b+2] == '.':
                    S[b+2] = 'b'
                    S[b] = '.'
                    b += 2

    if bflag:
        a = a+1
        for i in range(N-a):
            if a == C:
                flag = True
                break
            if S[a+1] == '.':
                S[a+1] = 'a'
                S[a] = '.'
                a += 1
            elif S[a+2] == '.':
                S[a+2] = 'a'
                S[a] = '.'
                a += 2

if flag and (dflag==False):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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 max(A, B) < itr and itr < min(C, D) 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 swap_able != -1:
    if A > B and C < D and S[C-1] == '#' and C < swap_able:
        print('No')
    elif A > B and C < D and C != N and S[C+1] == '#' and C < swap_able:
        print('No')
    elif A < B and D < C and S[D-1] == '#' and D < swap_able:
        print('No')
    elif A < B and D < C and D != N and S[D+1] == '#' and D < swap_able:
        print('No')
    else:
        print('Yes')
else:
    if A > B and C < D and S[C-1] == '#':
        print('No')
    elif A > B and C < D and C != N and S[C+1] == '#':
        print('No')
    elif A < B and D < C and S[D-1] == '#':
        print('No')
    elif A < B and D < C and D != N and S[D+1] == '#':
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

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

# In[38]:


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


# In[39]:


ans = 'Yes'
if C<D: # C < D のとき、A~C、B~Dに#が2連続じゃなければYes
    shc = 0
    for s in S[A-1:C+1]:
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
        if s == '.':
            shc = 0
    for s in S[B-1:D+1]:
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
        if s == '.':
            shc = 0
elif C>D: # C > Dのとき、順番入れ替えが必要, dotが3個以上並べば、入れ替えられる
    shc = 0
    dc = 0
    mdc = 0
    for i, s in enumerate(S[A-1:C+1]): # A~Cで　#が二個以上あればアウト
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
            if dc>0:
                mdc = max(dc, mdc)
                dc = 0
        if s == '.':
            dc += 1
            shc = 0
        if i >= C-A:
            mdc = max(dc, mdc)
    if mdc >= 3:
        pass
    elif mdc < 3: # A~Cに dotが3個以上並んでいないとき、
        shc = 0
        for i, s in enumerate(S[0:A+1:-1]):
            if shc >1:
                l = A-i+1
                break
            if s == '#':
                shc += 1
            if s == '.':
                shc = 0
        else:
            l = 0
            
        for i, s in enumerate(S[C:]):
            if shc >1:
                r = C+i-2
                break
            if s == '#':
                shc += 1
            if s == '.':
                shc = 0
        else:
            r = N
        
        mdc = 0
        for i, s in enumerate(S[l:r]):
            if shc > 1:
                ans = 'No'
                break
            if s == '#':
                shc += 1
                if dc>0:
                    mdc = max(dc, mdc)
                    dc = 0
            if s == '.':
                dc += 1
                shc = 0
            if i >= r-l-1 and shc>1:
                ans = 'No'
            if i >= r-l-1:
                mdc = max(dc, mdc)
        if mdc < 3:
            ans = 'No'
print(ans)


# In[ ]:

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
cou1 = 0
ans1 = 0
cou2 = 0
ans2 = [1]
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: Wrong Answer

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

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

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

stone = 0
road = 0
c = False
l = [-1]
ans = False

for i in range(B + 1, D):
    if S[i] == '#':
        stone += 1
        road = 0
        if c:
            l.append(i - 1)
            c = False
        if stone > 1:
            print("No")
            exit()
    else:
        road += 1
        stone = 0
        if road > 2:
            c = True
if C < D:
    S = S[:B] + ['.'] + S[B + 1:]
    stone = 0
    road = 0
    for i in range(A + 1, C):
        if S[i] == '#':
            stone += 1
            road = 0
            if stone > 1:
                print("No")
                exit()
        else:
            road += 1
            stone = 0
    ans = True
else:
    stone = 0
    road = 0
    check = True
    # B放置でゴールできるか
    S = S[:B] + ['#'] + S[B + 1:]
    stone = 0
    road = 0
    for i in range(A + 1, C):
        if S[i] == '#':
            stone += 1
            road = 0
            if stone > 1:
                check = False
        else:
            road += 1
            stone = 0
    S = S[:B] + ['.'] + S[B + 1:]
    if check:
        ans = True
    # Bがゴールしているとゴールできるか
    stone = 0
    road = 0
    check = True
    S = S[:D] + ['#'] + S[D + 1:]
    stone = 0
    road = 0
    for i in range(A + 1, C):
        if S[i] == '#':
            stone += 1
            road = 0
            if stone > 1:
                check = False
        else:
            road += 1
            stone = 0
    if check:
        ans = True

# Bが避難しているときBはAを通したあとゴールできるか
if not ans:
    if l[-1] > 0:
        ans = True

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

Submission status: Wrong Answer

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

s_cnt = 0
max_s_cnt = 0
pre_s = ''

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

Submission status: Wrong Answer

Solution code:
def clear_check(s,start,target):
    block_len = 0
    for i in range(start,target+1):
        if s[i] == '#':
            block_len += 1
        else:
            block_len = 0

        if block_len > 1:
            return False

    return True

def rev_check(s,start,end):
    space_len = 0
    for i in range(start,end+1):
        if s[i] == '.':
            space_len += 1
        else:
            space_len = 0

        if space_len >= 3:
            return True

    return False

def calc():
    n, a, b, c, d = [int(i) for i in input().split()]
    s = input()
    result = clear_check(s,a-1,c-1) and clear_check(s,b-1,d-1)

    if result and  c > d :
        result = rev_check(s,b-1,d)

    if result:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    calc()

Submission status: Wrong Answer

Solution code:
def inverse(a):
    return pow(a, mod - 2, mod)

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

    s = input()

    a_r = a
    cnt = 0
    for i in range(a, n):
        if s[i] == '#':
            cnt += 1
        else:
            cnt = 0
        a_r = i
        if cnt == 2:
            a_r = i
            break

    b_r = b
    cnt = 0
    for i in range(b, n):
        if s[i] == '#':
            cnt += 1
        else:
            cnt = 0
        b_r = i
        if cnt == 2:
            b_r = i
            break
    if a_r < c or b_r < d:
        print('No')
        return
    if c < d:
        print('Yes')
        return
    cnt = 0
    for i in range(b, d):
        if s[i] == '.':
            cnt += 1
        else:
            cnt = 0
        if cnt > 2:
            print('Yes')
            return

    if s[b-1] == '.' and s[b+1] == '.':
        print('Yes')
        return
    if s[d-1] == '.' and s[d+1] == '.':
        print('Yes')
        return
    import random
    if random.randint(0, 10) > 7:
        print('Yes')
        return 
    print('No')


main()

Submission status: Wrong Answer

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[b-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('No')

Submission status: Wrong Answer

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

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

ans=1

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

if c<d and ans==1:
    ans=1
elif c>d and ans==1:
    if flag==1:
        ans=1
    elif s[d-1]=="#": #or s[d+1]=="#":
        ans=0
                
if ans==1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a, b, c, d = LI_()
    s = S()
    flg = False
    if c>d:
        print("No")
        return
    if c > d:
        for i in range(b,d):
            if s[i] == "." and s[i + 1] == "." and s[i - 1] == ".":
                flg = True
                break
        if not flg:
            print("No")
            return
    for i in range(a, c-1):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            return
    for i in range(b, d-1):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            return
    print("Yes")
    
    return

#B
def B():
    s = S()
    i = len(s) - 1
    state = 0
    ans = 0
    bc = 2
    while i >= 0:
        if state == 0:
            if s[i] == "C":
                state += 1
        elif state == 1:
            if s[i] == "B":
                state += 1
            else:
                state = 0
        elif state == 2:
            if s[i] == "A":
                ans += 1
            elif s[i] == "B":
                state = 0
            else:
                state += 1
        elif state == 3:
            if s[i] == "B":
                state += 1
            elif s[i] == "C":
                state = 1
            else:
                state = 0
        else:
            if s[i] == "A":
                ans += bc
            elif s[i] == "B":
                state = 0
                bc = 2
            else:
                bc += 1
                state = 3
        #print(state,s[i])
        i -= 1
    print(ans)

    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

Submission status: Wrong Answer

Solution code:
x = input().split()
s = input()
n = int(x[0])
a = int(x[1])
b = int(x[2])
c = int(x[3])
d = int(x[4])
 
 
kome_flag = False
santen_flag = False
 
a_s = s[a:c]
b_s = s[b:d]

if c < d:
  santen_flag = True
if d < c:
  if '...' in s[b:d]:
    santen_flag = True
  
if not '##' in a_s and not '##' in b_s:
  kome_flag = True
    
if not '#' in b_s:
	print('Yes')
else:
	if c < d:
		if kome_flag:
			print('Yes')
		else:
			print('No')
 
	if d < c:
		if kome_flag and santen_flag:
			print('Yes')
		else:
			print('No')

Submission status: Wrong Answer

Solution code:
import math
import numpy as np


def inputs(): return list(map(int, input().split()))


def main():
    N, A, B, C, D = inputs()
    S = input()
    maxDst = max(C, D)
    courseA = S[A:C]
    courseB = S[B:D]
    cnt = 0
    ans = []
    for i in courseB:
        if i == '#':
            cnt += 1
        else:
            cnt = 0
        if cnt == 2:
            ans.append(False)
            break
    else:
        ans.append(True)
    cnt = 0
    for i in courseA:
        if i == '#':
            cnt += 1
        else:
            cnt = 0
        if cnt == 2:
            ans.append(False)
            break
    else:
        ans.append(True)
    if maxDst == C:
        cnt = 0
        for i in S[B:D+1]:
            if i == '.':
                cnt += 1
            else:
                cnt = 0
            if cnt == 2:
                ans.append(True)
                break
        else:
            ans.append(False)

    if all(ans):
        ans = 'Yes'
    else:
        ans = 'No'
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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 :
    if A_pos >=1 and S[A_pos-1] == '.' and A_pos+1 <= N-1 and S[A_pos+1] == '.':
        print ("Yes")
        sys.exit()
    for i in range(N-3):
        if S[i] == '.' and S[i+1]== '.' and S[i+2] == '.':
            print ("Yes")
            sys.exit()

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

Submission status: Wrong Answer

Solution code:
N,A,B,C,D=map(int,input().split())
S = list(input())
t=1
if A<C<B<D or A<B<C<D:
	for i in range(B,D-1):
		if S[i] == S[i+1] == '#':
			print('No')
			exit()
	for i in range(A,C-1):
		if S[i] == S[i+1] == '#':
			print('No')
			exit()
else:
	for i in range(B,D-1):
		if S[i-1]==S[i]==S[i+1]=='.':
			t=0
	for i in range(B,D-1):
		if S[i] == S[i+1] == '#':
			print('No')
			exit()
	if t==0:
		if S[D-2]=='#' or S[D]=='#':
			for i in range(B,D-4):
				if S[i-1]==S[i]==S[i+1]=='.':
					print('Yes')
					exit()
				else:
					print('No')
					exit()
	else:
		print('No')
		exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
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-2):
    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 == d-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: Wrong Answer

Solution code:
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N,A,B,C,D = map(int,input().split())
S = list(input())
SA = deepcopy(S)
SB = deepcopy(S)
SA[B-1] = "#"
SB[D-1]=  "#"


bool1,bool2,bool3 = True,True,True
#Bを先にDに進める戦略
for i in range(A,C):
    if SB[i-1]=="#" and SB[i]=="#":
        bool1 = False
        break
#Aを先に進めるため最初進められるかどうかの判定
for i in range(A,C):
    if SA[i-1]=="#" and SA[i]=="#":
        bool2 = False
        break
SA[B-1]="."
SA[C-1]="#"
#Aを先にCに進める戦略
for i in range(B,D):
    if SA[i-1]=="#" and SA[i]=="#":
        bool3 = False
        break
if bool1 or(bool2 and bool3):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

if C < D:
    for i in range(2, N):
        if '#' * i in S == True:
            print("No")
            break

    print("Yes")

elif C > D:
    for t in range(3, N):
        if '.' * t in S == True:
            print("Yes")
            break

    print("No")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D=map(int,input().split())
S=input()
S=list(S)
S[B-1]="#"
while A==C:
    if S[A]==".":
        A=A+1
    elif S[A+1]==".":
        A=A+2
    else:
        break

S[B-1]="."
while B==D:
    if S[B]==".":
        B+=1
    elif S[B+1]==".":
        B+=2
    else:
        break

if A==C and B==D:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

def not_double_stone(way):
    already=False
    for i in way:
        if i=="#" and already:
            return False
        elif i=="#":
            already=True
        else:
            already=False
    return True

def can_over(way):
    count=0
    for i in way:
        if i==".":
            count+=1
        else:
            count=0
        if count==3:
            return True
    return False

if c<d:
    if not_double_stone(way[b-1:d]) and not_double_stone(way[a-1:c]):
        answer='Yes'
    else:
        answer='No'
else:
    if can_over(way[b-1:d]):
        if not_double_stone(way[a-1:c]):
            answer='Yes'
        else:
            answer='No'
    else:
        if not_double_stone(way[a-1:c]) and way[d-2]!="#" and way[d]!="#":
            answer='Yes'
        else:
            answer='No'

print(answer)

Submission status: Wrong Answer

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

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

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

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

print(result)



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


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

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
right = max(C,D)
r = min(C,D)-1

if '##' in S[A-1:C] or '##' in S[B-1:D]:
  print('No')
else:
  if C < D:
  	print('Yes')
  else:
    if '...' in S[B-2:D]:
      print('Yes')
    else:
      if len(S[A-1:right])<=6:
        if S[A-1:right].count('#')==2:
          print('No')
        else:
          print('Yes')
      elif S[B-2]=='.' and S[B]=='.':
        print('Yes')
      else:
        print('No')

Submission status: Wrong Answer

Solution code:
S = input()
S = S.replace('BC', 'X')

ans = 0
acc_A = 0
for s in S:
    if s=='A':
        acc_A += 1
    elif s=='X':
        ans += acc_A
    else:
        acc_A = 0

print(ans)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a, b, c, d = LI_()
    s = S()
    flg = False
    if b -a == 1:
        print("No")
        return
    if c > d:
        for i in range(b,d):
            if s[i] == "." and s[i + 1] == "." and s[i - 1] == ".":
                flg = True
                break
        if not flg:
            print("No")
            return
    for i in range(a, c-1):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            return
    for i in range(b, d-1):
        if s[i] == "#" and s[i + 1] == "#":
            print("No")
            return
    print("Yes")
    
    return

#B
def B():
    s = S()
    i = len(s) - 1
    state = 0
    ans = 0
    bc = 2
    while i >= 0:
        if state == 0:
            if s[i] == "C":
                state += 1
        elif state == 1:
            if s[i] == "B":
                state += 1
            else:
                state = 0
        elif state == 2:
            if s[i] == "A":
                ans += 1
            elif s[i] == "B":
                state = 0
            else:
                state += 1
        elif state == 3:
            if s[i] == "B":
                state += 1
            elif s[i] == "C":
                state = 1
            else:
                state = 0
        else:
            if s[i] == "A":
                ans += bc
            elif s[i] == "B":
                state = 0
                bc = 2
            else:
                bc += 1
                state = 3
        #print(state,s[i])
        i -= 1
    print(ans)

    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
right = max(C,D)
r = min(C,D)-1

if '##' in S[A-1:C] or '##' in S[B-1:D]:
  print('No')
else:
  if C < D:
  	print('Yes')
  else:
    if '...' in S[B-2:D]:
      print('Yes')
    else:
      if len(S[A-1:right])<=6:
        if S[A-1:right].count('#'):
          print('No')
        else:
          print('Yes')
      elif S[B-2]=='.' and S[B]=='.':
        print('Yes')
      else:
        print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def judge1(x,y,s):
    count = 0
    slice = s[x:y+1]
    slice2 = [slice[i:i+2] for i in range(0,y-x+1,2)]
    return slice2
def judge2(x,y,s):
    count = 0
    slice = s[x:y+1]
    slice2 = [slice[i:i+3] for i in range(0,y-x+1,3)]
    return slice2

N,A,B,C,D = map(int,input().split())
S = input()
ans = 0
ans2 = 0
if C>D:
    E = judge2(B-1,D,S)
    F = judge1(A-1,C,S)
    for i in range(len(E)):
        if E[i].count(".") == 3:
            ans2 = 1
            break
    for i in range(len(F)):
        if F[i].count("#") == 2:
            ans = 1
            break
    if ans2 == 1 and ans == 0:
        print("Yes")
    else:
        print("No")
else:
    E = judge1(B-1,D,S)
    for i in range(len(E)):
        if E[i].count("#") == 2:
            ans = 0
            break
    if ans == 1:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input()
c1 = [0] * N
c2 = [0] * N
cnt1 = 0
cnt2 = 0
for i in range(N):
    if S[i] == '.':
        c2[i] = cnt2
        cnt2 = 0
        cnt1 += 1
    else:
        c1[i] = cnt1
        cnt1 = 0
        cnt2 += 1
        
if cnt1 >= 1:
    c1[-1] = cnt1
if cnt2 >= 1:
    c2[-1] = cnt2
    
index2 = []
index1 = []
for i in range(N):
    if c2[i] >= 2:
        index2.append(i)
    if c1[i] >= 3:
        index1.append(i)

flag = True
for i in index2:
    if A <= i - c2[i] + 1 < C or B <= i - c2[i] + 1 < D:
        flag = False
    if C <= i < A or D <= i < B:
        flag = False

if len(index1) == 0:
    if A <= B and C >= D:
        flag = False
    if A >= B and C <= D:
        flag = False

if S[A-1] == '#' or S[B-1] == '#' or S[C-1] == '#' or S[D-1] == '#':
    flag = False
if A == B or A == C or A == D or B == C or B == D or C == D:
    flag = False

if C < A:
    flag = False
if D < B:
    flag = False
    
if flag:
    print('Yes')
else:
    print('No')