using System; using System.Linq; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); string text= Console.ReadLine(); Palen Ans = new Palen(int.Parse(str[0]), text); Ans.calc(); Console.WriteLine(Ans.Ans(int.Parse(str[1])).ToString()); Console.ReadLine(); } class Palen { string Str = String.Empty; int[,] AnsPair; int PairCount=0; int[] StrIndex; public Palen(int StrLength,string ininput) { Str = ininput; AnsPair = new int[2,StrLength / 2]; StrIndex = new int[StrLength]; StrIndex = StrIndex.Select((x, index) => x = index+1).ToArray(); } public void calc() { while (Str!="") { int IndexPair = Str.IndexOf("()"); AnsPair[0, PairCount] = StrIndex[IndexPair]; AnsPair[1, PairCount] = StrIndex[IndexPair + 1]; Str = Str.Substring(0, IndexPair) + Str.Substring(IndexPair + 2);//Str.Length-1 int[] NewStrIndex = new int[StrIndex.Length - 2]; for (int Loop1 = 0; Loop1 < NewStrIndex.Length; Loop1++) { NewStrIndex[Loop1] = Loop1 < IndexPair ? StrIndex[Loop1] : StrIndex[Loop1 + 2]; } StrIndex = NewStrIndex; PairCount++; } } public int Ans(int inIndex) { for (int Loop1 = 0; Loop1 < AnsPair.GetLength(1); Loop1++) { if (inIndex == AnsPair[0,Loop1]) { return AnsPair[1, Loop1]; } if (inIndex == AnsPair[1, Loop1]) { return AnsPair[0, Loop1]; } } return -1; } } }