#include #include #include using namespace std; typedef long long ll; ll dp[251][251][601] = {}; ll inf = 1e18; int dx[4] = {-1,1,0,0},dy[4] = {0,0,-1,1}; int main(){ int H,W,gx,gy; cin >> H >> W >> gx >> gy; int K = min(H*W,600); vector> A(H+1,vector(W+1,0)); for(int i=1;i<=H;i++) for(int j=1;j<=W;j++){ cin >> A[i][j]; for(int k=1;k<=K;k++) dp[i][j][k] = inf; } dp[gx][gy][1] = A[gx][gy]; auto in = [&](int x,int y){ return 1<=x && x<=H && 1<=y && y<=W; }; for(int k=1;k> Q; /* vector ans(Q,0); struct query{ int id,x,y; ll level; bool operator<(const query& right)const{ return level> A(H+1,vector(W+1,0)); vector qs;*/ for(int q=0;q> x >> y >> k; ll ans = inf; for(ll i=1;i<=K;i++) ans = min(ans,dp[x][y][i]+i*k*k); cout << ans << endl; } }