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 (Python):
from collections import defaultdict

H, W, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
h = defaultdict(int)
for a, b in ab:
    for y in range(max([a - 2, 1]), min([a, H - 2]) + 1):
        for x in range(max([b - 2, 1]), min([b, W - 2]) + 1):
            h[(y, x)] += 1

ans = [0] * 10
for v in h.values():
    ans[v] += 1
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])

for a in ans:
    print(a)

Solution (Python):
h, w, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

d = dict()
for i in range(len(ab)):
    a = ab[i][0] - 1
    b = ab[i][0] - 1
    d[a] = set()

dp = [0] * 10
dp[0] = (h - 2) * (w - 2)
for i in range(n):
    a = ab[i][0] - 1
    b = ab[i][1] - 1
    for dx in [-1, 0, 1]:
        for dy in [-1, 0, 1]:
            nx, ny = a + dx, b + dy 
            if nx >= 1 and nx <= h - 2 and ny >= 1 and ny <= w - 2:
                
                tmp = 0
                for dx2 in [-1, 0, 1]:
                    for dy2 in [-1, 0, 1]:
                        if nx + dx2 in d and ny + dy2 in d[nx + dx2]:
                            tmp += 1

                dp[tmp] -= 1
                dp[tmp + 1] += 1

    d[a].add(b)

for x in dp:
    print(x)

Solution (Python):
def solve():
    diff = [(i-1,j-1) for i in range(3) for j in range(3)]
    H,W,N = map(int, input().split())
    count_dict = {}
    ret = [0]*10
    ret[0] = (W-2)*(H-2)
    for i in range(N):
        a, b = map(int,input().split())
        
        
        
        for da,db in diff:
            ra, rb = a+da, b+db
            if ra <= 1 or ra >= H or rb <= 1 or rb >= W : continue
            
            if (ra,rb) in count_dict:
                dom = count_dict[(ra,rb)]
                ret[dom] -= 1
                ret[dom+1] += 1
                count_dict[(ra,rb)] += 1
            else:
                ret[0] -= 1
                ret[1] += 1
                count_dict[(ra,rb)] = 1
                
    
    print('\n'.join(map(str,ret)))
    
solve()

Solution (Python):
import sys
from collections import defaultdict, Counter

h, w, n = map(int, sys.stdin.readline().split())
ab = map(int, sys.stdin.read().split())
ab = zip(ab, ab)

def main():
    c = defaultdict(int)
    for a, b in ab:
        for da in range(-2, 1):
            for db in range(-2, 1):
                
                i = a + da
                j = b + db
                if 1 <= i <= h - 2 and 1 <= j <= w - 2:
                    c[(i, j)] += 1
    
    res = Counter(c.values())
    cnt_0 = (h - 2) * (w - 2) - sum(res.values())
    yield cnt_0
    for i in range(1, 10):
        if i in res:
            yield res[i]
        else:
            yield 0

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Solution (Python):
H,W,N = map(int, input().split())

dic = {}
for _ in range(N):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    for i in range(-1, 2):
        for j in range(-1, 2):
            if a+i <= 0 or a+i >= H-1 or b+j <= 0 or b+j >= W-1:
                continue
            if (a+i, b+j) in dic:
                dic[(a+i, b+j)] += 1
            else:
                dic[(a+i, b+j)] = 1
                
ans = [0]*10
for t in dic.values():
    ans[t] += 1
ans[0] = (H-2)*(W-2)-sum(ans)

for i in range(10):
    print(ans[i])

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from itertools import product
from collections import defaultdict
def resolve():
    h,w,n=map(int,input().split())
    D=defaultdict(int)
    for _ in range(n):
        a,b=map(int,input().split())
        for i,j in product(range(a-1,a+2),range(b-1,b+2)):
            if(2<=i<=h-1 and 2<=j<=w-1):
                D[(i,j)]+=1

    ans=[0]*10
    for v in D.values():
        ans[v]+=1
    ans[0]=(h-2)*(w-2)-sum(ans)
    print(*ans,sep='\n')
resolve()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from itertools import product
from collections import defaultdict
def resolve():
    h,w,n=map(int,input().split())
    D=defaultdict(int)
    for _ in range(n):
        a,b=map(int,input().split())
        for i,j in product(range(a-1,a+2),range(b-1,b+2)):
            if(1<=i<=h and 1<=j<=w):
                D[(i,j)]+=1

    ans=[0]*10
    for k,v in D.items():
        i,j=k
        if(i==1 or i==h or j==1 or j==w): continue
        ans[v]+=1
    ans[0]=(h-2)*(w-2)-sum(ans)
    print(*ans,sep='\n')
resolve()

Solution (Python):
from collections import Counter
h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
d=(-1,0,1)
c=Counter()
for a,b in ab:
    for da in d:
        for db in d:
            aa=a+da
            bb=b+db
            if 2<=aa<=h-1 and 2<=bb<=w-1:
                c[(aa,bb)]+=1
ans=Counter(c.values())
count_0=(h-2)*(w-2)-sum(ans.values())
print(count_0)
for i in range(1,10):
    print(ans[i])

Solution (Python):

from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

h, w, n = [int(item) for item in input().split()]
blk_cnt = defaultdict(int) 

for i in range(n):
    a, b = [int(item) - 1 for item in input().split()]
    for j in range(-1, 2):
        for k in range(-1, 2):
            blk_cnt[(a + j, b + k)] += 1
ans = [0] * 10 
for key in blk_cnt.keys():
    if key[0] < 1 or key[1] < 1 or key[0] >= h-1 or key[1] >= w-1:
        continue
    ans[blk_cnt[key]] += 1
total = (w - 2) * (h - 2)
ans[0] = total - sum(ans)
for item in ans:
    print(item)

Solution (Python):
def examD():
    H, W, N = LI()
    ab = set()
    for _ in range(N):
        a, b = list(map(int,input().split()))
        ab.add((a-1,b-1))
    check = set()
    for c in ab:
        for i in range(-1,2):
            for j in range(-1,2):
                if 1<=c[0]+i<H-1 and 1<=c[1]+j<W-1:
                    check.add((c[0]+i,c[1]+j))


    ansC = [0]*10
    for c in check:
        cur = int(0)
        for i in range(-1,2):
            for j in range(-1,2):
                if (c[0]+i,c[1]+j) in ab:
                    cur += 1
        ansC[cur] +=1
    ansC[0] = (H-2)*(W-2)-sum(ansC)
    for v in ansC:
        print(v)


import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Solution (Python):

import sys
input = sys.stdin.readline


from collections import defaultdict
from collections import Counter
H,W,N = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]

dic = defaultdict(int)
for a,b in AB:
    for dh in range(3):
        for dw in range(3):
            if 0 < a-dh <= H-2 and 0 < b-dw <= W-2:
                dic[(a-dh,b-dw)] += 1

Ans = Counter(dic.values())
Ans[0] = (H-2)*(W-2) - sum(Ans.values())

for i in range(10):
    print(Ans[i])

Solution (Python):

import sys
input = sys.stdin.readline


from collections import defaultdict
H,W,N = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]

dic = defaultdict(int)
for a,b in AB:
    for dh in range(3):
        for dw in range(3):
            if 0 < a-dh <= H-2 and 0 < b-dw <= W-2:
                dic[(a-dh,b-dw)] += 1

Ans = [0]*10
total = 0
for v in dic.values():
    Ans[v] += 1
    total += 1

Ans[0] = (H-2)*(W-2) - total

for ans in Ans:
    print(ans)

Solution (Python):
import sys
import collections


def solve():
    sys.setrecursionlimit(2000)
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    h, w, n = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(int)
    for _ in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        for i in range(-1, 2):
            for j in range(-1, 2):
                if 1 <= a-1+i < h-1 and 1 <= b-1+j < w-1:
                    d[a-1+i, b-1+j] += 1
    nd = []
    for k, v in d.items():
        nd.append(v)
    nd = collections.Counter(nd)
    print((h - 2) * (w - 2) - sum(nd.values()))
    for i in range(1, 10):
        print(nd[i])


if __name__ == '__main__':
    solve()

Solution (Python):
from collections import deque


def solve():
    H, W, N = list(map(int, input().split()))
    

    
    blacks = {}
    for _ in range(N):
        pos = input().split()
        blacks[(int(pos[0]), int(pos[1]))] = 0

    

    
    
    
    
    def center_of_boxes_from_point(y, x):
        center_pos_lis = deque()

        for dy in range(-1, 2):
            for dx in range(-1, 2):
                cy = y + dy
                cx = x + dx
                if 1 <= cy <= H and 1 <= cx <= W:
                    center_pos_lis.append((cy, cx))
        return center_pos_lis

    ANS_TABLE = [0 for _ in range(10)]

    
    
    done_boxes = {}
    for blk in blacks:
        
        y, x = blk
        boxes = center_of_boxes_from_point(y, x)

        
        for center_of_box in boxes:
            if center_of_box not in done_boxes:
                y, x = center_of_box
                if 2 <= y < H and 2 <= x < W:
                    count = 0
                    for dy in range(-1, 2):
                        for dx in range(-1, 2):
                            cy = y + dy
                            cx = x + dx
                            if (cy, cx) in blacks:
                                count += 1
                    
                    ANS_TABLE[count] += 1
                    done_boxes[center_of_box] = 0

    
    ANS_TABLE[0] = (W - 2) * (H - 2) - sum(ANS_TABLE)

    return ANS_TABLE


if __name__ == '__main__':
    res = solve()
    for r in res:
        print(r)

Solution (Python):
H, W, N = map(int, input().split())
A = []
L = 0
ans = [0] * 10

for i in range(N):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for i in range(max(0, a - 2), min(a + 1,H-2)):
        for j in range(max(0, b - 2), min(b + 1,W-2)):
            A.append((i, j))
            L += 1

A.sort()
count = 1
for i in range(L - 1):
    if A[i] == A[i + 1]:
        count += 1
    else:
        ans[count] += 1
        count = 1
if L >= 1:
    ans[count] += 1

ans[0] = (H - 2) * (W - 2) - sum(ans)

for i in range(10):
    print(ans[i])

Solution (Python):
import sys
input = sys.stdin.readline
H,W,N = map(int,input().split())
count = []
L = 0
for i in range(N):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    for i in range(max(0,a-2),min(a+1,H-2)):
        for j in range(max(0,b-2),min(b+1,W-2)):
            count.append((i,j))
            L += 1
count.sort()
ans = [0]*10
tmp = 1
for i in range(L-1):
    if count[i] == count[i+1]:
        tmp += 1
    else:
        ans[tmp] += 1
        tmp = 1
if L>=1:
  ans[tmp] += 1
ans[0] = (H-2)*(W-2)-sum(ans)
for i in range(10):
    print(ans[i])

Solution (Python):
H,W,N = map(int,input().split())
count = []
L = 0
for i in range(N):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    for i in range(max(0,a-2),min(a+1,H-2)):
        for j in range(max(0,b-2),min(b+1,W-2)):
            count.append((i,j))
            L += 1
count.sort()
ans = [0]*10
tmp = 1
for i in range(L-1):
    if count[i] == count[i+1]:
        tmp += 1
    else:
        ans[tmp] += 1
        tmp = 1
if L>=1:
  ans[tmp] += 1
ans[0] = (H-2)*(W-2)-sum(ans)
for i in range(10):
    print(ans[i])

Solution (Python):
import sys
import bisect
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    h, w, n = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(int)
    dt = collections.defaultdict(int)
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        a -= 1
        b -= 1
        for j in range(max(1, a - 1), min(h-1, a + 2)):
            for k in range(max(1, b - 1), min(w-1, b + 2)):
                d[j, k] += 1
                dt[d[j, k]] += 1
                dt[d[j, k]-1] -= 1
    dt[0] += (h - 3 + 1) * (w - 3 + 1)
    for i in range(10):
        print(dt[i])


if __name__ == '__main__':
    slove()

Solution (Python):
import sys
import bisect
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    h, w, n = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(int)
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        a -= 1
        b -= 1
        for j in range(max(1, a - 1), min(h-1, a + 2)):
            for k in range(max(1, b - 1), min(w-1, b + 2)):
                d[j, k] += 1
    ls = [0] * 10
    for k, v in sorted(d.items(), key=lambda x: x[1]):
        ls[v] += 1
    ls[0] = (h - 3 + 1) * (w - 3 + 1) - sum(ls)
    for i in range(10):
        print(ls[i])


if __name__ == '__main__':
    slove()

Solution (Python):
from collections import defaultdict
import sys
input = sys.stdin.readline

def main():
    H, W, N = map(int, input().split())
    j = [0] * 10
    ans = [0] * 10
    ans[0] = (H - 2) * (W - 2)
    d = defaultdict(int)
    dt = [-1,0,1]
    for i in range(N):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        for i in dt:
            if 0 <= a + i <= H - 1:
                for j in dt:
                    if 0 <= b + j <= W - 1:
                        tmp = d[(a + i, b + j)]
                        d[(a + i, b + j)] += 1
                        if 1 <= a + i <= H - 2 and 1 <= b + j <= W - 2:
                            ans[tmp] -= 1
                            ans[tmp + 1] += 1
    
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from itertools import product
from collections import Counter
input = sys.stdin.readline

H, W, N = map(int, input().split())
udlr = [-1, 0, 1]
center = []

for _ in range(N):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    for i, j in product(udlr, repeat=2):
        if 0 < a + i < H - 1 and 0 < b + j < W - 1:
            center.append((a + i, b + j))

black = Counter(list(Counter(center).values()))
black[0] = (H - 2) * (W - 2) - sum(list(black.values()))

for i in range(10):
    if black.get(i):
        print(black[i])
    else:
        print(0)

Solution (Python):
from collections import defaultdict

H,W,N = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]

Cells = defaultdict(int)
Count = [(H-2)*(W-2)] + [0 for _ in range(9)]

for a,b in AB:
  a -= 1
  b -= 1
  for i in range(-1,2):
    for j in range(-1,2):
      if 1 <= a+i <= H-2 and 1 <= b+j <= W-2:
        Count[Cells[(a+i,b+j)]] -= 1
        Count[Cells[(a+i,b+j)]+1] += 1
      Cells[(a+i,b+j)] += 1
for c in Count:
  print(c)

Solution (Python):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




def main():
    high, width, num = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num)]

    ans_list = defaultdict(int)
    move_dic = [-2, -1, 0]
    for i in range(num):
        a, b = data[i]
        a -= 1
        b -= 1
        for move_a in move_dic:
            for move_b in move_dic:
                now_a = a + move_a
                now_b = b + move_b
                if 0 <= now_a < high - 2 and 0 <= now_b < width - 2:
                    ans_list[(now_a, now_b)] += 1
        

    ans = Counter(list(ans_list.values()))
    print((high - 2) * (width - 2) - sum(list(ans.values())))
    for i in range(1, 10):
        print(ans[i])

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from collections import defaultdict
    import sys
    input = sys.stdin.readline

    H, W, N = map(int, input().split())
    ans = [0] * 10
    ans[0] = (H - 2) * (W - 2)
    
    tmplst = [-1, 0, 1]
    dic = defaultdict(int)
    for _ in range(N):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        for i in tmplst:
            if 0 <= a + i <= H - 1:
                for j in tmplst:
                    if 0 <= b + j <= W - 1: 
                        tmp = dic[(a + i, b + j)]
                        dic[(a + i, b + j)] += 1
                        if 1 <= a + i <= H - 2 and 1 <= b + j <= W - 2:
                            ans[tmp] -= 1
                            ans[tmp + 1] += 1

    print (*ans, sep = '\n')

if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict
import sys
input = sys.stdin.readline

H, W, N = map(int, input().split())
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)

tmplst = [-1, 0, 1]
dic = defaultdict(int)
for _ in range(N):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for i in tmplst:
        if 0 <= a + i <= H - 1:
            for j in tmplst:
                if 0 <= b + j <= W - 1: 
                    tmp = dic[(a + i, b + j)]
                    dic[(a + i, b + j)] += 1
                    if 1 <= a + i <= H - 2 and 1 <= b + j <= W - 2:
                        ans[tmp] -= 1
                        ans[tmp + 1] += 1

print (*ans, sep = '\n')

Solution (Python):
import sys
input = sys.stdin.readline

lst = []
lst_append = lst.append
H, W, N = map(int, input().split())
tmplst = [-1, 0, 1]
for _ in range(N):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for i in tmplst:
        if 1 <= a + i <= H - 2:
            for j in tmplst:
                if 1 <= b + j <= W - 2:
                    lst_append((a + i, b + j))

lst.sort()
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)

tmp = None
count = 0
for i in lst:
    if i == tmp:
        count += 1
    else:
        ans[0] -= 1
        ans[count] += 1
        count = 1
        tmp = i

ans[0] -= 1
ans[count] += 1
print (*ans, sep = '\n')

Solution (Python):
import sys
input = sys.stdin.readline

lst = []
lst_append = lst.append
H, W, N = map(int, input().split())
tmplst = [-1, 0, 1]
for _ in range(N):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for i in range(-1, 2):
        for j in range(-1, 2):
            if 1 <= a + i <= H - 2 and 1 <= b + j <= W - 2:
                lst_append((a + i, b + j))

lst.sort()
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)

tmp = None
count = 0
for i in lst:
    if i == tmp:
        count += 1
    else:
        ans[0] -= 1
        ans[count] += 1
        count = 1
        tmp = i

ans[0] -= 1
ans[count] += 1
print (*ans, sep = '\n')

Solution (Python):
import sys
input = sys.stdin.readline

lst = []
lst_append = lst.append
H, W, N = map(int, input().split())
tmplst = [-1, 0, 1]
for _ in range(N):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for i in tmplst:
        for j in tmplst:
            if 1 <= a + i <= H - 2 and 1 <= b + j <= W - 2:
                lst_append((a + i, b + j))

lst.sort()
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)

tmp = None
count = 0
for i in lst:
    if i == tmp:
        count += 1
    else:
        ans[0] -= 1
        ans[count] += 1
        count = 1
        tmp = i

ans[0] -= 1
ans[count] += 1
print (*ans, sep = '\n')

Solution (Python):
from collections import defaultdict
import sys
input = sys.stdin.readline

H, W, N = map(int, input().split())
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)

tmplst = [-1, 0, 1]
dic = defaultdict(int)
for _ in range(N):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for i in tmplst:
        for j in tmplst:
            if 0 <= a + i <= H - 1 and 0 <= b + j <= W - 1: 
                tmp = dic[(a + i, b + j)]
                dic[(a + i, b + j)] += 1
                if 1 <= a + i <= H - 2 and 1 <= b + j <= W - 2:
                    ans[tmp] -= 1
                    ans[tmp + 1] += 1


print (*ans, sep = '\n')

Solution (Python):
def main():
    h,w,n=map(int,input().split(' '))
    if n==0:
        print((h-2)*(w-2))
        for i in range(9):
            print(0)
        exit()
    draw_list=[]
    for i in range(n):
        draw=tuple(map(int,input().split(' ')))
        for j in range(3):
            for k in range(3):
                if 0<draw[0]-j<=h-2 and 0<draw[1]-k<=w-2:
                    draw_list.append((draw[0]-j,draw[1]-k))
    ans = [0]*9
    sorted_draw = sorted(draw_list)
    for n,i in enumerate(sorted_draw):
        if not n:
            ans_num=0
            tmp = i
            continue
        if tmp == i:
            ans_num+=1
        else:
            ans[ans_num] += 1
            tmp = i
            ans_num = 0
    ans[ans_num] += 1
    print((h-2)*(w-2)-sum(ans))
    for i in ans:
        print(i)



if __name__ == '__main__':
    main()

Solution (Python):
h,w,n=map(int,input().split())
dic={}
dx=[-2,-1,0]
dy=[-2,-1,0]
ans=[0]*10
for _ in range(n):
  a,b=map(int,input().split())
  for x in dx:
    for y in dy:
      if 1<=a+y and a+y+2<=h and 1<=b+x and b+x+2<=w:
        if (a+y,b+x) not in dic:
          dic[(a+y,b+x)]=1
        else:
          dic[(a+y,b+x)]+=1
ans[0]=(h-2)*(w-2)-len(dic)
for v in dic.values():
  ans[v]+=1
for i in range(10):
  print(ans[i])

Solution (Python):
from collections import defaultdict

H, W, N = map(int,input().split())
  
ans =[(H-2)*(W-2)]+[0]*9
blacks = defaultdict(int)
for i in range(N):
  a, b = map(int,input().split())
  for dx in [-1,0,1]:
    for dy in [-1,0,1]:
      if 2 <= a+dx <H and 2 <= b+dy <W:
        ans[blacks[(a+dx,b+dy)]]-=1
        ans[blacks[(a+dx,b+dy)]+1]+=1
      blacks[(a+dx,b+dy)]+=1
        
for i in range(10): print(ans[i])

Solution (Python):
H,W,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in [0]*N]
d={}
for a,b in ab:
    for i in (a-1,a,a+1):
        for j in (b-1,b,b+1):
            d[(i,j)] = d.get((i,j),0)+1
cnt = [0]*10
for k,v in d.items():
    a,b = k
    if a<2 or b<2:continue
    if a>H-1 or b>W-1:continue
    cnt[v] += 1
cnt[0] = (W-2)*(H-2)-sum(cnt)
for ans in cnt:
    print(ans)

Solution (Python):
H,W,N = map(int,input().split())
dic={}
for _ in range(N):
  a,b = [int(x)-1 for x in input().split()]
  for h in range(a,a+3):
    for w in range(b,b+3):
      if 0<=h-2 and h<H and 0<=w-2 and w<W:
        dic[10**10*h+w] = dic.get(10**10*h+w,0)+1
ans = [0]*10
for x in dic.values():
  ans[x] += 1
ans[0] = (H-2)*(W-2)-sum(ans[1:])
for x in ans:
  print(x)

Solution (Python):
import collections

h, w, n = map(int, input().split())
squares = collections.defaultdict(lambda: collections.defaultdict(int))
for index in range(n):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for i in range(-2, 1):
        for j in range(-2, 1):
            y = a + i
            x = b + j
            if 0 <= x < w - 2 and 0 <= y < h - 2:
                squares[y][x] += 1
counter = collections.Counter()
for y, xs in squares.items():
    for x, count in xs.items():
        counter[count] += 1
print((h - 2) * (w - 2) - sum(counter.values()))
for i in range(1, 10):
    print(counter[i])

Solution (Python):
import collections

h, w, n = map(int, input().split())
squares = collections.defaultdict(lambda: collections.defaultdict(int))
for index in range(n):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for i in range(-2, 1):
        for j in range(-2, 1):
            y = a + i
            x = b + j
            if 0 <= x < w - 2 and 0 <= y < h - 2:
                squares[y][x] += 1
counter = collections.Counter()
for y, xs in squares.items():
    for x, count in xs.items():
        counter[count] += 1
print((h - 2) * (w - 2) - sum(counter.values()))
for i in range(1, 10):
    print(counter[i])

Solution (Python):
inp=input().split(" ")
H=int(inp[0])
W=int(inp[1])
N=int(inp[2])
plot=[]
times=[0 for i in range(10)]
times[0]=(H-2)*(W-2)
from collections import defaultdict
count=defaultdict(lambda:0)
def check(a,b,count):
    for i in range(3):
        for j in range(3):
            if a-i>=0 and b-j>=0 and a+2-i<=H-1 and b+2-j<=W-1:
                count[str([a-i,b-j])]+=1
for i in range(N):
    plot.append(list(map(int,input().split(" "))))
    check(plot[i][0]-1,plot[i][1]-1,count)
for i in count.values():
    times[i]+=1
    times[0]-=1
for i in range(len(times)):
    print(times[i])

Solution (Python):
import collections
h, w, n = map(int, input().split(" "))
list_include = []
for i in range(n):
  a, b = map(int, input().split(" "))
  for y in range(3):
    for x in range(3):
      if a - y > 0 and a - y + 2 <= h:
        if b - x > 0 and b - x + 2 <= w:
          list_include.append((a - y, b - x))
count = collections.Counter(list_include)
result = [0 for _ in range(10)]
for item in count.items():
  result[item[1]] += 1
result[0] = (h - 2) * (w - 2) - sum(result)
for one_result in result:
  print(one_result)

Solution (Python):
from collections import Counter as C;r=range(3)
def s():
	H,W,N,*L=map(int,open(0).read().split());D={};M=[(H-2)*(W-2)]+[0]*9
	for a,b in zip(*[iter(L)]*2):
		for x in r:
			for y in r:
				if H-1>a-y>0<b-x<W-1:
					t=(a-y)*W+b-x
					D[t]=D.get(t,0)+1
	for k,v in C(D.values()).items():M[0]-=v;M[k]+=v
	print(*M)
if __name__=="__main__":s()

Solution (Python):
from collections import Counter as C;H,W,N,*L=map(int,open(0).read().split());K=[];M=[(H-2)*(W-2)]+[0]*9
for a,b in zip(*[iter(L)]*2):
	for c in range(9):
		x=b-c//3;y=a-c%3
		if H-1>y>0<x<W-1:K+=[y*W+x]
for k,v in C(C(K).values()).items():M[0]-=v;M[k]+=v
print(*M)

Solution (Python):
from collections import Counter as C;r=range(3)
def s():
	H,W,N,*L=map(int,open(0).read().split());K=[];M=[(H-2)*(W-2)]+[0]*9
	for a,b in zip(*[iter(L)]*2):
		for x in r:
			for y in r:
				if H-1>a-y>0<b-x<W-1:K+=[(a-y)*W+b-x]
	for k,v in C(C(K).values()).items():M[0]-=v;M[k]+=v
	print(*M)
if __name__=="__main__":s()

Solution (Python):
import sys
from collections import defaultdict
input = sys.stdin.readline
H, W, N = map(int, input().split())

board = defaultdict(int)
black = []
for _ in range(N):
    a, b = map(int, input().split())
    black.append((a - 1, b - 1))
    board[(a-1) * W + (b - 1)] = 1

num = [0] * 10
for p in black:
    for ch in range(max(p[0] - 1, 1), min(p[0] + 2, H - 1)):
        for cw in range(max(p[1] - 1, 1), min(p[1] + 2, W - 1)):
            count = 0
            for h in range(ch - 1, ch + 2):
                for w in range(cw - 1, cw + 2):
                    if board[h * W + w] == 1:
                        count += 1
            num[count] += 1
for i in range(1, 10):
    num[i] //= i
print((H - 2) * (W - 2) - sum(num))
for i in range(1, 10):
    print(num[i])

Solution (Python):
H,W,N = map(int,input().split())
ab_list = [tuple(map(int,input().split())) for _ in range(N)]
table_dict = {}

diffs = [-1,0,1]
diff_tuples = [(a,b) for a in diffs for b in diffs]

for a, b in ab_list:
    for da,db in diff_tuples:
        if a+da in table_dict:
            row = table_dict[a+da]
            if b+db in row:
                row[b+db] += 1
            else:
                row[b+db] = 1
        else:
            table_dict[a+da] = {}
            table_dict[a+da][b+db] = 1

cnts = [0 for _ in range(10)]

for h,row in table_dict.items():
    for w,v in row.items():
        if 2 <= h <= H-1 and 2 <= w <= W-1:
            cnts[v] += 1

square_3x3 = (H-2) *(W-2)
cnts[0] = square_3x3 - sum(cnts[1:])

for cnt in cnts:
    print(cnt)

Solution (Python):
from collections import Counter

H, W, N, *AB = map(int, open(0).read().split())

move = [
    (-1, -1), (-1, 0), (-1, 1),
    (0, -1),  (0, 0),  (0, 1),
    (1, -1),  (1, 0),  (1, 1),
]

C = Counter()
for a, b in zip(*[iter(AB)] * 2):
    C.update(
        (a - i, b - j)
        for i, j in move
        if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1
    )

D = Counter(C.values())

print((H - 2) * (W - 2) - len(C))
for i in range(1, 10):
    print(D[i])

Solution (Python):
from collections import Counter

H, W, N, *AB = map(int, open(0).read().split())

move = [
    (-1, -1), (-1, 0), (-1, 1),
    (0, -1),  (0, 0),  (0, 1),
    (1, -1),  (1, 0),  (1, 1),
]

C = Counter()
for a, b in zip(*[iter(AB)] * 2):
    C.update(
        (a - i, b - j)
        for i, j in move
        if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1
    )

D = [0] * 10
for v in C.values():
    D[v] += 1

D[0] = (H - 2) * (W - 2) - len(C)
for d in D:
    print(d)

Solution (Python):
from collections import Counter

H, W, N, *AB = map(int, open(0).read().split())

move = [
    (-1, -1), (-1, 0), (-1, 1),
    (0, -1),  (0, 0),  (0, 1),
    (1, -1),  (1, 0),  (1, 1),
]

C = Counter()
for a, b in zip(*[iter(AB)] * 2):
    C.update(
        (a - i, b - j)
        for i, j in move
        if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1
    )

D = [0] * 10
for v in C.values():
    D[v] += 1

D[0] = (H - 2) * (W - 2) - len(C)
print("\n".join(map(str, D)))

Solution (Python):
from collections import Counter

H, W, N, *AB = map(int, open(0).read().split())

move = [
    (-1, -1), (-1, 0), (-1, 1),
    (0, -1),  (0, 0),  (0, 1),
    (1, -1),  (1, 0),  (1, 1),
]

C = Counter()
for a, b in zip(*[iter(AB)] * 2):
    C.update(
        (a - i, b - j)
        for i, j in move
        if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1
    )

D = [0] * 10
for v in C.values():
    D[v] += 1

print((H - 2) * (W - 2) - len(C))
for i in range(1, 10):
    print(D[i])

Solution (Python):
from collections import Counter

H, W, N, *AB = map(int, open(0).read().split())

move = [
    (-1, -1), (-1, 0), (-1, 1),
    (0, -1),  (0, 0),  (0, 1),
    (1, -1),  (1, 0),  (1, 1),
]

C = Counter()
for a, b in zip(*[iter(AB)] * 2):
    C.update(
        (a - i, b - j)
        for i, j in move
        if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1
    )

D = Counter(v for _, v in C.items())

print((H - 2) * (W - 2) - len(C))
for i in range(1, 10):
    print(D[i])