#include using namespace std; #define SPEED ios::sync_with_stdio(false); cin.tie(0) #define ll long long int #define FF first #define SS second #define mp make_pair #define pb push_back #define sd(x) scanf("%d",&x) #define slld(x) scanf("%lld",&x) #define pd(x) printf("%d\n",x) #define plld(x) printf("%lld\n",x) #define pss printf #define MOD 1000000007 #define INF 1e18 #define eps 0.00001 #define debug(n1) cout<adj[700]; ll make(ll a,ll b,ll cnt) { for(int i=0;i>>s; s.insert(mp(0,mp(0,0))); while(!s.empty()) { auto k=s.begin(); ll i=k->SS.FF; ll j=k->SS.SS; ll d=k->FF; //cout<d+1) { //auto h=s.find(mp(dist[i+a][j+b],mp(i+a,j+b))); //s.erase(h); dist[i+a][j+b]=d+1; s.insert(mp(d+1,mp(i+a,j+b))); } } if(i-a>=0 && j+bd+1) { //auto h=s.find(mp(dist[i-a][j+b],mp(i-a,j+b))); //s.erase(h); dist[i-a][j+b]=d+1; s.insert(mp(d+1,mp(i-a,j+b))); } } if(i-a>=0 && j-b>=0 && !visited[i-a][j-b]) { if(dist[i-a][j-b]>d+1) { //auto h=s.find(mp(dist[i-a][j-b],mp(i-a,j-b))); //s.erase(h); dist[i-a][j-b]=d+1; s.insert(mp(d+1,mp(i-a,j-b))); } } if(i+a=0 && !visited[i+a][j-b]) { if(dist[i+a][j-b]>d+1) { //auto h=s.find(mp(dist[i+a][j-b],mp(i+a,j-b))); //s.erase(h); dist[i+a][j-b]=d+1; s.insert(mp(d+1,mp(i+a,j-b))); } } swap(a,b); if(i+ad+1) { //auto h=s.find(mp(dist[i+a][j+b],mp(i+a,j+b))); //s.erase(h); dist[i+a][j+b]=d+1; s.insert(mp(d+1,mp(i+a,j+b))); } } if(i-a>=0 && j+bd+1) { //auto h=s.find(mp(dist[i-a][j+b],mp(i-a,j+b))); //s.erase(h); dist[i-a][j+b]=d+1; s.insert(mp(d+1,mp(i-a,j+b))); } } if(i-a>=0 && j-b>=0 && !visited[i-a][j-b]) { if(dist[i-a][j-b]>d+1) { //auto h=s.find(mp(dist[i-a][j-b],mp(i-a,j-b))); //s.erase(h); dist[i-a][j-b]=d+1; s.insert(mp(d+1,mp(i-a,j-b))); } } if(i+a=0 && !visited[i+a][j-b]) { if(dist[i+a][j-b]>d+1) { //auto h=s.find(mp(dist[i+a][j-b],mp(i+a,j-b))); //s.erase(h); dist[i+a][j-b]=d+1; s.insert(mp(d+1,mp(i+a,j-b))); } } swap(a,b); } return dist[n-1][n-1]; } int main() { slld (n); for(int i=1;i