#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; using ll = long long; using pint = pair; #include"atcoder/modint" using mint = atcoder::modint998244353; ostream &operator<<(std::ostream &os,const mint &p){return os << p.val();} istream &operator>>(std::istream &is, mint &a){int64_t x;is >> x;a = mint(x);return (is);} int main() { int N; cin >> N; string s; cin >> s; if(N == 1) { if(s[0] == '?') cout << 26 << endl; else cout << 1 << endl; return 0; } constexpr int AL = 26; for(auto &i : s) { i = (i == '?' ? AL : i - 'a'); } vector>> dp(N + 1, vector>(AL, vector(AL))); for(int i = 0; i < AL; i++) { for(int j = 0; j < AL; j++) { dp[2][i][j] = (s[0] == i || s[0] == AL) && (s[1] == j || s[1] == AL); if(i == j)dp[2][i][j] = 0; } } for(int i = 2; i < N; i++) { for(int f = 0; f < AL; f++) { if(s[i - 2] != AL && s[i - 2] != f)continue; for(int p = 0; p < AL; p++) { if(s[i - 1] != AL && s[i - 1] != p)continue; if(s[i] != AL){ if(f != s[i] && p != s[i])dp[i + 1][p][s[i]] += dp[i][f][p]; } else { for(int j = 0; j < AL; j++) { if(f != j && p != j) { dp[i + 1][p][j] += dp[i][f][p]; } } } } } } mint sum = 0; for(int i = 0; i < AL; i++) { if(s[N - 2] != AL && s[N - 2] != i) continue; for(int j = 0; j < AL; j++) { if(s[N - 1] != AL && s[N - 1] != j) continue; sum += dp[N][i][j]; } } cout << sum << endl; }