#include using namespace std; int H, W; int Si, Sj; int Gi, Gj; vector> grid; vector dx = {-1, 0, 1, 0}; vector dy = {0, -1, 0, 1}; int ans = 0; // rinsetu sitete saga 1 yori ookii mono ga attara toomawari siteru? void dfs(int cx, int cy, int t) { if (cx == Gi && cy == Gj) { bool ok = true; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { for (int k = 0; k < 4; k++) { int i2 = i + dx[k]; int j2 = j + dy[k]; if (i2 < 0 || H <= i2) continue; if (j2 < 0 || W <= j2) continue; if (grid[i][j] == -1) continue; if (grid[i2][j2] == -1) continue; if (abs(grid[i][j] - grid[i2][j2]) > 1) ok = false; } } } if (ok) ans++; return; /** bool ok = true; for (int i = 0; i < H - 1; i++) { for (int j = 0; j < W - 1; j++) { if (grid[i][j] == '#' && grid[i][j + 1] == '#' && grid[i + 1][j] == '#' && grid[i + 1][j + 1] == '#') { ok = false; } } } if (ok) ans++; return; **/ } for (int i = 0; i < 4; i++) { int nx = cx + dx[i]; int ny = cy + dy[i]; if (nx < 0 || H <= nx) continue; if (ny < 0 || W <= ny) continue; if (grid[nx][ny] == -1) { grid[nx][ny] = t; dfs(nx, ny, t + 1); grid[nx][ny] = -1; } } } int main() { cin >> H >> W; cin >> Si >> Sj; cin >> Gi >> Gj; Si--, Sj--, Gi--, Gj--; grid.assign(H, vector(W, -1)); grid[Si][Sj] = 0; dfs(Si, Sj, 1); cout << ans << endl; return 0; }