#include #include #include #include using namespace std; using ll=long long; #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} const int dx[]={1,0,-1,0},dy[]={0,1,0,-1}; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int H,W; cin>>H>>W; vector A(H,vector(W)); vector>V; for(int i=0;i>A[i][j]; V.push_back(make_tuple(A[i][j],i,j)); } vector D(H,vector(W)); sort(all(V)); for(auto[a,x,y]:V){ for(int i=0;i<4;i++){ int ex=x+dx[i],ey=y+dy[i]; if(ex>=0&&ex=0&&ey