ll@n,@m,u[m],v[]; rep(i,m){ ll@x,@y; u[i]=x+y-1; v[i]=x-y; } ll c=0; int mu=m; Unique(mu,u); int mv=m; Unique(mv,v); rep(j,mv) c+=n-abs(v[j]); ll mc=bsearch_min[ll,j,0,mv](v[j]>=0); if(1){ ll j=mc-1,k=mc; ll a[2]{0,0}; rep(i,mu){ ll un=u[i]; if(un>=n) break; c+=un; while(j>=0&&un+v[j]>0) ++a[v[j]&1],--j; while(k0) ++a[v[k]&1],++k; c-=a[un&1^1]; } } if(1){ ll j=mc-1,k=mc; ll a[2]{0,0}; rrep(i,mu){ ll un=2n-u[i]; if(un>n) break; c+=un; while(j>=0&&un+v[j]>0) ++a[v[j]&1],--j; while(k0) ++a[v[k]&1],++k; c-=a[un&1^1]; } } wt(c);