#include #include using Int = long long; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main() { int H, W; std::cin >> H >> W; int Si, Sj; std::cin >> Si >> Sj; --Si; --Sj; int Gi, Gj; std::cin >> Gi >> Gj; --Gi; --Gj; int ans = 0; std::vector vis(H, std::vector(W, false)); auto dfs = [&](auto dfs, int x, int y) { if (x < 0 || y < 0 || x >= H || y >= W ||vis[x][y]) return; int cnt = 0; for (int i = 0; i < 4; ++i) { int xx = x + dx[i]; int yy = y + dy[i]; if (xx < 0 || yy < 0 || xx >= H || yy >= W) continue; if (vis[xx][yy]) { ++cnt; } } if (cnt > 1) return; if (x == Gi && y == Gj) { ++ans; return; } vis[x][y] = true; for (int i = 0; i < 4; ++i) { dfs(dfs, x + dx[i], y + dy[i]); } vis[x][y] = false; }; dfs(dfs, Si, Sj); std::cout << ans << std::endl; }