#include #include using namespace std; using namespace atcoder; typedef long long ll; typedef long double ld; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m; i >= n; --i) #define ALL(v) (v).begin(),(v).end() #define ALLR(v) (v).rbegin(),(v).rend() #define fi first #define se second #define PB push_back #define EB emplace_back template using PQ = priority_queue; template using QP = priority_queue,greater>; templatevoid debug(const T &v,ll h,ll w){for(ll i=0;ivoid debug(const T &v,ll n){for(ll i=0;ivoid debug(const vector&v){debug(v,v.size());} templatevoid debug(const vector>&v){for(auto &vv:v)debug(vv,vv.size());} templatevoid debug(stack st){while(!st.empty()){cerr<void debug(queue st){while(!st.empty()){cerr<void debug(deque st){while(!st.empty()){cerr<void debug(PQ st){while(!st.empty()){cerr<void debug(QP st){while(!st.empty()){cerr<void debug(const set&v){for(auto z:v)cerr<void debug(const multiset&v){for(auto z:v)cerr<void debug(const array &a){for(auto z:a)cerr<void debug(const map&v){for(auto z:v)cerr<<"["<void foo(Head&& head, Tail&&... tail){cerr << head << " ";foo(move(tail)...);} templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> n >> m; vector x(m),y(m); vector a,b,c,d; REP(i,m){ cin >> x[i] >> y[i]; x[i]--,y[i]--; if((x[i]+y[i])%2==0) a.PB(x[i]+y[i]); else c.PB(x[i]+y[i]); if((x[i]+n-1-y[i]+n-1)%2==0) b.PB(x[i]+n-1-y[i]); else d.PB(x[i]+n-1-y[i]); } sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); sort(ALL(b)); b.erase(unique(ALL(b)),b.end()); sort(ALL(c)); c.erase(unique(ALL(c)),c.end()); sort(ALL(d)); d.erase(unique(ALL(d)),d.end()); ll ans=0; REP(i,a.size()) ans+=min(a[i]+1,n*2-a[i]-1); REP(i,b.size()) ans+=min(b[i]+1,n*2-b[i]-1); REP(i,c.size()) ans+=min(c[i]+1,n*2-c[i]-1); REP(i,d.size()) ans+=min(d[i]+1,n*2-d[i]-1); // debug(a); // debug(b); // debug(c); // debug(d); // n-1<=s<=3*n-3 // foo(ans); REP(i,a.size()){ int l=lower_bound(ALL(b),n-1-a[i])-b.begin(); int r=upper_bound(ALL(b),n*3-3-a[i])-b.begin(); ans-=r-l; // foo(a[i],l,r,r-l); } REP(i,c.size()){ int l=lower_bound(ALL(d),n-1-c[i])-d.begin(); int r=upper_bound(ALL(d),n*3-3-c[i])-d.begin(); ans-=r-l; // foo(c[i],l,r,r-l); } cout << ans << endl; }