using System; using System.Collections.Generic; public class Brackets{ private static void WritePairIndex(List s, int index, char dir){ if(dir == '('){ FindRight(s, index+1, 1); }else if(dir == ')'){ FindLeft(s, index-1, 1); } } private static void FindRight(List s, int index, int cnt){ if(s[index] == '('){ FindRight(s, index+1, cnt+1); }else if(s[index] == ')'){ if(cnt == 1){ Console.WriteLine(index+1); }else{ FindRight(s, index+1, cnt-1); } } } public static void FindLeft(List s, int index, int cnt){ if(s[index] == ')'){ FindLeft(s, index-1, cnt+1); }else if(s[index] == '('){ if(cnt == 1){ Console.WriteLine(index+1); }else{ FindLeft(s, index-1, cnt-1); } } } public static void Main(){ var input = Console.ReadLine(); var inputStr = input.Split(' '); //var n = int.Parse(inputStr[0]); var k = int.Parse(inputStr[1]) - 1; input = Console.ReadLine(); var bracketsArr = input.ToCharArray(); var bracketsList = new List(bracketsArr); var direction = bracketsList[k]; WritePairIndex(bracketsList, k, direction); } }