#include using namespace std; using ll = long long; struct P { ll x, y, bs, dist; }; int main(){ ll h, w; scanf("%lld %lld", &h, &w); vector> fig(h, vector(w)); for(ll i=0; i>s; for(ll j=0; j> ans(h, vector(w, 1e11)); queue

que; P p = {0, 0, -1, 0}; que.push(p); while(!que.empty()){ p = que.front(); que.pop(); if(fig[p.x][p.y]) p.dist += max(0ll, p.dist-p.bs*p.bs); if(ans[p.x][p.y]<=p.dist) continue; ans[p.x][p.y] = p.dist; for(ll i=0; i<2; i++){ ll tx = p.x-dx[i], ty = p.y-dy[i]; if(0<=tx && tx