#include #include #include #include #include #include using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; using modint = atcoder::static_modint<998244353>; using Matrix = std::array; Matrix mult(Matrix l, Matrix r){ Matrix res; rep(i,3) rep(j,3) res[(i+j)%3] += l[i] * r[j]; return res; } Matrix add(Matrix l, Matrix r){ Matrix res; rep(i,3) res[i] = l[i] + r[i]; return res; } int main(){ int N; cin >> N; string S; cin >> S; modint ans = 0; Matrix pre; rep(i,N){ pre[0] += 1; Matrix mat; if(S[i] == '?') mat = {4,3,3}; else mat[(S[i]-'0')%3] = 1; pre = mult(pre, mat); ans += pre[0]; } cout << ans.val() << '\n'; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;