#include "bits/stdc++.h" #include using namespace std; typedef long long ll; typedef pair pii; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define all(a) (a).begin(),(a).end() #define vi vector #define pb push_back #define INF 999999999 //#define INF (1LL<<59) #define MAX_V (500*500) #define MAX_B 2 struct edge{pii to;int cost;}; vector G[MAX_V][MAX_B]; int d[MAX_V][MAX_B]; void dijkstra(pii s){ priority_queue< pair,vector>,greater> > que; rep(i,MAX_V)rep(j,MAX_B)d[i][j]=INF; d[s.first][s.second]=0; que.push(make_pair(0,s)); while(que.size()){ pair p=que.top(); que.pop(); int v=p.second.first; int b=p.second.second; if(d[v][b]d[v][b]+e.cost){ d[e.to.first][e.to.second]=d[v][b]+e.cost; que.push(make_pair(d[e.to.first][e.to.second],e.to)); } } } } int main(){ int h,w; cin>>h>>w; vector data(h); rep(i,h)cin>>data[i]; int dy[]={1,-1,1,-1}; int dx[]={1,1,-1,-1}; rep(i,h){ rep(j,w){ rep(l,4){ int ddy = i+dy[l]; int ddx = j+dx[l]; int k=1; if( ddx>=0 && ddy>=0 && ddx=0 && ddy>=0 && ddx=0 && ddy>=0 && ddx=0 && ddy>=0 && ddx