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:
#!/usr/bin/env python
"""<https://github.com/cheran-senthil/PyRival>"""
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()


def solve(s, a, b, c, d):
    if s[d] == '#' or s[c] == '#' or c == d:
        return False
    else:
        def move_a():
            nonlocal a, b
            if s[a + 1] == 46 and b != a + 1:
                a += 1
            elif s[a + 2] == 46 and b != a + 2:
                a += 2
            elif a + 1 == b:
                if move_b():
                    a += 1
                else:
                    return False
            elif a + 2 == b:
                if move_b():
                    a += 2
                else:
                    return False
            else:
                return False
            return True

        def move_b():
            nonlocal a, b
            if s[b + 1] == 46:
                b += 1
                return True
            if s[b + 2] == 46:
                b += 2
                return True
            return False

        if c < d:
            while b < d:
                if not move_b():
                    return False
            if b != d:
                return False
            while a < c:
                if not move_a():
                    return False
            return True
        else:
            while a < c:
                if not move_a():
                    return False
            if b > d:
                return False
            while b < d:
                if not move_b():
                    return False
            return True


def solve_slow(s, a, b, c, d):
    if a == c and b == d:
        return True
    if a > c or b > d:
        return False
    if s[a + 1] == '.' and a + 1 != b:
        if solve_slow(s, a+1, b, c, d):
            return True
    if s[a + 2] == '.' and a + 2 != b:
        if solve_slow(s, a+2, b, c, d):
            return True
    if s[b + 1] == '.' and b + 1 != a:
        if solve_slow(s, a, b + 1, c, d):
            return True
    if s[b + 2] == '.' and b + 2 != a:
        if solve_slow(s, a, b + 2, c, d):
            return True
    return False


def main():
    n, a, b, c, d = read_int_array()
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    s = read() + b'###'
    if solve_slow(s, a, b, c, d):
        print("Yes")
    else:
        print("No")
    # sl, fst = solve_slow(s, a, b, c, d), solve(s, a, b, c, d)
    # print(sl, fst)

def gen_str(opts, n):
    import random
    str = []
    for _ in range(n):
        str.append(opts[random.randrange(0, len(opts))])
    return ''.join(str)


def main2():
    import random
    import itertools
    for _ in range(1000000):
        while True:
            n = random.randint(4, 15)
            a = random.randint(0, n-3)
            b = random.randint(a+1, n-2)
            c = random.randint(a+1, n-1)
            d = random.randint(b+1, n-1)
            if not(a < b and a < c and b < d):
                continue
            s = gen_str('.#', n) + '###'
            if s[a] != '.' or s[b] != '.' or s[c] != '.' or s[d] != '.':
                continue
            sl, fst = solve_slow(s, a, b, c, d), solve(s, a, b, c, d)
            if sl != fst:
                print(sl, fst, s, a, b, c, d)
            else:
                print(s)
                sys.stdout.flush()
            break





# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        if self.buffer.tell():
            return self.buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")


def read():
    return input()


def read_array(sep=None, maxsplit=-1):
    return read().split(sep, maxsplit)


def read_int():
    return int(read())


def read_int_array(sep=None, maxsplit=-1):
    return [int(a) for a in read_array(sep, maxsplit)]

# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = input() + "##"
line = [0 for i in range(len(S))]
for i in range(len(S)):
    line[i] = 0 if S[i]=="." else 1
A -= 1
B -= 1
C -= 1
D -= 1
line[A] = "A"
line[B] = "B"


A_checkin = False
B_checkin = False

while True:
    if (line[A+1] != 0) and (line[A+2] != 0) and(not A_checkin):
        if (line[D-1]=="B" or line[D-2]=="B"):
            B_checkin = True
            line[D] = "B"
            line[B] = 0
            B = D
        elif (line[B+1]==0 and not B_checkin):
            line[B+1] = "B"
            line[B] = 0
            B += 1
        elif (line[B+2]==0 and not B_checkin):
            line[B+2] = "B"
            line[B] = 0
            B += 2
        elif (S[B+1]=="C" and not B_checkin) :
            line[B+1] = "B"
            line[B] = 0
            B += 1
        elif (S[B+2]=="C" and not B_checkin) :
            line[B+2] = "B"
            line[B] = 0
            B += 2
        else:   
            break
    if (line[C-1]=="A" or line[C-2]=="A"):
        line[C] = "A"
        A_checkin = True
        line[A] = 0
        A = C
    
    elif (line[A+2]==0) and (not A_checkin):
        line[A+2] = "A"
        line[A] = 0
        A += 2
    elif (line[A+1]==0) and (not A_checkin):
        line[A+1] = "A"
        line[A] = 0
        A += 1
    else:
        break


while True:
    if (not B_checkin):
        if (line[D-1]=="B" or line[D-2]=="B"):
            B_checkin = True
            line[D] = "B"
            line[B] = 0
            B = D
        elif (line[B+2]==0) and (not B_checkin):
            line[B+2] = "B"
            line[B] = 0
            B += 2
        elif (line[B+1]==0) and (not B_checkin):
            line[B+1] = "B"
            line[B] = 0
            B += 1
        else:
            break
    else:
        break

print("YES" if (A_checkin and B_checkin) else "NO")

Submission status: Wrong Answer

Solution code:
l = list(map(str, input().split()))
str=input()

num = int(l[0])
ast = l[1]
bst = l[2]
afin=int(l[3])
bfin=int(l[4])
if(afin=="#" or bfin=="#"):
    print("No")



if(ast > bst):
    st=int(bst)
    fin=int(ast)
if(bst > ast):
    st=int(ast)
    fin=int(bst)


if(afin > bfin):
    fst=int(bfin)
    ffin=int(afin)
if(bfin > afin):
    fst=int(afin)
    ffin=int(bfin)


kiritorist= str[st+1:num]
kiritorifin=str[fin+1:fst]

if(kiritorist.find('##')>0):
    print("No")

if(kiritorist.find('##')<0):
    if((ast<bst and afin<bfin)or(bst<ast and bfin<afin)):
        print("Yes")

    if((ast<bst and bfin<afin)or(bst<ast and afin<bfin)):
        if(kiritorifin.find('...'))>0:
            print("Yes")
        else:
            print("No")

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[max(0, 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:
import sys
sys.setrecursionlimit(10**9)
W, A, B, C, D = map(int, input().split())
S = [i for i in input()]
action = [1,2,1,2]

def dfs(x, y, field):
    if C-1 == x and D-1 == y:
        return True
    for idx, n in enumerate(action):
        if idx <= 1:
            n += x
            if n < W:
                if n == y:
                    continue
                elif field[n] == "#":
                    continue
                field[x] = "."
                field[n] = "#"
                return dfs(n, y, field)
        else:
            n += y
            if n < W:
                if n == x:
                    continue
                elif field[n] == "#":
                    continue
                field[y] = "."
                field[n] = "#"
                return dfs(x, n, field)
    return False


if dfs(A-1,B-1,S):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(int, input().split())
s = input()
s = s[:max(c, d) + 2]
b_reachable = [b - 1]
current_b = b - 1
while True:
    target = s[current_b + 1:current_b + 3]
    if target == '..':
        b_reachable.extend([current_b + 1, current_b + 2])
        current_b += 2
    elif target == '#.':
        b_reachable.append(current_b + 2)
        current_b += 2
    elif target == '.#':
        b_reachable.append(current_b + 1)
        current_b += 1
    elif target == '.':
        b_reachable.append(current_b + 1)
        current_b += 1
    else:
        break
if c < d:
    if c - 1 in b_reachable and d - 1 in b_reachable:
        print('YES')
    else:
        print('NO')
else:
    if '#..#' in s:
        print('NO')
    else:
        print('YES')

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: A] and '##' in S[0:A]:
        print('No')
    elif '...' in S[D - 1: N] and '##' in S[D - 1: N]:
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
# coding:utf-8


def main():
    N, A, B, C, D = map(int, input().split())
    A -= 1
    B -= 1
    C -= 1
    D -= 1
    iwa = "#"
    S = input()
    ans = True
    canexchange = False

    exchagable_list = []
    for i in range(N-2):
        temps = S[i:i+3]
        if temps == "...":
            exchagable_list.append(i)

    if len(exchagable_list) > 0:
        for i in exchagable_list:
            if i >= A and i+1 <= min(C, D):
                canexchange = True

    # print(canexchange)
    for i in range(N-1):
        if S[i] == iwa and S[i+1] == iwa:
            if C < B and (C < i and i+1 < B):
                pass
            elif not (i+1 < A or i > max(C, D)):
                ans = False

    if ans:
        if C < D:
            ans = True
        elif C > D and canexchange:
            ans = True
        elif C > D and not canexchange:
            if S[D-1] == iwa or S[D+1] == iwa:
                ans = False
            else:
                ans = True

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding; utf 8 -*-
# KenKen race
# 2019. 6/2

import sys


def jump_right(S, current, goal):
    for i in range(current, goal - 1):
        if (S[i+1] == '#' and S[i+2] == '#'):
            return False
    return True

def check_OOO(S, start, end):
    for i in range(start, end - 2):
        if (S[i+1] == "#" and S[i+2] == "#" and S[i+3] == "#"):
            return False
    return True


if __name__ == '__main__':
    N, A, B, C, D = map(int, input().split())
    S = list(input())
    S.insert(0, "")

    if C < D:
        is_hunuke = jump_right(S, B, D)
        if not is_hunuke:
            print("No")
            sys.exit()

        if is_hunuke:
            S[D] = '#'

        is_sunuke = jump_right(S, A, C)
        if not is_sunuke:
            print("No")
            sys.exit()

        if is_sunuke:
            print("Yes")

    else:
        is_AC =jump_right(S, A, C)
        if not is_AC:
            print("No")
            sys.exit()

        is_BD = check_OOO(S, B, D)

        if not is_BD:
            print("No")
            sys.exit()
        else:
            print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from copy import copy
import numpy as np
from numpy.fft import fft, ifft
from fractions import gcd


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


def INT(): return int(input())


def MAP(): return map(int, input().split())


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


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

n, a, b, c, d = MAP()
s = list(input())

lis3  =[]
ct_iwa=0

tmp3 = []
tmp_iwa=[]
for i in range(n):
    #print(s[i])
    if s[i] =='.':
        tmp3.append(i)
        if len(tmp_iwa) > 1:
            ct_iwa += 1
            
        tmp_iwa.clear()
    else:
        tmp_iwa.append(1)
        if len(tmp3) > 2:
            tmp=tmp3.copy()
            lis3.append(tmp)
               
        tmp3.clear()
    
    #print(tmp3)


if len(tmp3) > 2:
    lis3.append(tmp3)
if len(tmp_iwa) > 1:
    ct_iwa += 1

#print(lis3, ct_iwa)

flag=0

if c < d:
    #print('1')
    if ct_iwa == 0:
        print('Yes')
    else:
        print('No')
else:
    #print('2')
    for x in lis3:
        if b - 1 < x[-1] and x[0] < d - 1 and ct_iwa == 0:
            print('Yes')
            flag = 1
            break

    if flag == 0:
        print('No')

Submission status: Wrong Answer

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

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


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

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

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

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

Submission status: Wrong Answer

Solution code:
n, a, b, c, d = map(int, input().split())
s = input()
s_flag = False
can_flag = True
count = 0
m = max(c, d)
for i in range(m):
  if s[i] == '#':
    count = 0
    if s_flag:
      can_flag = False
      break
    s_flag = True

  else:
    s_flag = False
    count += 1
if count <= 2:
  if c > d:
    can_flag = False

if can_flag:
  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()

a_to_c = s[a-1:c-1]
b_to_d = s[b-1:d-1]
b_to_d2 = s[b-2:c-1]    

possibility = True

if a_to_c.find("##")!=-1 or b_to_d.find("##")!=-1:
    possibility = False
if c>d:
    if not(b_to_d2.find('...')!=-1):
        possibility = False

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

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int, input().split())
s = input()
index = [(n+1) for n, v in enumerate(s) if s[n:n+3] == "..."]

if s.count("##")>=1:
    print("No")
    exit()

if C < D:
    print("Yes")

elif C > D:
    if len(index)>=1:
        for i in index:
            if A <= i and B <= i+1 and i+2<=C and i+1<=D:
                print("Yes")
                exit()
        print("No")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
# sample code

v = list(map(int, input().split()))
n, a, b, c, d = v[0], v[1], v[2], v[3], v[4]
s = input()

ac_cnt_1, ac_max_1 = 0, 0
bd_cnt_1, bd_max_1 = 0, 0
bd_cnt_0, bd_max_0 = 0, 0

for i in range(c-a-1):
	if s[i+a] == '#':
		ac_cnt_1 += 1
		if ac_max_1 < ac_cnt_1:
			ac_max_1 = ac_cnt_1
	else:
		ac_cnt_1 = 0
for i in range(d-b-1):
	if s[i+b] == '#':
		bd_cnt_0 = 0
		bd_cnt_1 += 1
		if bd_max_1 < bd_cnt_1:
			bd_max_1 = bd_cnt_1
	else:
		bd_cnt_0 += 1
		bd_cnt_1 = 0
		if bd_max_0 < bd_cnt_0:
			bd_max_0 = bd_cnt_0
if c < b:
	if (ac_max_1 <= 1) and (bd_max_1 <= 1):
		print('Yes')
	else:
		print('No')
elif c < d:
	if (ac_max_1 <= 1) and (bd_max_1 <= 1):
		print('Yes')
	else:
		print('No')
else:
	if (ac_max_1 <= 1) and (bd_max_1 <= 1) and (bd_max_0 >= 3):
		print('Yes')
	else:
		print('No')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
"""<https://github.com/cheran-senthil/PyRival>"""
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()


def solve(s, a, b, c, d):
    if s[d] == '#' or s[c] == '#' or c == d:
        return False
    else:
        def move_a():
            nonlocal a, b
            if s[a + 1] == 46 and b != a + 1:
                a += 1
            elif s[a + 2] == 46 and b != a + 2:
                a += 2
            elif a + 1 == b:
                if move_b():
                    a += 1
                else:
                    return False
            elif a + 2 == b:
                if move_b():
                    a += 2
                else:
                    return False
            else:
                return False
            return True

        def move_b():
            nonlocal a, b
            if s[b + 1] == 46:
                b += 1
                return True
            if s[b + 2] == 46:
                b += 2
                return True
            return False

        if c < d:
            while b < d:
                if not move_b():
                    return False
            if b != d:
                return False
            while a < c:
                if not move_a():
                    return False
            return True
        else:
            while a < c:
                if not move_a():
                    return False
            if b > d:
                return False
            while b < d:
                if not move_b():
                    return False
            return True


def solve_slow(s, a, b, c, d):
    if a == c and b == d:
        return True
    if a > c or b > d:
        return False
    if s[a + 1] == '.' and a + 1 != b:
        if solve_slow(s, a+1, b, c, d):
            return True
    if s[a + 2] == '.' and a + 2 != b:
        if solve_slow(s, a+2, b, c, d):
            return True
    if s[b + 1] == '.' and b + 1 != a:
        if solve_slow(s, a, b + 1, c, d):
            return True
    if s[b + 2] == '.' and b + 2 != a:
        if solve_slow(s, a, b + 2, c, d):
            return True
    return False


def main():
    n, a, b, c, d = read_int_array()
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    s = read() + b'###'
    if solve_slow(s, a, b, c, d):
        print("YES")
    else:
        print("NO")
    # sl, fst = solve_slow(s, a, b, c, d), solve(s, a, b, c, d)
    # print(sl, fst)

def gen_str(opts, n):
    import random
    str = []
    for _ in range(n):
        str.append(opts[random.randrange(0, len(opts))])
    return ''.join(str)


def main2():
    import random
    import itertools
    for _ in range(1000000):
        while True:
            n = random.randint(4, 15)
            a = random.randint(0, n-3)
            b = random.randint(a+1, n-2)
            c = random.randint(a+1, n-1)
            d = random.randint(b+1, n-1)
            if not(a < b and a < c and b < d):
                continue
            s = gen_str('.#', n) + '###'
            if s[a] != '.' or s[b] != '.' or s[c] != '.' or s[d] != '.':
                continue
            sl, fst = solve_slow(s, a, b, c, d), solve(s, a, b, c, d)
            if sl != fst:
                print(sl, fst, s, a, b, c, d)
            else:
                print(s)
                sys.stdout.flush()
            break





# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        if self.buffer.tell():
            return self.buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")


def read():
    return input()


def read_array(sep=None, maxsplit=-1):
    return read().split(sep, maxsplit)


def read_int():
    return int(read())


def read_int_array(sep=None, maxsplit=-1):
    return [int(a) for a in read_array(sep, maxsplit)]

# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
A = input() 
found = False
count = 0
while not found:
    n = A.count("ABC")
    if n == 0:
        found = True
    else:
        count += n
        A = A.replace("ABC","BCA")
print(count)

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 < C:
            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:
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def SI(): return input()

N,A,B,C,D=LI()
st=input()

if C < D:
    if st[A:C].find('##') >= 0 or st[B:D].find('##') >= 0:
        print('No')
    else:
        print('Yes')
else:
    # Cの方がおおきいケース 入れ替わる
    if st[A:C].find('##') >= 0:
        print('No')
    else:
        fnd = st.find('...', A-1, D+1)
        if fnd >= 0:
            if fnd+1 == B or fnd+3 == B:
                fnd = st.find('...', fnd+1, D+1)
                if fnd >= 0:
                    if fnd+3 == D:
                        print('No')
                    else:
                        print('Yes')
                else:
                    print('No')
            else:
                print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

Solution code:
n, a_, b_, c_, d_ = map(int, input().split())
s_ = input()

def unchi(a,b,c,d,s):
  ss, s = s, s[:b] + '#' + s[b+1:]
    
  if (len(max(s[b:d].split("."))) < 2):
    b = d
    s = s[:b] + '#' + s[b+1:]
  
  s = ss
  if(len(max(s[a:c].split("."))) < 2):
    a = c
    s = s[:a] + '#' + s[a+1:]
  
  if(a==c and b==d):
    print("Yes")
  else:
    print("No")
    
if (c_ < d_):
  unchi(a_-1,b_-1,c_-1,d_-1,s_)
else:
  unchi(b_-1,a_-1,d_-1,c_-1,s_)

Submission status: Wrong Answer

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from copy import copy
import numpy as np
from numpy.fft import fft, ifft
from fractions import gcd


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


def INT(): return int(input())


def MAP(): return map(int, input().split())


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


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

n, a, b, c, d = MAP()
s = list(input())

lis3  =[]
ct_iwa=0

tmp3 = []
tmp_iwa=[]
for i in range(n):
    #print(s[i])
    if s[i] =='.':
        tmp3.append(i)
        if len(tmp_iwa) > 1:
            ct_iwa += 1
            
        tmp_iwa.clear()
    else:
        tmp_iwa.append(1)
        if len(tmp3) > 2:
            tmp=tmp3.copy()
            lis3.append(tmp)
               
        tmp3.clear()
    
    #print(tmp3)


if len(tmp3) > 3:
    lis3.append(tmp3)
if len(tmp_iwa) > 1:
    ct_iwa += 1

#print(lis3, ct_iwa)

flag=0

if c < d:
    #print('1')
    if ct_iwa == 0:
        print('Yes')
    else:
        print('No')
else:
    #print('2')
    for x in lis3:
        if b - 1 < x[-1] and x[0] < d - 1 and ct_iwa == 0:
            print('Yes')
            flag = 1
            break

    if flag == 0:
        print('No')