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 itertools import product as pr
from collections import Counter as co
ans=[(h-2)*(w-2)]+[0]*9
io=[tuple(map(int,input().split())) for i in range(n)]
for k,v in co(co([(a-x)*w+b-y for x,y in pr(range(3),repeat=2) for a,b in io if h-1>a-x>0<b-y<w-1]).values()).items():
    ans[k]=v
    ans[0]-=v
print(*ans,sep='\n')

Solution (Python):
h,w,n=map(int,input().split())
spots=set([eval(input().replace(' ','*w+'))-w-1 for i in range(n)])
anss=[0]*10
from itertools import product as pr
moves=(tuple(x+w*y for x,y in pr(range(0,3),repeat=2)))
for i in spots:
    a,b=divmod(i,w)
    pre=[0]*9
    for x in range(max(0,a-2),min(h-2,a+1)):
        for y in range(max(0,b-2),min(w-2,b+1)):
            ind=w*x+y
            pre[x-a+(y-b)*3+8]+=sum(ind+m in spots for m in moves)
    for v in pre:anss[v]+=1
tans=[0]*10

ans0=(h-2)*(w-2)
for i in range(1,10):
    tans[i]=anss[i]//i
    ans0-=anss[i]//i
tans[0]=ans0
print(*tans,sep='\n')

Solution (Python):
def main():
	import sys
	input=sys.stdin.readline
	h,w,n=map(int,input().split())
	ans=[0]*10
	p=set()
	q=set()
	for i in range(n):
		a,b=map(int,input().split())
		for j in range(-1,2):
			for k in range(-1,2):
				if 2<=a+j<=h-1 and 2<=b+k<=w-1:
					r=(a+j)*(10**10)+b+k
					p.add(r)
		q.add(a*(10**10)+b)
	p=list(p)
	for x in p:
		cnt=0
		for j in range(-1,2):
			for k in range(-1,2):
				if x+j*(10**10)+k in q:
					cnt+=1
		ans[cnt]+=1
	print((h-2)*(w-2)-sum(ans[1:]))
	for i in range(1,10):
		print(ans[i])
if __name__ == '__main__':
	main()

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

while N:
  N-=1
  x,y = map(int,input().split())
  
  for i in range(9):
    a = (x+i%3,y+i//3)
    D[a] = D.get(a,0)+(H>=a[0]>2<a[1]<=W)

c = [list(D.values()).count(i+1) for i in range(9)]
print((H-2)*(W-2)-sum(c))

for i in range(9):
    print(c[i])

Solution (Python):
def main():
    from sys import stdin
    def input():
        return stdin.readline().strip()

    from itertools import product

    h, w, n = map(int, input().split())
    dic = {}
    for _ in range(n):
        a, b = map(int, input().split())
        a -= 2
        b -= 2
        for i in product([-1, 0, 1], repeat=2):
            aa = a + i[0]
            bb = b + i[1]
            if 0 <= aa <= h-3 and 0 <= bb <= w-3:
                try:
                    dic[(aa, bb)] += 1
                except:
                    dic[(aa, bb)] = 1

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

    for i in ans:
        print(i)

main()

Solution (Python):
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

itta={}
dic={}
for a,b in ab:
    dic[(a,b)]=1
def seek(t,y):
    if (not (t,y) in itta) and 2<=t<h and 2<=y<w:
        itta[(t,y)]=1
        cnt=0
        for i in range(3):
            for j in range(3):
                cnt+=(t-1+i,y-1+j) in dic
        return cnt
    else:
        return 0

lst=[0]*10
for i in range(n):
    a,b=ab[i]
    for i in range(3):
        for j in range(3):
            cnt=seek(a-1+i,b-1+j)
            if cnt:
                lst[cnt]+=1



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

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

def main():
    h, w, n = map(int, input().split())
    grid = [0]*n
    mod = 10**9
    judge = dict()
    for _ in range(n):
        a, b = map(int, input().split())
        for i in range(-1, 2):
            for j in range(-1, 2):
                if a+i <= 1 or a+i >= h or b+j <= 1 or b+j >= w:
                    continue
                if (a+i, b+j) in judge:
                    judge[(a+i, b+j)] += 1
                else:
                    judge[(a+i, b+j)] = 1
   
    ans = [0]*10
    
    for v in judge.values():
        ans[v] += 1
    ans[0] = (h-2)*(w-2)-sum(ans[1:])
    
    for a in ans:
        print(a)

    
if __name__ == "__main__":
    main()

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

def main():
    h, w, n = map(int, input().split())
    grid = [0]*n
    mod = 10**9
    judge = dict()
    for _ in range(n):
        a, b = map(int, input().split())
        for i in range(-1, 2):
            for j in range(-1, 2):
                if a+i <= 1 or a+i >= h or b+j <= 1 or b+j >= w:
                    continue
                if (a+i, b+j) in judge:
                    judge[(a+i, b+j)] += 1
                else:
                    judge[(a+i, b+j)] = 1
   
    ans = [0]*10
    
    for v in judge.values():
        ans[v] += 1
    ans[0] = (h-2)*(w-2)-sum(ans[1:])
    
    for a in ans:
        print(a)

    
if __name__ == "__main__":
    main()

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

xy_pos = dict()

for i in range(n):
    a, b = map(int, input().split())
    for k in range(-2,1):
        for l in range(-2,1):
            x = (a-1) + k
            y = (b-1) + l
            if (0 <= x <=(h-1)-2) and (0 <= y <=(w-1)-2):
                xy = str(x) + "x" + str(y)
                if xy in xy_pos:
                    xy_pos[xy] += 1
                else:
                    xy_pos[xy] = 1

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

Solution (Python):
from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

h,w,n=MI()
sq=defaultdict(int)
for _ in range(n):
    a,b=MI1()
    for i in range(max(0,a-2),min(h-2,a+1)):
        for j in range(max(0,b-2),min(w-2,b+1)):
            sq[i,j]+=1
cnt=[0]*10
for k,v in sq.items():cnt[v]+=1
cnt[0]=(h-2)*(w-2)-sum(cnt)
print(*cnt,sep="\n")

Solution (Python):
from collections import defaultdict
import sys

input = sys.stdin.readline

h,w,n = map(int,input().split())
d = defaultdict()
ans = [0]*10

for k 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,b+j) in d:
                d[(a+i,b+j)] += 1
            else:
                d[(a+i,b+j)] = 1

for k,v in d.items():
    if 0 < k[0] < h-1 and 0 < k[1] < w-1:
        ans[v] += 1

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

for i in ans:
    print(i)

Solution (Python):
def add_memo(tate,yoko):
    global memo
    if 2 <= tate <= h-1:
        if 2 <= yoko <= w-1:
            memo.append([tate,yoko])

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

memo = []
for i in range(0,n):
    x,y = map(int,input().split())
    add_memo(x-1,y-1)
    add_memo(x-1,y)
    add_memo(x-1,y+1)
    add_memo(x,y-1)
    add_memo(x,y)
    add_memo(x,y+1)
    add_memo(x+1,y-1)
    add_memo(x+1,y)
    add_memo(x+1,y+1)

memo.sort()
ans = [0] * 10
ans[0] = (h-2)*(w-2)
tmp_x = 0
tmp_y = 0
count = 0
for i in range(0,len(memo)):
    if tmp_x == memo[i][0] and tmp_y == memo[i][1]:
        ans[count] -= 1
        count += 1
        ans[count] += 1
    else:
        ans[0] -= 1
        count = 1
        ans[count] += 1
    tmp_x = memo[i][0]
    tmp_y = memo[i][1]


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

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,w,n = list(map(int, input().split()))
from collections import defaultdict, Counter
d = defaultdict(int)
for i in range(n):
    a,b = map(int, input().split())
    for i in range(a-2, a+1):
        for j in range(b-2, b+1):
            if 1<=i<=h-2 and 1<=j<=w-2:
                d[i,j] += 1
ans = [None]*10
ans[0] = (h-2)*(w-2) - len(d)
c = Counter(d.values())
for i in range(1,10):
    if i in c:
        ans[i] = c[i]
    else:
        ans[i] = 0
write("\n".join(map(str, ans)))

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,w,n = list(map(int, input().split()))
from collections import defaultdict, Counter
d = defaultdict(int)
for i in range(n):
    a,b = map(int, input().split())
    for i in range(a-2, a+1):
        for j in range(b-2, b+1):
            if 1<=i<=h-2 and 1<=j<=w-2:
                d[i,j] += 1
ans = [None]*10
ans[0] = (h-2)*(w-2) - len(d)
c = Counter(d.values())
for i in range(1,10):
    if i in c:
        ans[i] = c[i]
    else:
        ans[i] = 0
write("\n".join(map(str, ans)))

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

H,W,N = MI()

from collections import defaultdict,Counter

d = defaultdict(int)  
for i in range(N):
    a,b = MI()
    for j in range(max(1,a-2),min(a,H-2)+1):
        for k in range(max(1,b-2),min(b,W-2)+1):
            d[(j,k)] += 1

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

Solution (Python):
H,W,N=map(int,input().split())
s=set()
for i in range(N):
    a,b=map(lambda x:int(x)-1,input().split())
    s.add((a,b))
count=[0]*10

for x,y in s:
    for tx in range(x-2,x+1):
        for ty in range(y-2,y+1):
            if tx<0 or ty<0 or tx+2>=H or ty+2>=W:
                continue
            cnt=0
            for nx in range(tx,tx+3):
                for ny in range(ty,ty+3):
                    if (nx,ny) in s:
                        cnt+=1
            count[cnt]+=1
count=[0]+[count[i]//i for i in range(1,10)]
count[0]=(H-2)*(W-2)-sum(count)
print(*count,sep='\n')

Solution (Python):
import sys
input = sys.stdin.readline
H,W,N = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N)]
from collections import defaultdict
dic = defaultdict(lambda: 0)
for y,x in AB:
    for dx in range(-1,2):
        for dy in range(-1,2):
            nx,ny = x+dx,y+dy
            if not 1 <= nx <= W: continue
            if not 1 <= ny <= H: continue
            dic[(nx,ny)] += 1

ans = [0] * 10
for (x,y),c in dic.items():
    if x==1 or x==W or y==1 or y==H: continue
    ans[c] += 1
s = sum(ans)
ans[0] = (W-2)*(H-2)-s

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

Solution (Python):
from collections import defaultdict
def solve():
  H, W, N = map(int, input().split())
  ans = [0]*10
  dic = defaultdict(lambda: defaultdict(lambda: 0))
  for i in range(N):
    x,y = map(int, input().split())
    x -= 1
    y -= 1
    for i in range(x-1,x+2):
      for j in range(y-1,y+2):
        if i>0 and i<H-1 and j>0 and j<W-1:
          if dic[i][j]>0:
            ans[dic[i][j]] -= 1
          dic[i][j] += 1
          ans[dic[i][j]] += 1
  total = (H-2)*(W-2)
  ans[0] = total - sum(ans[1:])
  return ans
print(*solve(),sep='\n')

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

H,W,N = map(int,readline().split())
from collections import defaultdict




dic = defaultdict(int)

for i in range(N):
  a,b = map(int,readline().split())
  a,b = a - 1,b - 1
  for A in range(max(0,a - 2), min(a + 1,H - 2)):
    for B in range(max(0,b - 2), min(b + 1,W - 2)):
      dic[(A,B)] += 1

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

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

for a in ans:
  print(a)

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

H,W,N = map(int,readline().split())
from collections import defaultdict




dic = defaultdict(int)

for i in range(N):
  a,b = map(int,readline().split())
  a,b = a - 1,b - 1
  for A in range(max(0,a - 2), min(a + 1,H - 2)):
    if A < 0:
      continue
    for B in range(max(0,b - 2), min(b + 1,W - 2)):
      if B < 0:
        continue
      dic[(A,B)] += 1

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

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

for a in ans:
  print(a)

Solution (Python):
from collections import Counter

h,w,N=map(int,input().split())
rec=[]
for i 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):
           if 0<=a+i<h-2 and 0<=b+j<w-2:
               rec.append((a+i,b+j))

ans=[0]*10
ans[0]=(h-2)*(w-2)
c=Counter(rec)
for i in c.values():
    ans[i]+=1
    ans[0]-=1
for i in range(10):
    print(ans[i])

Solution (Python):
from collections import Counter
h, w, n = map(int, input().split())
c = Counter([])

for i 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):
            if 0<=a+i<h-2 and 0<=b+j<w-2:
                c[(a+i, b+j)]+=1

ans = [0] * 10
total = 0
for k, v in c.items():
    ans[v]+=1
    total+=1
ans[0]=(h-2)*(w-2) - total


for a in ans:
    print(a)

Solution (Python):
H,W,N=map(int,input().split())
D=dict()
for i in range(N):
  a,b=map(int,input().split())
  for p in range(-1,2):
    for q in range(-1,2):
      x=a+p
      y=b+q
      if 2<=x<=H-1 and 2<=y<=W-1:
        pos=(x,y)
        if pos in D:
          D[pos]+=1
        else:
          D[pos]=1
ans=[0]*10
V=list(D.values())
for v in V:
  ans[v]+=1
ans[0]=(H-2)*(W-2)-sum(ans)
print(*ans,sep='\n')

Solution (Python):
H,W,N = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
C = {}
for i in range(N):
    a,b = X[i]
    if a-2>=1 and b-2>=1:
        if (a-2,b-2) not in C:
            C[(a-2,b-2)] = 0
        C[(a-2,b-2)] += 1
    if a-2>=1 and b-1>=1 and b+1<=W:
        if (a-2,b-1) not in C:
            C[(a-2,b-1)] = 0
        C[(a-2,b-1)] += 1
    if a-2>=1 and b+2<=W:
        if (a-2,b) not in C:
            C[(a-2,b)] = 0
        C[(a-2,b)] += 1
    if a-1>=1 and b-2>=1 and a+1<=H:
        if (a-1,b-2) not in C:
            C[(a-1,b-2)] = 0
        C[(a-1,b-2)] += 1
    if a-1>=1 and b-1>=1 and a+1<=H and b+1<=W:
        if (a-1,b-1) not in C:
            C[(a-1,b-1)] = 0
        C[(a-1,b-1)] += 1
    if a-1>=1 and a+1<=H and b+2<=W:
        if (a-1,b) not in C:
            C[(a-1,b)] = 0
        C[(a-1,b)] += 1
    if b-2>=1 and a+2<=H:
        if (a,b-2) not in C:
             C[(a,b-2)] = 0
        C[(a,b-2)] += 1
    if b-1>=1 and a+2<=H and b+1<=W:
        if (a,b-1) not in C:
            C[(a,b-1)] = 0
        C[(a,b-1)] += 1
    if a+2<=H and b+2<=W:
        if (a,b) not in C:
            C[(a,b)] = 0
        C[(a,b)] += 1
D = {i:0 for i in range(10)}
for c in C:
    D[C[c]] += 1
cnt = 0
for i in range(1,10):
    cnt += D[i]
D[0] = (H-2)*(W-2)-cnt
for i in range(10):
    print(D[i])

Solution (Python):
H,W,N = map(int,input().split())
B = set([])
for i in range(N):
  a,b = map(int,input().split())
  a-=1;b-=1
  B.add((a,b))

BB = list(B)
ans = [0 for _ in range(10)]
for i in range(N):
  cnt = 0; temp = 0
  x,y = BB[i]
  
  for sx in range(max(0,x-2),min(x,H-3)+1):
    for sy in range(max(0,y-2),min(y,W-3)+1):
      temp = 0
      for p in range(3):
        for q in range(3):
          if (sx+p,sy+q) in B:
            temp += 1
      
      ans[temp] += 1
for i in range(1,10):
  ans[i] = ans[i]//i
ans[0] = (H-2)*(W-2)-sum(ans[1:])
for t in ans:
  print(t)

Solution (Python):
h,w,n=map(int,input().split())
dic={}
INF=10**10
for i in range(n):
  y,x=map(int,input().split())
  for j in range(max(2,x-1),min(w-1,x+1)+1):
    for k in range(max(2,y-1),min(h-1,y+1)+1):
      if j*INF+k in dic:
        dic[j*INF+k]+=1
      else:
        dic[j*INF+k]=1
ans=[0]*10
ans[0]=(h-2)*(w-2)
for i in dic:
  ans[0]-=1
  ans[dic[i]]+=1
for i in ans:
  print(i)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7





H, W, N = map(int, input().split())
query = [list(map(int, input().split())) for i in range(N)]
list_star = defaultdict(set)
H_max = 0
W_max = 0
for y, x in query:
    H_max = max(H_max, y)
    W_max = max(W_max, x)
    list_star[y - 1].add(x - 1)

dx = [0, 0, 1, 1, 1, 0, -1, -1, -1]
dy = [0, 1, 1, 0, -1, -1, -1, 0, 1]


lista = [0] * 10

def counter(x, y):
    if x <= 0 or W - 1 <= x or y <= 0 or H - 1 <= y:
        return 0
    cnt = 0
    for i in range(9):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0 <= nx < W and 0 <= ny < H:
            if nx in list_star[ny]:
                cnt += 1
    return cnt

star_list = set()
for y, x in query:
    x -= 1
    y -= 1
    for l in range(9):
        nx = x + dx[l]
        ny = y + dy[l]
        star_list.add((nx, ny))

star_list = list(star_list)
for x, y in star_list:
    if not (x <= 0 or W - 1 <= x or y <= 0 or H - 1 <= y):
        lista[counter(x, y)] += 1

left = (H - 2) * (W - 2) - sum(lista)
lista[0] = left
for i in lista:
    print(i)

Solution (Python):
h,w,n=map(int,input().split())
D=dict()
for i in range(n):
    a,b=map(int,input().split())
    for p in range(-1,2):
        for q in range(-1,2):
            aa=a+p
            bb=b+q
            if 2<=aa<=h-1 and 2<=bb<=w-1:
                aabb=str(aa)+"_"+str(bb)
                if aabb in D:
                    D[aabb]+=1
                else:
                    D[aabb]=1
ans=[0]*10
V=list(D.values())
for v in V:
    ans[v]+=1
ans[0]=(h-2)*(w-2)-sum(ans)
for i in range(10):
    print(ans[i])

Solution (Python):
import collections
from itertools import product

H, W, N = map(int,input().split())
PaintList = []
pat = list(product((-2,-1,0),repeat=2))
for i in range(N):
  x,y = map(int, input().split())
  for p in pat:
    xw = x + p[0]
    yw = y + p[1]
    
    if 1 <= xw <= H-2 and 1 <= yw <= W-2:
      PaintList.append((xw,yw))

c = collections.Counter(PaintList)

ans = [0] * 10
for k,v in c.items():
  if k[0] <= H-2 and k[1] <= W-2:
    ans[v] += 1
  
ans[0] = (H-2)*(W-2) - sum(ans[1:10])
 
for i in range(10):
  print(ans[i])

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



H, W, N = map(int, input().split())
X = (H - 2) * (W - 2)

A = defaultdict(int)
for i in range(N):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for p in range(3):
        for q in range(3):
            k, l = a - p, b - q
            if k < 0 or k >= H or l < 0 or l >= W:
                continue
            if k + 2 >= H or l + 2 >= W:
                continue
            A[(k, l)] += 1

ans = [0] * 10
for k, v in A.items():
    ans[v] += 1
ans[0] = X - sum(ans)

for a in ans:
    print(a)

Solution (Python):
import sys

def getsqs(coor,h,w):
    l=[coor[0]+x+h*(coor[1]+y-1) for x in range(-1,2) for  y in range(-1,2) \
        if coor[0]+x>1 and coor[0]+x<h and coor[1]+y>1 and coor[1]+y<w]
    return l

def main(h,w,coords):
    sq=[]
    ans=[0 for _ in range(10)]
    for coor in coords:
        sq.extend(getsqs(coor,h,w))

    sq.sort()
    sq.append(h*w)
    ind=0
    for x in range(len(sq)-1):
        if sq[x+1]-sq[x]!=0:
            ans[x-ind+1]+=1
            ind=x+1
    ans[0]=max(0,(h-2)*(w-2)-sum(ans))
    return ans

h,w,n=map(int,sys.stdin.readline().strip().split())
coords=[list(map(int,sys.stdin.readline().strip().split())) for _ in range(n)]

for x in main(h,w,coords):
    print(x)

Solution (Python):
def main():
    H, W, N = map(int, input().split())
    s = set()
    for _ in range(N):
        a, b = map(int, input().split())
        s.add((a,b))
    u = set()
    r = [0] * 10
    def search(ii, jj):
        t = 0
        for x in range(-1, 2):
            for y in range(-1, 2):
                xt = x + ii
                yt = y + jj
                if (x+ii, y+jj) in s:
                    t += 1
        r[t] += 1
    for t in s:
        for x in range(-1, 2):
            for y in range(-1, 2):
                xt = x + t[0]
                yt = y + t[1]
                if xt < 2 or yt < 2 or xt > H-1 or yt > W-1:
                    continue
                if (xt, yt) in u:
                    continue
                u.add((xt, yt))
                search(xt, yt)
    r[0] = (H-2) * (W-2) - len(u)
    for i in range(10):
        print(r[i])
main()

Solution (Python):
def main():
    H, W, N = map(int, input().split())
    C = {}
    for _ in range(N):
        a, b = map(int, input().split())
        for x in range(max(2, a - 1), min(H, a + 2)):
            for y in range(max(2, b - 1), min(W, b + 2)):
                C[(x, y)] = C.get((x, y), 0) + 1
    D = list(C.values())
    print((H - 2) * (W - 2) - len(C))
    for j in range(1, 10):
        print(D.count(j))

main()

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

count = defaultdict(lambda: 0)

H, W, N = map(int, input().split())
for _ in range(N):
    a, b = map(int, input().split())
    for a_2 in range(a-1, a+2):
        for b_2 in range(b-1, b+2):
            if 2 <= a_2 <= H-1 and 2 <= b_2 <= W-1:
                count[a_2, b_2] += 1

ans = [0] * 10
for _, v in count.items():
    ans[v] += 1

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

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

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

count = defaultdict(lambda: 0)

H, W, N = map(int, input().split())
for _ in range(N):
    a, b = map(int, input().split())
    for a_2 in range(a-1, a+2):
        for b_2 in range(b-1, b+2):
            if 2 <= a_2 <= H-1 and 2 <= b_2 <= W-1:
                count[a_2, b_2] += 1

ans = [0] * 10
for _, 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())
d = dict()
ans = [0] * 10
for _ in range(n):
    a, b = map(int, input().split())
    for i in range(-1, 2):
        for j in range(-1, 2):
            x, y = a + i, b + j
            if 1 < x < h and 1 < y < w:
                k = x * w + y
                if not k in d:
                    d[k] = 1
                    ans[1] += 1
                else:
                    ans[d[k]] -= 1
                    ans[d[k] + 1] += 1
                    d[k] += 1
ans[0] = (h - 2) * (w - 2) - sum(ans)
for i in ans:
    print(i)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import defaultdict
    h, w, n = map(int, readline().split())
    c = defaultdict(int)
    count = [0] * 10
    count[0] = (h - 2) * (w - 2)

    for _ in range(n):
        a, b = map(int, readline().split())
        a, b = a - 1, b - 1
        for row in range(max(2, a), min(h - 1, a + 2) + 1):
            for col in range(max(2, b), min(w - 1, b + 2) + 1):
                cur = c[(row, col)]
                count[cur] -= 1
                count[cur + 1] += 1
                c[(row, col)] += 1

    print(*count, sep="\n")


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	h, w, n = LI()
	black_points = []
	for i in range(n):
		a, b = LI()
		add_list = ((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))
		for c, d in add_list:
			if 1 <= c <= h-2 and 1 <= d <= w-2:
				black_points.append((c,d))
	counter = Counter(black_points)
	count_list = list(counter.values())
	counter2 = Counter(count_list)
	ans_list = [counter2[i] for i in range(1,10)]
	ans_list = [(h-2)*(w-2)-sum(ans_list)] + ans_list
	for ans in ans_list:
		print(ans)



if __name__ == '__main__':
    main()

Solution (Python):

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def foo(a,b,ans):
    z = d[a][b]
    for p in range(3):
        for q in range(3):
            if a-2+p<0 or a+p>=h or b-2+q<0 or b+q>=w:
                continue
            ok = True
            reachorig = False
            v = 0
            for i in range(3):
                for j in range(3):
                    if p+i==q+j==2:
                        reachorig = True
                    if z[p+i][q+j]==1:
                        if reachorig:
                            v += 1
                        else:
                            ok = False
                            break
            if ok:
                ans[v] += 1

h,w,n = inm()
d = {}
ab = []
for i in range(n):
    a,b = inm()
    a -= 1
    b -= 1
    ab.append((a,b))
    if a not in d:
        d[a] = {}
    d[a][b] = [[0]*5 for j in range(5)]
    d[a][b][2][2] = 1
for a,b in ab:
    for dx in range(-2,3):
        for dy in range(-2,3):
            if a+dx in d and b+dy in d[a+dx] and not (dx==dy==0):
                d[a+dx][b+dy][2-dx][2-dy] = 1

if False and DBG:
    for i in range(h):
        for j in range(w):
            if i in d and j in d[i]:
                
                for k in range(5):
                    print(d[i][j][k])
ans = [0]*10
for a,b in ab:
    foo(a,b,ans)
print((h-2)*(w-2)-sum(ans))
for i in range(1,10):
    print(ans[i])

Solution (Python):
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

from collections import deque,defaultdict,Counter
def main():
    H,W,N = map(int,input().split())
    point = [tuple(map(int,input().split())) for _ in range(N)]
    ans = [0] * 10

    dic = defaultdict(int)
    for p,q in point:
        for dy in (-1,0,1):
            for dx in (-1,0,1):
                if p + dy <= 1 or p + dy >= H:
                    continue
                if q + dx <= 1 or q + dx >= W:
                    continue
                center = (p + dy,q + dx)
                ans[dic[center]] -= 1
                dic[center] += 1
                ans[dic[center]] += 1
    ans[0] += (H - 2)*(W - 2)
    print('\n'.join(map(str,ans)))
if __name__ == '__main__':
    main()

Solution (Python):
h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
from collections import defaultdict
dct=defaultdict(int)
ans={i:0 for i in range(10)}
ans[0]=(h-2)*(w-2)
for a,b in ab:
  a-=1
  b-=1
  u=max(0,a-2)
  d=min(h-3,a)
  l=max(0,b-2)
  r=min(w-3,b)
  for i in range(u,d+1):
    for j in range(l,r+1):
      ans[dct[(i,j)]]-=1
      dct[(i,j)]+=1
      ans[dct[(i,j)]]+=1
for i in range(10):
  print(ans[i])

Solution (Python):
from collections import defaultdict

H, W, N = map(int,input().split())
d = defaultdict(int)
ta = [1,1,0,-1,-1,-1,0,1,0]
tb = [0,1,1,1,0,-1,-1,-1,0]

for _ in range(N):
    a, b = map(int,input().split())
    for i in range(9):
        na = a + ta[i]
        nb = b + tb[i]
        if 1 <= na <= H and 1 <= nb <= W:
            d[(na, nb)] += 1

ans = [0] * 10

for i, v in d.items():
    if 2 <= i[0] <= H-1 and 2 <= i[1] <= W-1:
        ans[v] += 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())
lst = []
for i in range(n):
    ai, bi = map(int, input().split())
    lst.append((ai, bi))

dic = {}
for i in range(10): dic[i] = 0
dic[0] = (h-2) * (w-2)
already = set([])
idx = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 0], [0, 1], [1, -1], [1, 0], [1, 1]]
for i in range(n):
    ai, bi = lst[i]
    for surround in idx:
        center = [ai+surround[0], bi+surround[1]]
        if min(center) < 2 or center[0] > h-1 or center[1] > w-1: continue
        cnt = 0
        for ind in idx:
            cell = (center[0]+ind[0], center[1]+ind[1])
            if cell in already: cnt += 1
        dic[cnt] -= 1
        dic[cnt+1] += 1
    already.add((ai, bi))

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