#line 1 "main.cpp" #include #include // #include "library/templates/template.hpp" using namespace atcoder; using namespace std; using ll = long long int; using mint = modint998244353; mint solve(int N, string S) { map t; t['.'] = 0; t['d'] = 1; t['k'] = 2; vector> dp(N + 2, vector(3, 0)); dp[0][0] = 1; for (int i = 1; i <= N; i++) { // odd if (i % 2) { if (S[i] == '.') { if (S[i + 1] == '.') { dp[i][0] += dp[i - 1][0]; dp[i][1] += dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2]; dp[i][2] += dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2]; } else { dp[i][0] += dp[i - 1][0]; dp[i][3 - t[S[i + 1]]] += dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2]; } } else { dp[i][t[S[i]]] += dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2]; } } else { if (S[i] == '.') { if (S[i + 1] == '.') { dp[i][0] += dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2]; dp[i][1] += dp[i - 1][1] + dp[i - 1][2]; dp[i][2] += dp[i - 1][1] + dp[i - 1][2]; } else { dp[i][0] += dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2]; dp[i][3 - t[S[i + 1]]] += dp[i - 1][1] + dp[i - 1][2]; } } else { dp[i][t[S[i]]] += dp[i - 1][1] + dp[i - 1][2]; } } } mint ans = 0; for (int k = 0; k < 3; k++) { ans += dp[N - 2][k]; } // cerr << dp << endl; return ans; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); int N; cin >> N; string S = ""; S += "."; for (int i = 0; i < N; i++) { string t; cin >> t; S += t; } S += "."; N = S.length(); auto ans = solve(N, S); std::cout << ans.val() << '\n'; return 0; }