Problem:
Score : 400 points

Problem Statement

We have a grid with H rows and W columns. At first, all cells were painted white.

Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.

Compute the following:

For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?

Constraints

3 \leq H \leq 10^9

3 \leq W \leq 10^9

0 \leq N \leq min(10^5,H×W)

1 \leq a_i \leq H (1 \leq i \leq N)

1 \leq b_i \leq W (1 \leq i \leq N)

(a_i, b_i) \neq (a_j, b_j) (i \neq j)

Input

The input is given from Standard Input in the following format:

H W N
a_1 b_1
:
a_N b_N

Output

Print 10 lines.
The (j+1)-th ( 0 \leq j \leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.

Sample Input 1

4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4

Sample Output 1

0
0
0
2
4
0
0
0
0
0

There are six subrectangles of size 3×3. Two of them contain three black cells each, and the remaining four contain four black cells each.

Sample Input 2

10 10 20
1 1
1 4
1 9
2 5
3 10
4 2
4 7
5 9
6 4
6 6
6 7
7 1
7 3
7 7
8 1
8 5
8 10
9 2
10 4
10 9

Sample Output 2

4
26
22
10
2
0
0
0
0
0

Sample Input 3

1000000000 1000000000 0

Sample Output 3

999999996000000004
0
0
0
0
0
0
0
0
0

Solution in C# (Mono 4.6.2.0) (judge verdict: Time Limit Exceeded)

using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using Enu = System.Linq.Enumerable;

public class Program
{
    static readonly long Big = (long)1e9;

    public void Solve()
    {
        int H = Reader.Int(), W = Reader.Int(), N = Reader.Int();
        var sw = Stopwatch.StartNew();
        var table = Reader.IntTable(N);
        var set = new TreapSortedSet(N * 9);
        var black = new TreapSortedSet(N);
        var ans = new long[10];
        ans[0] = (long)(H - 2) * (W - 2);
        Func<int, int, bool> IsInside = (r, c) => r >= 0 && r < H && c >= 0 && c < W;

        foreach (var t in table)
        {
            black.Add(--t[0] * Big + --t[1]);
            for (int dr = -2; dr <= 0; dr++)
                for (int dc = -2; dc <= 0; dc++)
                    if (IsInside(t[0] + dr, t[1] + dc))
                        set.Add((t[0] + dr) * Big + t[1] + dc);
        }
        for (int i = 0; i < set.Count; i++)
        {
            long mask = set[i];
            long r = mask / Big, c = mask % Big;
            if (r + 3 <= H && c + 3 <= W)
            {
                int count = 0;
                for (int dr = 0; dr < 3; dr++)
                    for (int dc = 0; dc < 3; dc++)
                        if (black.Contains((r + dr) * Big + c + dc))
                            count++;
                ans[0]--;
                ans[count]++;
            }
        }
        Console.WriteLine(string.Join("\n", ans));
    }


    public class TreapSortedSet
    {
        public struct Node
        {
            public int L, R;
            public int Count;
            public long Val;
            //public long Min;
            //public long Max;
            //public long Sum;
            public readonly uint Priority;
            static readonly XorShift random = new XorShift();

            public Node(long val)
            {
                L = R = None; Val = val; Count = 1;
                Priority = random.Next();
                //Min = val;
                //Max = val;
                //Sum = val;
            }
        }
        public class XorShift
        {
            uint m = 2463534242;
            public uint Next() { m = m ^ m << 13; m = m ^ m >> 17; return m = m ^ m << 5; }
        }

        static readonly int None = 0;
        int nodesIndex = 1;
        public Node[] nodes;
        public int Root;
        public int Count { get { return nodes[Root].Count; } }
        public TreapSortedSet(int size) { Init(size); }

        private void Init(int maxSize)
        {
            nodes = new Node[maxSize + 1];
            //nodes[None].Min = long.MaxValue;
            //nodes[None].Max = long.MinValue;
        }
        int GenNode(long val)
        {
            nodes[nodesIndex] = new Node(val);
            return nodesIndex++;
        }

        [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        int Update(int i)
        {
            nodes[i].Count = nodes[nodes[i].L].Count + nodes[nodes[i].R].Count + 1;
            //nodes[i].Min = Math.Min(nodes[i].Val, Math.Min(nodes[nodes[i].L].Min, nodes[nodes[i].R].Min));
            //nodes[i].Max = Math.Max(nodes[i].Val, Math.Max(nodes[nodes[i].L].Max, nodes[nodes[i].R].Max));
            //nodes[i].Sum = nodes[i].Val + nodes[nodes[i].L].Sum + nodes[nodes[i].R].Sum;
            return i;
        }

        public long this[int index]
        {
            get
            {
                if (index < 0 || index >= nodes[Root].Count)
                    throw new ArgumentException();
                int i = Root;
                while (index != nodes[nodes[i].L].Count)
                    if (index < nodes[nodes[i].L].Count) i = nodes[i].L;
                    else { index -= nodes[nodes[i].L].Count + 1; i = nodes[i].R; }
                return nodes[i].Val;
            }
        }

        public bool Add(long val)
        {
            int index = IndexOf(val);
            if (index >= 0) return false;
            Root = Insert(Root, GenNode(val), ~index);
            return true;
        }

        int Insert(int i, int newNodeIndex, int index)
        {
            if (i == None) return newNodeIndex;
            int Lsize = nodes[i].L == None ? 0 : nodes[nodes[i].L].Count;
            if (index == Lsize || nodes[newNodeIndex].Priority > nodes[i].Priority)
            {
                int L, R;
                Split(i, index, out L, out R);
                return Merge(L, Merge(newNodeIndex, R));
            }
            if (index < Lsize)
                nodes[i].L = Insert(nodes[i].L, newNodeIndex, index);
            else
                nodes[i].R = Insert(nodes[i].R, newNodeIndex, index - Lsize - 1);
            return Update(i);
        }

        public bool Contains(long val) { return IndexOf(val) >= 0; }

        public int IndexOf(long val)
        {
            int index = 0;
            for (int i = Root; i != None; )
            {
                if (val == nodes[i].Val) { index += nodes[nodes[i].L].Count; return index; }
                if (val < nodes[i].Val) i = nodes[i].L;
                else { index += nodes[nodes[i].L].Count + 1; i = nodes[i].R; }
            }
            return ~index;
        }


        long RangeQuery(int i, int L, int R, long init, Func<int, long> nF, Func<long, long, long> F)
        {
            if (i == None || L >= R) return init;
            if (L == 0 && R == nodes[i].Count) return nF(i);
            long res = init;
            int Lsize = nodes[nodes[i].L].Count;
            if (Lsize >= L && Lsize < R)
                res = nodes[i].Val;
            if (L < Lsize)
                res = F(res, RangeQuery(nodes[i].L, L, Math.Min(R, Lsize), init, nF, F));
            if (R - Lsize - 1 > 0)
                res = F(res, RangeQuery(nodes[i].R, Math.Max(0, L - Lsize - 1), R - Lsize - 1, init, nF, F));
            return res;
        }
        //public long Min(int L, int R) { return RangeQuery(Root, L, R, long.MaxValue, i => nodes[i].Min, Math.Min); }
        //public long Max(int L, int R) { return RangeQuery(Root, L, R, long.MinValue, i => nodes[i].Max, Math.Max); }
        //public long Sum(int L, int R) { return RangeQuery(Root, L, R, 0, i => nodes[i].Sum, (a, b) => a + b); }

        int Merge(int L, int R)
        {
            if (L == None) return R;
            if (R == None) return L;
            if (nodes[L].Priority > nodes[R].Priority)
            {
                nodes[L].R = Merge(nodes[L].R, R);
                return Update(L);
            }
            else
            {
                nodes[R].L = Merge(L, nodes[R].L);
                return Update(R);
            }
        }
        void Split(int i, int index, out int L, out int R)
        {
            if (i == None) { L = R = None; return; }
            if (index == nodes[nodes[i].L].Count)
            {
                L = nodes[i].L;
                R = i;
                nodes[i].L = None;
                Update(i);
                return;
            }
            int a, b;
            if (index < nodes[nodes[i].L].Count)
            {
                Split(nodes[i].L, index, out a, out b);
                nodes[i].L = b;
                L = a;
                R = Update(i);
            }
            else
            {
                Split(nodes[i].R, index - nodes[nodes[i].L].Count - 1, out a, out b);
                nodes[i].R = a;
                L = Update(i);
                R = b;
            }
        }
        void Split(int i, int L, int R, out int a, out int b, out int c)
        {
            int t;
            Split(i, R, out t, out c);
            Split(t, L, out a, out b);
        }
    }

}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    static string[] Split(string s) { return s.Split(separator, op); }
    static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}