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):
H, W , N = map(int,input().split())
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
    for x_r in [-2, -1 , 0]:
        for y_r in [-2, -1 , 0]:
            nowx = l[0] + x_r
            nowy = l[1] + y_r
            if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
                continue
            
            name = str(nowx) +"hoge" +str(nowy)
            try: cand[name] += 1
            except: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in cand.values():
    ans[x] += 1
    tmp -= 1
ans[0] = tmp
for x in ans:
    print(x)

Solution (Python):
from collections import Counter

h,w,n = map(int,input().split())

black_count = {}

for _ in range(n):
    a,b = map(int,input().split())
    for dx in (-1,0,1):
        for dy in (-1,0,1):
            y = a+dy
            x = b+dx
            if 2<=y<=h-1 and 2<=x<=w-1:
                black_count[(y,x)] = black_count.get((y,x),0) + 1

ans = Counter(black_count.values())
ans[0] = (h-2) * (w-2) - sum(ans.values())
for i in range(10):
    print(ans.get(i,0))

Solution (Python):
from collections import defaultdict, Counter

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

ctr = defaultdict(int)
for a, b in X:
    for k in range(3):
        for l in range(3):
            if 1 <= a - k <= H - 2 and 1 <= b - l <= W - 2:
                ctr[(a - k, b - l)] += 1

d = Counter(ctr.values())
for i in range(10):
    if i == 0:
        print((H - 2) * (W - 2) - sum(d.values()))
    else:
        print(d[i])

Solution (Python):
from collections import defaultdict
from bisect import *
h, w, n = map(int, input().split())

d = defaultdict(list)
q = [list(map(int, input().split())) for i in range(n)]
q.sort()
ans = [0]*10
for i in range(n):
    a, b = q[i]
    d[a].append(b)

for a, b in q:
    for i in range(max(1, a-2), min(h-2, a)+1):
        for j in range(max(1, b-2), min(w-2, b)+1):
            count = 0
            for k in range(3):
                count += bisect_right(d[i+k], j+2) - bisect_left(d[i+k], j)
            ans[count] += 1


for i in range(1, 10):
    ans[i] //= i

ans[0] = (w-2)*(h-2) - sum(ans[1:])
for i in range(10):
    print(ans[i])

Solution (Python):
h, w, n = [int(i) for i in input().split()]
A = [0 for _ in range(n)]
B = [0 for _ in range(n)]
cnt = {}


for i in range(n):
	a, b = [int(j) for j in input().split()]
	if a > 1 and b > 1 and a < h and b < w:
		if "{} {}".format(a, b) not in cnt.keys():
			cnt["{} {}".format(a, b)] = 0
		cnt["{} {}".format(a, b)] += 1
	if a > 2 and b > 2 and a <= h and b <= w:	
		if "{} {}".format(a-1, b-1) not in cnt.keys():
			cnt["{} {}".format(a-1, b-1)] = 0
		cnt["{} {}".format(a-1, b-1)] += 1
	if a > 2 and b > 1 and a <= h and b < w:	
		if "{} {}".format(a-1, b) not in cnt.keys():
			cnt["{} {}".format(a-1, b)] = 0
		cnt["{} {}".format(a-1, b)] += 1
	if a > 2 and b > 0 and a <= h and b < w-1:
		if "{} {}".format(a-1, b+1) not in cnt.keys():
			cnt["{} {}".format(a-1, b+1)] = 0
		cnt["{} {}".format(a-1, b+1)] += 1
	if a > 1 and b > 2 and a < h and b <= w:
		if "{} {}".format(a, b-1) not in cnt.keys():
			cnt["{} {}".format(a, b-1)] = 0
		cnt["{} {}".format(a, b-1)] += 1
	if a > 0 and b > 0 and a < h-1 and b < w-1:
		if "{} {}".format(a+1, b+1) not in cnt.keys():
			cnt["{} {}".format(a+1, b+1)] = 0
		cnt["{} {}".format(a+1, b+1)] += 1
	if a > 0 and b > 1 and a < h-1 and b < w:
		if "{} {}".format(a+1, b) not in cnt.keys():
			cnt["{} {}".format(a+1, b)] = 0
		cnt["{} {}".format(a+1, b)] += 1
	if a > 1 and b > 0 and a < h and b < w-1:
		if "{} {}".format(a, b+1) not in cnt.keys():
			cnt["{} {}".format(a, b+1)] = 0
		cnt["{} {}".format(a, b+1)] += 1
	if a > 0 and b > 2 and a < h-1 and b <= w:
		if "{} {}".format(a+1, b-1) not in cnt.keys():
			cnt["{} {}".format(a+1, b-1)] = 0
		cnt["{} {}".format(a+1, b-1)] += 1

count = [0 for i in range(10)]
for i in cnt.values():
	count[i] += 1
count[0] =  (h-2)*(w-2) - len(cnt)

for i in count:
	print(i)

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''









h,w,n = list(map(int, input().split()))
painted = []
for i in range(n):
    t = list(map(int, input().split()))
    for j in range(3):
        for k in range(3):
            painted.append([t[0]-2+j, t[1]-2+k])
    
painted.sort(key = lambda x : x[1])
painted.sort(key = lambda x : x[0])

p2 = []

for i in painted:
    if(i[0]>=1 and i[0]<h-1 and i[1]>=1 and i[1]<w-1):
        p2.append(i)


ans = [0 for i in range(10)]
chain=0
if(len(p2)>0):
    before = p2[0]
    chain = 1
for ii in range(len(p2)-1):
    i = ii+1
    if(p2[i][0] == before[0] and p2[i][1] == before[1]):
        chain += 1
    else:
        ans[chain]+=1
        chain=1
        before[0],before[1] = p2[i]
if(len(p2)>0): ans[chain]+=1

ans[0] = (h-2)*(w-2) - sum(ans[1:])
for i in ans:
    print(i)

Solution (Python):
from collections import defaultdict, Counter
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

H, W, N = map(int, input().split())
d = defaultdict(int)
for _ in range(N):
    x, y = map(int, input().split())
    for i in range(-2, 1):
        if 1 <= x + i <= H - 2:
            for j in range(-2, 1):
                if 1 <= y + j <= W - 2:
                    d[(x + i, y + j)] += 1

c = Counter(d.values())
zero = (H - 2) * (W - 2) - len(d)
print(zero)
for i in range(1, 10):
    print(c[i])

Solution (Python):
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

H, W, N = map(int, input().split())
cand = set()
dot = set()
for _ in range(N):
    x, y = map(int, input().split())
    dot.add((x, y))
    for i in range(-2, 1):
        if 1 <= x + i <= H - 2:
            for j in range(-2, 1):
                if 1 <= y + j <= W - 2:
                    cand.add((x + i, y + j))

ans = [0] * 10
for x, y in cand:
    cnt = 0
    for i in range(3):
        for j in range(3):
            cnt += int((x + i, y + j) in dot)
    ans[cnt] += 1

zero = (H - 2) * (W - 2) - sum(ans)
ans[0] = zero
print(*ans, sep="\n")

Solution (Python):
def main():
    h, w, n = map(int, input().split())
    dic = {}
    for _ in range(n):
        a, b = map(int, input().split())
        for i in range(max(2, a-1), min(h, a+2)):
            for j in range(max(2, b-1), min(w, b+2)):
                if (i, j) in dic:
                    dic[(i, j)] += 1
                else:
                    dic[(i, j)] = 1
    ans = [0]*10
    cnt = 0
    for v in dic.values():
        ans[v] += 1
        cnt += 1
    ans[0] = (h-2)*(w-2) - cnt
    for i in range(10):
        print(ans[i])

if __name__ == "__main__":
    main()

Solution (Python):
h,w,n = map(int, input().split())
ab = [tuple(map(int, input().split())) for i in range(n)]
J = [0] * 10
black = dict()
for i in ab:
  black[i] = 1
for a,b in ab:
  for x in range(max(0,3-a),min(3,h+1-a)):
    for y in range(max(0,3-b),min(3,w+1-b)):
      j = 0
      for X in range(a+x-2,a+x+1):
        for Y in range(b+y-2,b+y+1):
          if (X,Y) in black:
            j += 1
      J[j] += 1
for i in range(2,10):
  J[i] //= i
ALL = (h-2) * (w-2)
J[0] = ALL - sum(J[1:])
for i in J:
  print(i)

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

h,w,n = map(int,input().split())
ab = [tuple(map(int,input().split())) for _ in range(n)]

ans = [0] * 10
ans[0] = (h-2)*(w-2)

black = set(ab)
checked = set()

for tmp in ab:
    a,b = tmp
    y0 = max(1,a-2)
    y1 = min(h,a+2)-1
    x0 = max(1,b-2)
    x1 = min(w,b+2)-1
    for i in range(x0,x1):
        for j in range(y0,y1):
            if ((j,i) in checked):
                continue
            tmp = 0
            for x in range(3):
                for y in range(3):
                    tmp += ((j+y,i+x) in black)
            ans[0] -= 1
            ans[tmp] += 1
            checked.add((j,i))

print('\n'.join(map(str,ans)))

Solution (Python):
def main():
    import sys
    from collections import Counter
    
    readlines = sys.stdin.readlines
    H, W, N = map(int, input().split())
    P = set()
    for s in readlines():
        a, b = map(int, s.split())
        a -= 1; b -= 1
        P.add((a, b))

    cnt = Counter()
    for a, b in P:
        for oa in range(a - 2, a + 1):
            for ob in range(b - 2, b + 1):
                if 0 <= oa <= H - 3 and 0 <= ob <= W - 3:
                    cnt[(oa, ob)] += 1
    ans = Counter(cnt.values())
    ans[0] = (H - 2) * (W - 2) - sum(ans.values())

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


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    import sys
    
    readlines = sys.stdin.readlines
    H, W, N = map(int, input().split())
    grid = {}
    P = set()
    for s in readlines():
        a, b = map(int, s.split())
        a -= 1; b -= 1
        if a in grid:
            grid[a].add(b)
        else:
            grid[a] = set([b])
        P.add((a, b))

    ans = [0] * 10
    done = set()
    for a, b in P:
        for oa in range(a - 2, a + 1):
            for ob in range(b - 2, b + 1):
                if 0 <= oa <= H - 3 and 0 <= ob <= W - 3 and (oa, ob) not in done:
                    tmp = 0
                    for i in range(3):
                        for j in range(3):
                            na = oa + i
                            nb = ob + j
                            if (na, nb) in P:
                                tmp += 1
                    ans[tmp] += 1
                    done.add((oa, ob))
    
    ans[0] = (H - 2) * (W - 2) - sum(ans[1:])

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


if __name__ == "__main__":
    main()

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
import itertools


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

L = []
for _ in range(N):
    a,b = map(int, input().split())
    for i in range(3):
        if a+i-1 <= 1 or a+i-1 >= H: continue
        for j in range(3):
            if b+j-1 <= 1 or b+j-1 >= W: continue
            L.append((a+i-1, b+j-1))
L.sort()
C = Counter(L)

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

print('\n'.join(map(str, ans)))

Solution (Python):

import io
from collections import Counter

nim, mike, kite, *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 <= nim - 1 and 2 <= b - j <= mike - 1
    )

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

print((nim - 2) * (mike - 2) - sum(D.values()))
for i in range(1, 10):
    print(D[i])

Solution (Python):
H, W, N = input().split(" ")
H, W, N = int(H), int(W), int(N)
A = []
for i in range(N):
    A.append([int(j) for j in input().split(" ")])


import itertools
from collections import defaultdict, Counter

c = defaultdict(int)
for a, b in A:
    
    for dx,dy in itertools.product([-1,0,1],repeat = 2):
        aa = a + dx
        bb = b + dy
        if 2 <= aa <= H-1 and 2 <= bb <= W-1:
            c[(aa,bb)] += 1
            
result = Counter(c.values())
result[0] = (H-2)*(W-2) - sum(result.values())
 
for j in range(10):
    print(result[j])

Solution (Python):
import sys

input=sys.stdin.readline

H,W,N=map(int,input().split())
point=set([])
ans=[0 for i in range(0,10)]
ans[0]=(H-2)*(W-2)

def black(x,y):
    ans=0
    if (x-1,y-1) in point:
        ans+=1
    if (x-1,y) in point:
        ans+=1
    if (x-1,y+1) in point:
        ans+=1

    if (x,y-1) in point:
        ans+=1
    if (x,y) in point:
        ans+=1
    if (x,y+1) in point:
        ans+=1

    if (x+1,y-1) in point:
        ans+=1
    if (x+1,y) in point:
        ans+=1
    if (x+1,y+1) in point:
        ans+=1
        
    return ans

for _ in range(0,N):
    a,b=map(int,input().split())
    if a>2:
        if b>2:
            ss=black(a-1,b-1)
            ans[ss]-=1
            ans[ss+1]+=1

        if W>b>1:
            ss=black(a-1,b)
            ans[ss]-=1
            ans[ss+1]+=1

        if W-1>b:
            ss=black(a-1,b+1)
            ans[ss]-=1
            ans[ss+1]+=1
    if H>a>1:
        if b>2:
            ss=black(a,b-1)
            ans[ss]-=1
            ans[ss+1]+=1

        if W>b>1:
            ss=black(a,b)
            ans[ss]-=1
            ans[ss+1]+=1

        if W-1>b:
            ss=black(a,b+1)
            ans[ss]-=1
            ans[ss+1]+=1

    if H-1>a:
        if b>2:
            ss=black(a+1,b-1)
            ans[ss]-=1
            ans[ss+1]+=1
        if W>b>1:
            ss=black(a+1,b)
            ans[ss]-=1
            ans[ss+1]+=1

        if W-1>b:
            ss=black(a+1,b+1)
            ans[ss]-=1
            ans[ss+1]+=1

    point.add((a,b))

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

Solution (Python):
import sys

input=sys.stdin.readline

H,W,N=map(int,input().split())
point=set([])
ans=[0 for i in range(0,10)]
ans[0]=(H-2)*(W-2)

def black(x,y):
    ans=0
    if x!=1:
        if y!=1:
            if (x-1,y-1) in point:
                ans+=1
        if (x-1,y) in point:
            ans+=1
        if y!=W:
            if (x-1,y+1) in point:
                ans+=1
    if y!=1:
        if (x,y-1) in point:
            ans+=1
    if (x,y) in point:
        ans+=1
    if y!=W:
        if (x,y+1) in point:
            ans+=1
    if x!=H:
        if y!=1:
            if (x+1,y-1) in point:
                ans+=1
        if (x+1,y) in point:
            ans+=1
        if y!=W:
            if (x+1,y+1) in point:
                ans+=1
    return ans

for _ in range(0,N):
    a,b=map(int,input().split())
    if a>2:
        if b>2:
            ss=black(a-1,b-1)
            ans[ss]-=1
            ans[ss+1]+=1

        if W>b>1:
            ss=black(a-1,b)
            ans[ss]-=1
            ans[ss+1]+=1

        if W-1>b:
            ss=black(a-1,b+1)
            ans[ss]-=1
            ans[ss+1]+=1
    if H>a>1:
        if b>2:
            ss=black(a,b-1)
            ans[ss]-=1
            ans[ss+1]+=1

        if W>b>1:
            ss=black(a,b)
            ans[ss]-=1
            ans[ss+1]+=1

        if W-1>b:
            ss=black(a,b+1)
            ans[ss]-=1
            ans[ss+1]+=1

    if H-1>a:
        if b>2:
            ss=black(a+1,b-1)
            ans[ss]-=1
            ans[ss+1]+=1
        if W>b>1:
            ss=black(a+1,b)
            ans[ss]-=1
            ans[ss+1]+=1

        if W-1>b:
            ss=black(a+1,b+1)
            ans[ss]-=1
            ans[ss+1]+=1

    point.add((a,b))

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

Solution (Python):
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W, N = lr()
shift = ((0, 0), (0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (-1, 1), (1, -1))

l = []

for n in range(N):
    a, b = lr()
    for s in shift:
        aa = a + s[0] - 1
        bb = b + s[1] - 1
        if aa < 1 or aa > H-2:
            continue
        if bb < 1 or bb > W-2:
            continue
        l.append((aa-1, bb-1))
if len(l) == 0:
    print((H-2) * (W-2))
    [print(0) for _ in range(9)]
    exit(0)
l.sort()
m = {i: 0 for i in range(10)}
pre = l[0]
c = 1
for ll in l[1:]:
    if pre == ll:
        c += 1
    else:
        m[c] += 1
        pre = ll
        c = 1
m[c] += 1
m[0] = (H-2) * (W-2) - sum(m.values())
for v in m.values():
    print(v)

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

H, W, N = map(int, input().split())
count = defaultdict(int)
for _ in range(N):
    a, b = map(int, input().split())
    for da in range(3):
        for db in range(3):
            na, nb = a - da, b - db
            if 1 <= na <= H - 2 and 1 <= nb <= W - 2:
                count[(na, nb)] += 1
ans = [0] * 10
for k, v in count.items():
    ans[v] += 1
ans[0] = (H-2) * (W-2) - sum(ans)
print(*ans, sep='\n')

Solution (Python):
H, W, N = map(int, input().split())
li = []
for i in range(N):
  li.append(tuple(map(int, input().split())))
t = tuple(li)
st = set(t)


Js = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

for a, b in t:
  if a > H-2 or b > W-2:
    pass
  else:
    t_p1 = ((a, b), (a, b+1), (a, b+2),\
            (a+1, b), (a+1, b+1), (a+1, b+2),\
            (a+2, b), (a+2, b+1), (a+2, b+2))
    s1 = st & set(t_p1)
    ls1 = len(s1)
    Js[ls1] += 1
  
  if a > H-2 or b > W-1 or b < 2:
    pass
  else:
    t_p2 = ((a, b-1), (a, b), (a, b+1),\
            (a+1, b-1), (a+1, b), (a+1, b+1),\
            (a+2, b-1), (a+2, b), (a+2, b+1))
    s2 = st & set(t_p2)
    ls2 = len(s2)
    Js[ls2] += 1
  
  if a > H-2 or b < 3:
    pass
  else:
    t_p3 = ((a, b-2), (a, b-1), (a, b),\
            (a+1, b-2), (a+1, b-1), (a+1, b),\
            (a+2, b-2), (a+2, b-1), (a+2, b))
    s3 = st & set(t_p3)
    ls3 = len(s3)
    Js[ls3] += 1

  if a > H-1 or a < 2 or b > W-2:
    pass
  else:
    t_p4 = ((a-1, b), (a-1, b+1), (a-1, b+2),\
            (a, b), (a, b+1), (a, b+2),\
            (a+1, b), (a+1, b+1), (a+1, b+2))
    s4 = st & set(t_p4)
    ls4 = len(s4)
    Js[ls4] += 1
  
  if a > H-1 or a < 2 or b > W-1 or b < 2:
    pass
  else:
    t_p5 = ((a-1, b-1), (a-1, b), (a-1, b+1),\
            (a, b-1), (a, b), (a, b+1),\
            (a+1, b-1), (a+1, b), (a+1, b+1))
    s5 = st & set(t_p5)
    ls5 = len(s5)
    Js[ls5] += 1
  
  if a > H-1 or a < 2 or b < 3:
    pass
  else:
    t_p6 = ((a-1, b-2), (a-1, b-1), (a-1, b),\
            (a, b-2), (a, b-1), (a, b),\
            (a+1, b-2), (a+1, b-1), (a+1, b))
    s6 = st & set(t_p6)
    ls6 = len(s6)
    Js[ls6] += 1
  
  if a < 3 or b > W-2:
    pass
  else:
    t_p7 = ((a-2, b), (a-2, b+1), (a-2, b+2),\
            (a-1, b), (a-1, b+1), (a-1, b+2),\
            (a, b), (a, b+1), (a, b+2))
    s7 = st & set(t_p7)
    ls7 = len(s7)
    Js[ls7] += 1
  
  if a < 3 or b > W-1 or b < 2:
    pass
  else:
    t_p8 = ((a-2, b-1), (a-2, b), (a-2, b+1),\
            (a-1, b-1), (a-1, b), (a-1, b+1),\
            (a, b-1), (a, b), (a, b+1))
    s8 = st & set(t_p8)
    ls8 = len(s8)
    Js[ls8] += 1
  
  if a < 3 or b < 3:
    pass
  else:
    t_p9 = ((a-2, b-2), (a-2, b-1), (a-2, b),\
            (a-1, b-2), (a-1, b-1), (a-1, b),\
            (a, b-2), (a, b-1), (a, b))
    s9 = st & set(t_p9)
    ls9 = len(s9)
    Js[ls9] += 1

for i in range(1, 10):
  Js[i] = Js[i] // i

all = (H - 2) * (W - 2)
Js[0] = all - sum(Js)
  
for i in range(10):
  print(Js[i])

Solution (Python):
def solve(h,w,n,black_list):
  if len(black_list) == 0:
    return [(h-2)*(w-2)]+[0]*9
  idx_list = []
  for idx, (a,b) in enumerate(black_list):
    left = max(0, b-3)
    top = max(0, a-3)
    for row in range(top, a):
      if row+2 >= h:
        continue
      for col in range(left, b):
        if col+2 >= w:
          continue
        idx_list.append(row*w+col)

  set_count = set(idx_list)
  idx_list = sorted(idx_list)

  ans = [0]*9
  now = idx_list[0]
  count = 0
  for item in idx_list:
    if item == now:
      count += 1
    else:
      now = item
      if count == 10:
        print(item)
      ans[count-1] += 1
      count = 1
  ans[count-1] += 1
  return [(h-2)*(w-2)-len(set_count)]+ans


if __name__ == "__main__":
  h,w,n = map(int,input().split())
  black_list = [tuple(map(int,input().split())) for _ in range(n)]
  ret = solve(h,w,n,black_list)
  for i in ret:
    print(i)

Solution (Python):
from collections import defaultdict
h,w,n=map(int,input().split())
d=defaultdict(int)
s=set()
for _ in range(n):
  a,b=map(int,input().split())
  a-=1
  b-=1
  for dy in [-2,-1,0]:
    for dx in [-2,-1,0]:
      ny,nx=a+dy,b+dx
      if 0<=ny<h and 0<=nx<w and ny+2<h and nx+2<w:
        d[(ny,nx)]+=1
        s.add((ny,nx))
cnt=[0]*10
q=0
for y,x in s:
  cnt[d[(y,x)]]+=1
cnt[0]=(h-2)*(w-2)-len(s)
for i in cnt:
  print(i)

Solution (Python):
h,w,n=map(int,input().split())
d={}
s=set()
for _ in range(n):
  a,b=map(int,input().split())
  a-=1
  b-=1
  for dy in [-2,-1,0]:
    for dx in [-2,-1,0]:
      ny,nx=a+dy,b+dx
      if 0<=ny<h and 0<=nx<w and ny+2<h and nx+2<w:
        if (ny,nx) in s:
          d[(ny,nx)]+=1
        else:
          d[(ny,nx)]=1
          s.add((ny,nx))
cnt=[0]*10
q=0
for v in d.values():
  cnt[v]+=1
cnt[0]=(h-2)*(w-2)-len(s)
for i in cnt:
  print(i)

Solution (Python):
h,w,n = map(int,input().split())
grids = {}
D = [1,-1,0]
for _ in range(n):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  
  for dx in D:
    for dy  in D:
      na,nb = a+dx,b+dy
      if not(0<na<h-1 and 0<nb<w-1):
        continue
      if(na,nb) not in grids:
        grids[(na,nb)] = 0
      grids[(na,nb)] += 1
      
        
        
ans = [0 for _ in range(10)]

for v in grids.values():
  ans[v]+=1

ans[0] = (h-2)*(w-2)-sum(ans)

for a in ans:
  print(a)

Solution (Python):
h,w,n = map(int, input().split())
memo = {}
dxy = [(0,1), (0,0), (1,0), (-1,0), (0,-1), (1,1), (-1,-1), (-1,1), (1,-1)]
for i in range(n):
    a,b = map(int, input().split())
    for dx,dy in dxy:
        x,y = a+dx,b+dy
        if 1 < x < h and 1 < y < w:
            if (x,y) not in memo:
                memo[(x,y)] = 0
            memo[(x,y)] += 1

ans = [0 for i in range(10)]
for k,v in memo.items():
    ans[v] += 1
ans[0] = (h-2)*(w-2) - sum(ans)
[print(i) for i in ans]

Solution (Python):






h, w, n = map(int, input().split())

idx1 = 0
ab = [[0 for i in range(2)] for j in range(n)]

black_cnt = [0] * 10
black_cnt[0] = (h - 2) * (w - 2)

if n != 0:
    while idx1 < n:
        x = input().split()
        
        ab[idx1] = [int(x[0]), int(x[1])]
        idx1 += 1

    myDict = {}
    for abitem in ab:
        if abitem[0] < 3:
            sr = 0
        else:
            sr = abitem[0] - 3
        if abitem[0] > h - 3:
            lr = h - 2
        else:
            lr = abitem[0]
        if abitem[1] < 3:
            sc = 0
        else:
            sc = abitem[1] - 3
        if abitem[1] > w - 3:
            lc = w - 2
        else:
            lc = abitem[1]

        for nowRow in range(sr, lr):
            for nowCol in range(sc, lc):
                key = str(nowRow) + ',' + str(nowCol)
                if key in myDict:
                    myDict[key] += 1
                else:
                    myDict[key] = 1

    for bcnt in myDict.values():
        black_cnt[bcnt] += 1
        black_cnt[0]    -= 1

for item in black_cnt:
    print(item)

Solution (Python):
H,W,N = map(int,input().split())
d = {}
for _ in range(N):
    a,b = list(map(int,input().split()))
    for dy in range(-1,2):
        for dx in range(-1,2):
            cy = a + dy
            cx = b + dx
            if 2 <= cy <= H-1 and 2 <= cx <= W-1:
                if (cy,cx) not in d:
                    d[(cy,cx)] = 1
                else:
                    d[(cy, cx)] += 1
ans = [0]*10
for v in d.values():
    ans[v] += 1
ans[0] = (H-2)*(W-2) - sum(ans[1:])

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

Solution (Python):
import sys
input=sys.stdin.readline
h,w,n = map(int, input().split())
l=[list(map(int,input().split())) for i in range(n)]

from collections import defaultdict
d = defaultdict(int)
for tmp in l:
    y=tmp[0]-1
    x=tmp[1]-1
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if 1<=x+i<w-1 and 1<=y+j <h-1:
                s = str(x+i) + "_" + str(y+j)
                d[s]+=1

import collections
lis = list(d.values())
c = collections.Counter(lis)

ans=[0]*10
for itm in c.items():
    ans[itm[0]]=itm[1]

ans[0]=(h-2)*(w-2)-sum(ans)

for a in ans:
    print(a)

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

from collections import defaultdict
d = defaultdict(int)
for tmp in l:
    y=tmp[0]-1
    x=tmp[1]-1
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if 1<=x+i<w-1 and 1<=y+j <h-1:
                s = str(x+i) + "_" + str(y+j)
                d[s]+=1

import collections
lis = list(d.values())
c = collections.Counter(lis)

ans=[0]*10
for itm in c.items():
    ans[itm[0]]=itm[1]

ans[0]=(h-2)*(w-2)-sum(ans)

for a in ans:
    print(a)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
H,W,N=map(int,input().split())
d=[]
for i in range(N):
    a,b=map(int,input().split())
    for j in range(-1,2):
        if not 1<a+j<H:
            continue
        for k in range(-1,2):
            if not 1<b+k<W:
                continue
            t=(a+j,b+k)
            d.append(t)
d.sort()
l=[0]*10
t=0
c=0
for i in d:
    if i==t:
        c+=1
    else:
        l[c]+=1
        t=i
        c=1
l[c]+=1
l[0]=(H-2)*(W-2)-sum(l)+1
print(*l,sep="\n")

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
H,W,N=map(int,input().split())
d={}
for i in range(N):
    a,b=map(int,input().split())
    for j in range(-1,2):
        if not 1<a+j<H:
            continue
        for k in range(-1,2):
            if not 1<b+k<W:
                continue
            t=(a+j,b+k)
            if t in d:
                d[t]+=1
            else:
                d[t]=1
l=[0]*10
for i in d.values():
    l[i]+=1
l[0]=(H-2)*(W-2)-sum(l)
print(*l,sep="\n")

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
H,W,N=map(int,input().split())
d={}
for i in range(N):
    a,b=map(int,input().split())
    for j in range(-1,2):
        if not 1<a+j<H:
            continue
        for k in range(-1,2):
            if not 1<b+k<W:
                continue
            t=(a+j,b+k)
            if t in d:
                d[t]+=1
            else:
                d[t]=1
l=[0]*10
for i in d.values():
    l[i]+=1
l[0]=(H-2)*(W-2)-sum(l)
print(*l,sep="\n")

Solution (Python):
from itertools import product
from collections import defaultdict, Counter
import sys
input = sys.stdin.readline
h,w,n = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
pls = defaultdict(int)
for x,y in a:
  for arx,ary in product(list(range(x-1,x+2)),list(range(y-1,y+2))):
    if 2<=arx<=h-1 and 2<=ary<=w-1:
      pls[(arx,ary)] += 1
c = Counter(pls.values())
print((h-2)*(w-2)-sum(c.values()))
for i in range(1,10):
  print(c[i])

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

def main():
    h,w,n = map(int,input().split())
    dg = 10**10
    d = dict()

    def f(x,y):
        if 2 <= x <= h-1 and 2 <= y <= w-1:
            return True
        else:
            False

    for i in range(n):
        a,b = map(int,input().split())
        
        if f((a-1),b-1):
            if (a-1)*dg + b-1 in d:
                d[(a-1)*dg + b-1] += 1
            else:
                d[(a-1)*dg + b-1] = 1
        
        if f((a-1),b):
            if (a-1)*dg + b in d:
                d[(a-1)*dg + b] += 1
            else:
                d[(a-1)*dg + b] = 1
        
        if f((a-1),b+1):
            if (a-1)*dg + b+1 in d:
                d[(a-1)*dg + b+1] += 1
            else:
                d[(a-1)*dg + b+1] = 1

        if f((a),b-1):
            if (a)*dg + b-1 in d:
                d[(a)*dg + b-1] += 1
            else:
                d[(a)*dg + b-1] = 1
        
        if f(a,b):
            if a*dg + b in d:
                d[a*dg + b] += 1
            else:
                d[a*dg + b] = 1
        
        if f((a),b+1):
            if (a)*dg + b+1 in d:
                d[(a)*dg + b+1] += 1
            else:
                d[(a)*dg + b+1] = 1
        
        if f((a+1),b+1):
            if (a+1)*dg + b+1 in d:
                d[(a+1)*dg + b+1] += 1
            else:
                d[(a+1)*dg + b+1] = 1
        
        if f((a+1),b):
            if (a+1)*dg + b in d:
                d[(a+1)*dg + b] += 1
            else:
                d[(a+1)*dg + b] = 1
        
        if f((a+1),b-1):
            if (a+1)*dg + b-1 in d:
                d[(a+1)*dg + b-1] += 1
            else:
                d[(a+1)*dg + b-1] = 1
        
        
        
        
    res = [0]*10
 
    for e in d:
        res[d[e]] += 1
 
    res[0] = (h-2)*(w-2)-sum(res)
 
    for e in res:
        print(e)
 
if __name__ == "__main__":
    main()