use proconio::{input, marker::Chars}; type Mint = modint::ModInt998244353; fn main() { input! { n: usize, s: Chars, } let m = n / 2; let mut fact = vec![Mint::new(1); m + 1]; let mut finv = vec![Mint::new(1); m + 1]; for i in 2..=m { fact[i] = fact[i - 1] * i; } finv[m] = fact[m].inv(); for i in (2..=m).rev() { finv[i - 1] = finv[i] * i; } let binom = |n: usize, k: usize| { if k > n { Mint::new(0) } else { fact[n] * finv[k] * finv[n - k] } }; let is_type_a = (0..n / 2).all(|i| s[i] == '('); let ans = if is_type_a { (0..=m) .map(|i| { let x = binom(m, i); x * x }) .reduce(|acc, e| acc + e) .unwrap() } else { Mint::new(2).pow(m as u64) }; println!("{}", ans); } #[allow(dead_code)] mod modint { use std::{ fmt::{Debug, Display}, iter::{Product, Sum}, ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}, str::FromStr, }; pub type ModInt998244353 = ModInt<998244353>; pub type ModInt1000000007 = ModInt<1000000007>; type Val = u64; #[derive(Clone, Copy, PartialEq, Eq)] pub struct ModInt { val: Val, } impl ModInt { const IS_PRIME: bool = is_prime(M as u32); pub const fn modulus() -> Val { M } pub const fn new(val: Val) -> Self { assert!(M < (1 << 31)); Self { val: val.rem_euclid(M), } } pub const fn new_unchecked(val: Val) -> Self { Self { val } } pub const fn val(&self) -> Val { self.val } pub fn pow(self, mut exp: u64) -> Self { let mut result = Self::new(1); let mut base = self; while exp > 0 { if exp & 1 == 1 { result *= base; } base *= base; exp >>= 1; } result } pub fn inv(self) -> Self { assert!(Self::IS_PRIME); self.pow(M as u64 - 2).into() } } impl Display for ModInt { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.val) } } impl Debug for ModInt { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.val) } } impl FromStr for ModInt { type Err = std::num::ParseIntError; fn from_str(s: &str) -> Result { let value = s.parse::()?; Ok(ModInt::new(value)) } } impl Neg for ModInt { type Output = Self; fn neg(mut self) -> Self::Output { if self.val > 0 { self.val = M - self.val; } self } } impl>> AddAssign for ModInt { fn add_assign(&mut self, rhs: T) { self.val += rhs.into().val; if self.val >= M { self.val -= M; } } } impl>> SubAssign for ModInt { fn sub_assign(&mut self, rhs: T) { self.val = self.val.wrapping_sub(rhs.into().val); if self.val > M { self.val = self.val.wrapping_add(M); } } } impl>> MulAssign for ModInt { fn mul_assign(&mut self, rhs: T) { self.val = self.val * rhs.into().val % M; } } impl>> DivAssign for ModInt { fn div_assign(&mut self, rhs: T) { *self *= rhs.into().inv(); } } macro_rules! impl_binnary_operators { ($({ $trait: ident, $trait_assign: ident, $fn: ident, $fn_assign: ident, $type: ty }),*) => {$( impl> $trait for $type { type Output = $type; fn $fn(mut self, rhs: T) -> $type { self.$fn_assign(rhs.into()); self } } impl $trait<&$type> for $type { type Output = $type; fn $fn(self, rhs: &$type) -> $type { self.$fn(*rhs) } } impl> $trait for &$type { type Output = $type; fn $fn(self, rhs: T) -> $type { (*self).$fn(rhs.into()) } } impl $trait<&$type> for &$type { type Output = $type; fn $fn(self, rhs: &$type) -> $type { (*self).$fn(*rhs) } } impl $trait_assign<&$type> for $type { fn $fn_assign(&mut self, rhs: &$type) { *self = self.$fn(*rhs); } } )*}; } impl_binnary_operators!( {Add, AddAssign, add, add_assign, ModInt}, {Sub, SubAssign, sub, sub_assign, ModInt}, {Mul, MulAssign, mul, mul_assign, ModInt}, {Div, DivAssign, div, div_assign, ModInt} ); impl Sum for ModInt { fn sum>(iter: I) -> Self { iter.fold(Self::new(0), Add::add) } } impl Product for ModInt { fn product>(iter: I) -> Self { iter.fold(Self::new(1), Mul::mul) } } impl<'a, const M: Val> Sum<&'a Self> for ModInt { fn sum>(iter: I) -> Self { iter.fold(Self::new(0), Add::add) } } impl<'a, const M: Val> Product<&'a Self> for ModInt { fn product>(iter: I) -> Self { iter.fold(Self::new(1), Mul::mul) } } macro_rules! impl_rem_euclid_signed { ($($ty:tt),*) => { $( impl From<$ty> for ModInt { fn from(value: $ty) -> ModInt { Self::new_unchecked((value as i64).rem_euclid(M as i64) as Val) } } )* }; } impl_rem_euclid_signed!(i8, i16, i32, i64, isize); macro_rules! impl_rem_euclid_unsigned { ($($ty:tt),*) => { $( impl From<$ty> for ModInt { fn from(value: $ty) -> ModInt { Self::new_unchecked((value as u64).rem_euclid(M as u64) as Val) } } )* }; } impl_rem_euclid_unsigned!(u8, u16, u32, u64, usize); const fn is_prime(n: u32) -> bool { const fn is_sprp(n: u32, a: u32) -> bool { let (n, a) = (n as u64, a as u64); let mut d = n >> (n - 1).trailing_zeros(); let mut y = { let (mut res, mut base, mut e) = (1, a, d); while e > 0 { if e & 1 == 1 { res = res * base % n; } base = base * base % n; e >>= 1; } res }; while d != n - 1 && y != 1 && y != n - 1 { y = y * y % n; d <<= 1; } y == n - 1 || d & 1 == 1 } if matches!(n, 2 | 7 | 61) { return true; } if n <= 1 || n % 2 == 0 { return false; } is_sprp(n, 2) && is_sprp(n, 7) && is_sprp(n, 61) } }