#include #include #define pass (void)0 #define INF (1<<30)-1 #define INFLL (1LL<<60)-1 using namespace std; using namespace atcoder; using mint = modint998244353; using ll = long long; int H, W, sh, sw, gh, gw, ans = 0; vector> visited; vector> direction = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; bool judge() { deque> que; que.push_back({gh, gw}); vector> dist(H, vector(W, -1)); dist[gh][gw] = visited[gh][gw]; while (!que.empty()) { auto [h, w] = que.front(); que.pop_front(); if (h == sh && w == sw) return true; for (auto [dh, dw] : direction) { int nh = h + dh, nw = w + dw; if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (visited[nh][nw] != -1 && visited[h][w] - 1 > visited[nh][nw]) return false; if (visited[nh][nw] != -1 && dist[nh][nw] == -1) { dist[nh][nw] = dist[h][w] - 1; que.push_back({nh, nw}); } } } return false; } void dfs(int h, int w, int cnt) { visited[h][w] = cnt; cnt++; if (h == gh && w == gw) { if (judge()) ans++; visited[h][w] = -1; return; } for (auto [dh, dw] : direction) { int nh = h + dh, nw = w + dw; if (nh >= 0 && nh < H && nw >= 0 && nw < W && visited[nh][nw] == -1) { dfs(nh, nw, cnt); } } visited[h][w] = -1; } int main() { cin >> H >> W; cin >> sh >> sw; cin >> gh >> gw; sh--, sw--, gh--, gw--; visited.resize(H, vector(W, -1)); dfs(sh, sw, 0); cout << ans << endl; return 0; }