/* -*- coding: utf-8 -*- * * 1646.cc: No.1646 Avoid Palindrome - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 50000; const int MOD = 998244353; /* typedef */ /* global variables */ char s[MAX_N + 4]; int dp[MAX_N + 1][26][26]; /* subroutines */ inline void addmod(int &a, int b) { a = (a + b) % MOD; } /* main */ int main() { int n; scanf("%d%s", &n, s); if (n == 1) { printf("%d\n", (s[0] == '?') ? 26 : 1); return 0; } if (s[0] == '?') { for (int s0 = 0; s0 < 26; s0++) { if (s[1] == '?') for (int s1 = 0; s1 < 26; s1++) dp[2][s0][s1] = (s0 != s1) ? 1 : 0; else { int s1 = s[1] - 'a'; dp[2][s0][s1] = (s0 != s1) ? 1 : 0; } } } else { int s0 = s[0] - 'a'; if (s[1] == '?') for (int s1 = 0; s1 < 26; s1++) dp[2][s0][s1] = (s0 != s1) ? 1 : 0; else { int s1 = s[1] - 'a'; dp[2][s0][s1] = (s0 != s1) ? 1 : 0; } } for (int i = 2; i < n; i++) for (int s0 = 0; s0 < 26; s0++) for (int s1 = 0; s1 < 26; s1++) if (dp[i][s0][s1] > 0) { if (s[i] == '?') for (int s2 = 0; s2 < 26; s2++) { if (s0 != s2 && s1 != s2) addmod(dp[i + 1][s1][s2], dp[i][s0][s1]); } else { int s2 = s[i] - 'a'; if (s0 != s2 && s1 != s2) addmod(dp[i + 1][s1][s2], dp[i][s0][s1]); } } int sum = 0; for (int s0 = 0; s0 < 26; s0++) for (int s1 = 0; s1 < 26; s1++) addmod(sum, dp[n][s0][s1]); printf("%d\n", sum); return 0; }