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: Memory Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import Counter
import itertools

H,W,N = map(int,readline().split())
m = map(int,read().split())
AB = list(zip(m,m))

XY = []
for dx,dy in itertools.product((0,1,2), repeat=2):
    XY += [(x+dx,y+dy) for x,y in AB]

XY = [(x,y) for x,y in XY if 3<=x<=H and 3<=y<=W]

answer = [0] * 10
for x,y in Counter(Counter(XY).values()).items():
    answer[x] = y

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

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-=1
  b-=1
  for j in range(3):
    for k in range(3):
      x,y=a-j,b-k
      if 0<=x and x+2<H and 0<=y and y+2<W:
        d=(x,y)
        if d not in D:
          D[d]=1
        else:
          D[d]+=1
A=[0]*10
for i in D.values():
  A[i]+=1
A[0]=(W-2)*(H-2)-sum(A)
for i in A:
  print(i)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W, N = LI()

    # 黒マス1個が影響を与える3x3領域の数は9個
    # 黒マスごとに周りの各3x3に対して黒マス数をインクリメントすればよい
    cnt = collections.Counter()
    for _ in range(N):
        a, b = LI_()
        for i, j in itertools.product(range(-1, 2), repeat=2):
            c, d = a + i, b + j
            if 1 <= c < H - 1 and 1 <= d < W - 1:
                cnt[(c, d)] += 1

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

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

h,w,n,*ab = map(int, read().split())

M = iter(ab)
d = {}
for a,b in zip(M,M):
    for i in range(-1,2):
        na = a+i
        if 2 <= na <= h-1:
            for j in range(-1,2):
                nb = b+j
                if 2 <= nb <= w-1:
                    if (na,nb) in d:
                        d[(na,nb)] += 1
                    else:
                        d[(na,nb)] = 1
            
#print(d)
ans = [0]*10
for k,v in d.items():
    ans[v] += 1

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

Submission status: Accepted

Solution code:
from collections import Counter
import itertools

H, W, N = map(int,input().split())
blacks = []
for i in range(N):
    blacks.append(tuple(map(int,input().split())))

blacks_in_square = [(x+dx,y+dy) for x,y in blacks\
                    for dx in [-1,0,1] for dy in [-1,0,1]\
                    if 1 < x+dx < H and 1 < y+dy < W]

ans = [0] * 10
for x,y in Counter(Counter(blacks_in_square).values()).items():
    ans[x] = y
ans[0] = (H-2) * (W-2) - sum(ans)
print('\n'.join(map(str,ans)))

Submission status: Accepted

Solution code:
from collections import Counter
import sys
input=sys.stdin.buffer.readline
h,w,n=map(int,input().split())
cc=Counter()
for _ in range(n):
    b,a=map(int,input().split())
    for i in range(3):
        for j in range(3):
            x=a+i
            y=b-j #brute forcing valid bottom right corners
            if x>=1 and x<=w and y>=1 and y<=h:
                if x-2>=1 and x-2<=w and y+2>=1 and y+2<=h:
                    cc[(x,y)]+=1
#                    print(x,y,end=' xy\n')#a valid 3*3 grid bottom right
ans=[0]*10
for i in cc.keys():
    ans[cc[(i)]]+=1
ans[0]=(h-2)*(w-2)-sum(ans)
print(*ans,sep='\n')

Submission status: Accepted

Solution code:
from collections import Counter

h,w,n=map(int,input().split())
cc=Counter()
for _ in range(n):
    b,a=map(int,input().split())
    for i in range(3):
        for j in range(3):
            x=a+i
            y=b-j #brute forcing valid bottom right corners
            if x>=1 and x<=w and y>=1 and y<=h:
                if x-2>=1 and x-2<=w and y+2>=1 and y+2<=h:
                    cc[(x,y)]+=1
#                    print(x,y,end=' xy\n')#a valid 3*3 grid bottom right
ans=[0]*10
for i in cc.keys():
    ans[cc[(i)]]+=1
ans[0]=(h-2)*(w-2)-sum(ans)
print(*ans,sep='\n')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
W, H, N = map(int, input().split())
vs = set()
for _ in range(N):
    a, b = map(int, input().split())
    vs.add((a-1,b-1))

R = [0] * 10
vvs = set()
for a, b in vs:
    for i in range(3):
        for j in range(3):
            x, y = a+i-2, b+j-2
            if x < 0 or W-3 < x or y < 0 or H-3 < y:
                continue
            if (x, y) in vvs:
#                print(x, y, a, b)
                continue
            c = 0
#            print(x, y, a, b)
            for k in range(3):
                for l in range(3):
#                    print(x+k, y+l)
                    if (x+k, y+l) in vs:
                        c += 1
#            print(c, x, y)
            R[c] += 1
            vvs.add((x, y))

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

Submission status: Accepted

Solution code:
h,w,n = map(int, input().split())
grid = {}
count = {i:0 for i in range(10)}
for _ in range(n):
    a,b = map(int, input().split())
    for dx in range(-1,2):
        for dy in range(-1,2):
            x,y = b+dx,a+dy
            if not (2 <= y <= h-1) or not (2 <= x <= w-1):
                continue
            if (y,x) not in grid:
                grid[(y,x)] = 0
            grid[(y,x)] += 1

from collections import Counter
c = Counter(grid.values())

print((h-2)*(w-2) - sum(c.values()))
for i in range(1,10):
    print(c.get(i,0))

Submission status: Accepted

Solution code:
dx = [-1,-1,-1,0,0,1,1,1,0]
dy = [-1,0,1,-1,1,-1,0,1,0]
H,W,N = map(int,input().split())
from collections import defaultdict, Counter
d = defaultdict(int)
for i in range(N):
    a,b = map(int,input().split())
    for j in range(9):
        A = a + dy[j]
        B = b + dx[j]
        f = 0
        if 2 <= A <= H-1:
            if 2 <= B <= W-1:
                f = 1
        if f == 1:
            d[(A,B)] += 1
s = 0
c = Counter(d.values())
for i in range(1,10):
    s += c[i]
c[0] = (H-2)*(W-2) - s
for i in range(10):
    print(c[i])

Submission status: Accepted

Solution code:

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

ab = []

dic = {}

for i in range(N):

    a,b = map(int,input().split())

    for x in range(3):
        x -= 1
        for y in range(3):
            y -= 1

            if (1 < a+x  and a+x < H) and (1 < b+y and b+y < W):

                if (a+x,b+y) not in dic:
                    dic[(a+x,b+y)] = 1
                else:
                    dic[(a+x,b+y)] += 1

ans = [0] * 10
d = 0
for i in dic:
    ans[dic[i]] += 1

for i in range(10):
    d += ans[i]
ans[0] = (H-2) * (W-2) - d

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import Counter
import itertools

H,W,N = map(int,readline().split())
m = map(int,read().split())
AB = list(zip(m,m))

AB = [(x+dx,y) for x,y in AB for dx in [0,1,2] if 3 <= x+dx <= H]
AB = [(x,y+dy) for x,y in AB for dy in [0,1,2] if 3 <= y+dy <= W]

answer = [0] * 10
for x,y in Counter(Counter(AB).values()).items():
    answer[x] = y

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

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import product

H, W, N = map(int, input().split())
black = [tuple(map(int, input().split())) for _ in range(N)]
counter = defaultdict(int)
for a, b in black:
    a, b = a-1, b-1
    for i, j in product(range(3), repeat=2):
        if 0 <= a-i < H-2  and 0 <= b-j < W-2:
            counter[(a-i, b-j)] += 1
ans = [0 for _ in range(10)]
for v in counter.values():
    ans[v] += 1
ans[0] = (H-2) * (W-2) - sum(ans[1:])
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    H, W, N = map(int, input().split())
    d = defaultdict(int)
    dt = [-1,0,1]
    for _ in range(N):
        a, b = map(int, input().split())
        for i in dt:
            if 2 <= a + i <= H-1:
                for j in dt:
                    if 2 <= b + j <= W-1:
                        # 正方形の中点をkeyとして持つ
                        d[(a+i,b+j)] += 1
    
    ans = [0] * 10
    ans[0] = (H-2) * (W-2)
    for i in d.values():
        ans[i] += 1
        ans[0] -= 1

    for a in ans:
        print(a)
    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
h,w,n=map(int,input().split())
l=[list(map(int,input().split()))  for _ in range (n)]
ans=[0 for i in range(10)]
ans[0]=(w-2)*(h-2)
d=dict()
for j0,i0 in l:
    for i in range(i0,i0-3,-1):
        if i<1 or w-2<i:continue
        for j in range(j0,j0-3,-1):
            if j<1 or h-2<j:continue

            if "{},{}".format(i,j) in d:
                d["{},{}".format(i,j)]+=1
            else:
                d["{},{}".format(i,j)]=1
for i in list(d.values()):
    ans[i]+=1
    ans[0]-=1
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter()

for _ in range(N):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    for dx in range(-1, 2):
        for dy in range(-1, 2):
            na = a + dx
            nb = b + dy
            if not (1 <= na < H-1 and 1 <= nb < W-1): 
                continue
            c[(na, nb)] += 1

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

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

for a in ans:
    print(a)

Submission status: Accepted

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

from collections import defaultdict

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


def main():
	H, W, N = getlist()
	D = defaultdict(int)
	D[0] += (H - 2) * (W - 2)
	L = []
	for i in range(N):
		a, b = getlist()
		for j in range(3):
			for k in range(3):
				if H - 2 >= a - j and a - j >= 1 and W - 2 >= b - k and b - k >= 1:
					L.append((a - j, b - k))

	L = sorted(L)
	n = len(L)
	if n != 0:
		v = L[0]
	c = 0
	for i in range(n):
		if v == L[i]:
			c += 1
		else:
			D[c] += 1
			c = 1
		v = L[i]

	if n != 0:
		D[c] += 1
	for i in range(1, 10):
		D[0] -= D[i]

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


if __name__ == '__main__':
	main()

Submission status: Accepted

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

c = Counter()
for a,b in AB:
    for i in range(a-1,a+2):
        for j in range(b-1,b+2):
            if not 1 < i < H: continue
            if not 1 < j < W: continue
            c[(i,j)] += 1

ans = [0]*10
for k,v in c.items():
    ans[v] += 1
z = (H-2)*(W-2) - sum(ans)
ans[0] = z

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

grid = {}
for _ in range(N):
    a,b = map(int, input().split())

    for i in range(3):
        for j in range(3):
            if 0 < a-i <= H-2 and 0 < b-j <= W-2:
                if a-i not in grid:
                    grid[a-i] = {}
                if b-j not in grid[a-i]:
                    grid[a-i][b-j] = 0
                grid[a-i][b-j] += 1
ans = [0 for i in range(10)]
for a,bb in grid.items():
    for cnt in bb.values():
        ans[cnt] += 1
    
print((H-2)*(W-2) - sum(ans))
for i in range(1,10):
    print(ans[i])

Submission status: Accepted

Solution code:
H,W,N=map(int,input().split())
p=[list(map(int,input().split())) for i in range(N)]
from collections import defaultdict
d=defaultdict(int)
from itertools import product
r=[0]*10
for x,y in p:
    x-=1
    y-=1
    for i,j in product(range(3),repeat=2):
        if 0<=x-2+i and x+i<H and 0<=y-2+j and y+j<W:
            d[(x-2+i,y-2+j)]+=1
from collections import Counter
c=Counter(d.values())
for i in range(len(c)):
    r[c.most_common()[i][0]]=c.most_common()[i][1]
r[0]=(H-2)*(W-2)-sum(r[1:])
print(*r,sep='\n')

Submission status: Accepted

Solution code:
h,w,n=map(int,input().split())
import collections
tot=(h-2)*(w-2)
S=[]
append=S.append
for i in range(n):
  a,b=map(int,input().split())
  for j in range(3):
    for k in range(3):
      if 0<=a-3+j<h-2 and 0<=b-3+k<w-2:
        append((a-3+j,b-3+k))
SS=collections.Counter(collections.Counter(S).values())
print(tot-sum(SS.values()))
for i in range(1,10):
  print(0 if i not in SS.keys() else SS[i])

Submission status: Accepted

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

A = []

for i in range(N):
    a,b = list(map(int,input().split()))
    for j in range(3):
        for k in range(3):
            if a-j>0 and b-k>0 and a-j+2 < H+1 and b-k+2 < W+1:
                A.append(str(a-j)+" "+str(b-k))

from collections import Counter

counter = Counter(A)

from collections import defaultdict

dd=defaultdict(int)
count = 0
for k in counter.keys():
    dd[counter[k]]+=1
    count+=1
print((H-2)*(W-2)-count)
for i in range(1,10):
    print(dd[i])

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

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

h, w, n = li()
dic = defaultdict(int)

drs = [-1, 0, 1]
dcs = [-1, 0, 1]

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

for _ in range(n):
    a, b = li_()
    for dr in drs:
        for dc in dcs:
            if 0 < a+dr < h-1 and 0 < b+dc < w-1:
                dic[(a+dr, b+dc)] += 1

for _, val in dic.items():
    ans[val] += 1
    ans[0] -= 1

print(*ans, 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())
    d[(a-1,b-1)]=1
#print(d)
X=[-1,0,1,-1,0,1,-1,0,1]
Y=[-1,-1,-1,0,0,0,1,1,1]
C=[0 for i in range(10)]
D={}
#print(d)
for i in d.keys():
    #print(i[0])
    for j in range(9):
        D[(i[0]+X[j],i[1]+Y[j])]=1
#print(D)
for i in D.keys():
    cnt=0
    for j in range(9):
        if (i[0]+X[j])<0 or (H-1)<(i[0]+X[j]) or (i[1]+Y[j])<0 or (W-1)<(i[1]+Y[j]):
            cnt=0
            break
        elif (i[0]+X[j],i[1]+Y[j]) in d:
            cnt+=1
    #print(i,cnt)
    C[cnt]+=1
C[0]=(H-2)*(W-2)-sum(C[1:])
#print(C)
for i in range(10):
    print(C[i])

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
h, w, n = map(int,sys.stdin.readline().split())

m3x3 =defaultdict(list)
for _ in range(n):
    a, b = map(int,sys.stdin.readline().split())
    for i in range(max(0, a - 3),min(h - 2, a)):
        for j in range(max(0, b - 3),min(w - 2, b)):
            if (i,j) in  m3x3:
                m3x3[(i,j)] +=1
            else:
                m3x3[(i,j)] =1
v = list(m3x3.values())
k = m3x3.keys()
print((w-2)*(h-2)-len(k))
for j in range(1,10):
    print(v.count(j))

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
h, w, n = map(int,sys.stdin.readline().rstrip().split())

m3x3 =defaultdict(list)
for _ in range(n):
    a, b = map(int,sys.stdin.readline().rstrip().split())
    for i in range(max(0, a - 3),min(h - 2, a)):
        for j in range(max(0, b - 3),min(w - 2, b)):
            if (i,j) in  m3x3:
                m3x3[(i,j)] +=1
            else:
                m3x3[(i,j)] =1
v = list(m3x3.values())
k = m3x3.keys()
print((w-2)*(h-2)-len(k))
for j in range(1,10):
    print(v.count(j))

Submission status: Accepted

Solution code:
h, w, n = map(int,input().split())
from collections import defaultdict
m3x3 =defaultdict(list)
for _ in range(n):
    a, b = map(int,input().split())
    for i in range(max(0, a - 3),min(h - 2, a)):
        for j in range(max(0, b - 3),min(w - 2, b)):
            if (i,j) in  m3x3:
                m3x3[(i,j)] +=1
            else:
                m3x3[(i,j)] =1
v = list(m3x3.values())
k = m3x3.keys()
print((w-2)*(h-2)-len(k))
for j in range(1,10):
    print(v.count(j))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(H: int, W: int, N: int, a: "List[int]", b: "List[int]"):
    count = [0] * 10
    count[0] = (H-2) * (W-2)
    nutta = {}
    for i in range(N):
        for h in range(max([a[i]-2, 0]), min(a[i]+1,H-2)):
            for w in range(max(b[i]-2, 0), min(b[i]+1, W-2)):
                if (h, w) in nutta:
                    n = nutta[(h, w)]
                else:
                    n = 0
                count[n] -= 1
                count[n+1] += 1
                nutta[(h, w)] = n + 1
    for c in count:
        print(c)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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)) - 1
        b[i] = int(next(tokens)) -1 
    solve(H, W, N, a, b)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections
H,W,N = map(int,input().split())
abList = []
for _ in range(N):
    a,b = map(int, input().split())
    abList.append((a-1,b-1))
memo = []

for a,b in abList:
    for i in range(a-1,a+2):
        if H < i+2 or i < 1:
            continue
        for j in range(b-1, b+2):
            if W < j+2 or j < 1:
                continue
            memo.append((i,j))
x = collections.Counter(memo)
result = [0 for _ in range(9)]
s = 0
for k,v in x.items():
    if int(v) < 10:
        result[int(v)-1] += 1
    s += int(v)
print((W-2)*(H-2) - len(x))
for x in result:
    print(x)

Submission status: Accepted

Solution code:
H, W, N = map(int, input().split())
current_line = 0
ans = [0 for i in range(10)]
kuro = dict()

for i in range(N):
    a, b = map(int, input().split())
    for y in range(max(a-2, 1), min(a+1, H-1)):
        for x in range(max(b-2, 1), min(b+1, W-1)):
            p = (y, x)
            if p in kuro:
                kuro[p] += 1
            else:
                kuro[p] = 1

for n in kuro.values():
    ans[n] += 1
ans[0] = (H-2)*(W-2)-len(kuro)
print("\n".join([str(n) for n in ans]))
###

Submission status: Accepted

Solution code:
from collections import defaultdict

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

abd = defaultdict(int)
for _ in range(n):
  a, b = map(int, input().split())
  abd[(a, b)] += 1
  abd[(a, b-1)] += 1
  abd[(a, b-2)] += 1
  abd[(a-1, b)] += 1
  abd[(a-1, b-1)] += 1
  abd[(a-1, b-2)] += 1
  abd[(a-2, b)] += 1
  abd[(a-2, b-1)] += 1
  abd[(a-2, b-2)] += 1

suma = [0 for _ in range(10)]
for a, b in abd.keys():
  if 0 < a < h-1 and 0 < b < w-1:
    suma[abd[(a,b)]] += 1
suma[0] = (h - 2) * (w - 2) - sum(suma)
print(*suma, sep='\n')

Submission status: Accepted

Solution code:
from collections import*
input=open(0).readline
h,w,n=map(int,input().split())
d=defaultdict(int)
for _ in range(n):
    a,b=map(int,input().split())
    for i in(0,-1,-2):
        for j in(0,-1,-2):
            d[(a+i,b+j)]+=1
a=[0]*10
for i in d.keys():
    if 0<i[0]<h-1and 0<i[1]<w-1:
        a[d[i]]+=1
a[0]=(h-2)*(w-2)-sum(a)
print(*a,sep='\n')

Submission status: Accepted

Solution code:
H,W,N = map(int, input().split())
AB = [ [int(j)-1 for j in input().split()] for _ in range(N)]

s = []
for i in range(N):
    a,b = AB[i]

    y = [a-1, a, a+1]
    x = [b-1, b, b+1]

    for ey in y:
        if 1 <= ey < H-1:
            for ex in x:
                if 1 <= ex < W-1:
                    s.append( (ey, ex) )
    
# print(s)
from collections import Counter,defaultdict
c = Counter(s)
d = defaultdict(int)

allp = (H-2)*(W-2)

for k in c.keys():
    d[c[k]] += 1


ans = []
for i in range(1, 9+1):
    ans.append (  d[i] )

print(allp - sum(ans)) 

for i in range(1,9+1):
    print(ans[i-1])

Submission status: Accepted

Solution code:
f=lambda:map(int,input().split())
h,w,n=f()
c=[(h-2)*(w-2)]+[0]*9
d={}
while n:
 n-=1;x,y=f()
 for i in range(9):a=x+i%3,y+i//3;g=h>=a[0]>2<a[1]<=w;t=d[a]=d.get(a,0)+g;c[t-g]-=1;c[t]+=1
print(*c)

Submission status: Accepted

Solution code:
f=lambda:map(int,input().split())
h,w,n=f()
c=[(h-2)*(w-2)]+[0]*9
d={}
while n:
 n-=1;x,y=f()
 for i in range(9):
  a=x+i%3,y+i//3
  if h>=a[0]>2<a[1]<=w:t=d[a]=d.get(a,0)+1;c[t-1]-=1;c[t]+=1
print(*c)

Submission status: Accepted

Solution code:
f=lambda:map(int,input().split())
h,w,n=f()
c=[(h-2)*(w-2)]+[0]*9
d={}
while n:
 n-=1;x,y=f()
 for i in range(9):
  a=(x+i%3,y+i//3)
  if h>=a[0]>2<a[1]<=w:t=d[a]=d.get(a,0)+1;c[t-1]-=1;c[t]+=1
print(*c)

Submission status: Accepted

Solution code:
f=lambda:map(int,input().split())
h,w,n=f()
c=[(h-2)*(w-2)]+[0]*9
d={}
while n:
 n-=1;x,y=f()
 for i in range(9):
  a=(x+i%3,y+i//3)
  if h>=a[0]>2<a[1]<=w:d[a]=d.get(a,0)+1;c[d[a]-1]-=1;c[d[a]]+=1
print(*c)

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)
  if h>=a[0]>2<a[1]<=w:d[a]=d.get(a,0)+1
c=[0]*9
for i in d:c[d[i]-1]+=1
print((h-2)*(w-2)-sum(c),*c)

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),*c)

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)
  if h>=a[0]>2<a[1]<=w:d[a]=d.get(a,0)+1
c=[0]*10
for i in d:c[d[i]]+=1
c[0]=(h-2)*(w-2)-sum(c)
print(*c)

Submission status: Accepted

Solution code:
f=lambda:map(int,input().split())
h,w,n=f()
c=[0]*10
c[0]=(h-2)*(w-2)
d={}
while n:
 n-=1;x,y=f()
 for i in range(9):
  a=(x+i%3,y+i//3)
  if h>=a[0]>2<a[1]<=w:d[a]=d.get(a,0)+1;c[d[a]-1]-=1;c[d[a]]+=1
print(*c)

Submission status: Accepted

Solution code:
f=lambda:map(int,input().split())
h,w,n=f()
c=[0]*10
c[0]=(h-2)*(w-2)
d={}
while n:
 n-=1;x,y=f()
 for i in range(9):
  a=(x+i%3,y+i//3)
  if h>=x+i%3>2<y+i//3<=w:d[a]=d.get(a,0)+1;c[d[a]-1]-=1;c[d[a]]+=1
print(*c)

Submission status: Accepted

Solution code:
i=lambda:map(int,input().split())
h,w,n=i()
r=[0,1,2]
d={}
while n:
	a,b=i();n-=1
	for j in r:
		for k in r:
			if w>=b+k>2<a+j<=h:d[(a+j,b+k)]=d.get((a+j,b+k),0)+1
c=[0]*10
for i in d:c[d[i]]+=1
c[0]=(h-2)*(w-2)-sum(c)
print(*c,sep="\n")

Submission status: Accepted

Solution code:
i=lambda:map(int,input().split())
h,w,n=i()
r=[0,1,2]
d={} 
while n:
	a,b=i();n-=1
	for j in r:
		for k in r:
			if w>=b+k>2<a+j<=h:d[(a+j,b+k)]=d.get((a+j,b+k),0)+1
c=[0]*10
for i in d:c[d[i]]+=1
c[0]=(h-2)*(w-2)-sum(c)
print(*c,sep="\n")

Submission status: Accepted

Solution code:
i=lambda:map(int,input().split())
h,w,n=i()
r=[0,1,2]
d={} 
while n:
    a,b=i();n-=1
    for j in r:
        for k in r:
            if w>=b+k>2<a+j<=h:d[(a+j,b+k)]=d.get((a+j,b+k),0)+1
c=[0]*10
for i in d:c[d[i]]+=1
c[0]=(h-2)*(w-2)-sum(c)
print(*c,sep="\n")

Submission status: Accepted

Solution code:
from collections import Counter
h, w, n = map(int, input().split())
d = Counter()
for _ in range(n):
    a, b = map(int, input().split())
    for i in range(3):
        for j in range(3):
            if w > b+j-1 > 1 < a+i-1 < h:
                d[(a+i,b+j)] += 1
ans = Counter()
for i in d.values():
    ans[i] += 1
print((h-2)*(w-2) - sum(ans.values()))
for i in range(1,10):
    print(ans[i])

Submission status: Accepted

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

X = []
for _ in range(N):
    a, b = map(int, input().split())
    for i in range(0, 3):
        for j in range(0, 3):
            if a-i >= 1 and a-i <= H-2 and b-j >= 1 and b-j <= W-2:
                X.append((a-i, b-j))

X = sorted(X, key = lambda x: x[1]*10**9+x[0]) + [(H+1, W+1)]
# print(X)
ANS = [0] * 10

pre = (-1, -1)
c = -1
for x in X:
    if x == pre:
        c += 1
        
    else:
        if c >= 0:
            c += 1
            ANS[c] += 1
            
        c = 0
        pre = x

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

for ans in ANS:
    print(ans)

Submission status: Accepted

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

sys.setrecursionlimit(10000)

H, W, N = (int(i) for i in input().split())
if N == 0:
    reslis = [0] * 10
    reslis[0] = (H-2)*(W-2) - sum(reslis)
else:
    L = []
    for k in range(N):
        a, b = (int(i) for i in input().split())
        for i in range(3):
            for j in range(3):
                if 1 <= a - 2 + i <= H - 2 and 1 <= b - 2 + j <= W - 2:
                    L.append((a-2 + i, b-2 + j))
    L.sort()
    temp = None
    cc = 1
    reslis = [0] * 10
    for se in L:
        if temp == se:
            cc += 1
        else:
            if temp == None:
                pass
            else:
                reslis[cc] += 1
                cc = 1
            temp = se
    reslis[cc] += 1

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

for i in reslis:
    print(i)

Submission status: Accepted

Solution code:
h,w,n=map(int, input().split())
m=dict()
for _ in range(n):
    a,b=map(int, input().split())
    for i in range(3):
        for j in range(3):
            m[(a+i-1,b+j-1)]=m.get((a+i-1,b+j-1),0)+1
ans=[0]*10
for i,j in m.items():
    c,d=i
    if 1<c<h and 1<d<w:
        ans[j]+=1
ans[0]=(w-2)*(h-2)-sum(ans)
for i in ans:print(i)

Submission status: Accepted

Solution code:
from collections import defaultdict
def inpl(): return [int(i) for i in input().split()]

HW = defaultdict(lambda: 0)
direction = [(0,0),(1,1),(1,0),(1,-1),(0,-1),(-1,-1),(-1,0),(-1,1),(0,1)]

H, W, N = inpl()
for _ in range(N):
    a, b = inpl()
    for dh, dw in direction:
        if 2 <= a+dh <= H-1 and 2 <= b+dw <= W-1: 
            HW[(a+dh, b+dw)] += 1

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

Submission status: Accepted

Solution code:
from collections import Counter

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

# dict[(i, j)]: 左上が(i,j)である3*3のマスに含まれる、黒マスの個数
dict = {}
for  _ in range(N):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    for i in range(max(0, a - 2), min(H - 3, a) + 1):
        for j in range(max(0, b - 2), min(W - 3, b) + 1):
            dict[(i, j)] = dict.get((i, j), 0) + 1

nums = Counter(dict.values())
print((H - 2) * (W - 2) - sum(nums.values()))
for i in range(1, 10):
    if i in nums:
        print(nums[i])
    else:
        print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
h,w,n = map(int, input().split())

cube = {}
for _ in range(n):
    a,b = map(int, input().split())
    for k in range(3):
        for l in range(3):
            if h-2>=a-k>0 and w-2>=b-l>0:
                box = "-".join([str(a-k), str(b-l)])
                if box not in cube:
                    cube[box] = 0
                cube[box] += 1
# print(cube)
ret = [0 for _ in range(10)]
cnt = 0
for v in cube.values():
    ret[v] += 1
    cnt += 1
ret[0] = (h-2)*(w-2) - cnt

for r in ret:
    print(r)