#include using namespace std; int main(){ int h, w; cin >> h >> w; vector a(h, vector(w)); for (int i=0; i> a[i][j]; } } vector dp(h, vector(w)); vector seen(h, vector(w)); auto calc = [&](auto self, int i, int j) -> int { if (seen[i][j]) return dp[i][j]; int ret = 1; for (auto [x, y]:{ pair(i+1, j), pair(i-1, j), pair(i, j-1), pair(i, j+1) }){ if (!(0 <= x && x < h)) continue; if (!(0 <= y && y < w)) continue; if (a[i][j] < a[x][y]){ ret = max(ret, self(self, x, y) + 1); } } seen[i][j] = true; dp[i][j] = ret; return ret; }; int ans = 0; for (int i=0; i