use proconio::marker::*; use proconio::*; use std::collections::*; type Map = BTreeMap; type Set = BTreeSet; type Deque = VecDeque; type Heap = BinaryHeap; const MOD: u64 = 998_244_353; fn main() { input! { n: usize, mut s: Bytes, r: usize, m: usize, } if n & 1 == 1 { println!("-1"); return; } let mut ans = 0usize; let x = s.iter().filter(|c| **c == b'(').count(); if x * 2 > n { let mut d = x - n / 2; for c in s.iter_mut().rev() { if *c == b'(' { *c == b')'; ans += 1; d -= 1; if d == 0 { break; } } } } if x * 2 < n { let mut d = n / 2 - x; for c in s.iter_mut() { if *c == b')' { *c == b'('; ans += 1; d -= 1; if d == 0 { break; } } } } println!("{}", ans); }