#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; typedef pair> P; ll A[505][505]; int vis[505][505]; int dh[]={1,0,-1,0}; int dw[]={0,1,0,-1}; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int h,w,y,x; cin>>h>>w>>y>>x; y--,x--; rep(i,h) rep(j,w) cin>>A[i][j]; priority_queue,greater

> que; auto f=[&](int i,int j){ rep(k,4){ int ni=i+dh[k],nj=j+dw[k]; if(ni<0 || nj<0 || ni>=h || nj>=w) continue; if(vis[ni][nj]) continue; que.push({A[ni][nj],{ni,nj}}); vis[ni][nj]=1; } }; int cnt=1; ll now=A[y][x]; vis[y][x]=1; f(y,x); while(que.size()){ auto t=que.top(); que.pop(); ll a=t.first,i=t.second.first,j=t.second.second; if(a