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):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]


    H,W,N = LI()

    d = collections.Counter()
    for _ in range(N):
        x,y = LI()
        for dx in range(-1,2):
            for dy in range(-1,2):
                nx = x+dx
                ny = y+dy
                if 1 < nx < H and 1 < ny < W:
                    d[(nx,ny)] += 1
    ans = [0] * 10
    for x,c in collections.Counter(d.values()).items():
        ans[x] += c
    ans[0] = (H-2) * (W-2) - sum(ans[1:])

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]


    H,W,N = LI()

    d = collections.Counter()
    for _ in range(N):
        x,y = LI()
        for dx in range(-1,2):
            for dy in range(-1,2):
                nx = x+dx
                ny = y+dy
                if 1 < nx < H and 1 < ny < W:
                    d[(nx,ny)] += 1
    ans = [0] * 10
    for x in d.values():
        ans[x] += 1
    ans[0] = (H-2) * (W-2) - sum(ans[1:])

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

if __name__ == '__main__':
    main()

Solution (Python):
H, W, N = map(int, input().split())
AB = dict()
for i in range(N):
  a, b = list(map(int, input().split()))
  for i in range(3):
    for j in range(3):
      x = (a - 1) - i
      y = (b - 1) - j
      if (0 <= x < H - 2) and (0 <= y < W - 2):
        ab = str(x) + "ab" + str(y)
        if ab in AB:
          AB[ab] += 1
        else:
          AB[ab] = 1


ans = [0] * 10
for i in AB.values():
  ans[i] += 1
ans[0] = (H - 2) * (W - 2) - sum(ans)
for i in range(10):
  print(ans[i])

Solution (Python):
from collections import defaultdict
H,W,N = map(int,input().split())
d = defaultdict(int)
for i in range(N):
    a,b = map(int,input().split())
    for dy in range(-1,2):
        for dx in range(-1,2):
            if a+dy >= 2 and a+dy <= H-1 and b+dx >= 2 and b+dx <= W-1:
                d[(a+dy,b+dx)] += 1
ans = [0]*10
ans[0] = (H-2)*(W-2)-len(d)
for i in d.values():
    ans[i] += 1
for i in ans:
    print(i)

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-3 and 0 <= y <= w-3):
                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):
h,w,n=map(int,input().split())
black=[tuple(map(int,input().split())) for _ in range(n)]
sblack=set(black)
ans=[0]*10
for a,b in black:
    for x in range(3):
        for y in range(3):
            cnt=0
            ok=True
            for nx,ny in [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2),(2,0),(2,1),(2,2)]:
                dx,dy=nx-x,ny-y
                if 1<=a-dx<=h and 1<=b-dy<=w:
                    if (a-dx,b-dy) in sblack:
                        cnt+=1
                else:
                    ok=False
                    break
            if ok:
                ans[cnt]+=1
for i in range(1,10):
    ans[i]//=i
ans[0]=(h-2)*(w-2)-sum(ans[1:])
for num in ans:
    print(num)

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

d = {}
ab = []

for i in range(n):
    s = input()
    d[s] = 1
    a, b = map(int, s.split())
    ab.append((a, b))

memo = [0] * 10

def check(a,b):
    cnt = 0
    for i in range(a,a+3):
        for j in range(b,b+3):
            if str(i) + ' ' + str(j) in d:
                cnt += 1
    memo[cnt] += 1
                
for a, b in ab:
    for i in range(max(1,a-2), min(h-1,a+1)):
        for j in range(max(1,b-2), min(w-1,b+1)):
            check(i,j)

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

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

for memoi in memo:
    print(memoi)

Solution (Python):
h, w, n = map(int, input().split())
cnts = [0] * 10
cnts[0] = (h-2)*(w-2)

points = dict()
for _ in range(n):
    a, b = map(lambda x: int(x)-1, input().split())
    for i in (-1, 0, 1):
        for j in (-1, 0, 1):
            ai, bj = a+i, b+j
            if 1 <= ai < h-1 and 1 <= bj < w-1:
                ab = (a+i, b+j)
                points.setdefault(ab, 0)
                cnts[points[ab]] -= 1
                points[ab] += 1
                cnts[points[ab]] += 1
for c in cnts:
    print(c)

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


h, w, n = map(int,input().split())
d = {}
for i in range(n):
    ch, cw = map(int,input().split())
    for dh in [-1,0,1]:
        for dw in [-1,0,1]:
            if 2 <= ch + dh <= h-1 and 2 <= cw + dw <= w-1:
                x = (ch + dh)*10**10 + cw + dw
                
                if x in d:
                    d[x] += 1
                else:
                    d[x] = 1
ans = [0] * 10
ans[0]
for v in d.values():
    ans[v] += 1
ans[0] = (h-2)*(w-2) - sum(ans[1:])
for i in range(10):
    print(ans[i])

Solution (Python):
from collections import Counter
h,w,n=map(int,input().split())
d={}

for _ in range(n):
    a,b=map(int,input().split())

    for i in range(max(a-2,1),a+1):
        for j in range(max(b-2,1),b+1):
            if h<i+2 or w<j+2:
                continue
            if (i,j) in d:
                d[(i,j)]+=1
            else:
                d[(i,j)]=1
ans=[0]*10
ans[0]=(h-2)*(w-2)
for k,v in d.items():
    ans[v]+=1
    ans[0]-=1

for a in ans:
    print(a)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]



def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


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


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




H,W,N = IL()
data = ILL(N)

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

dic = DD(int)
for y,x in data:
  for i in range(9):
    ny,nx = y+dy[i], x+dx[i]
    if 2<=ny<=H-1 and 2<=nx<=W-1:
      dic[ny*W+nx] += 1
      
ans = [(H-2)*(W-2),0,0,0,0,0,0,0,0,0]
for k in dic:
  ans[0] -= 1
  ans[dic[k]] += 1

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W, n = map(int, input().split())
    AB = set(tuple(tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(n)))

    d = ((1, 1), (1, 0), (1, -1), (0, 1), (0, 0), (0, -1), (-1, 1), (-1, 0), (-1, -1))
    target = set()
    res = [0] * 10
    for h, w in AB:
        cnt = 0
        flg = True
        for dh, dw in d:
            next_h, next_w = h + dh, w + dw
            if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                flg = False
            if (next_h, next_w) in AB:
                cnt += 1
            else:
                if (next_h, next_w) not in AB:
                    target.add((next_h, next_w))
        if flg:
            res[cnt] += 1

    for h, w in target:
        cnt = 0
        for dh, dw in d:
            next_h, next_w = h + dh, w + dw
            if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                break
            if (next_h, next_w) in AB:
                cnt += 1
        else:
            res[cnt] += 1

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


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W, n = map(int, input().split())
    AB = set(tuple(tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(n)))

    d = ((1, 1), (1, 0), (1, -1), (0, 1), (0, 0), (0, -1), (-1, 1), (-1, 0), (-1, -1))
    target = set()
    res = [0] * 10
    for h, w in AB:
        cnt = 0
        flg = True
        for dh, dw in d:
            next_h, next_w = h + dh, w + dw
            if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                flg = False
            if (next_h, next_w) in AB:
                cnt += 1
            else:
                if (next_h, next_w) != (h, w):
                    target.add((next_h, next_w))
        if flg:
            res[cnt] += 1

    for h, w in target:
        cnt = 0
        for dh, dw in d:
            next_h, next_w = h + dh, w + dw
            if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                break
            if (next_h, next_w) in AB:
                cnt += 1
        else:
            res[cnt] += 1

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


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W, n = map(int, input().split())
    AB = set(tuple(tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(n)))

    d = ((1, 1), (1, 0), (1, -1), (0, 1), (0, 0), (0, -1), (-1, 1), (-1, 0), (-1, -1))
    target = set()
    res = [0] * 10
    for h, w in AB:
        cnt = 0
        flg = True
        for dh, dw in d:
            next_h, next_w = h + dh, w + dw
            if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                flg = False
            if (next_h, next_w) in AB:
                cnt += 1
            else:
                target.add((next_h, next_w))
        if flg:
            res[cnt] += 1

    for h, w in target:
        cnt = 0
        for dh, dw in d:
            next_h, next_w = h + dh, w + dw
            if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                break
            if (next_h, next_w) in AB:
                cnt += 1
        else:
            res[cnt] += 1

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


if __name__ == '__main__':
    resolve()

Solution (Python):
from collections import defaultdict, Counter
H, W, N = map(int, input().split())
L = []
for _ in range(N):
    a, b = map(int, input().split())
    L.append([a, b])


d = defaultdict()
for i in range(N):
    for sx in range(3):
        for sy in range(3):
            if 3 <= L[i][0] + sx <= H and 3 <= L[i][1] + sy <= W:
                if (L[i][0] + sx, L[i][1] + sy) not in d:
                    d[(L[i][0] + sx, L[i][1] + sy)] = 1
                else:
                    d[(L[i][0] + sx, L[i][1] + sy)] += 1


c = Counter(d.values())
ans = [0 for _ in range(10)]

for k, v in c.items():
    if v > 0:
        ans[k] = v

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

for i in ans:
    print(i)

Solution (Python):

h,w,n = map(int,input().split())
d = {}
for i in range(n):
    a,b = map(int,input().split())
    a,b = a-1,b-1

    am1_f = a-1 > 0
    ap1_f = a+1 < h-1
    bm1_f = b-1 > 0
    bp1_f = b+1 < w-1
    a_f = a > 0 and a < h-1
    b_f = b > 0 and b < w-1

    am1 = a-1
    ap1 = a+1
    bm1 = b-1
    bp1 = b+1

    if am1_f:
        baseid = am1 * w
        if b_f:
            pid = baseid + b

            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bm1_f:
            pid = baseid + bm1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bp1_f:
            pid = baseid + bp1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

    if ap1_f:
        baseid = ap1*w
        if b_f:
            pid = baseid + b

            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bm1_f:
            pid = baseid + bm1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bp1_f:
            pid = baseid + bp1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1
    if a_f:

        baseid = a * w
        if b_f:
            pid = baseid + b
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bm1_f:
            pid = baseid + bm1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bp1_f:
            pid = baseid + bp1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1
    

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

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

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

for a in ans:
    print(a)

Solution (Python):

h,w,n = map(int,input().split())
d = {}
for i in range(n):
    a,b = map(int,input().split())
    a,b = a-1,b-1

    am1_f = a-1 > 0
    ap1_f = a+1 < h-1
    bm1_f = b-1 > 0
    bp1_f = b+1 < w-1
    a_f = a > 0 and a < h-1
    b_f = b > 0 and b < w-1

    am1 = a-1
    ap1 = a+1
    bm1 = b-1
    bp1 = b+1

    if am1_f:
        baseid = am1 * w
        if b_f:
            pid = baseid + b

            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bm1_f:
            pid = baseid + bm1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bp1_f:
            pid = baseid + bp1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

    if ap1_f:
        baseid = ap1*w
        if b_f:
            pid = baseid + b

            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bm1_f:
            pid = baseid + bm1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bp1_f:
            pid = baseid + bp1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1
    if a_f:

        baseid = a * w
        if b_f:
            pid = baseid + b
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bm1_f:
            pid = baseid + bm1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bp1_f:
            pid = baseid + bp1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1
    

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

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

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

for a in ans:
    print(a)

Solution (Python):


h,w,n = map(int,input().split())
d = {}
for i in range(n):
    a,b = map(int,input().split())
    a,b = a-1,b-1

    am1_f = a-1 > 0
    ap1_f = a+1 < h-1
    bm1_f = b-1 > 0
    bp1_f = b+1 < w-1
    a_f = a > 0 and a < h-1
    b_f = b > 0 and b < w-1

    am1 = a-1
    ap1 = a+1
    bm1 = b-1
    bp1 = b+1

    if am1_f:
        baseid = am1 * w
        if b_f:
            pid = baseid + b

            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bm1_f:
            pid = baseid + bm1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bp1_f:
            pid = baseid + bp1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

    if ap1_f:
        baseid = ap1*w
        if b_f:
            pid = baseid + b

            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bm1_f:
            pid = baseid + bm1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bp1_f:
            pid = baseid + bp1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1
    if a_f:

        baseid = a * w
        if b_f:
            pid = baseid + b
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bm1_f:
            pid = baseid + bm1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bp1_f:
            pid = baseid + bp1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1
    

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

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

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

for a in ans:
    print(a)

Solution (Python):
import numpy as np
from collections import Counter

h,w,n = map(int,input().split())
d = {}
for i in range(n):
    a,b = map(int,input().split())
    a,b = a-1,b-1

    am1_f = a-1 > 0
    ap1_f = a+1 < h-1
    bm1_f = b-1 > 0
    bp1_f = b+1 < w-1
    a_f = a > 0 and a < h-1
    b_f = b > 0 and b < w-1

    am1 = a-1
    ap1 = a+1
    bm1 = b-1
    bp1 = b+1

    if am1_f:
        baseid = am1 * w
        if b_f:
            pid = baseid + b

            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bm1_f:
            pid = baseid + bm1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bp1_f:
            pid = baseid + bp1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

    if ap1_f:
        baseid = ap1*w
        if b_f:
            pid = baseid + b

            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bm1_f:
            pid = baseid + bm1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bp1_f:
            pid = baseid + bp1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1
    if a_f:

        baseid = a * w
        if b_f:
            pid = baseid + b
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bm1_f:
            pid = baseid + bm1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bp1_f:
            pid = baseid + bp1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1
    

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

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

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

for a in ans:
    print(a)

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

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


dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
       [-1, 0], [-1, -1], [0, -1], [1, -1]]


dict = defaultdict(int)

for i in range(N):
    a, b = map(int, input().split())
    for dy, dx in dir:
        
        if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
            dict[(a + dy, b + dx)] += 1

c = Counter(dict.values())
ans = [0 for _ in range(10)]


for k, v in c.items():
    if v > 0:
        ans[k] = v



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

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

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

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


dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
       [-1, 0], [-1, -1], [0, -1], [1, -1]]


dict = defaultdict(int)

for i in range(N):
    a, b = map(int, input().split())
    for dy, dx in dir:
        
        if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
            dict[(a + dy, b + dx)] += 1

c = Counter(dict.values())
ans = [0 for _ in range(10)]


for k, v in c.items():
    if v > 0:
        ans[k] = v



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

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

Solution (Python):
from collections import Counter

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


dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
       [-1, 0], [-1, -1], [0, -1], [1, -1]]


dict = {}

for i in range(N):
    a, b = map(int, input().split())
    for dy, dx in dir:
        
        if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
            if (a + dy, b + dx) not in dict:
                dict[(a + dy, b + dx)] = 1
            else:
                dict[(a + dy, b + dx)] += 1

c = Counter(dict.values())
ans = [0 for _ in range(10)]


for k, v in c.items():
    if v > 0:
        ans[k] = v



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

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

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

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


dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
       [-1, 0], [-1, -1], [0, -1], [1, -1]]


dict = defaultdict(int)

for i in range(N):
    a, b = map(int, input().split())
    for dy, dx in dir:
        
        if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
            dict[(a + dy, b + dx)] += 1

c = Counter(dict.values())
ans = [0 for _ in range(10)]


for k, v in c.items():
    if v > 0:
        ans[k] = v



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

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

Solution (Python):
from collections import Counter

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


dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
       [-1, 0], [-1, -1], [0, -1], [1, -1]]


dict = {}

for i in range(N):
    a, b = map(int, input().split())
    for dy, dx in dir:
        
        if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
            if (a + dy, b + dx) not in dict:
                dict[(a + dy, b + dx)] = 1
            else:
                dict[(a + dy, b + dx)] += 1

c = Counter(dict.values())
ans = [0 for _ in range(10)]


for k, v in c.items():
    if v > 0:
        ans[k] = v



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

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

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

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


dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
       [-1, 0], [-1, -1], [0, -1], [1, -1]]


dict = defaultdict(int)

for i in range(N):
    a, b = map(int, input().split())
    for dy, dx in dir:
        
        if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
            dict[(a + dy, b + dx)] += 1

c = Counter(dict.values())
ans = [0 for _ in range(10)]


for k, v in c.items():
    if v > 0:
        ans[k] = v



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

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

Solution (Python):
from collections import Counter

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


dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
       [-1, 0], [-1, -1], [0, -1], [1, -1]]


dict = {}

for i in range(N):
    a, b = map(int, input().split())
    for dy, dx in dir:
        
        if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
            if (a + dy, b + dx) not in dict:
                dict[(a + dy, b + dx)] = 1
            else:
                dict[(a + dy, b + dx)] += 1

c = Counter(dict.values())
ans = [0 for _ in range(10)]


for k, v in c.items():
    if v > 0:
        ans[k] = v



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

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

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

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


dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
       [-1, 0], [-1, -1], [0, -1], [1, -1]]


dict = defaultdict(int)

for i in range(N):
    a, b = map(int, input().split())
    for dy, dx in dir:
        
        if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
            dict[(a + dy, b + dx)] += 1

c = Counter(dict.values())
ans = [0 for _ in range(10)]


for k, v in c.items():
    if v > 0:
        ans[k] = v



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

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

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

def main():
    """
    https://atcoder.jp/contests/abc045/submissions/14945636
    が高速に動作していたので参考に写経する。

    各黒マスに対して、それを含むテンプレートを左上の座標値で管理する。
    （写経元は右下座標で管理してる）
    このテンプレート及びそこに黒マスが何個入っているかを管理しておけば
    黒マス位置をソートして全体位置を把握していなくてもオンラインで更新が可能。
    """
    H, W, N = map(int, input().split())
    ans = [0] * 10
    templates = {}
    for _ in range(N):
        a, b = map(int, input().split())
        for i in range(9):
            
            h, w = (a - 3) + i // 3, (b - 3) + i % 3
            if h < 0 or w < 0: continue
            if h > H - 3 or w > W - 3: continue
            idx = h * W + w
            if idx in templates:
                ans[templates[idx]] -= 1
                templates[idx] += 1
                ans[templates[idx]] += 1
            else:
                templates[idx] = 1
                ans[1] += 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 bisect import bisect_left
from collections import defaultdict
def input(): return sys.stdin.readline().strip()

def main():
    H, W, N = map(int, input().split())
    black = []
    d = defaultdict(list)
    for _ in range(N):
        a, b = map(int, input().split())
        black.append((a - 1, b - 1))
        d[a - 1].append(b - 1)
    for key in d: d[key].sort()

    ans = [0] * 10
    checked = set()
    
    for i in range(9):
        for a, b in black:
            h, w = a - i // 3, b - i % 3
            if (h, w) in checked: continue
            if h < 0 or w < 0: continue
            if h > H - 3 or w > W - 3: continue
            cnt = 0
            idx1 = bisect_left(d[h], w)
            idx2 = bisect_left(d[h], w + 3)
            cnt += idx2 - idx1
            idx1 = bisect_left(d[h + 1], w)
            idx2 = bisect_left(d[h + 1], w + 3)
            cnt += idx2 - idx1
            idx1 = bisect_left(d[h + 2], w)
            idx2 = bisect_left(d[h + 2], w + 3)
            cnt += idx2 - idx1
            
            ans[cnt] += 1
            checked.add((h, w))
    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())
Draw = [tuple(map(int, input().split())) for _ in range(N)]
from collections import defaultdict as dd
Sq =  dd(lambda:0) 
In = lambda x,y:[(x-i,y-j) for i in range(3) for j in range(3) if 0<=x-i<H-2 and 0<=y-j<W-2] 
for a,b in Draw:
    for x,y in In(a-1,b-1): 
        Sq[x,y] += 1 
Ans = [(H-2)*(W-2)-len(Sq)] + [sum(v==i for v in Sq.values()) for i in range(1,10)]         
for ans in Ans:
    print(ans)

Solution (Python):
H, W, N = map(int, input().split())
from collections import defaultdict as dd
Grid =  dd(lambda:0) 
Draw = lambda x,y:[(x-i,y-j) for i in range(3) for j in range(3) if 0<=x-i<H-2 and 0<=y-j<W-2] 
for _ in range(N):
    a, b = map(int, input().split())
    for x,y in Draw(a-1,b-1): 
        Grid[x,y] += 1
Ans = [(H-2)*(W-2)-len(Grid) if i == 0 else sum(v==i for v in Grid.values()) for i in range(10)]         
for ans in Ans:
    print(ans)

Solution (Python):
h,w,n=map(int,input().split());I=[list(map(int,input().split()))for i in[0]*n]
from itertools import product as p;from collections import Counter as c;ans=[0]*9;o=(h-2)*(w-2)
for k,v in c(c([(a-x)*w+b-y for x,y in p(range(3),repeat=2) for a,b in I if h-1>a-x>0<b-y<w-1]).values()).items():ans[k-1]=v;o-=v
print(o,*ans,sep='\n')

Solution (Python):
h,w,n=map(int,input().split());from itertools import product as p;from collections import Counter as c;I=[list(map(int,input().split()))for i in[0]*n];ans=[0]*9
for k,v in c(c([(a-x)*w+b-y for x,y in p(range(3),repeat=2) for a,b in I if h-1>a-x>0<b-y<w-1]).values()).items():ans[k-1]=v
print((h-2)*(w-2)-sum(ans),*ans,sep='\n')