#include #include #include #include #define rep(i,n) for(int i=0; i> H >> W; vector X(H); rep(y,H) cin >> X[y]; vector>> dp(H, vector>(W, vector(H+W))); dp[0][0][1] = 1; rep(i,H) rep(j,W) rep(k,H+W) if(dp[i][j][k]){ if(i != H-1 && X[i+1][j] != '#'){ int nx = k + (X[i+1][j] == 'o' ? 1 : -1); if(0 <= nx) dp[i+1][j][nx] += dp[i][j][k]; } if(j != W-1 && X[i][j+1] != '#'){ int nx = k + (X[i][j+1] == 'o' ? 1 : -1); if(0 <= nx) dp[i][j+1][nx] += dp[i][j][k]; } } int ans = 0; rep(i,H+W) ans += dp[H-1][W-1][i]; cout << ans << '\n'; return 0; }