#pragma GCC optimize("Ofast") #pragma GCC target("avx2") char*mmap(); #define rd(v) long v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;} #define wbuf_end (wbuf+sizeof wbuf) #define wt(v) {long _z=v;do*--wp=_z%10+48;while(_z/=10);} #define rep(v,e) for(long v=0;v=b?a:b) int a[1001][1000]; main(){ char*rp=mmap(0l,1l<<25,1,2,0,0ll); rd(n); long w=n*n*(n+1)>>1; rep(y,n){ rep(x,n){ rd(t); a[t][max(0,y-x)]++; a[t][min(n-1,y+x)]++; w-=(y-x)-max(0,y-x); } } rep3(t,1,n+1){ long y=0,s=n; for(;s>0;s-=a[t][y++]){ w-=s; } } char wbuf[64],*wp=wbuf_end; *--wp=10; wt(w); write(1,wp,wbuf_end-wp); _exit(0); }