#include #include using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define FAST_IO \ ios::sync_with_stdio(false); \ cin.tie(0); const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<998244353>; int main() { FAST_IO auto ans = 0LL; int H, W; cin >> H >> W; vector S(H); for (auto& x : S) cin >> x; int m = H + W - 1; vector dp(2, vector(H, vector(H, Modint(0)))); dp[1][1][0] = 1; for (int i = 1; i < m; i++) { int from = i & 1; int to = 1 - from; for (int j = 0; j < H; j++) { for (int k = 0; k < H; k++) { dp[to][j][k] = 0; if (j > i || k > i) continue; if (S[j][i - j] != '.' || S[k][i - k] != '.') continue; if (i < m - 1 && j == k) continue; if (j > 0 && k > 0) { dp[to][j][k] += dp[from][j - 1][k - 1]; } if (j > 0) { dp[to][j][k] += dp[from][j - 1][k]; } if (k > 0) { dp[to][j][k] += dp[from][j][k - 1]; } dp[to][j][k] += dp[from][j][k]; } } } cout << dp[m & 1][H - 1][H - 1].val() << endl; }