use std::io::{self, BufRead}; fn main() { let input = io::stdin() .lock() .lines() .map(|l| { l.unwrap() .split(' ') .map(std::string::ToString::to_string) .collect::>() }) .collect::>(); let pos = input[0][1].parse::().unwrap() - 1; let chars = input[1][0].chars().enumerate().collect::>(); let part = if chars[pos].1 == '(' { chars.iter().skip(pos).collect::>() } else { chars.iter().take(pos + 1).rev().collect::>() }; let mut diff = 0; for c in part { if c.1 == '(' { diff += 1; } else { diff -= 1; } if diff == 0 { println!("{}", c.0 + 1); break; } } }