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

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

namespace AGC034.A
{
    using System.Collections.Generic;
    using System.Linq;
    using static System.Console;

    using static System.Math;

    public class Program
    {
        public static void Main(string[] args)
        {
            var l = ReadInputsAsInt().ToList();

            var n = l[0];
            var a = l[1];
            var b = l[2];
            var c = l[3];
            var d = l[4];

            var s = ReadLine();

            WriteLine(Solve(n, a, b, c, d, s) ? "Yes" : "No");
        }


        public static bool Solve(int n, int a, int b, int c, int d, string s)
        {
            var needOvertake = (a < b && c > d) || (a > b || c < d);
            var ini1 = Min(a, b);
            var ini2 = Max(a, b);
            var fin1 = Min(c, d);
            var fin2 = Min(c, d);

            var line = ParseArray(s);

            //岩が全くない場合
            if (line.Skip(Min(a, b)).Take(Max(c, d) - Min(a, b)).All(r => !r)) return true;


            //岩が二連続である場合：移動できない
            if (MaxConsec(line.Skip(Min(a, b)).Take(Max(c, d) - Min(a, b))) >= 2) return false;


            //Corner case
            //0. 途中で抜かせない場合
            if (needOvertake)
            {
                //抜かせない
                if (MaxConsec(line.Skip(ini2).Take(fin1 - ini2)) > 2) return false;
                //一個目の目的地の一つ前に岩ありの場合，それまでに抜かす必要がある
                if (line[fin1 - 1 - 1])
                {
                    if (MinContinuousSpace(line.Skip(ini2).Take(fin1 - 1 - ini2)) < 3) return false;
                }
            }

            //1. 近いほうの直前に岩ある場合，途中で抜かさなければいけない

            return true;
        }

        public static int MaxConsec(IEnumerable<bool> vs)
        {
            int max = 0;
            int now = 0;
            bool b = false;
            foreach (var item in vs)
            {
                if (!b && item)
                {
                    now = 1;
                }
                if (b && item) now++;

                if (!item)
                {
                    max = now > max ? now : max;
                    now = 0;
                }
            }
            max = now > max ? now : max;
            return max;
        }
        public static int MinContinuousSpace(IEnumerable<bool> vs)
        {
            if (MaxConsec(vs) > 1) return 0;
            int max = 0;
            int now = 0;
            bool b = true;
            foreach (var item in vs)
            {
                if (b && !item)
                {
                    now = 1;
                }
                if (!b && !item) now++;

                if (item)
                {
                    max = now < max ? now : max;
                    now = 0;
                }
            }
            max = now > max ? now : max;
            return max;
        }

        public static List<bool> ParseArray(string s) => s.Select(c => c == '#').ToList();

        static IEnumerable<int> ReadInputsAsInt() => ReadLine().Split(' ').Select(x => int.Parse(x));

    }
}