const MOD: usize = 998244353; const SIZE: usize = 26; fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s = s.trim().chars().collect::>(); let mut dp = vec![vec![0usize; SIZE+1]; SIZE+1]; dp[SIZE][SIZE] = 1; for i in 0..n { let mut next_dp = vec![vec![0usize; SIZE+1]; SIZE+1]; if s[i] == '?' { let mut summary = vec![0usize; SIZE+1]; for pprev in 0..=SIZE { for prev in 0..=SIZE { summary[prev] += dp[pprev][prev]; summary[prev] %= MOD; } } for cur in 0..SIZE { for prev in 0..=SIZE { if prev == cur { continue; } next_dp[prev][cur] = MOD + summary[prev] - dp[cur][prev]; next_dp[prev][cur] %= MOD; } } } else { let idx = s[i] as usize - 'a' as usize; for prev in 0..=SIZE { if prev == idx { continue; } for pprev in 0..=SIZE { if pprev == idx { continue; } next_dp[prev][idx] += dp[pprev][prev]; next_dp[prev][idx] %= MOD; } } } dp = next_dp; } println!("{}", dp.iter().map(|v| v.iter().sum::()).sum::() % MOD); }