/****************************************** * AUTHOR: BHUVNESH JAIN * * INSTITUITION: BITS PILANI, PILANI * ******************************************/ #include using namespace std; typedef long long LL; typedef long double LD; typedef pair pii; typedef pair pll; #define fi first #define sec second const int MAX = 1e3 + 3; int n, m, q; int a[MAX][MAX]; int du[4] = {1, 1, -1, -1}; int dv[4] = {1, -1, 1, -1}; int dx[MAX], dy[MAX]; map dp[MAX][MAX]; int solve(int x, int y, int mask) { // cerr << x << " " << y << " " << mask << "\n"; if (mask == (1<= 0 && _x < n && _y >= 0 && _y < m) { val = solve(_x, _y, mask | (1<