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 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):
    for i, j in move:
        if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1:
            C[(a - i, b - j)] += 1

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

print((H - 2) * (W - 2) - sum(D.values()))
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) - sum(D.values()))
for i in range(1, 10):
    print(D[i])

Solution (Python):
from collections import Counter
from itertools import product

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) - sum(D.values()))
for i in range(1, 10):
    print(D[i])

Solution (Python):
from collections import Counter
from itertools import product

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

C = Counter()
for a, b in zip(*[iter(AB)] * 2):
    C.update(
        (a - i, b - j)
        for i, j in product((-1, 0, 1), repeat=2)
        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) - sum(D.values()))
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())

C = Counter()
for a, b in zip(*[iter(AB)] * 2):
    C.update(
        (a - i, b - j)
        for i in range(-1, 2) for j in range(-1, 2)
        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) - sum(D.values()))
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())

C = Counter()
for a, b in zip(*[iter(AB)] * 2):
    C.update(
        [(a - i, b - j)
        for i in range(-1, 2)
        for j in range(-1, 2)
        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) - sum(D.values()))
for i in range(1, 10):
    print(D[i])

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

for i in range(n):
    for j in range(2):
        A[i][j] -= 1

D = {}

for i in range(n):
    
    for j in range(-1, 2):
        for k in range(-1, 2):
            if 1 <= A[i][0]+j <= h-2 and 1 <= A[i][1]+k <= w-2:
                try:
                    D[(A[i][0]+j, A[i][1]+k)] += 1
                except:
                    D[(A[i][0]+j, A[i][1]+k)] = 1

ANS = [0] * 10
for i in D.values():
    ANS[i] += 1
ANS[0] = (h-2) * (w-2) - sum(ANS[1:])

for i in ANS:
    print(i)

Solution (Python):
from collections import defaultdict as dd
H, W, N = map(int, input().split())
res = [0] * 10
res[0] = H * W - 2 * H - 2 * W + 4
p = dd(int)
d = [-1, 0, 1]
for _ in range(N):
  y, x = map(int, input().split())
  for i in d:
    for j in d:
      if 1 < y + i < H and 1 < x + j < W:
        p[(y + i) * (H * W + 1) + x + j] += 1
for k in p.keys():
  res[p[k]] += 1
  res[0] -= 1
for r in res:
  print(r)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



h, w, n = LI()
A = []
for a, b in LIR(n):
    for i, j in product((1, 0, -1), (1, 0, -1)):
        if 2 <= a + i <= h - 1 and 2 <= b + j <= w - 1:
            A += [(a + i, b + j)]


ans = [0 for i in range(9)]
for k, v in Counter(A).items():
    ans[v - 1] += 1


print((h - 2) * (w - 2) - sum(ans))
for j in ans:
    print(j)

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

delta = (-1, 0, 1)

ans = []
for i in range(N):
    a, b = map(int, input().split())
    for da in delta:
        for db in delta:
            if 1 <= a-1+da <= H-2 and 1 <= b-1+db <= W-2:
                ans.append((a-1+da, b-1+db))

cc = collections.Counter(collections.Counter(ans).values())
zc = (H-2)*(W-2)-sum(cc.values())
print(zc)
for i in range(1, 10):
    print(cc[i])

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

h, w, n = map(int, input().split())
d = defaultdict(int)
dx = [1, 1, 1, 0, 0, 0, -1, -1, -1]
dy = [1, 0, -1, 1, 0, -1, 1, 0, -1]
for i in range(n):
    a, b = map(int, input().split())
    for k in range(9):
        na = a+dx[k]
        nb = b+dy[k]
        if na <= 1 or nb <= 1 or na > h-1 or nb > w-1:
            continue
        d[(na, nb)] += 1

ans = [0] * 10
for key in d:
    ans[d[key]] += 1
ans[0] = (h-2) * (w-2) - sum(ans)

for ans_i in ans:
    print(ans_i)

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

h, w, n = map(int, input().split())
d = defaultdict(int)
dx = [1, 1, 1, 0, 0, 0, -1, -1, -1]
dy = [1, 0, -1, 1, 0, -1, 1, 0, -1]
for i in range(n):
    a, b = map(int, input().split())
    for k in range(9):
        d[(a+dx[k], b+dy[k])] += 1

ans = [0] * 10
for a, b in d:
    if a <= 1 or b <= 1 or a > h-1 or b > w-1:
        continue
    ans[d[(a, b)]] += 1
ans[0] = (h-2) * (w-2) - sum(ans)

for ans_i in ans:
    print(ans_i)

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


graph = {}
for _ in range(N):
    a, b = list(map(int, input().split()))
    for i in [-1, 0, 1]:
        for j in [-1, 0, 1]:
            na, nb = a-1+i, b-1+j
            if 1 <= na <= H-2 and 1 <= nb <= W-2:
                if not na in graph.keys():
                    graph[na] = {nb: 1}
                elif not nb in graph[na].keys():
                    graph[na][nb] = 1
                else:
                    graph[na][nb] += 1

ans = [0 for _ in range(10)]
S = 0
for a, v_graph in graph.items():
    for b, v in v_graph.items():
        ans[v] += 1
        S += 1
ans[0] = (H-2)*(W-2) - S
for a in ans:
    print(a)

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


graph = {}
for _ in range(N):
    a, b = list(map(int, input().split()))
    for i in [-1, 0, 1]:
        for j in [-1, 0, 1]:
            na, nb = a-1+i, b-1+j
            if 1 <= na <= H-2 and 1 <= nb <= W-2:
                if not graph.get(na, False):
                    graph[na] = {nb: 1}
                elif not graph[na].get(nb, False):
                    graph[na][nb] = 1
                else:
                    graph[na][nb] += 1

ans = [0 for _ in range(10)]
S = 0
for a, v_graph in graph.items():
    for b, v in v_graph.items():
        ans[v] += 1
        S += 1
ans[0] = (H-2)*(W-2) - S
for a in ans:
    print(a)

Solution (Python):
from collections import defaultdict

縦, 横, _, *点 = map(int, open(0).read().split())

あー = defaultdict(int)
for y, x in zip(*[iter(点)]*2):
    y -= 1; x -= 1
    for i in range(9):
        あー[y - 1 + i//3, x - 1 + i%3] += 1

答 = [0] * 10
for [y, x], c in あー.items():
    答[c] += 横 - 1 > x > 0 < y < 縦 - 1
答[0] = (縦 - 2) * (横 - 2) - sum(答)
print(*答)

Solution (Python):
from collections import defaultdict

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

memo = defaultdict(int)
for y, x in YX:
    y -= 1; x -= 1
    for i in range(9):
        memo[y - 1 + i//3, x - 1 + i%3] += 1

ans = [0] * 10
for y, x in memo:
    if 0 < x < W-1 and 0 < y < H-1:
        ans[memo[y, x]] += 1
ans[0] = (H - 2) * (W - 2) - sum(ans)
print(*ans)

Solution (Python):
from collections import Counter
h,w,n = map(int,input().split())
need = []
append = need.append
for i in range(n):
    a,b = map(int,input().split())
    for x in range(-2,1):
        for y in range(-2,1):
            s = a + x
            t = b + y
            if 1 <= s <= h-2 and 1 <= t <= w-2:
                append(s*10**9 + t)

data = Counter(need).most_common()
ans = [0 for i in range(10)]
for x,y in data:
    ans[y] += 1

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

Solution (Python):
from collections import Counter
h,w,n = map(int,input().split())
need = []
append = need.append
for i in range(n):
    a,b = map(int,input().split())
    for x in range(-2,1):
        for y in range(-2,1):
            s = a + x
            t = b + y
            if 1 <= s <= h-2 and 1 <= t <= w-2:
                append(s*10**9 + t)

data = Counter(need).most_common()
ans = [0 for i in range(10)]
for x,y in data:
    ans[y] += 1

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

Solution (Python):
from collections import Counter
h,w,n = map(int,input().split())
need = []
append = need.append
for i in range(n):
    a,b = map(int,input().split())
    for x in range(-2,1):
        for y in range(-2,1):
            s = a + x
            t = b + y
            if 1 <= s <= h-2 and 1 <= t <= w-2:
                append(s*10**10 + t)

data = Counter(need).most_common()
ans = [0 for i in range(10)]
for x,y in data:
    ans[y] += 1

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

Solution (Python):
from collections import Counter
h,w,n = map(int,input().split())
need = []
for i in range(n):
    a,b = map(int,input().split())
    for x in range(-2,1):
        for y in range(-2,1):
            s = a + x
            t = b + y
            if 1 <= s <= h-2 and 1 <= t <= w-2:
                need.append(s*10**10 + t)

data = Counter(need).most_common()
ans = [0 for i in range(10)]
for x,y in data:
    ans[y] += 1

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

Solution (Python):
H, W, N = map(int, input().split())
S = {}
for i in range(N):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  for i in range(max(0, a-1), min(H, a+2)):
    for j in range(max(0, b-1), min(W, b+2)):
      if (i, j) not in S: S[(i, j)] = 0
      S[(i, j)] += 1
rs = [0]*10
rs[0] = (H-2)*(W-2)
for (i, j) in S:
  if i > 0 and j > 0 and i < H-1 and j < W-1:
    n = S[(i, j)]
    
    rs[0] -= 1
    rs[n] += 1
for j in range(0, 9+1):
  r = rs[j]
  print(r)

Solution (Python):
from collections import Counter, defaultdict

ans = defaultdict(lambda: 0)
h, w, n = map(int, input().split())
for _ in range(n):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for a_i in range(a - 2, a + 1):
        for b_i in range(b - 2, b + 1):
            if (0 <= a_i < h - 2) & (0 <= b_i < w - 2):
                ans[(a_i, b_i)] += 1

k = Counter(ans.values())
print((h - 2) * (w - 2) - sum(k.values()))
for i in range(1, 10):
    if i in k.keys():
        print(k[i])
    else:
        print(0)

Solution (Python):
import collections
h,w,n=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
L=[]
for i in range(n):
  for j in range(3):
    for k in range(3):
      if 0<l[i][0]-j<h-1 and 0<l[i][1]-k<w-1:
        L.append((l[i][0]-j-1)*10**9+l[i][1]-k-1)
L=collections.Counter(L)
L2=list(L.values())
ans=[0 for i in range(10)]
for i in range(len(L2)):
  ans[L2[i]]+=1
ans[0]=(h-2)*(w-2)-len(L2)
for i in range(10):
  print(ans[i])

Solution (Python):
import collections
h,w,n=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
L=[]
for i in range(n):
  for j in range(3):
    for k in range(3):
      if 0<l[i][0]-j<h-1 and 0<l[i][1]-k<w-1:
        L.append((l[i][0]-j-1)*10**9+l[i][1]-k-1)
L=collections.Counter(L)
L2=list(L.values())
ans=[0 for i in range(10)]
for i in range(len(L2)):
  ans[L2[i]]+=1
ans[0]=(h-2)*(w-2)-len(L2)
for i in range(10):
  print(ans[i])

Solution (Python):
h,w,n=map(int,input().split())
s=set()
l=[[0,0],[1,1],[1,-1],[-1,1],[-1,-1],[0,1],[0,-1],[1,0],[-1,0]]
ans=[(h-2)*(w-2),0,0,0,0,0,0,0,0,0]
for i in range(n):
    a,b=[int(j) for j in input().split()]
    s.add((a,b))
    for i,j in l:
        if a+i>=1 and a+i<=h and b+j>=1 and b+j<=w:
            c=0
            for p,q in l:
                if a+i+p>=1 and a+i+p<=h and b+j+q>=1 and b+j+q<=w:
                    if (a+i+p,b+j+q) in s:
                        c+=1
                else:
                    c=0
                    break
            if c!=0:
                ans[c-1]-=1
                ans[c]+=1

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

Solution (Python):
from collections import*
h,w,_,*t=map(int,open(0).read().split())
d=defaultdict(int)
for a,b in zip(*[iter(t)]*2):
  for i in range(9):d[a-i//3,b-i%3]+=1
a=[0]*10
for i,j in d:a[d[i,j]]+=h-1>i>0<j<w-1
a[0]=(h-2)*(w-2)-sum(a)
print(*a)

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

field = {}
for i in range(N):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    for j in range(a-1, a+2):
        for k in range(b-1, b+2):
            if not j in field:
                field[j] = {}
            if not k in field[j]:
                field[j][k] = 0
            field[j][k] += 1

ans = [0] * 10
for kh in field.keys():
    for kw in field[kh].keys():
        if 1 <= kh <= H-2 and 1 <= kw <= W-2:
            ans[field[kh][kw]] += 1

tmp = (H-2)*(W-2)
for i in range(1,10):
    tmp -= ans[i]

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

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

field = {}
for i in range(N):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    for j in range(a-1, a+2):
        for k in range(b-1, b+2):
            if not field.get(j):
                field[j] = {}
            if not field[j].get(k):
                field[j][k] = 0
            field[j][k] += 1

ans = [0] * 10
for kh in field.keys():
    for kw in field[kh].keys():
        if 1 <= kh <= H-2 and 1 <= kw <= W-2:
            ans[field[kh][kw]] += 1

tmp = (H-2)*(W-2)
for i in range(1,10):
    tmp -= ans[i]

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

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

field = {}
for i in range(N):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    for j in range(a-1, a+2):
        for k in range(b-1, b+2):
            if not field.get(j):
                field[j] = {}
            if not field[j].get(k):
                field[j][k] = 0
            field[j][k] += 1

ans = [0] * 10
for kh in field.keys():
    for kw in field[kh].keys():
        if 1 <= kh <= H-2 and 1 <= kw <= W-2:
            ans[field[kh][kw]] += 1

tmp = (H-2)*(W-2)
for i in range(1,10):
    tmp -= ans[i]

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

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

H,W,N = map(int,input().split())
A = []
for i in range(N):
    a,b = map(int,input().split())
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if (1< a+i <H) and (1 < b+j < W):
                A.append([a+i,b+j])
A.sort()
ans = [0]*10
hoge = 0
for i in range(len(A)):
    if A[i] == A[i-1]:
        hoge += 1
    else:
        ans[hoge]+= 1
        hoge = 1
ans[hoge]+= 1


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

for i in ans:
    print(i)

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

Solution (Python):
from collections import defaultdict as de
from collections import Counter as C
h,w,n=map(int,input().split())
s=[0]*10
c=de(int)
for i in range(n):
    a,b=map(int,input().split())
    for j in range(max(2,a-1),min(a+2,h)):
        for q in range(max(2,b-1),min(b+2,w)):
            c[(j,q)]+=1
a=C(c.values())
print((h-2)*(w-2)-sum(a.values()))
for i in range(1,10):
    print(a[i])

Solution (Python):



import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 

h,w,n = [int(i) for i in readline().split()]
ab = [[int(i)-1 for i in readline().split()] for _ in range(n)]

ans = [0]*10


d = {}
for a,b in ab:
    for i in range(3):
        for j in range(3):
            if a-i < 0 or b-j < 0 or a-i >= h-2 or b-j >= w-2: continue
            if (a-i,b-j) in d:
                d[(a-i,b-j)] += 1
            else:
                d[(a-i,b-j)] = 1
        

for i in d.values():
    ans[i] += 1




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

Solution (Python):
from collections import defaultdict, Counter

def main():
  H, W, N, *A = map(int,open(0).read().split())
  D = defaultdict(int)

  while A:
    b, a = A.pop(), A.pop()
    for i in [a - 2, a - 1, a]:
      if 1 <= i <= H - 2:
        for j in [b - 2, b - 1, b]:
          if 1 <= j <= W - 2:
            D[(i, j)] += 1

  print((H - 2) * (W - 2) - len(D))

  c = Counter(D.values())
  for i in range(1, 10):
    print(c.get(i, 0))

if __name__ == '__main__':
  main()

Solution (Python):
from collections import defaultdict, Counter

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

D = defaultdict(int)

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

print((H - 2) * (W - 2) - len(D))

c = Counter(D.values())
for i in range(1, 10):
  print(c.get(i, 0))

Solution (Python):
from collections import defaultdict

def sol():
    H, W, N = map(int, input().split())
    origin = defaultdict(int)

    ans = [0 for _ in range(10)]
    ans[0] = (H - 2) * (W - 2)

    def addBlack(h, w):
        ans[origin[(h, w)]] -= 1
        ans[origin[(h, w)] + 1] += 1
        origin[(h, w)] += 1

    for _ in range(N):
        h, w = map(int, input().split())

        for a in [-1, 0, 1]:
            for b in [-1, 0, 1]:
                if 2 <= h + a <= H - 1 and 2 <= w + b <= W - 1:
                    addBlack(h + a, w + b)

    for a in ans:
        print(a)

sol()

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

h, w, n = [ int(v) for v in input().split() ]
ans_list = [ 0 for i in range(10) ]
ans_list[0] = (h-2)*(w-2) 
adjust_counter = collections.Counter([])
adjust_list = [ [i,j] for i in range(-1,2) for j in range(-1,2)]


def makehash(a,b):
    return a*10**9+b

for i in range(n):
    a, b = [ int(v) - 1 for v in input().split() ]
    for j in adjust_list:
        p, q = j
        if 1 <= p+a <= h-2 and 1 <= q+b <= w-2:
            c = adjust_counter[makehash(p+a,q+b)]
            adjust_counter[makehash(p+a,q+b)] += 1
            ans_list[c] -= 1
            ans_list[c+1] += 1

for i in ans_list:
    print(i)

Solution (Python):
from collections import*
h,w,n=map(int,input().split())
d=defaultdict(int)
for x in[0]*n:
  a,b=map(int,input().split())
  for i in[a-1,a,a+1]:
    for j in[b-1,b,b+1]:d[(i,j)]+=1
c=[0]*10;c[0]=(w-2)*(h-2)
for i in d:
  a,b=i
  if 1<a<h and 1<b<w:c[d[i]]+=1;c[0]-=1
for i in c:print(i)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b, h = IR(3)
    print((a+b)*h//2)
    return


def B():
    d = defaultdict(int)
    d["a"] = deque(S())
    d["b"] = deque(S())
    d["c"] = deque(S())
    tern = "a"
    while d[tern]:
        tern =  d[tern].popleft()
    print(str.capitalize(tern))
    return


def C():
    n, x = LI()
    a = LI()
    ans = 0
    for i in range(n-1):
        if a[i] + a[i + 1] > x:
            if x > a[i]:
                ans += a[i] + a[i + 1] - x
                a[i + 1] = x - a[i]
            else:
                ans += a[i] + a[i + 1] - x
                a[i + 1] = 0
    print(ans)
    return


def D():
    h, w, n = LI()
    ans = [(h - 2) * (w - 2)] + [0] * 9
    d = defaultdict(int)
    for _ in range(n):
        a, b = LI()
        for mb in range(-1, 2):
            mb += b
            for ma in range(-1, 2):
                if mb == ma == 0:
                    continue
                ma += a
                if 2 <= ma < h and 2 <= mb < w:
                    d[(ma, mb)] += 1
    for _, value in d.items():
        ans[value] += 1
        ans[0] -= 1
    print("\n".join(map(str, ans)))
    return


if __name__ == '__main__':
    D()

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

h,w,n = map(int,input().split())
f = defaultdict(lambda : 0)
for _ in range(n):
    a,b = map(int,input().split())
    if a-2 >= 1 and b-2 >= 1:
        f[(a-2,b-2)] += 1
    if a-2 >= 1 and b-1 >= 1 and b+1 <= w:
        f[(a-2,b-1)] += 1
    if a-2 >= 1 and b+2 <= w:
        f[(a-2,b)] += 1
    if a-1 >= 1 and b-2 >= 1 and a+1 <= h:
        f[(a-1,b-2)] += 1
    if a-1 >= 1 and b-1 >= 1 and a+1 <= h and b+1 <= w:
        f[(a-1,b-1)] += 1
    if a-1 >= 1 and b+2 <= w and a+1 <= h:
        f[(a-1,b)] += 1
    if a+2 <= h and b-2 >= 1:
        f[(a,b-2)] += 1
    if a+2 <= h and b-1 >= 1 and b+1 <= w:
        f[(a,b-1)] += 1
    if a+2 <= h and b+2 <= w:
        f[(a,b)] += 1
ans = [0]*10
cnt = 0
for i in f.values():
    ans[i] += 1
    cnt += 1
ans[0] = (h-2)*(w-2) - cnt
for i in ans:
    print(i)

Solution (Python):
h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in [0]*n]
ab_d={a*(10**9)+b-1 for a,b in ab}

ans=[set() for _ in range(9)]
for a,b in ab:
    temp=[None for _ in [0]*25]
    for p in range(25):
        i,j=p//5,p%5
        if 0<a+i-2<=h and 0<b+j-2<=w:
            if (a+i-2)*(10**9)+b+j-3 in ab_d:
                temp[i*5+j]=1
            else:
                temp[i*5+j]=0
    for p in range(9):
        i,j=p//3,p%3
        cnt=[temp[(i+k)*5+j+l] for k in range(3) for l in range(3)]
        if None not in cnt:
            ans[sum(cnt)-1].add((a+i-2)*(10**9)+b+j-3)
                
ans=[len(ans[i]) for i in range(9)]

print((h-2)*(w-2)-sum(ans))
for i in ans:
    print(i)

Solution (Python):
h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in [0]*n]
ab_d={a*(10**9)+b-1 for a,b in ab}

ans=[set() for _ in range(9)]
for a,b in ab:
    temp=[None for _ in [0]*25]
    for i in range(5):
        for j in range(5):
            if 0<a+i-2<=h and 0<b+j-2<=w:
                if (a+i-2)*(10**9)+b+j-3 in ab_d:
                    temp[i*5+j]=1
                else:
                    temp[i*5+j]=0
    for i in range(3):
        for j in range(3):
            cnt=[temp[(i+k)*5+j+l] for k in range(3) for l in range(3)]
            if None not in cnt:
                ans[sum(cnt)-1].add((a+i-2)*(10**9)+b+j-3)
                
for i in range(9):
    ans[i]=len(ans[i])

print((h-2)*(w-2)-sum(ans))
for i in ans:
    print(i)

Solution (Python):

import sys
sys.setrecursionlimit(300000)


def solve(W: int, H: int, N: int, a: "List[int]", b: "List[int]"):
    ret = [0] * 10
    ret[0] = (H - 2) * (W - 2)
    reduces = []
    for i in range(N):
        lx = max(0, a[i] - 3)
        rx = min(W - 2, a[i])
        ly = max(0, b[i] - 3)
        ry = min(H - 2, b[i])
        for bx in range(lx, rx):
            for by in range(ly, ry):
                reduces.append((bx, by))
    reduces.sort()
    cnt = 1
    for i in range(1, len(reduces)):
        if reduces[i] == reduces[i - 1]:
            cnt += 1
        else:
            ret[0] -= 1
            ret[cnt] += 1
            cnt = 1
    if len(reduces):
        ret[0] -= 1
        ret[cnt] += 1
    for r in ret:
        print(r)
    return


def _solve(W: int, H: int, N: int, a: "List[int]", b: "List[int]"):
    ret = [0] * 10
    ret[0] = (H - 2) * (W - 2)
    reduces = []
    for i in range(N):
        lx = max(0, a[i] - 3)
        rx = min(W - 2, a[i])
        ly = max(0, b[i] - 3)
        ry = min(H - 2, b[i])
        for bx in range(lx, rx):
            for by in range(ly, ry):
                cnt = 0
                for x in range(0, 3):
                    for y in range(0, 3):
                        
                        if grid[by + y][bx + x]:
                            cnt += 1
                ret[cnt] -= 1
                ret[cnt + 1] += 1
        
        grid[b[i] - 1][a[i] - 1] = True
    for r in ret:
        print(r)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  
    W = int(next(tokens))  
    N = int(next(tokens))  
    a = [int()] * (N)  
    b = [int()] * (N)  
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(H, W, N, a, b)

if __name__ == '__main__':
    main()

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 da in (-1,0,1):
        for db in (-1,0,1):
            if not ( 2<=a+da<=H-1 and 2<=b+db<=W-1):continue
            d[(a+da,b+db)] = d.get((a+da,b+db),0)+1

ans = [0]*10
for v in d.values():
    ans[v] += 1
ans[0] = (H-2)*(W-2) - sum(ans[1:])
print(*ans,sep="\n")

Solution (Python):
H, W, N = map(int, input().split())
d = 10**9+1
L = []
S = set()
for _ in range(N):
    a, b = map(int, input().split())
    S.add((a, b))
Map =[[0]*5 for _ in range(5)]
ans = [0]*10
for i in S:
    a, b = i
    for i in range(-2, 3):
        for j in range(-2, 3):
            a1, b1 = a+i, b+j

            if (1<=a1<=H) and (1<=b1<=W):
                if (a1, b1) in S:
                    Map[i+2][j+2] = 1
                else:
                    Map[i+2][j+2] = 0
            else:
                Map[i+2][j+2] = -100
    for i in range(-1, 2):
        for j in range(-1, 2):
            res = 0
            for k in range(3):
                for l in range(3):
                    res+=Map[i+1+k][j+1+l]
            if res>=0:
                ans[res]+=1
for i in range(1, 10)[::-1]:
    ans[i] //=i
ans[0] = (W-2)*(H-2)-sum(ans)
for i in ans:
    print(i)

Solution (Python):
import sys
input = sys.stdin.readline
from collections import defaultdict
H, W, N = map(int, input().split())
cnt = defaultdict(lambda : 0)
for i in range(N):
    a, b = map(lambda x: int(x)-1, input().split())
    for y in range(a-2, a+1):
        for x in range(b-2, b+1):
            if 0 <= y < H-2 and 0 <= x < W-2:
                cnt[(y, x)] += 1
ans = [0] * 10
for key in cnt:
    ans[cnt[key]] += 1
ans[0] += ans[0] + (H-2) * (W-2) - len(cnt)
for i in ans:
    print(i)

Solution (Python):
H, W, N = map(int, input().split())
S = set()
toCheck = set()
rs = [0] * 10
for _ in range(N):
    a, b = map(int, input().split())
    S.add((a, b))
    for i in range(3):
        for j in range(3):
            toCheck.add((a - i, b - j))

for a, b in toCheck:
    if a + 2 > H or b + 2 > W or b < 1 or a < 1:
        continue
    cnt = 0
    for i in range(3):
        for j in range(3):
            na, nb = a + i, b + j
            if (na, nb) in S:
                cnt += 1
    rs[cnt] += 1

total = max(0, H - 2) * max(0, W - 2)
rs[0] = total - sum(rs[1:])
for it in rs:
    print(it)

Solution (Python):
from collections import defaultdict

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

mem = defaultdict(int)
for _ in range(N) :
    a, b = map(int, input().split())
    for i in range(max(2, a-1), min(H-1, a+1)+1) :
        for j in range(max(2, b-1), min(W-1, b+1)+1) :
            mem[(i, j)] += 1
            
ret = [0] * 10
for k, v in mem.items() :
    ret[v] += 1

ret[0] = (H - 2) * (W - 2) - sum(ret)
 
for r in ret :
    print(r)

Solution (Python):
from collections import defaultdict

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

mem = defaultdict(int)
for _ in range(N) :
    a, b = map(int, input().split())
    for i in range(max(1, a-1), min(H, a+1)+1) :
        for j in range(max(1, b-1), min(W, b+1)+1) :
            mem[(i, j)] += 1
            
ret = [0] * 10
for k, v in mem.items() :
    if 2 <= k[0] <= H - 1 and 2 <= k[1] <= W - 1 :
        ret[v] += 1

ret[0] = (H - 2) * (W - 2) - sum(ret)
 
for r in ret :
    print(r)