#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(ac) return 1; if(a>b&&b>w>>h; vector> st(h,vector(w)); for(int i=0;i>st[i][j]; using T = tuple; map dp; queue qu; if(st[0][0]!=st[0][1]){ dp[T(0,0,0,1)]=1; qu.emplace(0,0,0,1); } if(st[0][0]!=st[1][0]){ dp[T(0,0,1,0)]=1; qu.emplace(0,0,1,0); } int dy[]={0,0,1,-1}; int dx[]={1,-1,0,0}; auto in=[&](int y,int x){return 0<=y&&y