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: Wrong Answer

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

r_b=[0]
for i in range(1,N):
  if ab[i][0]!=ab[i-1][0]:
    r_b.append(i)
r_b.append(N)

ab=[ab[r_b[i]:r_b[i+1]] for i in range(len(r_b)-1)]

if N is 0:
  ab=[]


area_n=[0 for i in range(1,10)]  
  
for r_n in range(len(ab)):
  row=ab[r_n][0][0]
  ched_list_min_add=[0,0,0]
  ch_list_min_add=[0,0,0]
  for c_n in range(len(ab[r_n])):
    col=ab[r_n][c_n][1]
    
    ched_list=[]

    
    for i in range(max(0,r_n-2),r_n+1):
      min_flag=True
      if (ab[i][0][0]==row-2 if i==r_n-2 else True) and (ab[i][0][0]>=row-2 if i==r_n-1 else True):
        for j in range(ched_list_min_add[i-max(0,r_n-2)],len(ab[i]) if i!=r_n else c_n):
          if ab[i][j][1]>col+2:
            break
          elif ab[i][j][1] in [col+k for k in [-2,-1,0,1,2]]:
            ched_list.append(ab[i][j])
            if min_flag:
              ched_list_min_add[i-max(0,r_n-2)]=j
              min_flag=False
            
    ch_list=[]    
    for i in range(r_n,min(r_n+3,len(ab))):
      min_flag=True
      if (ab[i][0][0]==row+2 if i==r_n+2 else True) and (ab[i][0][0] if i==r_n+1 else True):
        for j in range(ch_list_min_add[i-r_n] if i!=r_n else c_n,len(ab[i])):
          if ab[i][j][1]>col+2:
            break
          elif ab[i][j][1] in [col+k for k in [-2,-1,0,1,2]]:
            ch_list.append(ab[i][j])
            if min_flag:
              ch_list_min_add[i-r_n]=j
              min_flag=False

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

r_b=[0]
for i in range(1,N):
  if ab[i][0]!=ab[i-1][0]:
    r_b.append(i)
r_b.append(N)

ab=[ab[r_b[i]:r_b[i+1]] for i in range(len(r_b)-1)]

if N is 0:
  ab=[]


area_n=[0 for i in range(1,10)]

Submission status: Wrong Answer

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

area_n=[0 for i in range(1,10)]

r_b=[0]
for i in range(1,N):
  if ab[i][0]!=ab[i-1][0]:
    r_b.append(i)
r_b.append(N)


ab=[ab[r_b[i]:r_b[i+1]] for i in range(len(r_b)-1)]

if N is 0:
  ab=[]
  
for r_n in range(len(ab)):
  row=ab[r_n][0][0]
  
  ch_row_min=row-2
  if (ab[r_n-1][0][0]!=row-2 if r_n>=1 else True) and (ab[r_n-2][0][0]!=row-2 if r_n>=2 else True):
    ch_row_min=row-1
    if (ab[r_n-1][0][0]!=row-1 if r_n>=1 else True):
      ch_row_min=row
  
  ch_row_max=row+2
  if (ab[r_n+1][0]!=row+2 if r_n<len(ab)-1 else True) and (ab[r_n+2][0][0]!=row+2 if r_n<len(ab)-2 else True):
    ch_row_max=row+1
    if (ab[r_n+1][0][0]!=row+1 if r_n<len(ab)-1 else True):
      ch_row_max=row

  for c_n in range(len(ab[r_n])):
    col=ab[r_n][c_n][1]
    

    for ch_box_or_r in range(max(1,row-2),min(H-2,row)+1):
      for ch_box_or_c in range(max(1,col-2),min(W-2,col)+1):      
        check_on_off=True
        
        ch_old_ab=ab[r_n][max(0,c_n-(col-ch_box_or_c)):c_n]\
        +(ab[r_n-2] if ch_row_min==row-2 and ch_box_or_r==row-2 else [])\
        +(ab[r_n-1] if ch_row_min<=row-1 and ch_box_or_r<=row-1 else [])
        
        ch_new_ab=ab[r_n][c_n:c_n+ch_box_or_c-col+2+1]\
        +(ab[r_n+1] if ch_row_max>=row+1 and ch_box_or_r>=row-1 else [])\
        +(ab[r_n+2] if ch_row_max==row+2 and ch_box_or_r==row else [])
  
         
        
        for ch_box_p_r in range(max(ch_box_or_r,ch_row_min),row+1):
          for ch_box_p_c in range(ch_box_or_c,(ch_box_or_c+3 if ch_box_p_r!=row else col)):
            if [ch_box_p_r,ch_box_p_c] in ch_old_ab:
              check_on_off=False
        if check_on_off:
          count=0
          
         
          for ch_box_p_r in range(row,ch_box_or_r+3):
            for ch_box_p_c in range(ch_box_or_c if ch_box_p_r!=row else col,ch_box_or_c+3):
              if [ch_box_p_r,ch_box_p_c] in ch_new_ab:
                count+=1
                
          area_n[count-1]+=1
          
area_n=[area_n[n] for n in range(len(area_n))]
print((H-2)*(W-2)-sum(area_n))
for i in range(9):
  print(area_n[i])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as de
from collections import Counter as C
h,w,n=map(int,input().split())
s=[0]*10
c=de(int)
for i in range(n):
    a,b=map(int,input().split())
    for j in range(max(2,a-1),min(a+2,h)):
        for q in range(max(2,b-1),min(b+2,w)):
            c[(j,q)]+=1
a=C(c.values())
print((h-8)*(w-8)-sum(a.values()))
for i in range(1,10):
    print(a[i])

Submission status: Wrong Answer

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

area_n=[0 for i in range(1,10)]

r_b=[0]
for i in range(1,N):
  if ab[i][0]!=ab[i-1][0]:
    r_b.append(i)
r_b.append(N)
    
ab=[ab[r_b[i]:r_b[i+1]] for i in range(len(r_b)-1)]
print(len(ab))
if N!=0:
  for r_n in range(len(ab)):
    row=ab[r_n][0][0]-1
    for c_n in range(len(ab[r_n])):
      col=ab[r_n][c_n][1]-1

      for ch_r in range(max(0,row-2),min(H-3,row)+1):
        for ch_c in range(max(0,col-2),min(W-3,col)+1):
          count=0
          ch_p=[[ch_p_r,ch_c] for ch_p_r in range(ch_r,ch_r+3)]
          ch_p+=[[ch_p_r,ch_c+1] for ch_p_r in range(ch_r,ch_r+3)]
          ch_p+=[[ch_p_r,ch_c+2] for ch_p_r in range(ch_r,ch_r+3)]
        
          ch_r_n_min=max(0,r_n+ch_r-row)
          ch_r_n_max=min(len(ab)-1,r_n+ch_r-row+2)
          for ch_r_n in range(ch_r_n_min,ch_r_n_max+1):
            for ch_c_n in range(len(ab[ch_r_n])):
              if [ab[ch_r_n][ch_c_n][0]-1,ab[ch_r_n][ch_c_n][1]-1] in ch_p:
                count+=1
          area_n[count-1]+=1
area_n=[area_n[n]//(n+1) for n in range(len(area_n))]
print((H-2)*(W-2)-sum(area_n))
for i in range(9):
  print(area_n[i])

Submission status: Wrong Answer

Solution code:
h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in [0]*n]
ab_d={a*(10**9)+b-1 for a,b in ab}

ans=[set() for _ in range(9)]
for a,b in ab:
    temp=[None for _ in [0]*25]
    for p in range(25):
        i,j=p//5,p%5
        if 0<a+i-2<=h and 0<b+j-2<=w:
            if (a+i-2)*(10**9)+b+j-3 in ab_d:
                temp[i*5+j]=1
            else:
                temp[i*5+j]=0
    for p in range(3):
        i,j=p//3,p%3
        cnt=[temp[(i+k)*5+j+l] for k in range(3) for l in range(3)]
        if None not in cnt:
            ans[sum(cnt)-1].add((a+i-2)*(10**9)+b+j-3)
                
ans=[len(ans[i]) for i in range(9)]

print((h-2)*(w-2)-sum(ans))
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in [0]*n]

ab_d={a*(10**6)+b for a,b in ab}

ans=[set() for _ in range(9)]
for a,b in ab:
    temp=[[2 for _ in [0]*5] for _ in [0]*5]
    for i in range(5):
        for j in range(5):
            if 0<a+i-2<=h and 0<b+j-2<=w:
                if (a+i-2)*(10**6)+b+j-2 in ab_d:
                    temp[i][j]=1
                else:
                    temp[i][j]=0
    for i in range(3):
        for j in range(3):
            cnt=[temp[i+k][j+l] for k in range(3) for l in range(3)]
            if 2 not in cnt:
                ans[sum(cnt)-1].add((a+i-2)*(10**6)+b+j-2)
                
for i in range(9):
    ans[i]=len(ans[i])

print((h-2)*(w-2)-sum(ans))
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in [0]*n]
ab_d=dict()
for a,b in ab:
    if a not in ab_d.keys():
        ab_d[a]={b}
    else:
        ab_d[a].add(b)

ans=[set() for _ in range(9)]
for a,b in ab:
    temp=[[2 for _ in [0]*5] for _ in [0]*5]
    for i in range(5):
        if 0<a+i-2<=h:
            if a+i-2 in ab_d.keys():
                for j in range(5):
                    if 0<b+j-2<=w:
                        if b+j-2 in ab_d[a+i-2]:
                            temp[i][j]=1
                        else:
                            temp[i][j]=0
    for i in range(3):
        for j in range(3):
            cnt=[temp[i+k][j+l] for k in range(3) for l in range(3)]
            if 2 not in cnt:
                ans[sum(cnt)-1].add((a+i-2,b+j-2))
                
for i in range(9):
    ans[i]=len(ans[i])

print((h-2)*(w-2)-sum(ans))
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
import numpy as np
H, W, N = map(int, input().split())
d = 10**9+1
L = []
S = set()
for _ in range(N):
    a, b = map(int, input().split())
    S.add((a, b))
Map = np.zeros([5, 5], dtype = 'int')
ans = [0]*10
for i in S:
    a, b = i
    for i in range(-2, 3):
        for j in range(-2, 3):
            a1, b1 = a+i, b+j
            """
            if (1<=a1<=H) and (1<=b1<=W):
                if (a1, b1) in S:
                    Map[i+2, j+2] = 1
                else:
                    Map[i+2, j+2] = 0
            else:
                Map[i+2, j+2] = -100
    for i in range(-1, 2):
        for j in range(-1, 2):
            k = 1#Map[i+1:i+4, j+1:j+4].sum()
            if k>=0:
                ans[k]+=1
for i in range(1, 10)[::-1]:
    ans[i] //=i
ans[0] = (W-2)*(H-2)-sum(ans)
for i in ans:
    print(i)"""

Submission status: Wrong Answer

Solution code:
import numpy as np
H, W, N = map(int, input().split())
d = 10**9+1
L = []
S = set()
for _ in range(N):
    a, b = map(int, input().split())
    S.add((a, b))
Map = np.zeros([5, 5], dtype = 'int')
ans = [0]*10
"""
for i in S:
    a, b = i
    for i in range(-2, 3):
        for j in range(-2, 3):
            a1, b1 = a+i, b+j
            if (1<=a1<=H) and (1<=b1<=W):
                if (a1, b1) in S:
                    Map[i+2, j+2] = 1
                else:
                    Map[i+2, j+2] = 0
            else:
                Map[i+2, j+2] = -100
    for i in range(-1, 2):
        for j in range(-1, 2):
            k = 1#Map[i+1:i+4, j+1:j+4].sum()
            if k>=0:
                ans[k]+=1
for i in range(1, 10)[::-1]:
    ans[i] //=i
ans[0] = (W-2)*(H-2)-sum(ans)
for i in ans:
    print(i)
"""

Submission status: Wrong Answer

Solution code:
import numpy as np
H, W, N = map(int, input().split())
d = 10**9+1
L = []
S = set()
for _ in range(N):
    a, b = map(int, input().split())
    S.add((a, b))
Map = np.zeros([5, 5], dtype = 'int')
ans = [0]*10
for i in S:
    a, b = i
    for i in range(-2, 3):
        for j in range(-2, 3):
            a1, b1 = a+i, b+j
            if (1<=a1<=H) and (1<=b1<=W):
                if (a1, b1) in S:
                    Map[i+2, j+2] = 1
                else:
                    Map[i+2, j+2] = 0
            else:
                Map[i+2, j+2] = -100
    for i in range(-1, 2):
        for j in range(-1, 2):
            k = 1#Map[i+1:i+4, j+1:j+4].sum()
            if k>=0:
                ans[k]+=1
for i in range(1, 10)[::-1]:
    ans[i] //=i
ans[0] = (W-2)*(H-2)-sum(ans)
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
H, W, N = map(int, input().split())
S = set()
toCheck = set()
rs = [0] * 10
for _ in range(N):
    a, b = map(int, input().split())
    S.add((a, b))
    for i in range(3):
        for j in range(3):
            toCheck.add((a - i, b - j))

for a, b in toCheck:
    if a + 2 > H or b + 2 > W or b < 1 or a < 1:
        continue
    cnt = 0
    for i in range(3):
        for j in range(3):
            na, nb = a + i, b + j
            if (na, nb) in S:
                cnt += 1
    rs[cnt] += 1

for it in rs:
    print(it)

Submission status: Wrong Answer

Solution code:
def sol():
    import sys
    input=sys.stdin.readline
    h,w,n=map(int,input().split())
    d={}
    for i in range(n):
        y,x=map(int,input().split())
        if (y,x) in d:
            d[(y,x)]+=1
        else:
            d[(y,x)]=1
        if y+1<=h and (y+1,x) in d:
            d[(y+1,x)]+=1
        elif y+1<=h:
            d[(y+1,x)]=1
        if y+2<=h and (y+2,x) in d:
            d[(y+2,x)]+=1
        elif y+2<=h:
            d[(y+2,x)]=1

        if x+1<=w and (y,x+1) in d:
            d[(y,x+1)]+=1
        elif x+1<=w:
            d[(y,x+1)]=1
        if x+2<=w and (y,x+2) in d:
            d[(y,x+2)]+=1
        elif x+2<=w:
            d[(y,x+2)]=1
        if x+1<=w and y+1<=h and (y+1,x+1) in d:
            d[(y+1,x+1)]+=1
        elif x+1<=w and y+1<=h:
            d[(y+1,x+1)]=1
        if x+2<=w and y+1<=h and (y+1,x+2) in d:
            d[(y+1,x+2)]+=1
        elif x+2<=w and y+1<=h:
            d[(y+1,x+2)]=1
        if x+1<=w and y+2<=h and (y+2,x+1) in d:
            d[(y+2,x+1)]+=1
        elif x+1<=w and y+2<=h:
            d[(y+2,x+1)]=1
        if x+2<=w and y+2<=h and (y+2,x+2) in d:
            d[(y+2,x+2)]+=1
        elif x+2<=w and y+2<=h:
            d[(y+2,x+2)]=1
    ans=[0]*10
    for i in d:
        if i[0]>2 and i[1]>2:
            print(i,d[i])
            ans[d[i]]+=1

    ans[0]=h*w-sum(ans)-w*2-h*2+4
    for i in ans:
        print(i)
        
if __name__=="__main__":
    sol()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def read_input():
    h, w, n = map(int, input().split())
    alist = []
    for i in range(n):
        (px, py) = map(int, input().split())
        alist.append((px, py))

    return h, w, n, alist


def count_arround(px, py, count):
    for xx in [-2, -1, 0]:
        for yy in [-2, -1, 0]:
            count[(px+xx, py+yy)] += 1


def is_area(p, h, w):
    if 1 <= p[0] <= h - 2:
        if 1 <= p[1] <= w - 2:
            return True
    return False


def submit():
    h, w, n, alist = read_input()

    count = defaultdict(int)

    for a in alist:
        count_arround(a[0], a[1], count)

    counts = count.items()
    counts = [c[1] for c in counts if is_area(c[0], h, w)]

    for i in range(10):
        print(sum([1 for c in counts if c == i]))


if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

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

from itertools import product

# S = [set() for _ in range(10)]
# S[i]: set(黒いマスをi個こ含む3*3マスの中心セル)

memo = {}
ans = [0]*10

P = list(product([-1,0,1], repeat=2))

print(AB)

for a,b in AB:
  for x,y in P:
    X = a+x-1
    Y = b+y-1
    #print(a,b,x,y,X,Y, ans)
    if X<=0 or H-1<=X or Y<=0 or W-1<=Y:
      continue
    memo[(X,Y)] = memo.get((X,Y),0) + 1
    ans[memo[(X,Y)]] += 1
    ans[memo[(X,Y)]-1] -= 1
    
#print(memo)

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

for n in ans[1:]:
  print(n)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
H,W,N = [int(n) for n in input().split()]
# N = int(input())
dxy = [[0,0],[1,0],[0,1],
[-1,0],[0,-1],[1,1],
[-1,-1], [1,-1], [-1,1]]

effdic = defaultdict(int)
for i in range(N):
    a,b = [int(n)-1 for n in input().split()]
    for d in dxy:
        ta, tb = a+d[0], b+d[1]
        if(1 <= ta < H-1 and 1 <= tb < W-1):
            s = str(ta) + str(tb)
            effdic[s] += 1
print((H-2)*(W-2) - len(effdic))
for i in range(1,10):
    tmp=0
    for v in effdic.values():
        if(v == i):
            tmp+=1
    print(tmp)

Submission status: Wrong Answer

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

for i in range(N):
    a, b = map(int, input().split())
    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:
                A[(a + j, b + k)] += 1
                
for i in range(10):
    cnt = 0
    for v in A.values():
        if v == i:
            cnt += 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
h, w, n = [int(item) for item in input().split()]
ab = [[int(item) for item in input().split()] for _ in range(n)]
poe = []

for a, b in ab:
    for i in range(3):
        for j in range(3):
            if a+i-1 > 1 and a+i-1 <= h-1 and b+j-1 > 1 and b+j-1 <= w-1:
                poe.append([a+i-1, b+j-1])
poe.sort()

ans = [0] * 10 
count = 1
for i in range(1,len(poe)):
    if poe[i] == poe[i-1]:
        count += 1
    else:
        ans[count] += 1
        count = 1
ans[count] += 1

print((w-2)*(h-2) - sum(ans))
for item in ans[1:]:
    print(item)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

def main():
	H, W, N = map(int, input().split(" "))
	AB = []
	for _ in range(N):
		a, b = map(int, input().split(" "))
		AB.append((a, b))

	ans = {}
	for i, val in enumerate(AB):
		a, b = val
		a, b = a-1, b-1
		for ba in range(max(0, a-2), min(H-2, a+1)):
			for bb in range(max(0, b-2), min(W-2, b+1)):
				if (ba, bb) in ans.keys():
					ans[(ba, bb)] += 1
				else:
					ans[(ba, bb)] = 1

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

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

def main():
	H, W, N = map(int, input().split(" "))
	AB = []
	for _ in range(N):
		a, b = map(int, input().split(" "))
		AB.append((a, b))

	ans = {}
	for i, val in enumerate(AB):
		a, b = val
		a, b = a-1, b-1
		for ba in range(max(0, a-2), min(H-2, a+1)):
			for bb in range(max(0, b-2), min(W-2, b+1)):
				if (ba, bb) in ans.keys():
					ans[(ba, bb)] += 1
				else:
					ans[(ba, bb)] = 1
				if bb == 3:
					print("{} {}".format(a+1, b+1))

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

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
H,W,N=map(int,input().split())
data=[[0 for i in range(W-2)] for j in range(H-2)]
def check(a,b):
    if a>1:
        if b>1:
            data[a-2][b-2]+=1
        elif b>0 and b<W-1:
            data[a-2][b-1]+=1
        elif b<W-2:
            data[a-2][b]+=1
    if a>0 and a<H-1:
        if b>1:
            data[a-1][b-2]+=1
        elif b>0 and b<W-1:
            data[a-1][b-1]+=1
        elif b<W-2:
            data[a-1][b]+=1
    if a<H-2:
        if b>1:
            data[a][b-2]+=1
        elif b>0 and b<W-1:
            data[a][b-1]+=1
        elif b<W-2:
            data[a][b]+=1
    return
for k in range(N):
    a,b=map(int,input().split())
    a-=1
    b-=1
    check(a,b)
for i in range(10):
    count=0
    for j in range(len(data)):
        count+=data[j].count(i)
    print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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]*9
ans[0] = (h-2)*(w-2)-len(a)
for i in a:
  ans[i-1] += 1
for i in ans:
  print(i)

Submission status: Wrong Answer

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

from collections import defaultdict

h, w, n = map(int, sdin().split())
ab = []
for _ in range(n):
    ab.append(tuple(map(int, sdin().split())))
    
# フィールドを作って塗る
field = defaultdict(int)

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
            
# 数え上げる
for j in range(10):
    ans = list(field.values())
    ans = ans.count(j)
    print(ans)

Submission status: Wrong Answer

Solution code:
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
print(*ans,sep='\n')

Submission status: Wrong Answer

Solution code:

# -*- coding: utf-8 -*-
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(i, 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()

Submission status: Wrong Answer

Solution code:

# -*- coding: utf-8 -*-
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 = defaultdict(lambda: defaultdict(lambda: 0))

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

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

    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()

Submission status: Wrong Answer

Solution code:
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())
for i in range(10):
    print(ans[i])

Submission status: Wrong Answer

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

sa = {}
for a,b in ab:
    for i in range(3):
        aa = a + i
        if aa < 3 or h < aa:
            continue
        for j in range(3):
            bb = b + j
            if bb < 3 or w < bb:
                continue
            id = "%d,%d" % (aa, bb)
            sa[id] = sa.get(id, 0) + 1

s = {}
for x in sa.values():
    s[x] = s.setdefault(x, 0) + 1
print((w - 2) * (h - 2) - len(sa.keys()))
for i in range(10):
    print(s.get(i, 0))

Submission status: Wrong Answer

Solution code:
H, W, N = map(int, input().split())
A = []
for i in range(N):
  a, b = map(int, input().split())
  for j in range(3):
    for k in range(3):
      if (a - j > 0) and (b - k > 0):
        A.append([a - j, b - k])
A = sorted(sorted(A, key=lambda x: x[1]), key=lambda x: x[0])
prev = None
count = 0
C = [0 for i in range(10)]
for a in A:
  if a == prev:
    count += 1
  else:
    C[count] += 1
    count = 1
  prev = a
print((H - 2) * (W - 2) - sum(C[1:]))
for c in C[1:]:
  print(c)

Submission status: Wrong Answer

Solution code:
H, W, N = map(int, input().split())
A = []
for i in range(N):
  a, b = map(int, input().split())
  for j in range(3):
    for k in range(3):
      if (a - j > 0) and (b - k > 0):
        A.append([a - j, b - k])
A = sorted(sorted(A, key=lambda x: x[1]), key=lambda x: x[0])
prev = None
count = 0
C = [0 for i in range(10)]
for a in A:
  if a == prev:
    count += 1
  else:
    C[count] += 1
    count = 1
  prev = a
print((H - 2) * (W - 2) - sum(C))
for c in C[1:]:
  print(c)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ss = set()
for i in range(n):
    a, b = map(int, input().split())
    ss.add((a-1, b-1))

ret = np.array([0] * 10)

for dot in ss:
    x = dot[0]
    y = dot[1]
    for x in [-2, -1, 0]:
        x += dot[0]
        if x < 0 or h <= x + 2:
            continue
        for y in [-2, -1, 0]:
            y += dot[1]
            if y < 0 or w <= y + 2:
                continue
            tmp_sum = 0
            for i in range(3):
                if h <= x + i:
                    continue
                for j in range(3):
                    if w <= y + j:
                        continue
                    if (x + i, y + j) in ss:
                        tmp_sum += 1
            ret[tmp_sum] += 1

ret2 = np.array([tmp / i for i, tmp in enumerate(ret) if i])
print(int((h - 2) * (w - 2) - ret2.sum()))
[print(int(tmp)) for  tmp in ret2]

Submission status: Wrong Answer

Solution code:
import sys
H, W, N = map(int,input().split())
if N ==0:
  print((H-1)*(W-1))
  for i in range(9): print(0)
  sys.exit()
  
blacks = [[0 for i in range(W+2)] for j in range(H+2)]
for i in range(N):
  a, b = map(int,input().split())
  blacks[a-1][b-1] +=1
  blacks[a-1][b] +=1
  blacks[a-1][b+1] +=1
  blacks[a][b+1] +=1
  blacks[a][b-1] +=1
  blacks[a][b] +=1
  blacks[a+1][b+1] +=1
  blacks[a+1][b-1] +=1
  blacks[a+1][b] +=1

ans =[0 for i in range(10)]
for j in range(2,H):
  for i in range(2,W):
    ans[blacks[j][i]]+=1
for i in range(10): print(ans[i])

Submission status: Wrong Answer

Solution code:
import sys
H, W, N = map(int,input().split())
if N ==0:
  print((H-1)*(W-1))
  for i in range(9): print(0)
  sys.exit()
  
blacks = [[0 for i in range(W+2)] for j in range(H+2)]
for i in range(N):
  a, b = map(int,input().split())
  blacks[a-1][b-1] +=1
  blacks[a-1][b] +=1
  blacks[a-1][b+1] +=1
  blacks[a][b+1] +=1
  blacks[a][b-1] +=1
  blacks[a][b] +=1
  blacks[a+1][b+1] +=1
  blacks[a+1][b-1] +=1
  blacks[a+1][b] +=1

ans =[0 for i in range(10)]
for j in range(2,H):
  for i in range(2,W):
    print(j,i,blacks[j][i])
    ans[blacks[j][i]]+=1
for i in range(10): print(ans[i])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

h, w, n = list(map(int, input().split()))
ans = [0 for i in range(10)]

if n != 0:
    board = defaultdict(int)
    for i in range(n):
        a, b = list(map(int, input().split()))
        a = a - 1
        b = b - 1
        for dx in range(b-1, b+2):
            if dx <= 0 or dx >= w - 1:
                continue
            for dy in range(a-1, a+2):
                if dy <= 0 or dy >= h - 1:
                    continue
                board[(dx, dy)] += 1

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

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

h, w, n = list(map(int, input().split()))
ans = [0 for i in range(10)]

if n != 0:
    board = defaultdict(int)
    for i in range(n):
        a, b = list(map(int, input().split()))
        a = a - 1
        b = b - 1
        for dx in range(b-1, b+2):
            if dx < 0 or dx >= w:
                continue
            for dy in range(a-1, a+2):
                if dy < 0 or dy >= h:
                    continue
                board[(dx, dy)] += 1

    for x in range(1, w-1):
        for y in range(1, h-1):
            num = board[(x, y)]
            ans[num] += 1

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

Submission status: Wrong Answer

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

if n != 0:
    board = [[0 for i in range(h)] for j in range(w)]
    for i in range(n):
        a, b = list(map(int, input().split()))
        a = a - 1
        b = b - 1
        for dx in range(b-1, b+2):
            if dx < 0 or dx >= w:
                continue
            for dy in range(a-1, a+2):
                if dy < 0 or dy >= h:
                    continue
                board[dx][dy] += 1

    for x in range(1, w-1):
        for y in range(1, h-1):
            num = board[x][y]
            ans[num] += 1

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