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: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict
import math


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def mod_inv(x):
    # available only when mod is prime
    global mod
    return pow(x, mod - 2, mod)


def gcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    ret = math.factorial(x)
    ret = ret // (math.factorial(x - y) * math.factorial(y))

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)


###############################################################################


def f(s, start, goal):
    count = 0
    for i in range(start, goal):
        if s[i] == '#':
            count += 1
            if count >= 2:
                return False
        if s[i] == '.':
            count = 0
    return True


def main():
    n, a_start, b_start, a_goal, b_goal = intin()
    s = input()
    a_start -= 1
    b_start -= 1
    a_goal -= 1
    b_goal -= 1

    if b_goal < a_goal and \
       (s[b_start-1] == '#' or s[b_start+1] == '#') and \
       (s[b_goal-1] == '#' or s[b_goal+1] == '#'):
        count = 0
        for i in range(b_start, b_goal + 1):
            if s[i] == '.':
                count += 1
                if count >= 3:
                    break
            if s[i] == '#':
                count = 0
        else:
            print('No')
            return

    if not f(s, a_start, a_goal):
        print('No')
        return

    if not f(s, b_start, b_goal):
        print('No')
        return

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B,C,D = map(int,input().split())
S = input()
if C<D:
    print('No' if ('##' in S[A-1:C]) or ('##' in S[B-1:D]) else 'Yes')
    exit()

if '##' in S[A-1:C]:
    print('No')
    exit()
for bi in range(B-1,D):
    if S[bi-1] == S[bi] == S[bi+1] == '.':
        print('Yes')
        exit()
print('No')

Submission status: Accepted

Solution code:
n,a,b,c,d=map(int,input().split())
s=["#"]+list(input())
if c<d:
    for now,goal in [(b,d),(a,c)]:
        while now < goal:
            if s[now+1]==".":
                now+=1
            elif now < n-1 and s[now+2]==".":
                now+=2
            else:
                print("No")
                exit()
    print("Yes")
else:
    for now,goal in [(b,d),(a,c)]:
        while now < goal:
            if now < n-1 and s[now+2]==".":
                now+=2
            elif s[now+1]==".":
                now+=1
            else:
                print("No")
                exit()
    for i in range(b-1,d):
        if s[i]=="." and s[i+1]=="." and s[i+2]==".":
            print("Yes")
            break
    else:
        print("No")

Submission status: Accepted

Solution code:
N, A, B, C, D = [int(x) for x in input().split()]
# N < 200_000
S = " " + input()

# A sunuke -> C
# B funuke -> D
# .
# # 

def solve(N, A, B, C, D, S):
    if S[A:C].find("##") != -1:
        return "No"
    if S[B:D].find("##") != -1:
        return "No"

    # A C B D
    if A < C < B < D:
        return "Yes"

    # A B C D
    if A < B < C < D:
        return "Yes"

    # A B D C
    if A < B < D < C:
        if S[B-1:D+2].find("...") != -1:
            return "Yes"
    return "No"

print(solve(N, A, B, C, D, S))

Submission status: Accepted

Solution code:
n,a,b,c,d=map(int, input().split(' '))
a -= 1
b -= 1
c -= 1
d -= 1
s = input()
if c == d:
    ans = 'No'
elif c < d:
    n0 = s[a:d].count('##')
    if n0 != 0:
        ans = 'No'
    else:
        ans = 'Yes'
else:
    n0 = s[a:c].count('##')
    n1 = s[b-1:d+2].count('...')
    if n0 == 0 and n1 != 0:
        ans = 'Yes'
    else:
        ans = 'No'
print(ans)

Submission status: Accepted

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

possible = True
if '##' in S[A:C] or '##' in S[B:D]:
    possible = False
if D < C:
    if '...' not in S[B-1:D+2]:
        possible = False

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

Submission status: Accepted

Solution code:

def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    A = int(buflist[1])-1
    B = int(buflist[2])-1
    C = int(buflist[3])-1
    D = int(buflist[4])-1
    buf = input()
    S = buf
    if D < C:
        space = 0
        for i in range(B-1, min(D+2, N)):
            if S[i] == '.':
                space += 1
                if space >= 3:
                    break
            else:
                space = 0
        if space < 3:
            print('No') # unswappable
            return
    rock_count = 0
    for i in range(A, max(C, D)+1):
        if S[i] == '#':
            rock_count += 1
            if rock_count >= 2:
                break
        else:
            rock_count = 0
    if rock_count >= 2:
        print('No')
    else:
        print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, A, B, C, D =  map(int, input().split())
S = input()
S = [False] + [s == '.' for s in S] + [False]
def check(s, t):
    i = s
    for _ in range(s, t+1):
        if i + 1 == t or i + 2 == t:
            return True
        if S[i+2]:
            i += 2
            continue
        if S[i+1]:
            i += 1
            continue
        return False

def checki(s, t):
    for i in range(s, t+1):
        if S[i-1] and S[i] and S[i+1]:
            return True
    return False



if A < B < D < C:
    if not check(B, D) or not check(A, C):
        print('No')
    elif checki(B, D):
        print('Yes')
    else:
        print('No')
else:
    if check(A, C) and check(B, D):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

if C < D:
    flag = 1
    for i in range(A-1, C-1):
        if S[i+1] == "#" and S[i] == "#":
            flag = 0
            break
    for i in range(B-1, D-1):
        if S[i+1] == "#" and S[i] == "#":
            flag = 0
            break

else:
    flag = 1
    for i in range(A-1, C-1):
        if S[i+1] == "#" and S[i] == "#":
            flag = 0
            break
    for i in range(B-1, D-1):
        if S[i+1] == "#" and S[i] == "#":
            flag = 0
            break

    if flag == 1:
        flag = 0
        for i in range(B-2, D-1):
            if S[i+2] == "." and S[i+1] == "." and S[i] == ".":
                flag = 1

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

Submission status: Accepted

Solution code:
def main():
	n,a,b,c,d = map(int,input().split())
	s = input()
	ans = ""
	if c < d:
		if s.count("##",a, d) > 0:
			ans = "No"
		else:
			ans = "Yes"
	else:
		if s.count("##", a ,c) > 0 or s.count("...",b-2, d+1) == 0:
			ans = "No"
		else:
			ans = "Yes"
	print(ans)
	return
main()

Submission status: Accepted

Solution code:
n,a,b,c,d=map(int,input().split())
s="."+input()
if(c>d):
    if("..." in s[b-1:d+2] and not "##" in s[a:c+1]):
        print("Yes")
    else:
        print("No")
else:
    if("##" in s[a:d+1]):
        print("No")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)


def main():
    n,a,b,c,d = LI_()
    n += 1
    s = S()
    if d < c:
        f = 0
        for i in range(max(0,b-1), min(min(n-1,d), c-1)):
            if s[i:i+3] == '...':
                f = 1
                break
        if f == 0:
            return 'No'

    for i in range(a+1,c-1):
        if s[i:i+2] == '##':
            return 'No'
    for i in range(b+1,d-1):
        if s[i:i+2] == '##':
            return 'No'


    return 'Yes'


print(main())

Submission status: Accepted

Solution code:

(N,A,B,C,D) = (int(i) for i in input().split(" "))
S = input()

if "##" in S[A-1:max(C,D)]:
	print("No")
else:
	if C < D:
		print("Yes")
	else:
		if "..." in S[max(0,B-2):min(D+1,N)]:
			print("Yes")
		else:
			print("No")

Submission status: Accepted

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

f1 = True
for i in range(A, C-1):
  if S[i]=="#" and S[i+1]=="#":
    f1 = False

f2 = True
for i in range(B, D-1):
  if S[i]=="#" and S[i+1]=="#":
    f2 = False

if C<D:
  f3 = True
else:
  f3 = False
  for i in range(B-1, D):
    if S[i]=="." and S[i+1]=="." and S[i+2]==".":
      f3 = True

if f1 and f2 and (C<D or f3):
  print "Yes"
else:
  print "No"

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(a, b, c, d, s):
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    ss = s[a:c + 1]
    fs = s[b:d + 1]
    if '##' in ss or '##' in fs:
        return False

    if c < d:
        return True

    fs2 = s[b - 1:d + 2]
    if '...' in ss and '...' in fs2:
        return True

    return False


n, a, b, c, d = list(map(int, input().split()))
s = input()
print('Yes' if solve(a, b, c, d, s) else 'No')

Submission status: Accepted

Solution code:
def solve():
    N, A, B, C, D = map(int, input().split())
    S = input()
    for i in range(A - 1, C - 1):
        if S[i] == '#' and S[i + 1] == '#':
            return "No"
    for i in range(B - 1, D - 1):
        if S[i] == '#' and S[i + 1] == '#':
            return "No"
    if C < D:
        return "Yes"
    for i in range(B - 2, D - 1):
        if S[i] == '.' and S[i + 1] == '.' and S[i + 2] == '.':
            return "Yes"
    return "No"
print(solve())

Submission status: Runtime Error

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

ok = True
overtake = False

if c < d:
    overtake = True
    
for i in range(a,d):
    if S[i] == "#" and S[i+1] == "#":
        ok = False

for i in range(b,d+1):
    if S[i] == "." and S[i-1] == "." and S[i+1] == ".":
        overtake = True
        
if ok and overtake:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import numpy as np

n, a, b, c, d = map(lambda x:int(x)-1,input().split())
n += 1
S = input()

ok = True
overtake = False

if c < d:
    overtake = True
    
for i in range(a,d):
    if S[i] == "#" and S[i+1] == "#":
        ok = False

for i in range(b,n-1):
    if S[i] == "." and S[i-1] == "." and S[i+1] == ".":
        overtake = True
        
if ok and overtake:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import numpy as np

n, a, b, c, d = map(lambda x:int(x)-1,input().split())
n += 1
S = [1 if s == "." else 0 for s in input()]

ok = True
overtake = False

if a<b and c<d:
    overtake= True
if b<a and d<c:
    overtake = True
    
groups = []
tmp = 0
zeros = 0
for n in S:
    if n == 1:
        if zeros != 0:#直前まで０だったとき
            groups.append(zeros)
            zeros = 0#リセット
        tmp += 1
    elif n == 0:
        if tmp != 0:#直前まで１だったとき
            groups.append(tmp)
            tmp = 0#リセット
        zeros -= 1
if tmp != 0:
    groups.append(tmp)
if zeros != 0:
    groups.append(zeros)

now = 0
for i in range(len(groups)):
    if now+abs(groups[i]) >= max(a,b):
        ind = i
        break
    now += abs(groups[i])

for i in range(ind+1,len(groups)):
    if groups[i] >= 3:
        overtake = True
    if groups[i] <= -2:
        ok = False

if now+groups[ind]-max(a,b) >= 2:
    overtake= True
if now+groups[ind]-max(a,b) >= 1 and max(a,b)-now >= 1:
    overtake = True

if overtake and ok:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
#58 A - Kenken Race
N,A,B,C,D = map(int,input().split())
S = input()
A,B,C,D = A-1,B-1,C-1,D-1

# A が B を抜かせるエリア
if B == 1:
    a = S.find('...') + 1
else:
    a = S.find('...',3) + 1

dx = [1,2]

# 先に移動させる方の関数
def dfs_ini(v,seen_ini,X):
    seen_ini[v] = True# v を訪問済みにする
    for i in range(2):
        next_v = v + dx[i]
        # next_v が範囲外 or 壁の場合 or 他方が存在する場合
        if not(-1<next_v<N):
            continue
        if (S[next_v] == '#') or (next_v == X):
            continue
        if seen_ini[next_v] == True:# next_v が探索済みならスルー
            continue
        dfs_ini(next_v,seen_ini,X)

# 後に移動させる方の関数
def dfs_fin(w,seen_fin,Y):
    seen_fin[w] = True# w を訪問済みにする
    for j in range(2):
        next_w = w + dx[j]
        # next_w が範囲外 or 壁の場合 or 他方が存在する場合
        if not(-1<next_w<N):
             continue
        if (S[next_w] == '#')  or (next_w == Y):
             continue
        if seen_fin[next_w] == True:# next_w が探索済みならスルー
             continue
        dfs_fin(next_w,seen_fin,Y)

# A を先に動かした方がいいとき
# B を 先に a まで移動させる
if C>D:
    seen_ini_A = [False]*N
    seen_fin_B = [False]*N
    # B を抜かせるエリアがないとき、B の位置はスタート位置
    if (a < B) or (a > D):
        a = B
    dfs_ini(A,seen_ini_A,a)
    dfs_fin(B,seen_fin_B,C)
    result = 'No'
    if seen_ini_A[C] and seen_fin_B[D]:
        result = 'Yes'

# B を先に動かした方がいいとき
else:
    seen_ini_B = [False]*N
    seen_fin_A = [False]*N
    dfs_ini(B,seen_ini_B,A)
    dfs_fin(A,seen_fin_A,D)
    result = 'No'
    if seen_ini_B[D] and seen_fin_A[C]:
        result = 'Yes'

print(result)

Submission status: Runtime Error

Solution code:
def main():
    N, A, B, C, D = map(int, input().split())
    S = list(input())
    E = max(C, D)
    cnt = 0
    for i in range(A-1, E):
        if S[i] == '#':
            cnt += 1
        else:
            cnt = 0
        if cnt >= 2:
            print('No')
            return
    if C < D:
        print('Yes')
        return
    cnt = 0
    for i in range(B-1, D+2):
        if S[i] == '.':
            cnt += 1
        else:
            cnt = 0
        if cnt >= 3:
            print('Yes')
            return
    print('No')
        
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n,a,b,c,d = map(int,input().split())
s = list(input())
s.insert(0,0)
for i in range(a,max(c,d)+1):
    if '#' == s[i] and '#' == s[i+1]:
        print('No')
        exit(0)
if c < d:
    print('Yes')
else:
    for i in range(b,d+1):
        if '.' == s[i] and '.' == s[i+1] and '.' == s[i+2]:
            print('Yes')
            exit(0)
    print('No')

Submission status: Runtime Error

Solution code:
# https://atcoder.jp/contests/agc034/tasks/agc034_a

import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, a, b, c, d = input_int_list()
    S = input()

    for i in range(a - 1, max(c, d) - 1):
        if S[i] == S[i + 1] == "#":
            print("No")
            quit()
    if c < d:
        print("Yes")
        quit()
    if c > d:
        for i in range(b - 2, d - 1):
            if S[i, i + 3] == "...":
                print("Yes")
                quit()
        print("No")
        quit()


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n,a,b,c,d=map(int,input().split())
S=input()
answer=0
rock=0
for n_ in range(a,max(c,d)):
    if S[n_]=='#':
        rock+=1
    else:
        rock=0
    if rock>=2:
        answer=1
        break
if answer==1:
    print('No')
else:
    if c > d:
        answer=1
        rock = 0
        for n_ in range(a,d):
            if S[n_] == '.':
                rock += 1
            else:
                rock = 0
            if rock >= 3:
                answer=0
                break
    if N==4:
        print('Yes')
    elif answer == 0:
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:
n,a,b,c,d=map(int,input().split())
S=input()
answer=0
rock=0
for n_ in range(a,max(c,d)+1):
    if S[n_]=='#':
        rock+=1
    else:
        rock=0
    if rock>=2:
        answer=1
        break
if answer==1:
    print('No')
else:
    if c > d:
        answer=1
        rock = 0
        for n_ in range(a,d+1):
            if S[n_] == '.':
                rock += 1
            else:
                rock = 0
            if rock >= 3:
                answer=0
                break
    if answer == 0:
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:
N,A,B,C,D = map(int,input().split())
S = ['#']+list(input())
CanReach = True
CanChange = False
for i in range(A,C):
    if S[i] == '#' and S[i+1] == '#':
        CanReach = False
for i in range(B,D):
    if S[i] == '#' and S[i+1] == '#':
        CanReach = False
if C < D:
    CanChange = True
for i in range(B,D+1):
    if S[i-1] == '.' and S[i] == '.' and S[i+1] == '.':
        CanChange = True
if CanReach and CanChange:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

if c<d:
    for i in range(b+1,d):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    
    for i in range(a+1,c):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    print('Yes')
else:
    for i in range(b,min(d+1,n)):
        if s[i]=='#':
            continue

        if s[i-1]=='.' and s[i+1]=='.':
            break
    else:
        print('No')
        exit(0)
    
    for i in range(a+1,c):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    
    for i in range(b+1,d):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    
    print('Yes')

Submission status: Runtime Error

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

if c<d:
    for i in range(b+1,d):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    
    for i in range(a+1,c):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    print('Yes')
else:
    for i in range(b,d+1):
        if s[i]=='#':
            continue

        if s[i-1]=='.' and s[i+1]=='.':
            break
    else:
        print('No')
        exit(0)
    
    for i in range(a,c):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    
    for i in range(b,d):
        if s[i]=='#' and s[i+1]=='#':
            print('No')
            exit(0)
    
    print('Yes')

Submission status: Runtime Error

Solution code:
s=[0]+list(input())
if c<d:
    for i in range(a,d):
        if s[i]==s[i+1]=="#":
            print("No")
            break
    else:
        print("Yes")
else:
    for j in range(a,c):
        if s[j]==s[j+1]=="#":
            print("No")
            break
    else:
        for k in range(b-1,d-2):
            if s[k]==s[k+1]==s[k+2]==".":
                    print("Yes")
                    break
        else:
            print("No")

Submission status: Runtime Error

Solution code:
n,a_start,b_start,a_goal,b_goal = map(int,input().split())
s = input()

no_rock_double = True
for i in range(a_start, b_goal):
    if i < n:
        if s[i] == '#' and s[i+1] == '#':
            no_rock_double = False
can_switch = False
if a_goal > b_goal:
    for i in range(b_start+1, b_goal):
        if i + 1 < n:
            if s[i] == '.' and s[i+1] == '.' and s[i+2] == '.':
                can_switch = True
if a_goal > b_goal:
    if no_rock_double and can_switch:
        print('Yes')
    else:
        print('No')
else:
    if no_rock_double:
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

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

if '##' in s[a-1:d]:
    print('No')
    exit()

if c < d:
    print('Yes')
    exit()

if '...' in s[b-2:d+1]:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

massesExist = True
overtakeFlag = False if C > D else True
proceedableFlag = True

if max(A, B, C, D) > N:
    massesExist = False

for i in range(B, D+1):
    if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
        overtakeFlag = True

for i in range(A, max(C, D)-1):
    if S[i]=="#" and S[i+1]=="#":
        proceedableFlag = False

if overtakeFlag and proceedableFlag and massesExist:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

# c<dの場合
tooi = max(c, d)
for i in range(a, tooi - 1):
    # 二連続石は無理
    if s[i] == '#' and s[i + 1] == '#':
        print('No')
        exit()
# d<cなら飛び越え必要=b~d区間に3マス連続空きが必要
if d < c:
    for i in range(b, d + 1):
        if s[i - 1] == '.' and s[i] == '.' and s[i + 1] == '.':
            print('Yes')
            exit()
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
if c<d and b<c:
  s=s[a-1:d]
elif c>d and b<d:
  t=s[b-1:d]
  s_=s[a-1:c]
elif a<c and c<b and b<d:
  s_=s[a-1:c]
  s=s[b-1:d]
  f=0
  f_=0
  for i in range(len(s_)):
    if s_[i]=='.':
      f=0
    elif s_[i]=='#' and f==0:
      f=1
    elif s_[i]=='#' and f==1:
      print('No')
      exit()
  for j in range(len(s)):
    if s[i]=='.':
      f_=0
    elif s[i]=='#' and f_==0:
      f_=1
    elif s[i]=='#' and f_==1:
      print('No')
      exit()
  print('Yes')
  exit()
if c<d and b<c:
  f=0
  for i in range(len(s)):
    if s[i]=='.':
      f=0
    elif s[i]=='#' and f==0:
      f=1
    elif s[i]=='#' and f==1:
      print('No')
      exit()
  print('Yes')
elif c>d and b<c
  f=0
  g=0
  h='No'
  for i in range(len(s)):
    if s_[i]=='.':
      f=0
    elif s_[i]=='#' and f==0:
      f=1
    elif s_[i]=='#' and f==1:
      print('No')
      exit()
  for j in range(len(t)):
    if t[j]=='.':
      g+=1
      if g==3:
        h='Yes'
    else:
      g=0
  print(h)

Submission status: Runtime Error

Solution code:
n,a,b,c,d=map(int,input().split())
s=input()
if c<d and b<c and not(a<c<b<d):
  s=s[a-1:d]
elif c>d and b<d and not (a<c<b<d):
  t=s[b-1:d]
  s=s[a-1:c]
elif a<c<b<d:
  s_=s[a-1:c]
  s=s[b-1:d]
  f=0
  f_=0
  for i in range(len(s_)):
    if s_[i]=='.':
      f=0
    elif s_[i]=='#' and f==0:
      f=1
    elif s_[i]=='#' and f==1:
      print('No')
      exit()
  for j in range(len(s)):
    if s[i]=='.':
      f_=0
    elif s[i]=='#' and f_==0:
      f_=1
    elif s[i]=='#' and f_==1:
      print('No')
      exit()
  print('Yes')
  exit()
if c<d:
  f=0
  for i in range(len(s)):
    if s[i]=='.':
      f=0
    elif s[i]=='#' and f==0:
      f=1
    elif s[i]=='#' and f==1:
      print('No')
      exit()
  print('Yes')
else:
  f=0
  g=0
  h='No'
  for i in range(len(s)):
    if s[i]=='.':
      f=0
    elif s[i]=='#' and f==0:
      f=1
    elif s[i]=='#' and f==1:
      print('No')
      exit()
  for j in range(t):
    if t[j]=='.':
      g+=1
      if g==3:
        h='Yes'
    else:
      g=0
  print(h)

Submission status: Runtime Error

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

if c < d:
    while b < d:
        if S[b+1] == '.':
            b += 1
        elif b+2 <= d and S[b+2] == '.':
            b += 2
        else:
            print('No')
            exit()
    while a < c:
        if S[a+1] == '.':
            a += 1
        elif a+2 <= c and S[a+2] == '.':
            a += 2
        else:
            print('No')
            exit()
else:
    while a < c:
        if a+1 == b and S[a+2] == '.' :
            a += 2
        elif a+1 == b and S[a+3] == '.' and a+3 <= d:
            b += 2
            a += 1
        elif S[a+1] == '.' and a+1 != b:
            a += 1
        elif a+2 == b and S[a+3] == '.' and a+3 <= d:
            a += 2
            b += 1
        elif a+2 == b and S[a+4] == '.' and a+4 <= d:
            a += 2
            b += 2
        elif S[a+2] == '.' and a+2 != b:
            a += 2
        else:
            print('No')
            exit()
    while b < d:
        if S[b+1] == '.':
            b += 1
        elif b+2 <= d and S[b+2] == '.':
            b += 2
        else:
            print('No')
            exit()
print('Yes')

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,a,b,c,d = readInts()
s = readChar()
if (a-b)*(c-d)<0:
	if "..." in s[max(a,b)-1:] and "##" not in s[min(a,b)]:
		print("Yes")
	else:
		print("No")
elif c<b:
	if "##" not in s[a:c] and "##" not in s[b:d]:
		print("Yes")
	else:
		print("No")
else:
	if "##" not in s[min(a,b):]:
		print("Yes")
	else:
		print("No")
	raise Exception

Submission status: Runtime Error

Solution code:
n,a,b,c,d = map(int,input().split())
S = list(input())
S = ['#'].expand(S)
print(S)

flg = 1
for i in range(a-1,c-2):
    if S[i:i+2] == ['#','#']:
        flg *= 0

for i in range(b-1,d-2):
    if S[i:i+2] == ['#','#']:
        flg *= 0

if c>d:
    flg2 = 0
    for i in range(b-1,d):
        if S[i-1:i+2] == ['.','.','.']:
            flg2 = 1
    flg *= flg2

if flg == 0:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

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

c1=S[B-2:C].count('...')
c2=S[A-1:D].count('##')

if c2>=1:
    print('No')
    exit()
else:
    pass

if C>D:
    if c1==0:
    print('No')
    exit()
    else:
        print('Yes')
        exit()

Submission status: Runtime Error

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,A,B,C,D = I()
maze = s()
Flag = 0
for i in range(A,max(C,D)):
    if maze[i-1:i+1] == '##':
        print('No')
        exit()
if C < D:
    print('Yes')
    exit()
for i in range(B-1,D)
    if maze[i-1:i+2] == '...':
        print('Yes')
        exit()
print('No')