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



Sample input:
4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4


Sample output:
0
0
0
2
4
0
0
0
0
0

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

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

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

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

for cnt in cnts:
    print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

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

D = Counter(C.values())

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

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

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

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

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

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

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

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

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

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

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

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

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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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):
    # print(D)
    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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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
#print(graph)
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)

Submission status: Accepted

Solution code:
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
#print(graph)
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)

Submission status: Accepted

Solution code:
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(*答)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)]
    #print(i, j, n)
    rs[0] -= 1
    rs[n] += 1
for j in range(0, 9+1):
  r = rs[j]
  print(r)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 
#n = int(input())
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

#print(ab)
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
        
#print(d)
for i in d.values():
    ans[i] += 1




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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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')

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

#B
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

#C
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

#D
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

#Solve
if __name__ == '__main__':
    D()