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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N,A,B,C,D = IL()
S = S()

dA = [0 for i in range(N)]
dB = [0 for i in range(N)]

dA[A-1] = 1
dB[B-1] = 1

q = deque([A-1])
while q:
  x = q.pop()
  for i in [-2,-1,1,2]:
    nx = x+i
    if 0<=nx<N:
      if dA[nx] == 0 and S[nx]==".":
        dA[nx] = 1
        q.append(nx)

q = deque([B-1])
while q:
  x = q.pop()
  for i in [1,2]:
    nx = x+i
    if 0<=nx<N:
      if dB[nx] == 0 and S[nx]==".":
        dB[nx] = 1
        q.append(nx)

if dA[C-1] == dB[D-1] == 1:
  if C<D:
    print("Yes")
  else:
    count = 0
    MAX = 0
    prev = 0
    for c in dB[B-1:D]:
      if c == 1:
        if prev == 1:
          count += 1
          MAX = max(MAX,count)
        else:
          count = 1
      prev = c
    if MAX >= 3:
      print("Yes")
    else:
      print("No")
else:
  print("No")

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N,A,B,C,D = IL()
S = S()

dA = [0 for i in range(N)]
dB = [0 for i in range(N)]

dA[A-1] = 1
dB[B-1] = 1

q = deque([A-1])
while q:
  x = q.pop()
  for i in [-2,-1,1,2]:
    nx = x+i
    if 0<=nx<N:
      if dA[nx] == 0 and S[nx]==".":
        dA[nx] = 1
        q.append(nx)

q = deque([B-1])
while q:
  x = q.pop()
  for i in [-2,-1,1,2]:
    nx = x+i
    if 0<=nx<N:
      if dB[nx] == 0 and S[nx]==".":
        dB[nx] = 1
        q.append(nx)

if dA[C-1] == dB[D-1] == 1:
  if C<D:
    print("Yes")
  else:
    dC = [min(dA[i],dB[i]) for i in range(N)]
    count = 0
    MAX = 0
    prev = 0
    for c in dB:
      if c == 1:
        if prev == 1:
          count += 1
          MAX = max(MAX,count)
        else:
          count = 1
          MAX = max(MAX,count)
      prev = c
    if MAX >= 3:
      print("Yes")
    else:
      print("No")
else:
  print("No")

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N,A,B,C,D = IL()
S = S()

dA = [0 for i in range(N)]
dB = [0 for i in range(N)]

dA[A-1] = 1
dB[B-1] = 1

q = deque([A-1])
while q:
  x = q.pop()
  for i in [-2,-1,1,2]:
    nx = x+i
    if 0<=nx<N:
      if dA[nx] == 0 and S[nx]==".":
        dA[nx] = 1
        q.append(nx)

q = deque([B-1])
while q:
  x = q.pop()
  for i in [-2,-1,1,2]:
    nx = x+i
    if 0<=nx<N:
      if dB[nx] == 0 and S[nx]==".":
        dB[nx] = 1
        q.append(nx)

if dA[C-1] == dB[D-1] == 1:
  if C<D:
    print("Yes")
  else:
    dC = [min(dA[i],dB[i]) for i in range(N)]
    count = 0
    MAX = 0
    prev = 0
    for c in dC:
      if c == 1:
        if prev == 1:
          count += 1
          MAX = max(MAX,count)
        else:
          count = 1
          MAX = max(MAX,count)
      prev = c
    if MAX >= 3:
      print("Yes")
    else:
      print("No")
else:
  print("No")

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N,A,B,C,D = IL()
S = S()

dA = [0 for i in range(N)]
dB = [0 for i in range(N)]

dA[A-1] = 1
dB[B-1] = 1

q = deque([A-1])
while q:
  x = q.pop()
  for i in [-2,-1,1,2]:
    nx = x+i
    if 0<=nx<N:
      if dA[nx] == 0 and S[nx]==".":
        dA[nx] = 1
        q.append(nx)

q = deque([B-1])
while q:
  x = q.pop()
  for i in [-2,-1,1,2]:
    nx = x+i
    if 0<=nx<N:
      if dB[nx] == 0 and S[nx]==".":
        dB[nx] = 1
        q.append(nx)

if dA[C-1] == dB[D-1] == 1:
  if A<B<C<D or A<C<B<D:
    print("Yes")
  else:
    dC = [min(dA[i],dB[i]) for i in range(N)]
    count = 0
    MAX = 0
    prev = 0
    for c in dC:
      if c == 1:
        if prev == 1:
          count += 1
          MAX = max(MAX,count)
        else:
          count = 1
      prev = c
    if MAX >= 3:
      print("Yes")
    else:
      print("No")
else:
  print("No")

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N,A,B,C,D = IL()
S = S()

dA = [0 for i in range(N)]
dB = [0 for i in range(N)]

dA[A-1] = 1
dB[B-1] = 1

q = deque([A-1])
while q:
  x = q.pop()
  for i in [-2,-1,1,2]:
    nx = x+i
    if 0<=nx<N:
      if dA[nx] == 0 and S[nx]==".":
        dA[nx] = 1
        q.append(nx)

q = deque([B-1])
while q:
  x = q.pop()
  for i in [-2,-1,1,2]:
    nx = x+i
    if 0<=nx<N:
      if dB[nx] == 0 and S[nx]==".":
        dB[nx] = 1
        q.append(nx)

if dA[C-1] == dB[D-1] == 1:
  if A<B<C<D or A<C<B<D:
    print("Yes")
  else:
    dC = [min(dA[i],dB[i]) for i in range(N)]
    count = 0
    MAX = 0
    prev = 0
    for c in dC:
      if c == 1:
        if prev == 1:
          count += 1
          MAX = max(MAX,count)
        else:
          count = 1
      prev = c
    if MAX >= 3:
      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:
    if "##" in S:
        print("No")
    else:
        print("Yes")
else:
    if "..." in S and "##" not in S:
        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:
    if "##" in S:
        print("No")
    else:
        print("Yes")
else:
    if "..." in S:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

goal = max(C,D)
if '##' in S[A-1:goal]:
  print("No")
  exit()

ok = True
# 追い越す必要がある
if D < C:
  # 間に3マスあきがない or B,Dの間に3マス空きがない
  if ('...' in S[B-1:D+2]) or ('...' in S[B-2:B+1]) or ('...' in S[D-2:D+1]):
    ok = True
  else:
    ok = False
  
  

# 必要がない場合は問題ない

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

Submission status: Wrong Answer

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

goal = max(C,D)
if '##' in S[A-1:goal]:
  print("No")
  exit()

ok = True
# 追い越す必要がある
if D < C:
  # 間に3マスあきがない or B,Dの間に3マス空きがない
  if not ('...' in S[B-1:D+2]) or not ('...' in S[B-2:B+1]) or not ('...' in S[D-2:D+1]):
    ok = False
  
  

# 必要がない場合は問題ない

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

Submission status: Wrong Answer

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

goal = max(C,D)
if '##' in S[A-1:goal]:
  print("No")
  exit()

ok = True
# 追い越す必要がある
if D < C:
  # 間に3マスあきがない or (.D.)でない
  if not ('...' in S[B-1:D+2]):
    ok = False

# 必要がない場合は問題ない

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

Submission status: Wrong Answer

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

goal = max(C,D)
if '##' in S[A-1:goal]:
  print("No")
  exit()

ok = True
# 追い越す必要がある
if D < C:
  # 間に3マスあきがない or (.D.)でない
  if '...' in S[B-1:D+1]:
    ok = False

# 必要がない場合は問題ない

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

Submission status: Wrong Answer

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

goal = max(C,D)
if '##' in S[A-1:goal]:
  print("No")
  exit()

ok = True
# 追い越す必要がある
if D < C:
  # 間に3マスあきがない or (.D.)でない
  if '...' in S[B-1:D+2]:
    ok = False

# 必要がない場合は問題ない

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

Submission status: Wrong Answer

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

goal = max(C,D)
if '##' in S[A-1:goal]:
  print("No")
  exit()

ok = True
# 追い越す必要がある
if D < C:
  # 間に3マスあきがない or (.D.)でない
  if not ('...' in S[B-1:D]):
    ok = False

# 必要がない場合は問題ない

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

Submission status: Wrong Answer

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

goal = max(C,D)
if '##' in S[A-1:goal]:
  print("No")
  exit()

ok = True
# 追い越す必要がある
if D < C:
  # 間に3マスあきがない or (.D.)でない
  if not ('...' in S[B-1:D]):
    print(S[B-1:D])
    ok = False

# 必要がない場合は問題ない

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

Submission status: Wrong Answer

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

goal = max(C,D)
if '##' in S[A-1:goal]:
  print("No")
  exit()

ok = True
# 追い越す必要がある
if D < C:
  # 間に3マスあきがない or (.D.)でない
  if not ('...' in S[B-1:D]):
    ok = False

# 必要がない場合は問題ない

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

Submission status: Wrong Answer

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

goal = max(C,D)
if '##' in S[A-1:goal]:
  print("No")
  exit()

ok = True
# 追い越す必要がある
if D < C:
  # 間に3マスあきがない or (.D.)でない
  if not ('...' in S[B-1:D]) or not ('...' in S[D-2:D+1]):
    ok = False

# 必要がない場合は問題ない

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

Submission status: Wrong Answer

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

goal = max(C,D)
if '##' in S[A:goal+1]:
  print("No")
  exit()

ok = True
# 追い越す必要がある
if D < C:
  # 間に3マスあきがない or (.D.)でない
  if not ('...' in S[B:D+1]) or not ('...' in S[D-1:D+2]):
    ok = False

# 必要がない場合は問題ない

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

Submission status: Wrong Answer

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

# ##となっていたら無理
# C < D のとき、それぞれが移動可能かでわかる
# C > D のときは? 追い越しは...となる箇所があればいける

if '##' in S[min(A, B)-1:]:
    print('No')
    quit()

if C < D:
    print('Yes')
else:
    if '...' in S[B-2:]:
        print('Yes')
        quit()
    print('No')

Submission status: Wrong Answer

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

cnt = 0
if C < D:
    for i in range(A, D):
        if S[i] == "#":
            cnt += 1
            if cnt > 1:
                print("No")
                exit()
        else:
            cnt = 0
    print("Yes")
else:
    scnt = 0
    tcnt = 0
    ok = False
    for i in range(A, D):
        if S[i] == "#":
            tcnt = 0
            scnt += 1
            if scnt > 1:
                print("No")
                exit()
        else:
            scnt = 0
            if ok is False and i >= B:
                tcnt += 1
                if tcnt > 2:
                    ok = True
    if ok:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

cnt = 0
if C < D:
    for i in range(A, D):
        if S[i] == "#":
            cnt += 1
            if cnt > 1:
                print("No")
                exit()
        else:
            cnt = 0
    print("Yes")
else:
    scnt = 0
    tcnt = 0
    ok = False
    for i in range(A, D):
        if S[i] == "#":
            tcnt = 0
            scnt += 1
            if scnt > 1:
                print("No")
                exit()
        else:
            scnt = 0
            if ok is False:
                tcnt += 1
                if tcnt > 2 and i != B:
                    ok = True
    if ok:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

cnt = 0
if C < D:
    for i in range(A, D):
        if S[i] == "#":
            cnt += 1
            if cnt > 1:
                print("No")
                exit()
        else:
            cnt = 0
    print("Yes")
else:
    scnt = 0
    tcnt = 0
    ok = False
    for i in range(A, D):
        if S[i] == "#":
            tcnt = 0
            scnt += 1
            if scnt > 1:
                print("No")
                exit()
        else:
            scnt = 0
            if ok is False:
                tcnt += 1
                if tcnt > 2:
                    ok = True
    if ok:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = list(map(int, input().split()))
s = '#' + input()

# 今いる位置から目的地まで進めるか？
def can_forward(start, end):
    steps = s[start:end+1]
    return not "##" in steps

if not (can_forward(a, c) or can_forward(b, d)):
    print('No')
    exit()

if c>d:
    # 追い越し可能区間があるか？
    if '...' in s[b:d+2]:
        print('Yes')
    else:
        print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = list(map(int, input().split()))
s = '#' + input()

# 今いる位置から目的地まで進めるか？
def can_forward(start, end):
    steps = s[start:end+1]
    if "##" in steps:
        return False
    return True

if not (can_forward(a, c) or can_forward(b, d)):
    print('No')
    exit()

if c>d:
    # 追い越し可能区間があるか？
    if '...' in s[b:d+1]:
        print('Yes')
        exit()
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n,a,b,c,d = list(map(int, input().split()))
s = '#' + input()

import re

# 今いる位置から目的地まで進めるか？
def can_forward(start, end):
    if start>end:
        end,start = start,end
    steps = s[start:end+1]
    if "##" in steps:
        return False
    return True

if not (can_forward(a, c) or can_forward(b, d)):
    print('No')
    exit()

if s[c]=='#' or s[d]=='#':
    print('No')
    exit()

if a<b and c>d or a>b and c<d:
    # 二人とも追い越し可能区間にいけるか？
    for m in re.finditer(r'\.\.\.+',s):
        f,t = m.span()
        if can_forward(a, f) and can_forward(b, f):
            print('Yes')
            exit()
    print('No')
else:
    print('Yes')