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)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;

namespace AtCoder_1
{
    class Program
    {
        static void Main(string[] args)
        {
            var temp = CinTAr();
            var S = Cin();

            int N = temp[0];
            int A = temp[1] -1;
            int B = temp[2] -1 ;
            int C = temp[3] -1 ;
            int D = temp[4]-1;


           // StringBuilder DBS = new StringBuilder(S);
            bool[] can = new[] { false, false };
            //DBS[A] = 'A';
            //DBS[B] = 'B';
            //Cout(DBS);

            bool BHelp = false;
            bool AHelp = false;
            if(Regex.IsMatch(S.Substring(Math.Min(A,B), Math.Max(C,D) - Math.Min(A, B) + 1), "##"))
            {
                Cout("No");
            }

            while (true)
            {
                int Av = (A < C) ? 1 : -1;
                int Bv = (B < D) ? 1 : -1;
                bool flg = false;
                if (A != C)
                {
                    if (A + 2 * Av != B && A + 2 * Av < N && A + 2 * Av > -1 && S[A + 2 * Av] != '#')
                    {
                        //DBS[A] = '.';
                        A += 2 * Av;
                        flg = true;
                       //DBS[A] = 'A';
                    }
                    else if (A + 1 * Av != B && A + 1 * Av < N && A + 1 * Av > -1 && S[A + 1 * Av] != '#')
                    {
                        //DBS[A] = '.';
                        A += 1 * Av;
                        flg = true;
                        //DBS[A] = 'A';
                    }else if(B == D && !AHelp && A !=C)
                    {
                        flg = true;
                        AHelp = true;
                    }
                }
                else
                {
                    if (!BHelp && !AHelp)
                    {
                        can[0] = true;
                    }
                    else
                    {
                        for (int i = -1; i < 2; i += 2) {
                            if (A + 2 * i != B && A + 2 * i < N && A + 2 * i > -1 && S[A + 2 * i] != '#')
                            {
                                //DBS[A] = '.';
                                A += 2 * i;
                                flg = true;
                                BHelp = false;
                                //DBS[A] = 'A';
                            }
                            else if (A + 1 * i != B && A + 1 * i < N && A + 1 * i > -1 && S[A + 1 * i] != '#')
                            {
                                //DBS[A] = '.';
                                A += 1 * i;
                                flg = true;
                                BHelp = false;
                                //DBS[A] = 'A';
                            }
                        }
                    }
                }
                if (B != D)
                {
                    if (B + 2 *Bv!= A && B + 2 * Bv < N && B + 2 * Bv > -1 && S[B + 2 * Bv] != '#')
                    {
                        //DBS[B] = '.';
                        B += 2 * Bv;
                        flg = true;
                        //DBS[B] = 'B';
                    }
                    else if (B + 1 * Bv != A && B + 1 * Bv < N && B + 1 * Bv > -1 && S[B + 1 * Bv] != '#')
                    {
                        //DBS[B] = '.';
                        B += 1 * Bv;
                        flg = true;
                        //DBS[B] = 'B';
                    }
                    else if(A ==C && B != D)
                    {
                        if (!BHelp)
                        {
                            flg = true;
                            BHelp = true;
                        }
                    }
                }
                else
                {
                    if (!AHelp && !BHelp)
                    {
                        can[1] = true;
                    }
                    else
                    {
                        for (int i = -1; i < 2; i += 2)
                        {
                            if (B + 2 * i != A && B + 2 * i < N && B + 2 * i > -1 && S[B + 2 * i] != '#')
                            {
                                //DBS[B] = '.';
                                B+= 2 * i;
                                flg = true;
                                AHelp = false;
                                //DBS[B] = 'B';
                            }
                            else if (B + 1 * i != A && B + 1 * i < N && B + 1 * i > -1 && S[B + 1 * i] != '#')
                            {
                                //DBS[B] = '.';
                                B += 1 * i;
                                flg = true;
                                AHelp = false;
                                //DBS[B] = 'B';
                            }
                        }
                    }
                }
               // Cout(DBS);

                if(AHelp && BHelp) { break; }
                if (!flg) { break; }

            }
            if (can[0] && can[1])
            {
                Cout("Yes");
            }
            else
            {
                Cout("No");
            }
            Cin();
        }

        static readonly int MOD1E9 = (int)1e9 + 7;
        static string Cin() { return ReadLine(); }
        static string[] CinAr() { return ReadLine().Split(' '); }
        static int CinT() { return S2i(Cin()); }
        static int[] CinTAr() { return CinAr().Select((x, i) => { return S2i(x); }).ToArray(); }
        static long CinL() { return S2L(Cin()); }
        static long[] CinLAr() { return CinAr().Select((x, i) => { return S2L(x); }).ToArray(); }
        static double CinD() { return S2D(Cin()); }
        static double[] CinDAr() { return CinAr().Select((x, i) => { return S2D(x); }).ToArray(); }
        static int S2i(string s) { return int.Parse(s); }
        static long S2L(string s) { return long.Parse(s); }
        static double S2D(string s) { return double.Parse(s); }
        static void Cout(object s) { WriteLine(s); }
        /// <summary>
        /// Debug時のみの使用を推奨
        /// </summary>
        /// <typeparam name="Type"></typeparam>
        /// <param name="types"></param>
        static void CoutAr<Type>(IEnumerable<Type> types)
        {
            string text = "";
            foreach (var i in types)
            {
                text += " " + i;
            }
            WriteLine(text.Substring(1));
        }
    }
}