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:
# 全長、　スヌケすたーと、　ふぬけスタート、　すねけえんど、ふねけエンド
# 不可能なじょうけん
# どちらかのスタートとゴールのあいだに2連続でゴールが行われている
# C > Dの場合、いわと岩の間が3つ以上離れている場所が存在する。（それがないと超えることができない）
n, a, b, c, d = map(int, input().split())

def mymain(s):
    for i, p in list(enumerate(s))[a-1:c if c > d else d]:
        if p == "#" and s[i+a] == "#":
            return 'No'
    if c > d:
        flg = "No"
        if s[b] == "." and s[b-2] == "." or s[b] == "." and s[b+1] == ".":
                flg = 'Yes'
        else:
            for i, s_b_d_point in list(enumerate(s))[b-1:d]:
                if i+b+1 < len(s) and i+b+2 < len(s) and s_b_d_point == '.' and s[i+b+1] == '.' and s[i+b+2] == '.':
                    flg = "Yes"
        return flg
    return 'Yes'
                
print(mymain(input()))

Submission status: Wrong Answer

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

S = input()

def AA(mojiretu):
    if '##' in mojiretu:
     print("No")
    else:
     print("Yes")

Scp = S
if C < D:
      AA(Scp[A:D])
      
else:
    if "..." in Scp[B-2:D-1]:
      AA(Scp[A:C])
    else:
      Scp = Scp[:D-1]+"#" + Scp[D:]
      AA(Scp[A:C])

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]:
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
        if s == '.':
            shc = 0
    for s in S[B-1:D]:
        if shc > 1:
            ans = 'No'
            break
        if s == '#':
            shc += 1
        if s == '.':
            shc = 0
elif C>D: # C > Dのとき、A~B
    shc = 0
    dc = 0
    mdc = 0
    for s in S[A-1: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 mdc < 3:
        shc = 0
        for i, s in enumerate(S[0:A:-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
                break
            if s == '#':
                shc += 1
            if s == '.':
                shc = 0
        else:
            r = N
        
        mdc = 0
        for s in 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 mdc < 3:
            ans = 'No'
print(ans)


# 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: 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]=  "#"

bool=False
for i in range(B-1,D):
    if i >= N-1:
        break
    if S[i] == "." and S[i-1]=="." and S[i+1]==".":
        bool = True
        break

if bool:
    print("Yes")
else:
    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:
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
    elif (A > C) or (B > D):
        print('No')
        return
    else:
        possible_trans = False
        trans_index = -1
        for i in range(N-1):
            if placing_objects[i] and placing_objects[i+1]:
                print('No')
                return
            if i < N-2 and (not placing_objects[i]) and (not placing_objects[i+1]) and (not placing_objects[i+2]):
                possible_trans = True
                trans_index = 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 > trans_index:
                    print('No')
                    return
            else:
                if B > trans_index:
                    print('No')
                    return
        print('Yes')
        
main()

Submission status: Wrong Answer

Solution code:
#A問題
N,A,B,C,D = map(int,input().split())
Slist = list(str(input()))
if C < D:
    now = B-1
    Rock = 0
    flag = 0
    for i in range(D-B):
        I = i+now
        if i == 0:
            pass
        else:
            if Slist[I] == "#":
                Rock+=1
                if Rock == 2:
                    flag = 1
                    break
            else:
                Rock = 0
    now = A-1
    Rock = 0
    for i in range(C-A):
        I = i+now
        if i == 0:
            pass
        else:
            if Slist[I] == "#":
                Rock+=1
                if Rock == 2:
                    flag = 1
                    break
            else:
                Rock = 0

    if flag == 1:
        print("No")
    else:
        print("Yes")
    
else:
    now = B-1
    Rock = 0
    flag = 0
    for i in range(D-B):
        I = i+now
        if i == 0:
            pass
        else:
            if Slist[I] == "#":
                Rock+=1
                if Rock == 2:
                    flag = 1
                    break
            else:
                Rock = 0
    now = A-1
    Rock = 0
    mass = 0
    Maxmass = 0
    aflag = 0
    for i in range(C-A):
        I = i+now
        if i == 0:
            pass
        else:
            if Slist[I] == "#":
                Rock+=1
                if Rock == 2:
                    flag = 1
                    break
            else:
                Rock = 0
                
    now = A-1
    for i in range(D-B+2):
        I = now + i
        if i == 0:
            mass+=1
        else:
            if Slist[I] == "#":
                Maxmass = max(Maxmass,mass)
                mass = 0
            else:
                mass+=1
    Maxmass = max(Maxmass,mass)

    if Maxmass <= 2:
        flag = 1
    
    if flag == 1:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
length, a, b, c, d = [int(i) for i in input().split()]
road = input()

e = []
e.append(a)
e.append(b)
e.append(c)
e.append(d)

road = road[min(e) - 1:max(e) - 1]

if '##' in road:
    print('No')
elif '...' in road:
    print('Yes')
elif c > d:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map( int, input().split())
S = input()
check = "Yes"
for i in range(A-1, C-1):
    if S[i] == "#" and S[i+1] == "#":
        check = "No"
        break
if check == "Yes":
    for i in range(B-1, D-1):
        if S[i] == "#" and S[i+1] == "#":
            check = "No"
            break    
if check == "Yes":
    if C < D:
        pass
    else:
        check = "No"
        B -= 1
        D -= 1
        t = 0
        for i in range(B-1, D+2):
            if S[i] == ".":
                if t <= 1:
                    t += 1
                else:
                    check = "Yes"
                    break
            else:
                t = 0
            print(t)
print(check)

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]=="#" or s[d+1]=="C":
        ans=0
    else:
        ans=1
                
if ans==1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

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

if '##' in S[A:]:
    print('No')
elif C<D:
    print('Yes')
else:
    if '...' in S[B:]:
        print('Yes')
    elif S[B] == '.' and S[B-2] == '.':
        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 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:
n,a,b,c,d=map(int,input().split())
s=str(input())
arr=[]
for i in range(len(s)):
	if(s[i]=='#'):
		arr.append(-1)
	elif(s[i]=='.'):
		arr.append(0)

a-=1
b-=1
c-=1
d-=1
flag=0
arr[a]=1
arr[b]=2
arr[c]=3
arr[d]=4

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

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



else:
    flag2 = False
    flag3 = False
    if s[b-2]==".":
        temp = 1
    else:
        temp = 0
    block = 0
    for i in range(b-1,c-1):
        if temp == 3:
            flag2 = True
            temp = i-2
            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 flag3:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys;
import string;
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

import copy
import itertools

from functools import lru_cache
#@lru_cache(maxsize = None)

# 整数の入力
#n = int(input())

# スペース区切りの整数の入力
#a = [x for x in map(int, input().split())]
n, a, b, c, d = map(int, input().split())
#print("sp", n, q, file=sys.stderr)

# 改行区切りの整数の入力
#a = []
#for x in range(m):
#  a.append([int(x) for x in input().split()])
#p = [int(x) for x in input().split()]

# 文字列の入力
s = input()

# 出力
#print("{} {}".format(a+b+c, s))
#a.sort()
#print(set(a), file=sys.stderr)
#print(len(set(a)))

#cache = dict()

a -= 1
b -= 1
c -= 1
d -= 1

def canswap(s, b, d):
  print("canswap", s, file=sys.stderr)
  for x in range(b, d + 1):
    #print(x, file=sys.stderr)
    prev = s[x - 1] != '#'
    curr = s[x] != '#'
    post = s[x + 1] != '#'
    print(prev, post, file=sys.stderr)
    if post and prev:
      return True
  return False

def canmove(s, a, c):
  print(s, file=sys.stderr)
  if a + 1 == c:
    return s[a + 1] != '.'
  prev = s[a + 1] != '.'
  for x in range(a + 2, c):
    #print(x, file=sys.stderr)
    post = s[x] != '.'
    if post and prev:
      return False
    prev = post
      
  return True

def doit():  
  s2 = list(s)
  print(s2, file=sys.stderr)
  s2[a] = 'A'
  s2[b] = 'B'
  print('s2 ', s2, file=sys.stderr)

  res = list(s)
  res[c] = 'A'
  res[d] = 'B'
  print('res', res, file=sys.stderr)
  
  if c < d:
    if not canmove(s2, b, d):
      return False
    s2[b] = '.'
    s2[d] = 'B'
    return canmove(s2, a, c)
  else:
    if not canmove(s2, a, c):
      if not canswap(s2, b, d):
        return False
      else:
        s2[b] = '.'
        return canmove(s2, a, c)
    s2[a] = '.'
    s2[c] = 'A'
    return canmove(s2, b, d)

#print(doit([0] * 4))
#doit()
try:
  print('Yes' if doit() else 'No')
    
except Exception as e:
  print("e", e, file=sys.stderr)

Submission status: Wrong Answer

Solution code:
a=input().split()
b=input()

ans = 0
re = 0
if int(a[3])>int(a[4]):
	re = 1

p = 0
rock = 0
dot = 0
rock_ver = 0
re_ok = 0
for i in range(int(a[0])):
	if i + 1 == int(a[2]):
		p = 1
	b_i = b[int(i)]
	if b_i == "#":
		if rock == 1:
			ans = 1
			break
		if p == 1:
			if rock_ver == 0:
				rock_ver = 1
		rock = 1
		dot = 0
	else:
		rock = 0
		if p == 1:
			dot += 1
			if rock_ver == 0:
				if dot >=2 and b[i-2] == ".":
					if i > int(a[3]) and i-1 > int(a[4]) :
						re_ok = 0
					else: 
						re_ok = 1
					break
			elif dot >= 3:
				if i > int(a[3]) and i - 1 > int(a[4]):
					re_ok = 0
				else: 
					re_ok = 1
				break

if re == 1:
	if re_ok == 0:
		ans = 1

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

Submission status: Wrong Answer

Solution code:
# 2019/06/02
# AtCoder Grand Contest 034 - A

# For the answer:
# 1-1. Search min(ac) and max(abcd)
# 1-2. Search ## between min and max
# 2. Case:B<C, Left of B is . and (. or C), or exist .. -> Yes

# Def 1 : True is "Case No"
def searchRock(in_l, in_r, in_str, in_tg):

    wflg = False    
    rcflg = False
    for i in range(in_l - 1, in_r - 1): # Change -2 -> -1
        if in_str[i] == in_tg and in_str[i+1] == in_tg:
            if wflg == True:
                rcflg = True
                break
            else:
                wflg = True
        else:
            wflg = False
    return rcflg

# Input
n, a, b, c, d = map(int, input().split())
s = input()
ans = ""

# 1. Search ##
if c < b:
    # Search between a and c, b and d
    rflg = searchRock(a, c, s, "#")
    if rflg == True:
        ans = "No"
    else:
        rflg = searchRock(b, d, s, "#")
        if rflg == True:
            ans = "No"

else:
    # Search between a and max(c, d)
    rflg = searchRock(a, max(c, d), s, "#")
    if rflg == True:
        ans = "No"
    
# 2. Check around b
if ans != "No":
    if (b < c and d < c):
        # Case: B < D < C 
        pflg = searchRock(b, c, s, ".")
        if pflg == False:
            if s[b-2] == "." and s[b] == ".":
                ans = "Yes"
            else:
                ans = "No"
        else:
            ans = "Yes"
    else:
        ans = "Yes"

# Output
print(ans)

Submission status: Wrong Answer

Solution code:
def solve3():
    N, A, B, C, D = [int(_) for _ in raw_input().split()]
    A -= 1
    B -= 1
    C -= 1
    D -= 1
    S = raw_input()
    R3 = False
    E3 = False
    EREE = False
    EERE = False
    for i in range (A+1, max(C,D)-1):
        if S[i:(i+3)] == '###':
            R3 = True
            break
    if C == D or R3:
        return False
    elif C < D:
        return True
    elif C > D:
        for i in range (B - 1, D-1):
            if S[i:(i+3)] == '...':
                E3 = True
                break
            elif S[i:(i+4)] == '.#..':
                EREE = True
                break
            elif S[i:(i+4)] == '..#.':
                EERE = True
                break
        if S[(D-1):(D+2)] == '...':
            E3 = True
        elif S[(D-1):(D+3)] == '..#.':
            EERE = True
        ret = E3 or EREE or EERE
        return ret

if __name__ == '__main__':
    ret = solve3()
    if ret:
        print 'Yes'
    else:
        print 'No'

Submission status: Wrong Answer

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

curval = "x"
cnt = 0
initidx = 0
ngarea = [-1]
triarea = [-1]

for idx,val in enumerate(S):
    if val == curval:
        cnt += 1
    else:
        if cnt >= 2 and curval == '#':
            ngarea.append(initidx + 1)
        elif cnt >= 3 and curval == '.':
            for i in range(3,cnt+1):
                triarea.append(initidx + 1 + i - 3)
        initidx = idx
        cnt = 1
    curval = val
else:
    if cnt >= 2 and curval == '#':
        ngarea.append(initidx + 1)
    elif cnt >= 3 and curval == '.':
        triarea.append(initidx + 1)

if C < D:
    isBflg = True
    isABflg = True
    for ngp in ngarea:
        if ngp > B and ngp < D:
            isBflg = False
        if ngp > A and ngp < B:
            isABflg = False
    if isBflg and isABflg:
        print('Yes')
        exit()
    else:
        print('No')
        exit()
else:
    isChangeFlg = False
    # Changepoint = -1
    for trp in triarea:
        if trp >= A and trp + 1 >= B:
            Changepoint = trp + 1
            isChangeFlg = True
            break
    if isChangeFlg == False:
        print('No')
        exit()
    else:
        isBflg = True
        isABflg = True
        isChange2DFlg = True
        for ngp in ngarea:
            if ngp > B and ngp < Changepoint:
                isBflg = False
            if ngp > A and ngp < B:
                isABflg = False
            if ngp > Changepoint and ngp < D:
                isChange2DFlg = False
        if isBflg and isABflg and isChange2DFlg:
            print('Yes')
            exit()
        else:
            print('No')
            exit()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, A: int, B: int, C: int, D: int, S: str):
    ret = YES
    if '##' in S[A - 1:C] or '##' in S[B - 1:D]:
        ret = NO
    else:
        if D < C:
            #if S[B - 2:B] == '..' or S[B - 1:B + 1] == '..':
            if not '...' in S[B - 3:D + 2]:
                ret = NO
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)

if __name__ == '__main__':
    main()

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-1: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 S[B-2] == '.' 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:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, A: int, B: int, C: int, D: int, S: str): 
    if(S[A-1] == '#' or S[B-1] == '#' or  S[C-1] == '#' or S[D-1] == '#'):
        print(NO)
        sys.exit()

    if(S[A-1:C].count('##') == 0 and S[B-1:D].count('##') == 0):
        if(D < C):
            sf = (S[B-1:D].count('...'))
            if(sf == 0):
                print(NO)
            elif(sf == 1):
                tS = list(S)
                tS[B-1] = 'b'
                tS = ''.join(tS)
                if(tS[A-1:D].count('...') == 0 and tS[A-1:D].count('..b#') == 1):
                    print(NO)
                else:
                    print(YES)
            elif(sf >= 2):
                print(YES)
        else: # D > Cの場合
            print(YES)  
    else:
        print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def spaceinput():
    return list(map(int, input().split(" ")))

def count3(S, l, r):
    for i in range(l, r+1):
        if S[i:i+3] == "...":
            return True
    return False

def is_twocontinusblock(S, l, r):
    for i in range(l,r+1):
        if S[i:i+2] == "##":
            return True
    return False


N, A, B, C, D = spaceinput()
S = input()

def solve():
    if is_twocontinusblock(S, A, C-1) or is_twocontinusblock(S, B, D-1):
        return False
    if D < C:
        if count3(S, B-1, D-1):
            return True
        else:
            return False

    return True


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

Submission status: Wrong Answer

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

if D > C:
    if '##' in S[B:D] or '##' in S[A:C]:
        print('No')
    else:
        print('Yes')
elif C > D:
    if '...' in S[0: N] and '##' not in S:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

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

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

if '##' in S:
    print('No')
elif C<D:
    print('Yes')
else:
    if '...' in S[B:]:
        print('Yes')
    elif S[B] == '.' and S[B-2] == '.':
        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

def cd():
    two_block_flg = False
    for s in S[A:C+1]:
        if two_block_flg:
            if s=='#':
                return 'No'
            else:
                two_block_flg = False
        else:
            if s=='#':
                two_block_flg = True
    two_block_flg = False
    for s in S[B:D+1]:
        if two_block_flg:
            if s=='#':
                return 'No'
            else:
                two_block_flg = False
        else:
            if s=='#':
                two_block_flg = True
    return 'Yes'

def dc():
    block_cnt = 0
    space_cnt = 0
    if S[D-1]=='.' and S[D+1]=='.':
        space_flg = True
    else: 
        space_flg = False
    for i,s in enumerate(S[A:C+1]):
        if s=='#':
            block_cnt += 1
            if B<=i+A and i+A<D and (not space_flg):
                space_cnt = 0
        else:
            block_cnt = 0
            if B<=i+A and i+A<D and (not space_flg):
                space_cnt += 1
        #print(i+A, block_cnt, space_cnt)
        if block_cnt>=2:
            return 'No'
        if space_cnt>=3:
            space_flg = True
    if space_flg:
        return 'Yes'
    else:
        return 'No'
                


if C<D:
    print(cd())
else:
    print(dc())