#include #include #include using namespace std; int H,W; int A[100][100]; int vis[100][100]; int d[3]={0,1,-1}; void f(pairz,int dr,vector >&now) { int dx=d[dr/3],dy=d[dr%3]; int x=z.first,y=z.second; do{ x+=dx,y+=dy; if(0<=x&&x>H>>W; for(int i=0;i>A[i][j]; vector >OUT; for(int i=-1;i<=H;i++) { OUT.push_back(make_pair(i,-1)); OUT.push_back(make_pair(i,W)); } for(int j=0;j >now; int visT=0; int ans=0; for(int P=0;Pz:now) { int x=z.first,y=z.second; if(vis[x][y]