Problem:
Score : 2000 points

Problem Statement

You are given an H \times W grid.
The square at the top-left corner will be represented by (0, 0), and the square at the bottom-right corner will be represented by (H-1, W-1).

Of those squares, N squares (x_1, y_1), (x_2, y_2), ..., (x_N, y_N) are painted black, and the other squares are painted white.

Let the shortest distance between white squares A and B be the minimum number of moves required to reach B from A visiting only white squares, where one can travel to an adjacent square sharing a side (up, down, left or right) in one move.

Since there are H × W - N white squares in total, there are _{(H×W-N)}C_2 ways to choose two of the white squares.

For each of these _{(H×W-N)}C_2 ways, find the shortest distance between the chosen squares, then find the sum of all those distances, modulo 1 000 000 007=10^9+7.

Constraints

1 \leq H, W \leq 10^6

1 \leq N \leq 30

0 \leq x_i \leq H-1

0 \leq y_i \leq W-1

If i \neq j, then either x_i \neq x_j or y_i \neq y_j.

There is at least one white square.

For every pair of white squares A and B, it is possible to reach B from A visiting only white squares.

Input

Input is given from Standard Input in the following format:

H W
N
x_1 y_1
x_2 y_2
:
x_N y_N

Output

Print the sum of the shortest distances, modulo 10^9+7.

Sample Input 1

2 3
1
1 1

Sample Output 1

20

We have the following grid (.: a white square, #: a black square).

...
.#.

Let us assign a letter to each white square as follows:

ABC
D#E

Then, we have:

dist(A, B) = 1

dist(A, C) = 2

dist(A, D) = 1

dist(A, E) = 3

dist(B, C) = 1

dist(B, D) = 2

dist(B, E) = 2

dist(C, D) = 3

dist(C, E) = 1

dist(D, E) = 4

where dist(A, B) is the shortest distance between A and B. The sum of these distances is 20.

Sample Input 2

2 3
1
1 2

Sample Output 2

16

Let us assign a letter to each white square as follows:

ABC
DE#

Then, we have:

dist(A, B) = 1

dist(A, C) = 2

dist(A, D) = 1

dist(A, E) = 2

dist(B, C) = 1

dist(B, D) = 2

dist(B, E) = 1

dist(C, D) = 3

dist(C, E) = 2

dist(D, E) = 1

The sum of these distances is 16.

Sample Input 3

3 3
1
1 1

Sample Output 3

64

Sample Input 4

4 4
4
0 1
1 1
2 1
2 2

Sample Output 4

268

Sample Input 5

1000000 1000000
1
0 0

Sample Output 5

333211937

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<math.h>
#include<stdlib.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
typedef pair<ll, ll>pii;
typedef pair<ll, pii>pi3;
vector<pii>zat(vector<ll>v, ll gen)
{
	sort(v.begin(), v.end());
	vector<ll>zv;
	ll now = -1;
	for (int i = 0; i < v.size(); i++)
	{
		if (now != v[i])now = v[i], zv.push_back(now);
	}
	v = zv;
	vector<pii>ret;
	int beg = 0;
	for (int i = 0; i < v.size(); i++)
	{
		if (beg < v[i])ret.push_back(make_pair(beg, v[i] - 1));
		ret.push_back(make_pair(v[i], v[i]));
		beg = v[i] + 1;
	}
	if (beg != gen)ret.push_back(make_pair(beg, gen - 1));
	return ret;
}
ll dat[100][100];
ll dist[70][70][70][70];
bool flag[70][70];
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
void calcdist(int sx, int sy, int mx, int my)
{
	queue<pi3>que;
	que.push(make_pair(0, make_pair(sx, sy)));
	for (int i = 0; i < mx; i++)for (int j = 0; j < my; j++)flag[i][j] = false;
	for (;;)
	{
		if (que.empty())break;
		pi3 z = que.front();
		que.pop();
		ll x = z.second.first, y = z.second.second;
		if (flag[x][y])continue;
		flag[x][y] = true;
		dist[sx][sy][x][y] = z.first;
		for (int i = 0; i < 4; i++)
		{
			int nx = x + dx[i], ny = y + dy[i];
			if (0 <= nx&&nx < mx && 0 <= ny&&ny < my&&dat[nx][ny] == 0)
			{
				que.push(make_pair(z.first + 1, make_pair(nx, ny)));
			}
		}
	}
}
ll getall(ll x, ll y)
{
	return (y*y%mod*((x + 1)*x*(x - 1) / 6 % mod) + x*x%mod*((y + 1)*y*(y - 1) / 6 % mod)) % mod;
}
ll get1d(ll mx, ll x)
{
	ll a = x*(x + 1) / 2;
	ll b = (mx - x - 1)*(mx - x) / 2;
	return (a + b) % mod;
}
ll get(ll mx, ll my, ll x, ll y)
{
	return (get1d(mx, x)*my + get1d(my, y)*mx) % mod;
}
int main()
{
	ll mx, my;
	int num;
	scanf("%lld%lld%d", &mx, &my, &num);
	vector<ll>zx, zy;
	vector<pii>v;
	for (int i = 0; i < num; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		v.push_back(make_pair(za, zb));
		zx.push_back(za);
		zy.push_back(zb);
	}
	vector<pii>xs = zat(zx, mx), ys = zat(zy, my);
	//for (int i = 0; i < xs.size(); i++)printf("%lld %lld\n", xs[i].first, xs[i].second);
	//for (int i = 0; i < ys.size(); i++)printf("%lld %lld\n", ys[i].first, ys[i].second);
	for (int i = 0; i < num; i++)
	{
		int lx = lower_bound(xs.begin(), xs.end(), make_pair(v[i].first, v[i].first)) - xs.begin();
		int ly = lower_bound(ys.begin(), ys.end(), make_pair(v[i].second, v[i].second)) - ys.begin();
		dat[lx][ly] = 1;
	}
	for (int i = 0; i < xs.size(); i++)for (int j = 0; j < ys.size(); j++)if (dat[i][j] == 0)calcdist(i, j, xs.size(), ys.size());
	ll ans = getall(mx, my);
	for (int i = 0; i < v.size(); i++)ans = (ans + mod - get(mx, my, v[i].first, v[i].second)) % mod;
	for (int i = 0; i < v.size(); i++)for (int j = i + 1; j < v.size(); j++)ans = (ans + abs(v[i].first - v[j].first) + abs(v[i].second - v[j].second)) % mod;
	ll add = 0;
	for (int i = 0; i < xs.size(); i++)
	{
		for (int j = 0; j < ys.size(); j++)
		{
			for (int k = 0; k < xs.size(); k++)
			{
				for (int l = 0; l < ys.size(); l++)
				{
					if (dat[i][j] == 1 || dat[k][l] == 1)continue;
					ll t = (xs[i].second - xs[i].first + 1)*(ys[j].second - ys[j].first + 1) % mod;
					ll s = (xs[k].second - xs[k].first + 1)*(ys[l].second - ys[l].first + 1) % mod;
					ll u = dist[i][j][k][l] - abs(k - i) - abs(l - j);
					add += t*s%mod*u;
					add %= mod;
				}
			}
		}
	}
	add = add*(mod + 1) / 2 % mod;
	printf("%lld\n", (ans + add) % mod);
}