#include using namespace std; constexpr int mod = 998244353; int dp[200200][3]; int main() { int N; string S; cin >> N >> S; dp[0][0] = 1; int ans = 0; for(int i = 0; i < N; i++) { for(int j = 0; j < 3; j++) { if(S[i] == '?') { for(int k = 0; k < 3; k++) { dp[i+1][(j+k)%3] += 1ll*dp[i][j]*((k == 0)?4:3)%mod; if(dp[i+1][(j+k)%3] >= mod) dp[i+1][(j+k)%3] -= mod; } } else { dp[i+1][(j+S[i]-'0')%3] += dp[i][j]; if(dp[i+1][(j+S[i]-'0')%3] >= mod) dp[i+1][(j+S[i]-'0')%3] -= mod; } } ans += dp[i+1][0]; if(ans >= mod) ans -= mod; dp[i+1][0]++; if(dp[i+1][0] >= mod) dp[i+1][0] -= mod; } cout << ans << endl; }