fn main() { let vec: Vec = read_vec(); let (len, index_1org) = (vec[0], vec[1]); let chars: Vec = read::().chars().collect(); let mut ans_1org: usize = 0; match chars[index_1org - 1] { '(' => { let mut prev_char: char = '('; let mut indent_lv = 0u32; for i_0org in index_1org..len { match (chars[i_0org], prev_char) { ( '(', '(' ) => { indent_lv += 1; }, ( ')', ')') => { indent_lv -= 1; }, _ => {} } prev_char = chars[i_0org]; if indent_lv == 0 { ans_1org = i_0org + 1; break; } } }, ')' => { let mut prev_char: char = ')'; let mut indent_lv = 0u32; for i_0org in (0..index_1org-1).rev() { match (chars[i_0org], prev_char) { ( '(', '(' ) => { indent_lv -= 1; }, ( ')', ')') => { indent_lv += 1; }, _ => {} } prev_char = chars[i_0org]; if indent_lv == 0 { ans_1org = i_0org + 1; break; } } }, _ => { println!("error"); } } println!("{}", ans_1org); } fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec() -> Vec { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().split_whitespace() .map(|e| e.parse().ok().unwrap()).collect() }