#include #include #include #define rep(i, l, r) for(int i=l; i<=r; i++) #define dow(i, l, r) for(int i=l; i>=r; i--) #define clr(x, c) memset(x, c, sizeof(x)) #define travel(x) for(edge *p=fir[x]; p; p=p->n) #define all(x) (x).begin,(x).end #define pb push_back #define fi first #define se second #define l(x) Left[x] #define r(x) Right[x] #define lowbit(x) (x&-x) using namespace std; typedef long long ll; typedef pair Pii; typedef long double ld; typedef unsigned int ull; inline int read() { int x=0; bool f=0; char ch=getchar(); while (ch<'0' || '9'k[i][j]) top--; L[i][j]=j-q[top], q[++top]=j; } } rep(i, 1, n) { q[top=0]=m+1; dow(j, m, 1) { while (top && k[i][q[top]]>k[i][j]) top--; R[i][j]=q[top]-j, q[++top]=j; } } rep(j, 1, m) { q[top=0]=0; rep(i, 1, n) { while (top && k[q[top]][j]