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[prev][pprev]; summary[prev] %= MOD; } } for prev in 0..=SIZE { for cur in 0..SIZE { if prev == cur { continue; } next_dp[cur][prev] = MOD + summary[prev] - dp[prev][cur]; next_dp[cur][prev] %= MOD; } } } else { let cur = s[i] as usize - 'a' as usize; for pprev in 0..=SIZE { if cur == pprev { continue; } for prev in 0..=SIZE { if cur == prev { continue; } next_dp[cur][prev] += dp[prev][pprev]; next_dp[cur][prev] %= MOD; } } } dp = next_dp; } println!("{}", dp.iter().map(|v| v.iter().sum::()).sum::() % MOD); }