#include #include #define chmin(x,y) (x) = min((x),(y)) #define chmax(x,y) (x) = max((x),(y))z using namespace std; using namespace atcoder; using ll = long long; const ll mod = 998244353; using mint = modint998244353; using Graph = vector>>; const vector dx = {1,0,-1,0}, dy = {0,1,0,-1}; double dist(int x1, int y1, int x2, int y2){ double res = (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2); return sqrt(res); } ll need(ll n, ll m){ ll res = 0; if(n < 0) return res; res = n / m; if(n % m > 0) res++; return res; } ll d2(ll x1, ll y1, ll x2, ll y2){ // auto [x1,y1] = p; // auto [x2,y2] = q; ll res = (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2); return res; } int main(){ // input int H,W; cin >> H >> W; int si,sj,gi,gj; cin >> si >> sj >> gi >> gj; --si, --sj, --gi, --gj; // solve int ans = 0; // const pair dummy = {-1,-1}; //queue>> q; queue> q; q.emplace(si*W+sj,0LL); while(!q.empty()){ auto[now,cant] = q.front(); q.pop(); int x = now / W, y = now % W; ll nxt_cant = cant; for(int i = 0; i < 4; i++){ int nx = x + dx[i], ny = y + dy[i]; if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue; // grid hamidashi ll pos = 1LL << (nx * W + ny); nxt_cant |= pos; } for(int i = 0; i < 4; i++){ int nx = x + dx[i], ny = y + dy[i]; if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue; // grid hamidashi ll pos = 1LL << (nx * W + ny); if(cant & pos) continue; // not saitan keiro if(nx == gi && ny == gj) ans++; else q.emplace(nx * W + ny, nxt_cant); } } // output cout << ans << endl; }