Problem:
 Score : 400 points    Problem Statement We have a grid with H rows and W columns. At first, all cells were painted white.  Snuke painted N of these cells. The i -th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i -th row and b_i -th column.  Compute the following:   For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?       Constraints  3 \leq H \leq 10^9  3 \leq W \leq 10^9  0 \leq N \leq min(10^5,H×W)  1 \leq a_i \leq H  (1 \leq i \leq N)  1 \leq b_i \leq W  (1 \leq i \leq N)  (a_i, b_i) \neq (a_j, b_j)  (i \neq j)         Input The input is given from Standard Input in the following format:  H  W  N  a_1  b_1 : a_N  b_N       Output Print 10 lines.
The (j+1) -th ( 0 \leq j \leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.        Sample Input 1 4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4      Sample Output 1 0
0
0
2
4
0
0
0
0
0   There are six subrectangles of size 3×3 . Two of them contain three black cells each, and the remaining four contain four black cells each.       Sample Input 2 10 10 20
1 1
1 4
1 9
2 5
3 10
4 2
4 7
5 9
6 4
6 6
6 7
7 1
7 3
7 7
8 1
8 5
8 10
9 2
10 4
10 9      Sample Output 2 4
26
22
10
2
0
0
0
0
0       Sample Input 3 1000000000 1000000000 0      Sample Output 3 999999996000000004
0
0
0
0
0
0
0
0
0

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007








h,w,n = LI()
dp = [0 for i in range(10)]
dp[0] = (h-2)*(w-2)
q = defaultdict(int)
for i in range(n):
    a,b = LI()
    a -= 1
    b -= 1
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if 0 < a+i < h-1 and 0 < b+j < w-1:
                q[(a+i)*w+b+j] += 1
                dp[q[(a+i)*w+b+j]] += 1
                dp[q[(a+i)*w+b+j]-1] -= 1
for i in dp:
    print(i)

Solution (Python):

from collections import defaultdict
h,w,n=map(int,input().split())
ans=defaultdict(int)
for i in range(n):
    a,b=map(int,input().split())
    for j in range(0,-3,-1):
        for k in range(0,-3,-1):
            if a+j>0 and a+j<=h-2 and b+k>0 and b+k<=w-2:
                ans[(a+j,b+k)]+=1
res=[0 for i in range(10)]
for x in ans.values():
    res[x]+=1
res[0]=((h-2)*(w-2))-sum(res[1:])
for i in range(10):
    print(res[i])

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

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

for _ in range(n):
  a, b = map(int, input().split())
  for i in range(3):
    for j in range(3):
      if a-i>0 and b-j>0 and a-i<=h-2 and b-j<=w-2:
        d[(a-i, b-j)] += 1
d = dict(d)
con = Counter(d.values())
con[0] = (h-2)*(w-2) - sum(con.values())
for i in range(10):
  print(con[i])

Solution (Python):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [H, W, N] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    b_list = []
    b_set = set([])
    for i in range(N):
        input_raw = read_func().strip().split()
        [a, b] = [int(input_raw[0]) - 1, int(input_raw[1]) - 1]
        
        b_set.add((a, b))

    black_count = {}
    for i in range(10):
        black_count[i] = 0



    already_set = set([])
    for m in b_set:
        for x in range(0, -3, -1):
            for y in range(0, -3, -1):
                square_upper_left_x = m[1] + x
                square_upper_left_y = m[0] + y
                if ((square_upper_left_y, square_upper_left_x) not in already_set and
                    square_upper_left_x + 2 < W and
                    square_upper_left_y + 2 < H and
                    square_upper_left_x >= 0 and
                    square_upper_left_y >= 0):
                        already_set.add((square_upper_left_y, square_upper_left_x))
                        count = 0
                        for i in range(3):
                            for j in range(3):
                                if (square_upper_left_y + j, square_upper_left_x + i) in b_set:
                                    count += 1
                        black_count[count] += 1
    s = 0L
    for i in range(1, 10):
        s += black_count[i]
    print (H -2) * (W - 2) - s
    for i in range(1, 10):
        print black_count[i]




if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

H, W, N = [int(v) for v in input().split()]

square_list = []
for i in range(N):
    a, b = [int(v) for v in input().split()]
    for p in range(3):
        for q in range(3):
            if 1 <= a-p <= H-2 and 1 <= b - q <= W-2:
                square_list.append((a - p, b - q))

square_cnt = Counter(square_list)
ans = {i: 0 for i in range(10)}
ans[0] = (H-2) * (W-2) - len(square_cnt)
for cnt in square_cnt.values():
    ans[cnt] += 1

for k in sorted(ans.keys()):
    print(ans[k])

Solution (Python):
from collections import defaultdict as dd

h,w,n=map(int,input().split())
d=dd(int)
c={i:0 for i in range(10)}

for _ in range(n):
    a,b=map(int,input().split())
    for i in range(3):
        for j in range(3):
            if a-i>0 and b-j>0 and a-i<=h-2 and b-j<=w-2:
                d[(a-i,b-j)]+=1

d=dict(d)
v=0
for i in d.values():
    c[i]+=1
    v+=1
c[0]=(h-2)*(w-2)-v

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

Solution (Python):
from collections import defaultdict as dd

h,w,n=map(int,input().split())
d=dd(int)
c={i:0 for i in range(10)}

for _ in range(n):
    a,b=map(int,input().split())
    for i in range(3):
        for j in range(3):
            if a-i>0 and b-j>0 and a-i<=h-2 and b-j<=w-2:
                d[(a-i,b-j)]+=1

d=dict(d)
v=0
for i in d.values():
    c[i]+=1
    v+=1
c[0]=(h-2)*(w-2)-v

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

Solution (Python):
from collections import Counter, defaultdict

h, w, n = map(int, input().split())
dic = defaultdict(int)
for _ in range(n):
    a, b = map(int, input().split())
    for y in range(a - 2, a + 1):
        for x in range(b - 2, b + 1):
            if 1 <= y <= h - 2 and 1 <= x <= w - 2:
                dic[(x, y)] += 1
counter = Counter(dic.values())
cntSum = (w - 2) * (h - 2)
counter[0] = cntSum - sum(counter.values())
for k in range(10):
    print(counter[k])

Solution (Python):


"""
参考：http://arc061.contest.atcoder.jp/data/arc/061/editorial.pdf
・各点が影響を与える9か所の正方形をメモしておく。
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W, N = MAP()

xy = []
for i in range(N):
    a, b = MAP()
    a -= 1
    b -= 1
    for j in range(3):
        for k in range(3):
            
            if 0 <= a-j < H-2 and 0 <= b-k < W-2:
                xy.append((a-j, b-k))

c = Counter(xy)

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

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

for num in ans:
    print(num)

Solution (Python):


"""
参考：http://arc061.contest.atcoder.jp/data/arc/061/editorial.pdf
・各点が影響を与える9か所の正方形をメモしておく。
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W, N = MAP()

xy = []
for i in range(N):
    a, b = MAP()
    a -= 1
    b -= 1
    for j in range(3):
        for k in range(3):
            
            if 0 <= a-j < H-2 and 0 <= b-k < W-2:
                xy.append((a-j, b-k))

c = Counter(xy)

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

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

for num in ans:
    print(num)

Solution (Python):
from collections import Counter


def solve(H, W, N, ABs):
    total = (H - 2) * (W - 2)
    points = {}
    for a, b in ABs:
        a -= 1
        b -= 1
        for i in [-1, 0, 1]:
            for j in [-1, 0, 1]:
                if 0 < a + i < H - 1 and 0 < b + j < W - 1:
                    d = (a + i, b + j)
                    if d not in points:
                        points[d] = 0
                    points[d] += 1
    c = Counter([v for v in points.values()])
    ans = [total - len(points)] + [c[f] if f in c else 0 for f in range(1, 10)]
    return "\n".join([str(a) for a in ans])

if __name__ == "__main__":
    H, W, N = map(int, input().split(" "))
    ABs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(solve(H, W, N, ABs))

Solution (Python):
from collections import defaultdict
H,W,N=map(int,input().split())
ans=[0 for i in range(10)]

data=defaultdict(int)
def check(a,b):
    if a>0 and a<H-1 and b>0 and b<W-1:return True
    else:return False

def count(a,b):
    for i in range(a-2,a+1):
        for j in range(b-2,b+1):
            if check(i,j):
                x=(i,j)
                data[x]+=1
                
for k in range(N):
    a,b=map(int,input().split())
    count(a,b)

for v in data.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 defaultdict, Counter
H, W, N = map(int, input().split())
D = defaultdict(int)

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

C = Counter(D.values())
SUM = sum(C.values())

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

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

comb_map = {}


for a, b in ab:
    for k in range(3):
        for m in range(3):
            if 0 <= a - k < H - 2 and 0 <= b - m < W - 2:
                if (a-k, b-m) in comb_map.keys():
                    comb_map[(a - k, b - m)] += 1
                else:
                    comb_map[(a - k, b - m)] = 1

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

for v in comb_map.values():
    count[v] += 1

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

for c in count:
    print(c)

Solution (Python):
import itertools
H, W, N = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(N)]

memo = {}
for a, b in AB:
    
    a -= 1
    b -= 1
    for na, nb in itertools.product(range(a - 2, a + 1), range(b - 2, b + 1)):
        if na in range(H - 2) and nb in range(W - 2):
            memo[na + H * nb] = memo.get(na + H * nb, 0) + 1
result = [0] * 10
for k, v in memo.items():
    result[v] += 1
result[0] = (H - 2) * (W - 2) - sum(result)
[print(_) for _ in result]

Solution (Python):
H,W,N = map(int,input().split())
dic = {}
for i in range(N):
    a,b = map(int,input().split())
    for dh in range(3):
        for dw in range(3):
            if 0<a-dh<=H-2 and 0<b-dw<=W-2:
                if (a-dh,b-dw) not in dic.keys():
                    dic[(a-dh,b-dw)] = 1
                else:
                    dic[(a-dh,b-dw)] += 1

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

Ans[0] = (H-2)*(W-2) - total

for ans in Ans:
    print(ans)

Solution (Python):
import collections

h, w, n = [int(i) for i in input().split()]
s = [tuple(int(i) for i in input().split()) for j in range(n)]

def dictadd(d, si):
    dc = d
    for i in range(si[0]-2, si[0]+1):
        if 1 <= i <= h-2:
            for j in range(si[1]-2, si[1]+1):
                if 1 <= j <= w-2:
                    dc[(i, j)] += 1
    return dc


d = collections.defaultdict(lambda: 0)
dc = d

for i in s:
    dc = dictadd(dc, i)

dcv = list(dc.values())
ans = []
tot = 0

for i in range(1, 10):
    x = dcv.count(i)
    ans.append(x)
    tot += x

z = (w-2)*(h-2)-tot

print(z)
for i in ans:
    print(i)

Solution (Python):
import collections

h, w, n = [int(i) for i in input().split()]
s = [tuple(int(i) for i in input().split()) for j in range(n)]

def dictadd(d, si):
    dc = d
    for i in range(si[0]-2, si[0]+1):
        if 1 <= i <= h-2:
            for j in range(si[1]-2, si[1]+1):
                if 1 <= j <= w-2:
                    dc[(i, j)] += 1
    return dc


d = collections.defaultdict(lambda: 0)
dc = d

for i in s:
    dc = dictadd(dc, i)

dcv = list(dc.values())
ans = collections.defaultdict(lambda: 0)
tot = 0

for i in range(1, 10):
    ans[i] += dcv.count(i)
    tot += dcv.count(i)

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


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

Solution (Python):

import collections
H, W, N = map(int, input().split())
table = collections.defaultdict(int) 
for i in range(N):
    a, b = map(int, input().split())
    for yy in range(3):
        for xx in range(3):
            y = a - 1 - yy
            x = b - 1 - xx
            if 0 <= y and y + 2 < H and 0 <= x and x + 2 < W:
                table[(y, x)] += 1
counts = [0] * 10
for v in table.values():
    counts[v] += 1
counts[0] = (H - 2) * (W - 2) - sum(counts)
for c in counts:
    print(c)

Solution (Python):
from collections import defaultdict

Dic = defaultdict(int)
H, W, N = map(int, input().split())
ans = [0]*10

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

for i in Dic:
    ans[Dic[i]] += 1
ans[0] = (H-2)*(W-2) - sum(ans)

for i in ans:
    print(i)

Solution (Python):
H, W, N = map(int, input().split())
 
Dic = {}
for i in range(N):
    a, b = map(int, input().split())
    for j in range(3):
        for k in range(3):
            if 1 <= a-j <= H-2 and 1 <= b-k <= W-2:
                if (a-j, b-k) in Dic:
                    Dic[(a-j, b-k)] += 1
                else:
                    Dic[(a-j, b-k)] = 1
                    
Painted = [0 for _ in range(10)]
colered = 0

for i in Dic:
    Painted[Dic[i]] += 1
    colered += 1


Painted[0] = (H-2) * (W-2) - colered
 
for i in Painted:
    print(i)

Solution (Python):
H,W,N=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]

from collections import defaultdict
from collections import Counter

ANS = defaultdict(int)

for a,b in AB:
    for i in [a-1,a,a+1]:
        for j in [b-1,b,b+1]:
            if 2<=i<H and 2<=j<W:
                ANS[(i,j)]+=1

counter=Counter(ANS.values())
ANSLIST=[0]*10
for c in counter:
    ANSLIST[c]=counter[c]
ANSLIST[0]=(H-2)*(W-2)-sum(counter.values())

for a in ANSLIST:
    print(a)

Solution (Python):
from collections import defaultdict
H,W,N=map(int,input().split())
d=defaultdict(int)
for n in range(N):
  y,x=map(int,input().split())
  for i in range(3):
    for j in range(3):
      if W-3>=x+i-3>=0 and H-3>=y+j-3>=0:
        d[(x+i-3,y+j-3)]+=1
ans=[0]*10
S=0
for t,t_num in d.items():
  ans[t_num]+=1
  S+=1
ans[0]=(H-2)*(W-2)-S
for i in range(10):
  print(ans[i])

Solution (Python):
H, W, N = map(int, raw_input().split())
p = set()
for i in range(N):
  a, b = map(int, raw_input().split())
  p.add((a,b))
r = [0]*10
c = set()
for a, b in p:
  for y0 in range(a-2, a+1):
    for x0 in range(b-2, b+1):
      if x0<1 or x0+2>W or y0<1 or y0+2>H or (y0,x0) in c:
        continue
      c.add((y0,x0))
      s = 0
      for y in range(y0, y0+3):
        for x in range(x0, x0+3):
          if (y,x) in p:
            s += 1
      r[s] += 1
print (H-2)*(W-2)-sum(r[1:10])
for ri in r[1:10]:
  print ri

Solution (Python):
from collections import defaultdict
H, W, N = map(int, input().split())
P = [0] * 10
P[0] = (H - 2) * (W - 2)
G = defaultdict(lambda: defaultdict(int))
for i in range(N):
  a, b = map(int, input().split())
  for i in range(max(a - 3, 0), min(a, H - 2)):
    for j in range(max(b - 3, 0), min(b, W - 2)):
      p = G[i][j]
      P[p] -= 1
      P[p + 1] += 1
      G[i][j] += 1
for i in range(10):
  print(P[i])

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

dic={}
for _ in range(N):
    a,b=list(map(int,input().split()))
    for i in range(-1,2):
        for j in range(-1,2):
            if (a+i)<=1 or b+j<=1 or a+i>=H or b+j >=W:
                continue
            s=(a+i)*W+b+j
            if dic.get(s,0)==0:
                dic[s]=1
            else:
                dic[s]+=1
arr=[0 for i in range(10)]
for v in dic.values():
    arr[v]+=1
arr[0]=(H-2)*(W-2)-sum(arr)
for x in arr:
    print(x)

Solution (Python):

from collections import Counter
H, W, N = map(int, input().split())
L = []
for k in range(N):
    a, b = map(int, input().split())
    for k in range(3):
        for l in range(3):
            if 1 <= a-k <= H-2  and 1 <= b-l <= W-2:
                L.append((a-k,b-l))

M = Counter(L)
A = [0 for k in range(10)]
s = 0
for e in M:
    A[M[e]] += 1
    s += 1

A[0] = (H-2)*(W-2)-s
for a in A:
    print(a)

Solution (Python):
from collections import defaultdict
Delta = [-1,0,1]
d = defaultdict(lambda:0)
def paint(d,x,y):
    for dx in Delta:
        for dy in Delta:
            d[(x+dx,y+dy)] += 1
H,W,N = map(int,input().split())
for i in range(N):
    a,b = map(int,input().split())
    paint(d,a,b)
ans = defaultdict(lambda:0)
for x,y in d.keys():
    if 2<=x<=H-1 and 2<=y<=W-1:
        ans[d[(x,y)]] += 1
ans0 = (H-2)*(W-2)
for i in range(10):
    ans0 -= ans[i]
ans[0] = ans0
for i in range(10):
    print(ans[i])

Solution (Python):
h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
x=[]
di=[0,0,0,1,1,1,2,2,2]
dj=[0,1,2,0,1,2,0,1,2]
from collections import defaultdict,Counter
x=defaultdict(int)
for a,b in ab:
    for ti,tj in zip(di,dj):
        if 3<=a+ti<=h and 3<=b+tj<=w:
            x[(a+ti,b+tj)]+=1

c=Counter(x.values())
print((h-2)*(w-2)-sum(c.values()))
for i in range(1,10):
    print(c[i])

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import defaultdict, Counter

dic = defaultdict(int)

h,w,n = li()

dhs = [-1,-1,-1, 0, 0, 0, 1, 1, 1]
dws = [-1, 0, 1,-1, 0, 1,-1, 0, 1]

for _ in range(n):
    r,c = li()
    for dh, dw in zip(dhs, dws):
        if 1 < r+dh < h and 1 < c+dw < w:
            dic[(r+dh, c+dw)] += 1
            
vals = Counter(dic.values())

for i in range(10):
    if i == 0:
        print((h-2)*(w-2) - sum(vals.values()))
    else:
        print(vals[i])

Solution (Python):
from collections import defaultdict
H, W, N = map(int, input().split())
dic = defaultdict(int)
for i in range(N):
    a, b = map(int, input().split())
    for j in range(3):
        for k in range(3):
            if 1 <= a + j - 2 <= H - 2 and 1 <= b + k - 2 <= W - 2:
                dic[(a + j - 2, b + k - 2)] += 1

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

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

Solution (Python):
import sys
def 解():
    iH,iW,iN = [int(_) for _ in input().split()]
    aD = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]

    iMax = (iH - 2) * (iW -2)
    

    dC={}
    for i in range(10):
        dC[i]=0

    
    
    
    
    
    
    
    

    
    
    dM = {}
    for a in aD:
        y=a[0]
        x=a[1]
        for aP in [(y-2,x-2),(y-2,x-1),(y-2,x),(y-1,x-2),(y-1,x-1),(y-1,x),(y,x-2),(y,x-1),(y,x)]:
            if 0< aP[0]<iH-1 and 0 < aP[1] < iW-1:
                iP = aP[0]*iW + aP[1]
                if iP in dM: 
                    dM[iP] += 1
                else:
                    dM[iP] = 1
    for i in dM:
        dC[dM[i]]+=1

    iAllBM=0
    for i in range(1,10):
        iAllBM+=dC[i]
    dC[0] = iMax -iAllBM 

    for i in range(10):
        print(dC[i])
解()

Solution (Python):
import sys
iH,iW,iN = [int(_) for _ in input().split()]
aD = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]

iMax = (iH - 2) * (iW -2)


dC={}
for i in range(10):
    dC[i]=0









dM = {}
for a in aD:
    y=a[0]
    x=a[1]
    for aP in [(y-2,x-2),(y-2,x-1),(y-2,x),(y-1,x-2),(y-1,x-1),(y-1,x),(y,x-2),(y,x-1),(y,x)]:
        if 0< aP[0]<iH-1 and 0 < aP[1] < iW-1:
            iP = aP[0]*iW + aP[1]
            if iP in dM:
                dM[iP] += 1
            else:
                dM[iP] = 1
for i in dM:
    dC[dM[i]]+=1

iAllBM=0
for i in range(1,10):
    iAllBM+=dC[i]
dC[0] = iMax -iAllBM

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

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

Dic = {}
for i in range(N):
    a, b = map(int, input().split())
    for j in range(3):
        for k in range(3):
            if 1 <= a-j <= H-2 and 1 <= b-k <= W-2:
                if (a-j, b-k) in Dic:
                    Dic[(a-j, b-k)] += 1
                else:
                    Dic[(a-j, b-k)] = 1

Painted = [0 for _ in range(10)]
colered = 0
for i in Dic:
    Painted[Dic[i]] += 1
    colered += 1
Painted[0] = (H-2) * (W-2) - colered

for i in Painted:
    print(i)

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

c = dict()
for _ in range(n):
    a, b = map(int, input().split())
    for da in -1, 0, 1:
        for db in -1, 0, 1:
            if (2 <= a + da <= h - 1) and (2 <= b + db <= w - 1):
                c[(a + da, b + db)] = c.get((a + da, b + db), 0) + 1


ans_cnt = [0 for _ in range(10)]
for cnt in c.values():
    ans_cnt[cnt] += 1

ans_cnt[0] = ((h - 1) - 2 + 1) * ((w - 1) - 2 + 1) - sum((1 for cnt in c.values() if cnt > 0))

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

Solution (Python):
from collections import defaultdict,Counter
d=defaultdict(int)
h,w,n=map(int,input().split())
for _ in range(n):
  p,q=map(int,input().split())
  for x in [q-2,q-1,q]:
    for y in [p-2,p-1,p]:
      if 1<=y<=h-2 and 1<=x<=w-2:
        d[(x,y)]+=1

cnt=Counter(d.values())
print((h-2)*(w-2)-sum(cnt.values()))
for i in range(1,10):
  print(cnt[i])

Solution (Python):
from collections import defaultdict
h,w,n = map(int,input().split())
x = []
for i in range(n):
  x.append(list(map(int,input().split())))
d = defaultdict(int)
for i in x:
  a = []
  for j in range(3):
    for k in range(3):
      if (i[0]-j-1>=0 and i[1]-k-1 >= 0 and i[0]-j-1<=h-3 and i[1]-k-1 <= w-3):
        a.append((i[0]-j-1,i[1]-k-1))
  for j in a:
    d[j] += 1
a = list(d.values())
ans = [0]*10
ans[0] = (h-2)*(w-2)-len(a)
for i in a:
  ans[i] += 1
for i in ans:
  print(i)

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

from collections import defaultdict, Counter

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

field = defaultdict(int)
grid_num = (h-2)*(w-2)

x = [-1,-1,-1, 0, 0, 0, 1, 1, 1]
y = [-1, 0, 1,-1, 0, 1,-1, 0, 1]

for a, b in ab:
    for dx,dy in zip(x, y):
        if a+dx > 1 and a+dx < h and b+dy > 1 and b+dy < w:
            field[(a+dx, b+dy)] += 1



cnt = Counter(field.values())

for j in range(10):
    if j == 0:
        print(grid_num - sum(cnt.values()))
    else:
        print(cnt[j])

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

from collections import defaultdict, Counter

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

field = defaultdict(int)
grid_num = (h-2)*(w-2)

x = [-1,-1,-1, 0, 0, 0, 1, 1, 1]
y = [-1, 0, 1,-1, 0, 1,-1, 0, 1]

for a, b in ab:
    for dx,dy in zip(x, y):
        if a+dx > 1 and a+dx < h and b+dy > 1 and b+dy < w:
            field[(a+dx, b+dy)] += 1



cnt = Counter(field.values())

for j in range(10):
    if j == 0:
        print(grid_num - sum(cnt.values()))
    else:
        print(cnt[j])

Solution (Python):
from collections import Counter
H,W,N = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]

blacks = Counter()
for y,x in src:
    for i in range(-1,2):
        if not 0 <= y+i < H: continue
        for j in range(-1,2):
            if not 0 <= x+j < W: continue
            blacks[(x+j, y+i)] += 1

ans = [0] * 10
for (x,y),v in blacks.items():
    if x<2 or y<2: continue
    ans[v] += 1
ans[0] = (H-2)*(W-2) - sum(ans[1:])
print(*ans,sep='\n')

Solution (Python):


import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(H, W, N, AB):
    c = Counter()

    ij = list(product([-1, 0, 1], repeat=2))
    for a, b in AB:
        for i, j in ij:
            c[(a+i, b+j)] += 1

    ans = Counter()
    for (i, j), v in c.items():
        if 2 <= i < H and 2 <= j < W:
            ans[v] += 1

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


def main():
    H, W, N = read_int_n()
    AB = [read_int_n() for _ in range(N)]

    slv(H, W, N, AB)


if __name__ == '__main__':
    main()

Solution (Python):


import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(H, W, N, AB):
    c = Counter()

    ij = list(product([-1, 0, 1], repeat=2))
    for a, b in AB:
        for i, j in ij:
            c[(a+i, b+j)] += 1

    ans = Counter()
    for (i, j), v in c.items():
        if 2 <= i < H and 2 <= j < W:
            ans[v] += 1

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


def main():
    H, W, N = read_int_n()
    AB = [read_int_n() for _ in range(N)]

    slv(H, W, N, AB)


if __name__ == '__main__':
    main()

Solution (Python):

"""
Created on Wed Aug  8 22:33:01 2018
ABC045D
@author: maezawa
"""
import collections
h, w, n = list(map(int, input().split()))
areas = []
for i in range(n):
    ai, bi = list(map(int, input().split()))
    ai -= 1
    bi -= 1
    for j in range(3):
        for k in range(3):
            ci = ai + j - 1
            di = bi + k - 1
            if ci>=1 and ci <= h-2 and di>=1 and di <= w-2:
                areas.append(str(ci)+'-'+str(di))
c = collections.Counter(areas)

cn = list(c.values())
cn0 = (h-2)*(w-2)-sum([cn.count(i) for i in range(1,10)])
print(cn0)
for i in range(1,10):
    print(cn.count(i))

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

sdin = sys.stdin.readline

H,W,N = map(int, sdin().split())
AB = []
for i in range(N):
    AB.append(tuple(map(int, sdin().split())))
    
grid_num = (min(H,W)-2)*(max(H,W)-2)
    
AB = [(a-1,b-1) for a,b in AB]

dic = defaultdict(int)

for a,b in AB:
    for h in range(-1,2):
        if a+h < 1 or a+h > H-2:
            continue
        
        for w in range(-1,2):
            if b+w < 1 or b+w > W-2:
                continue
            
            dic[(a+h,b+w)] += 1
            

cnt = Counter(dic.values())

for i in range(10):
    if i==0:
        print(grid_num - sum(cnt.values()))
    elif not i in cnt.keys():
        print(0)
    else:
        print(cnt[i])

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

h, w, n = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n)]

board = defaultdict(int)

for a, b in A:
    for dx, dy in product((-1, 0, 1), repeat=2):
        board[(a+dx, b+dy)] += 1

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

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

for a in ans:
    print(a)

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

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

c = defaultdict(int)
for _ in range(N):
    a, b = map(int, input().split())
    for dx, dy in product([-1, 0, 1], repeat=2):
        y = a - 2 + dy
        x = b - 2 + dx
        if 0 <= y < H - 2 and 0 <= x < W - 2:
            c[(x, y)] += 1

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