#include using namespace std; using ll = long long; #define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++) // For debug // Ref: https://qiita.com/ysuzuki19/items/d89057d65284ba1a16ac #define dump(var) do{std::cerr << #var << " : ";view(var);}while(0) template void view(T e){std::cerr << e << "\n";} template void view(const std::vector& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << "\n";} template void view(const std::vector >& vv){ std::cerr << "\n"; for(const auto& v : vv){ view(v); } } template void dump_cout(const T& v) { for(long long i = 0; i < v.size(); i++) std::cout << v[i] << (i == v.size()-1 ? "\n" : " "); } #include using mint = atcoder::modint998244353; void solve() { ll n; string s; cin >> n >> s; bool f = true; for(auto e : s) if(e == '?') f = false; if(f) { cout << (s == string(s.rbegin(), s.rend()) ? 0 : 1) << endl; return; } vector cnt(n, 0); vector ok(n, vector(26, true)); rep(i, 0, n) { if(s[i] == '?') { if(i+1 <= n-1) { if(s[i+1] == '?') cnt[i+1]++; else ok[i][s[i+1] - 'a'] = false; } if(i-1 >= 0) { if(s[i-1] != '?') ok[i][s[i-1] - 'a'] = false; } } for(ll j = 1; i - j >= 0 && i + j <= n-1; j++) { if(s[i-j] == '?' && s[i+j] == '?') { cnt[i+j]++; break; } else if(s[i-j] == '?') { ok[i-j][s[i+j] - 'a'] = false; break; } else if(s[i+j] == '?') { ok[i+j][s[i-j] - 'a'] = false; break; } else if(s[i-j] != s[i+j]) { break; } else { cout << 0 << endl; } } } mint ans = 1; rep(i, 0, n) { if(s[i] != '?') continue; ll tmp = 0; rep(j, 0, 26) if(ok[i][j]) tmp++; tmp -= cnt[i]; ans *= max(0LL, tmp); } cout << ans.val() << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }