# bzoj4558 [JLoi2016]方（容斥原理，计数，Hash）

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 1000003
#define mod 100000007
inline char gc(){
static char buf[1<<16],*S,*T;
return *S++;
}
ll x=0,f=1;char ch=gc();
while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=gc();}
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc();
return x*f;
}
int n,m,K,ans0,ans1,ans2,ans3,ans4,h[N],num=0;
inline void inc(int &x,int y){x+=y;if(x>=mod) x-=mod;}
struct P{
int x,y;
}a[2010];
struct Hash_table{
ll key;int next;
}data[2010];
inline void ins(ll key){
int x=key%N;
for(int i=h[x];i;i=data[i].next)
if(data[i].key==key) return;
data[++num].key=key;data[num].next=h[x];h[x]=num;
}
inline bool hs(ll key){
int x=key%N;
for(int i=h[x];i;i=data[i].next)
if(data[i].key==key) return 1;return 0;
}
inline int cal(int l1,int l2,int h){
h--;if(l1>l2) swap(l1,l2);
if(h<=l1) return (ll)h*(h+1)/2%mod;
if(h<=l2) return ((ll)l1*(l1+1)/2+(ll)l1*(h-l1))%mod;
if(h>=l1+l2) return (ll)l1*l2%mod;
return ((ll)l1*(l1+1)/2+(ll)l1*(l2-l1)+(ll)(l1-1+l1-h+l2)*(h-l2)/2)%mod;
}
inline void check(int x1,int y1,int x2,int y2){
if(x1<0||x1>n||x2<0||x2>n||y1<0||y1>m||y2<0||y2>m) return;
int res=hs((ll)x1*(m+1)+y1)+hs((ll)x2*(m+1)+y2);
ans2++;ans3+=res;ans4+=res==2;
}
int main(){
//  freopen("a.in","r",stdin);
for(int i=1;i<=min(n,m);++i) inc(ans0,(ll)i*(n-i+1)*(m-i+1)%mod);
for(int i=1;i<=K;++i){
inc(ans1,min(a[i].x,a[i].y)+min(a[i].x,m-a[i].y)+min(n-a[i].x,a[i].y)+min(n-a[i].x,m-a[i].y));
inc(ans1,cal(a[i].x,n-a[i].x,a[i].y));
inc(ans1,cal(a[i].x,n-a[i].x,m-a[i].y));
inc(ans1,cal(a[i].y,m-a[i].y,a[i].x));
inc(ans1,cal(a[i].y,m-a[i].y,n-a[i].x));
}for(int i=1;i<=K;++i)
for(int j=i+1;j<=K;++j){
int x1=a[i].x,y1=a[i].y,x2=a[j].x,y2=a[j].y;
check(x1+y2-y1,y1+x1-x2,x2+y2-y1,y2+x1-x2);
check(x1+y1-y2,y1+x2-x1,x2+y1-y2,y2+x2-x1);
if((x1+x2+y1+y2)&1) continue;
check(x1+x2+y2-y1>>1,y1+y2+x1-x2>>1,x1+x2+y1-y2>>1,y1+y2+x2-x1>>1);
}printf("%d\n",((ans0-ans1+ans2-ans3/3+ans4/6)%mod+mod)%mod);
return 0;
}

06-14 1204
06-02 406

04-19 476
05-23 1664
01-10 25
03-03 124
12-08 1413
03-28 113
09-30 383
12-11 135
06-07 920
01-07 1283
08-07 520