#include #include #define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++) using namespace atcoder; using namespace std; typedef long long ll; using mint = modint998244353; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); int h, w; cin >> h >> w; vector s(h); rep(i, 0, h) cin >> s[i]; map, mint> dp; dp[{1, w}] = 1; rep(dist, 1, h + w - 3) { map, mint> ndp; for (auto [p, v] : dp) { int ai = p.first / w, aj = p.first % w; int bi = p.second / w, bj = p.second % w; rep(i, 0, 2) rep(j, 0, 2) { int nai = ai + i, naj = aj + 1 - i; int nbi = bi + j, nbj = bj + 1 - j; if (nai >= h || naj >= w || nbi >= h || nbj >= w) continue; if (s[nai][naj] == '#' || s[nbi][nbj] == '#') continue; if (nai == nbi && naj == nbj) continue; if (nai == bi && naj == bj) continue; if (ai == nbi && aj == nbj) continue; int np = nai * w + naj, nq = nbi * w + nbj; ndp[{np, nq}] += v; } } dp = ndp; } if (dp.size() == 0) { cout << 0 << endl; return 0; } for (auto [p, v] : dp) { cout << v.val() << endl; } }