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())
li = []
for i in range(N):
  li.append(tuple(map(int, input().split())))
t = tuple(li)
st = set(t)
#print(t)

Js = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

for a, b in t:
  if a > H-2 or b > W-2:
    pass
  else:
    t_p1 = ((a, b), (a, b+1), (a, b+2),\
            (a+1, b), (a+1, b+1), (a+1, b+2),\
            (a+2, b), (a+2, b+1), (a+2, b+2))
    s1 = st & set(t_p1)
    ls1 = len(s1)
    Js[ls1] += 1
  
  if a > H-2 or b > W-1 or b < 2:
    pass
  else:
    t_p2 = ((a, b-1), (a, b), (a, b+1),\
            (a+1, b-1), (a+1, b), (a+1, b+1),\
            (a+2, b-1), (a+2, b), (a+2, b+1))
    s2 = st & set(t_p2)
    ls2 = len(s2)
    Js[ls2] += 1
  
  if a > H-2 or b < 3:
    pass
  else:
    t_p3 = ((a, b-2), (a, b-1), (a, b),\
            (a+1, b-2), (a+1, b-1), (a+1, b),\
            (a+2, b-2), (a+2, b-1), (a+2, b))
    s3 = st & set(t_p3)
    ls3 = len(s3)
    Js[ls3] += 1

  if a > H-1 or a < 2 or b > W-2:
    pass
  else:
    t_p4 = ((a-1, b), (a-1, b+1), (a-1, b+2),\
            (a, b), (a, b+1), (a, b+2),\
            (a+1, b), (a+1, b+1), (a+1, b+2))
    s4 = st & set(t_p4)
    ls4 = len(s4)
    Js[ls4] += 1
  
  if a > H-1 or a < 2 or b > W-1 or b < 2:
    pass
  else:
    t_p5 = ((a-1, b-1), (a-1, b), (a-1, b+1),\
            (a, b-1), (a, b), (a, b+1),\
            (a+1, b-1), (a+1, b), (a+1, b+1))
    s5 = st & set(t_p5)
    ls5 = len(s5)
    Js[ls5] += 1
  
  if a > H-1 or a < 2 or b < 3:
    pass
  else:
    t_p6 = ((a-1, b-2), (a-1, b-1), (a-1, b),\
            (a, b-2), (a, b-1), (a, b),\
            (a+1, b-2), (a+1, b-1), (a+1, b))
    s6 = st & set(t_p6)
    ls6 = len(s6)
    Js[ls6] += 1
  
  if a < 3 or b > W-2:
    pass
  else:
    t_p7 = ((a-2, b), (a-2, b+1), (a-2, b+2),\
            (a-1, b), (a-1, b+1), (a-1, b+2),\
            (a, b), (a, b+1), (a, b+2))
    s7 = st & set(t_p7)
    ls7 = len(s7)
    Js[ls7] += 1
  
  if a < 3 or b > W-1 or b < 2:
    pass
  else:
    t_p8 = ((a-2, b-1), (a-2, b), (a-2, b+1),\
            (a-1, b-1), (a-1, b), (a-1, b+1),\
            (a, b-1), (a, b), (a, b+1))
    s8 = st & set(t_p8)
    ls8 = len(s8)
    Js[ls8] += 1
  
  if a < 3 or b < 3:
    pass
  else:
    t_p9 = ((a-2, b-2), (a-2, b-1), (a-2, b),\
            (a-1, b-2), (a-1, b-1), (a-1, b),\
            (a, b-2), (a, b-1), (a, b))
    s9 = st & set(t_p9)
    ls9 = len(s9)
    Js[ls9] += 1

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

all = (H - 2) * (W - 2)
Js[0] = all - sum(Js)
  
for i in range(10):
  print(Js[i])

Submission status: Accepted

Solution code:
def solve(h,w,n,black_list):
  if len(black_list) == 0:
    return [(h-2)*(w-2)]+[0]*9
  idx_list = []
  for idx, (a,b) in enumerate(black_list):
    left = max(0, b-3)
    top = max(0, a-3)
    for row in range(top, a):
      if row+2 >= h:
        continue
      for col in range(left, b):
        if col+2 >= w:
          continue
        idx_list.append(row*w+col)

  set_count = set(idx_list)
  idx_list = sorted(idx_list)

  ans = [0]*9
  now = idx_list[0]
  count = 0
  for item in idx_list:
    if item == now:
      count += 1
    else:
      now = item
      if count == 10:
        print(item)
      ans[count-1] += 1
      count = 1
  ans[count-1] += 1
  return [(h-2)*(w-2)-len(set_count)]+ans


if __name__ == "__main__":
  h,w,n = map(int,input().split())
  black_list = [tuple(map(int,input().split())) for _ in range(n)]
  ret = solve(h,w,n,black_list)
  for i in ret:
    print(i)

Submission status: Accepted

Solution code:
from collections import defaultdict
h,w,n=map(int,input().split())
d=defaultdict(int)
s=set()
for _ in range(n):
  a,b=map(int,input().split())
  a-=1
  b-=1
  for dy in [-2,-1,0]:
    for dx in [-2,-1,0]:
      ny,nx=a+dy,b+dx
      if 0<=ny<h and 0<=nx<w and ny+2<h and nx+2<w:
        d[(ny,nx)]+=1
        s.add((ny,nx))
cnt=[0]*10
q=0
for y,x in s:
  cnt[d[(y,x)]]+=1
cnt[0]=(h-2)*(w-2)-len(s)
for i in cnt:
  print(i)

Submission status: Accepted

Solution code:
h,w,n=map(int,input().split())
d={}
s=set()
for _ in range(n):
  a,b=map(int,input().split())
  a-=1
  b-=1
  for dy in [-2,-1,0]:
    for dx in [-2,-1,0]:
      ny,nx=a+dy,b+dx
      if 0<=ny<h and 0<=nx<w and ny+2<h and nx+2<w:
        if (ny,nx) in s:
          d[(ny,nx)]+=1
        else:
          d[(ny,nx)]=1
          s.add((ny,nx))
cnt=[0]*10
q=0
for v in d.values():
  cnt[v]+=1
cnt[0]=(h-2)*(w-2)-len(s)
for i in cnt:
  print(i)

Submission status: Accepted

Solution code:
h,w,n = map(int,input().split())
grids = {}
D = [1,-1,0]
for _ in range(n):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  
  for dx in D:
    for dy  in D:
      na,nb = a+dx,b+dy
      if not(0<na<h-1 and 0<nb<w-1):
        continue
      if(na,nb) not in grids:
        grids[(na,nb)] = 0
      grids[(na,nb)] += 1
      
        
        
ans = [0 for _ in range(10)]

for v in grids.values():
  ans[v]+=1

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

for a in ans:
  print(a)

Submission status: Accepted

Solution code:
h,w,n = map(int, input().split())
memo = {}
dxy = [(0,1), (0,0), (1,0), (-1,0), (0,-1), (1,1), (-1,-1), (-1,1), (1,-1)]
for i in range(n):
    a,b = map(int, input().split())
    for dx,dy in dxy:
        x,y = a+dx,b+dy
        if 1 < x < h and 1 < y < w:
            if (x,y) not in memo:
                memo[(x,y)] = 0
            memo[(x,y)] += 1

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

Submission status: Accepted

Solution code:
#in1 = '4 5 8'
#in2 = ['1 1', '1 4', '1 5', '2 3', '3 1', '3 2', '3 4', '4 4']
#in1 = '10 10 20'
#in2 = ['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']
#in1 = '1000000000 1000000000 0'
#h, w, n = map(int, in1.split())
h, w, n = map(int, input().split())

idx1 = 0
ab = [[0 for i in range(2)] for j in range(n)]

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

if n != 0:
    while idx1 < n:
        x = input().split()
        #x = in2[idx1].split()
        ab[idx1] = [int(x[0]), int(x[1])]
        idx1 += 1

    myDict = {}
    for abitem in ab:
        if abitem[0] < 3:
            sr = 0
        else:
            sr = abitem[0] - 3
        if abitem[0] > h - 3:
            lr = h - 2
        else:
            lr = abitem[0]
        if abitem[1] < 3:
            sc = 0
        else:
            sc = abitem[1] - 3
        if abitem[1] > w - 3:
            lc = w - 2
        else:
            lc = abitem[1]

        for nowRow in range(sr, lr):
            for nowCol in range(sc, lc):
                key = str(nowRow) + ',' + str(nowCol)
                if key in myDict:
                    myDict[key] += 1
                else:
                    myDict[key] = 1

    for bcnt in myDict.values():
        black_cnt[bcnt] += 1
        black_cnt[0]    -= 1

for item in black_cnt:
    print(item)

Submission status: Accepted

Solution code:
H,W,N = map(int,input().split())
d = {}
for _ in range(N):
    a,b = list(map(int,input().split()))
    for dy in range(-1,2):
        for dx in range(-1,2):
            cy = a + dy
            cx = b + dx
            if 2 <= cy <= H-1 and 2 <= cx <= W-1:
                if (cy,cx) not in d:
                    d[(cy,cx)] = 1
                else:
                    d[(cy, cx)] += 1
ans = [0]*10
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])

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
h,w,n = map(int, input().split())
l=[list(map(int,input().split())) for i in range(n)]

from collections import defaultdict
d = defaultdict(int)
for tmp in l:
    y=tmp[0]-1
    x=tmp[1]-1
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if 1<=x+i<w-1 and 1<=y+j <h-1:
                s = str(x+i) + "_" + str(y+j)
                d[s]+=1

import collections
lis = list(d.values())
c = collections.Counter(lis)

ans=[0]*10
for itm in c.items():
    ans[itm[0]]=itm[1]

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

for a in ans:
    print(a)

Submission status: Accepted

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

from collections import defaultdict
d = defaultdict(int)
for tmp in l:
    y=tmp[0]-1
    x=tmp[1]-1
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if 1<=x+i<w-1 and 1<=y+j <h-1:
                s = str(x+i) + "_" + str(y+j)
                d[s]+=1

import collections
lis = list(d.values())
c = collections.Counter(lis)

ans=[0]*10
for itm in c.items():
    ans[itm[0]]=itm[1]

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

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
H,W,N=map(int,input().split())
d={}
for i in range(N):
    a,b=map(int,input().split())
    for j in range(-1,2):
        if not 1<a+j<H:
            continue
        for k in range(-1,2):
            if not 1<b+k<W:
                continue
            t=(a+j,b+k)
            if t in d:
                d[t]+=1
            else:
                d[t]=1
l=[0]*10
for i in d.values():
    l[i]+=1
l[0]=(H-2)*(W-2)-sum(l)
print(*l,sep="\n")

Submission status: Accepted

Solution code:
from itertools import product
from collections import defaultdict, Counter
import sys
input = sys.stdin.readline
h,w,n = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
pls = defaultdict(int)
for x,y in a:
  for arx,ary in product(list(range(x-1,x+2)),list(range(y-1,y+2))):
    if 2<=arx<=h-1 and 2<=ary<=w-1:
      pls[(arx,ary)] += 1
c = Counter(pls.values())
print((h-2)*(w-2)-sum(c.values()))
for i in range(1,10):
  print(c[i])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    h,w,n = map(int,input().split())
    dg = 10**10
    d = dict()

    def f(x,y):
        if 2 <= x <= h-1 and 2 <= y <= w-1:
            return True
        else:
            False

    for i in range(n):
        a,b = map(int,input().split())
        
        if f((a-1),b-1):
            if (a-1)*dg + b-1 in d:
                d[(a-1)*dg + b-1] += 1
            else:
                d[(a-1)*dg + b-1] = 1
        
        if f((a-1),b):
            if (a-1)*dg + b in d:
                d[(a-1)*dg + b] += 1
            else:
                d[(a-1)*dg + b] = 1
        
        if f((a-1),b+1):
            if (a-1)*dg + b+1 in d:
                d[(a-1)*dg + b+1] += 1
            else:
                d[(a-1)*dg + b+1] = 1

        if f((a),b-1):
            if (a)*dg + b-1 in d:
                d[(a)*dg + b-1] += 1
            else:
                d[(a)*dg + b-1] = 1
        
        if f(a,b):
            if a*dg + b in d:
                d[a*dg + b] += 1
            else:
                d[a*dg + b] = 1
        
        if f((a),b+1):
            if (a)*dg + b+1 in d:
                d[(a)*dg + b+1] += 1
            else:
                d[(a)*dg + b+1] = 1
        
        if f((a+1),b+1):
            if (a+1)*dg + b+1 in d:
                d[(a+1)*dg + b+1] += 1
            else:
                d[(a+1)*dg + b+1] = 1
        
        if f((a+1),b):
            if (a+1)*dg + b in d:
                d[(a+1)*dg + b] += 1
            else:
                d[(a+1)*dg + b] = 1
        
        if f((a+1),b-1):
            if (a+1)*dg + b-1 in d:
                d[(a+1)*dg + b-1] += 1
            else:
                d[(a+1)*dg + b-1] = 1
        
        
        
        
    res = [0]*10
 
    for e in d:
        res[d[e]] += 1
 
    res[0] = (h-2)*(w-2)-sum(res)
 
    for e in res:
        print(e)
 
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
 
h, w, n = [int(item) for item in input().split()]
blk_cnt = defaultdict(int) 
 
for i in range(n):
    a, b = [int(item) - 1 for item in input().split()]
    for j in range(-1, 2):
        for k in range(-1, 2):
            blk_cnt[(a + j, b + k)] += 1
ans = [0] * 10 
for key in blk_cnt.keys():
    if key[0] < 1 or key[1] < 1 or key[0] >= h-1 or key[1] >= w-1:
        continue
    ans[blk_cnt[key]] += 1
total = (w - 2) * (h - 2)
ans[0] = total - sum(ans)
for item in ans:
    print(item)

Submission status: Accepted

Solution code:
h, w, n = map(int, input().split())
a = {tuple(map(int, input().split())) for _ in range(n)}

d = {}
c = [0] * 10

def next(x, y):
    ret = []
    for i in range(max(0, x-2), min(h-2, x+1)):
        for j in range(max(0, y-2), min(w-2, y+1)):
            ret.append((i, j))
    return ret

for x, y in a:
    x -= 1
    y -= 1
    for s, t in next(x, y):
        if (s, t) not in d:
            count = 0
            for i in range(3):
                for j in range(3):
                    if (s + i + 1, t + j + 1) in a:
                        count += 1
            d[(s, t)] = count
            c[count] += 1

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

for x in c:
    print(x)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    H,W,N=MI()
    B=set([])
    from collections import defaultdict
    used = defaultdict(int)
    ans=[0]*10
    
    for _ in range(N):
        a,b=MI()
        a-=1
        b-=1
        B.add((a,b))
        
    def cnt(i,j):#i,jが左上の9ます
        if i+2<H and j+2<W:
            temp=0
            for di in range(3):
                for dj in range(3):
                    ii=i+di
                    jj=j+dj
                    if (ii,jj) in B:
                        temp+=1
            used[(i,j)]=1
            return temp
        return -1
    
    def se(i,j):#i,jが中心の25ます
        for di in range(-2,1,1):
            for dj in range(-2,1,1):
                ii=i+di
                jj=j+dj
                if ii>=0 and jj>=0:
                    if not used[(ii,jj)]:
                        cc=cnt(ii,jj)
                        if cc!=-1:
                            #print(ii,jj,cc)
                            ans[cnt(ii,jj)]+=1
                        
    for k in B:
        i,j=k[0],k[1]
        se(i,j)
        
    S=sum(ans)
    ans[0]=(H-2)*(W-2) - S
    for i in range(10):
        print(ans[i])
                    

main()

Submission status: Accepted

Solution code:
import sys

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

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

for item in A:#for every paint
    cord = list(item)
#    print("----{},{}----".format(cord[0],cord[1]))
    #update candidate
    upcand = []#max9
    for i in range(cord[0]-1,cord[0]+2):
        for j in range(cord[1]-1,cord[1]+2):
#            print("----({},{})----".format(i,j))
            upcand.append([i,j])
#    print(upcand)
    for cand in upcand:
#        print(cand)
        if 1 < cand[0] < h and 1 < cand[1] < w:
#            print(cand)
            dict[(cand[0],cand[1])] = dict.get((cand[0],cand[1]), 0) + 1
#        print(dict)
for v in dict.values():
    ans[v] += 1
    ans[0] -= 1

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import sys

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

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

for item in A:#for every paint
    cord = list(item)
#    print("----{},{}----".format(cord[0],cord[1]))
    #update candidate
    upcand = []#max9
    for i in range(cord[0]-1,cord[0]+2):
        for j in range(cord[1]-1,cord[1]+2):
#            print("----({},{})----".format(i,j))
            upcand.append([i,j])
#    print(upcand)
    for cand in upcand:
#        print(cand)
        if 1 < cand[0] < h and 1 < cand[1] < w:
#            print(cand)
            dict[(cand[0],cand[1])] = dict.get((cand[0],cand[1]), 0) + 1
#        print(dict)
for k,v in dict.items():
    ans[v] += 1
    ans[0] -= 1

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W, N = lr()
pairs = []
for _ in range(N):
    a, b = lr()
    a -= 1; b -= 1
    for dh in [-2, -1, 0]:
        if a + dh < 0 or a + dh > H-3:
            continue
        for dw in [-2, -1, 0]:
            if b + dw < 0 or b + dw > W-3:
                continue
            pairs.append((a+dh, b+dw))

counter = Counter(pairs)
answer = [0] * 10
counter2 = Counter(counter.values())
for k, v in counter2.items():
    answer[k] = v

answer[0] = (H-2) * (W-2) - sum(answer)
print('\n'.join(map(str, answer)))
# 30

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter

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

d = defaultdict(int)

for a, b in ab:
    for hi in range(a - 2, a + 1):
        for wi in range(b - 2, b + 1):
            if 1 <= hi <= h - 2 and 1 <= wi <= w - 2:
                d[(hi, wi)] += 1

c = Counter(d.values())

print((h - 2) * (w - 2) - sum(c.values()))

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d = defaultdict(int)

for a, b in ab:
    for hi in range(a - 2, a + 1):
        for wi in range(b - 2, b + 1):
            if 1 <= hi <= h - 2 and 1 <= wi <= w - 2:
                d[(hi, wi)] += 1

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

cnt[0] = (h - 2) * (w - 2) - sum(cnt[1:])
print(*cnt, sep="\n")

Submission status: Accepted

Solution code:
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
    for j in range(-1, 2):
        for k in range(-1, 2):
            if 1 <= a+j < H-1 and 1 <= b+k < W-1:
                if d.get((a+j, b+k)) is None:
                    d[(a+j, b+k)] = 0
                d[(a+j, b+k)] += 1


ans = [0] * 10
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])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")

XX = (-2, -2, -2, -1, -1, -1, 0, 0, 0)
YY = (-2, -1, 0, -2, -1, 0, -2, -1, 0)


def solve(H: int, W: int, N: int, a: "List[int]", b: "List[int]"):
    counter = Counter()
    for aa, bb in zip(a, b):
        for x, y in zip(XX, YY):
            if aa+x < 1:
                continue
            elif aa+x+2 > H:
                continue
            elif bb+y < 1:
                continue
            elif bb+y+2 > W:
                continue
            counter[(aa+x, bb+y)] += 1
    ans = [0]*10
    for key, val in counter.items():
        ans[val] += 1

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


def main():

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
h,w,n=map(int,input().split())
z=(h-2)*(w-2)
p=[]
for i in range(n):
    x,y=map(int,input().split())
    for j in range(3):
        for k in range(3):
            p.append([x+j-1,y+k-1])
p.sort(key=lambda x:(10**10)*x[0]+x[1])
n=len(p)
p.append([10**20,10**20])
ans=[0]*10
f=1
for i in range(n):
    if 2<=p[i][0]<=h-1 and 2<=p[i][1]<=w-1:
        if p[i]==p[i+1]:
            f+=1
        else:
            ans[f]+=1
            f=1
ans[0]=z-sum(ans)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
#すぬけくんの塗り絵
h,w,n=map(int,input().split())
dic={}
for  _ in range(n):
    a,b=map(int,input().split())
    for i in range(a-1,a+2):
        for j in range(b-1,b+2):
            if (i,j) in dic.keys():
                dic[(i,j)]+=1
            else:
                dic[(i,j)]=1
              
howmany=[0 for i in range(10)]
for some in dic.keys():
    a,b=some[0],some[1]
    if 2<=a<=h-1 and 2<=b<=w-1:
        howmany[dic[some]]+=1
J=(h-2)*(w-2)-sum(howmany)
print(J)
for i in range(1,10):
    print(howmany[i])

Submission status: Accepted

Solution code:
from collections import Counter
H,W,N = map(int,input().split())
ab = []
corner = []
countlist = [0 for i in range(10)]
for i in range(N):
    a,b = map(int,input().split())
    for h in range(-2,1):
        for w in range(-2,1):
            if 1 <= a+h <= H-2 and 1 <= b+w <= W-2:
                corner.append((a+h,b+w))
cc = Counter(corner)
clist = list(cc.values())
clistc = Counter(clist)
for k,v in clistc.items():
    countlist[k] += v
countlist[0] = (H-2)*(W-2) - sum(countlist)
for i in countlist:
    print(i)

Submission status: Accepted

Solution code:
from collections import Counter
H, W, N, *L = map(int, open(0).read().split())
dic = {}
for a, b in zip(*[iter(L)]*2):
  for i in range(a-2,a+1):
    for j in range(b-2,b+1):
      if 0<i and i+2<=H and 0<j and j+2<=W:
        dic[i*W+j] = dic.get(i*W+j,0)+1
c = Counter(dic.values())
ans = [(H-2)*(W-2)]+[0]*9
for k in c.keys():
  ans[k] = c[k]
  ans[0] -= c[k]
print('\n'.join(map(str,ans)))

Submission status: Accepted

Solution code:
H, W, N, *L = map(int, open(0).read().split())
dic = {}
for a, b in zip(*[iter(L)]*2):
  for i in range(a-2,a+1):
    for j in range(b-2,b+1):
      if 0<i and i+2<=H and 0<j and j+2<=W:
        dic[i*W+j] = dic.get(i*W+j,0)+1
ans = [0]*10
ans[0] = (W-2)*(H-2)
for k in dic.keys():
  ans[dic[k]] += 1
  ans[0] -= 1
print('\n'.join(map(str,ans)))

Submission status: Accepted

Solution code:
from collections import defaultdict
H, W, N, *L = map(int, open(0).read().split())
dic = defaultdict(int)
for a, b in zip(*[iter(L)]*2):
  for i in range(a-2,a+1):
    for j in range(b-2,b+1):
      if 0<i and i+2<=H and 0<j and j+2<=W:
        dic[(i,j)] += 1
ans = [0]*10
ans[0] = (W-2)*(H-2)
for k in dic.keys():
  ans[dic[k]] += 1
  ans[0] -= 1
print(*ans,sep='\n')

Submission status: Accepted

Solution code:
from collections import defaultdict
H, W, N, *L = map(int, open(0).read().split())
dic = defaultdict(int)
for a, b in zip(*[iter(L)]*2):
  for i in range(a-2,a+1):
    for j in range(b-2,b+1):
      if 0<i and i+2<=H and 0<j and j+2<=W:
        dic[(i,j)] += 1
ans = [0]*10
ans[0] = (W-2)*(H-2)
for k in dic.keys():
  ans[dic[k]] += 1
  ans[0] -= 1
print(*ans,sep='\n')

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
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



h, w, n = LI()
D = defaultdict(int)
for _ in range(n):
    a, b = LI()
    a -= 1; b -= 1;
    for i, j in product(range(a - 1, a + 2), range(b - 1, b + 2)):
        if 1 <= i < h - 1 and 1 <= j < w - 1:
            D[(i, j)] += 1


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



ans[0] = (h - 2) * (w - 2) - sum(ans)
print('\n'.join(list(map(str, ans))))

Submission status: Accepted

Solution code:
from collections import defaultdict

h, w, n = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]
d = defaultdict(int)
L = [0]*10
L[0] = (h-2) * (w-2)
for a, b in AB:
  for i in range(-1, 2):
    for j in range(-1, 2):
      y, x = a+i, b+j
      if 1 < y < h and 1 < x < w:
        d[(y, x)] += 1
        L[d[(y, x)]] += 1
        L[d[(y, x)]-1] -= 1
print(*L, sep="\n")

Submission status: Accepted

Solution code:
H,W,N=map(int,input().split())
direc=[[0,0],[-1,0],[-2,0],[0,-1],[-1,-1],[-2,-1],[0,-2],[-1,-2],[-2,-2]]
dic={}
for i in range(N):
  h,w=map(int,input().split())
  for d in direc:
    if 1<=h+d[0]<=(H-2) and 1<=w+d[1]<=(W-2):
      l=(h+d[0],w+d[1])
      if l in dic:
        dic[l]=dic[l]+1
      else:
        dic[l]=1
A=list(dic.values())
print((H-2)*(W-2)-len(A))
for i in range(1,10):
  print(A.count(i))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter, defaultdict
from itertools import product
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(H: int, W: int, N: int, a: "List[int]", b: "List[int]"):
    d = defaultdict(int)
    for ai, bi in zip(a, b):
        for da, db in product((-1, 0, 1), repeat=2):
            aj = ai - 1 + da
            bj = bi - 1 + db
            if 1 <= aj <= H - 2 and 1 <= bj <= W - 2:
                d[aj, bj] += 1
    c = Counter(d.values())
    e = [c[i] for i in range(1, 10)]
    print((H - 2) * (W - 2) - sum(e))
    for ei in e:
        print(ei)


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H,W,N = map(int,input().split())
Nli=[0 for j in range(9*N)]
q=0
for k in range(N):
    a,b=map(int,input().split())
    for n in range(-1,2):
        for m in range(-1,2):
            if 0<=a-2-m<H-2 and 0<=b-2-n<W-2:
                Nli[q]=(b-n)*(H)+(a-m)
                q+=1
del Nli[q:]
import collections
s = collections.Counter(Nli)
v = list(s.values())
print((H-2)*(W-2)-len(set(Nli)))
for k in range(1,10):
    print(v.count(k))

Submission status: Accepted

Solution code:
H,W,N = map(int,input().split())
Nli=[]
for k in range(N):
    a,b=map(int,input().split())
    for n in range(-1,2):
        for m in range(-1,2):
            if 0<=a-2-m<H-2 and 0<=b-2-n<W-2:
                Nli.append((b-n)*(H)+(a-m))
import collections
s = collections.Counter(Nli)
v = list(s.values())
print((H-2)*(W-2)-len(set(Nli)))
for k in range(1,10):
    print(v.count(k))

Submission status: Accepted

Solution code:
from collections import *
h,w,n = map(int,input().split())
dic = defaultdict(int)
for _ in range(n):
  a,b = map(int,input().split())
  for i in range(9):
    dic[a - i //3,b - i % 3] += 1
ans =[0]*10
for i, j in dic:
  ans[dic[i,j]] += h-1 > i > 0 < j < w -1
ans[0] = (h -2)*(w-2) - sum(ans)
for item in ans:
  print(item)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
from collections import defaultdict

def main():
    H,W,N = map(int,input().split())
    d = defaultdict(int)
    for i in range(N):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        for x in range(3):
            for y in range(3):
                na,nb = a-x,b-y
                if (0 <= na < H-2 and 0 <= nb < W-2):
                    d[na*W+nb] += 1
    
    d = list(d.values())
    ans = (H-2)*(W-2)-len(d)
    print(ans)
    for i in range(9):
        i += 1
        print(d.count(i))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
"""
l = input().split(" ")
w = int(l[0])
h = int(l[1])
n = int(l[2])

array = [[0 for i in range(h)] for j in range(w)]

for i in range(n):
	l = input().split(" ")
	x = int(l[0]) - 1
	y = int(l[1]) - 1
	for i in range(3):
		for j in range(3):
			if x+j-1 >=0 and x+j-1<w and y+i-1 >=0 and y+i-1<h:
				array[x+j-1][y+i-1] += 1

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

for i in range(h-2):
	for j in range(w-2):
		ans[array[j+1][i+1]] += 1

for a in ans:
	print(a)

"""

l = input().split(" ")
w = int(l[0])
h = int(l[1])
n = int(l[2])

array = dict()

for i in range(n):
	l = input().split(" ")
	x = int(l[0])
	y = int(l[1])
	for i in range(3):
		if y-i < 1 or y-i > h-2:
			continue
		for j in range(3):
			if x-j < 1 or x-j > w-2:
				continue
			if (x-j, y-i) in array:
				array[(x-j, y-i)] +=1
			else:
				array[(x-j, y-i)] = 1

ans = [0] * 10
ans[0] = (h-2) * (w-2)
 
for i in array:
    ans[array[i]] += 1
    ans[0] -= 1

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

Submission status: Accepted

Solution code:
f=lambda:map(int,input().split())
h,w,n = f()

d={}
while n:
 n-=1
 x,y=f()
 for i in range(9):
     a=(x+i%3,y+i//3)
     d[a]=d.get(a,0)+(h>=a[0]>2<a[1]<=w)

c=[list(d.values()).count(i+1)for i in range(9)]

print((h-2)*(w-2)-sum(c))
for i in range(9):
    print(c[i])

Submission status: Accepted

Solution code:
h,w,n=map(int,input().split())
d=dict()
def change(a,b):
    global h,w,d
    if 1<=a<h-1 and 1<=b<w-1:
        if (a,b) in d:
            d[(a,b)]+=1
        else:
            d[(a,b)]=1
for i in range(n):
    a,b=map(int,input().split())
    a-=1
    b-=1
    for j in range(3):
        for k in range(3):
            change(a+j-1,b+k-1)
ans=[0]*10
ans[0]=(h-2)*(w-2)

for i in d:
    ans[d[i]]+=1
    ans[0]-=1
for i in range(10):
    print(ans[i])