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 = Max(c, d);

            var line = ParseArray(s);

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

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


            //Corner case
            //0. 途中で抜かせない場合を考える
            if (needOvertake)
            {
                //抜かせる
                if (
                    !line[(fin1 - 1) + 1]
                    && !line[(fin1 - 1) - 1]
                    )
                {
                    return true;
                }
                //一個目の目的地の一つ前に岩ありの場合，それまでに抜かす必要がある
                if (line[fin1 - 1 - 1])
                {
                    if (MaxContinuousSpace(line.Skip(ini2).Take(fin1 - 1 - ini2)) <= 2) return false;
                }
                //抜かせない
                if (MaxContinuousSpace(line.Skip(ini2).Take(fin1 - ini2)) <= 2) return false;
                //二個目の目的地と一個目の目的地が連続している場合もそれまでに抜かす必要がある:すでに考慮されている
                //if (fin2 - fin1 = 1)
                //{
                //    if(MinContinuousSpace(line.Skip(ini2).Take( ))
                //}
                //二個目の目的地と一個目の目的地の差が2の場合，もそれまでに抜かす必要がある:すでに考慮されている
                //
                //初期位置の問題
                if (ini2 - ini1 == 1)
                {
                    //抜かせない

                }

            }

            //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 MaxContinuousSpace(IEnumerable<bool> vs)
        {
            var l = vs.ToList();
            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;
                    b = item;
                    continue;
                }
                if (!b && !item) { now++; b = item; continue; }

                if (item)
                {
                    max = now > max ? now : max;
                    now = 0;
                    b = item;
                    continue;
                }

            }
            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));

    }
}