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, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

H, W, N = MAP()

ab = [LIST() for _ in range(N)]

dic = defaultdict(int)
for a, b in ab:
	dic[(a, b)] = 1

check = defaultdict(int)

def count_black(Y, X):
	cnt = 0
	if 3 <= Y and 3 <= X:
		for i in range(3):
			for j in range(3):
				if dic[(Y-i, X-j)]:
					cnt += 1
		if cnt:
			ans[cnt] += 1


ans = [0]*10
for y, x in ab:
	for i in range(3):
		for j in range(3):
			if y+i <= H and x+j <= W and check[(y+i, x+j)] == 0:
				count_black(y+i, x+j)
				check[(y+i, x+j)] = 1

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

Submission status: Memory Limit Exceeded

Solution code:
from collections import defaultdict
from collections import Counter

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

# 3*3マスの処理用リスト
dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
       [-1, 0], [-1, -1], [0, -1], [1, -1]]

# そのマスを中心とする3*3グリッドに含まれる黒マスの数
dict = defaultdict(int)

for i in range(N):
    a, b = map(int, input().split())
    for dy, dx in dir:
        # 3*3グリッドは、H*Wの中に完全に含まれていなければならないことに注意
        if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
            dict[(a + dy, b + dx)] += 1

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

# ans[1], ans[2], ..., ans[9]を確定させる（ans[0]は後述）
for k, v in c.items():
    if v > 0:
        ans[k] = v

# 全体で作れる3*3グリッドは(H-2)*(W-2)個
# ans[1],...,ans[9]の総和を引くとans[0]になる
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])

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

Submission status: Memory Limit Exceeded

Solution code:
from collections import Counter

h,w,N=map(int,input().split())
rec=[]
for i in range(N):
    a,b=map(int,input().split())
    a-=1
    b-=1
    for i in range(-2,1):
        for j in range(-2,1):
           if 0<=a+i<h-2 and 0<=b+j<w-2:
               rec.append((a+i,b+j))

ans=[0]*10
ans[0]=(h-2)*(w-2)
c=Counter(rec)
for i in c.values():
    ans[i]+=1
    ans[0]-=1
for i in range(10):
    print(ans[i])

Submission status: Memory Limit Exceeded

Solution code:
import sys
from collections import Counter
sys.setrecursionlimit(10000000)
h,w,N=map(int,input().split())
rec=[]
for i in range(N):
    a,b=map(int,input().split())
    a-=1
    b-=1
    for i in range(-2,1):
        for j in range(-2,1):
           if 0<=a+i<h-2 and 0<=b+j<w-2:
               rec.append((a+i,b+j))

ans=[0]*10
ans[0]=(h-2)*(w-2)
c=Counter(rec)
for i in c.values():
    ans[i]+=1
    ans[0]-=1
for i in range(10):
    print(ans[i])

Submission status: Memory Limit Exceeded

Solution code:
from collections import defaultdict, deque, Counter

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

H, W, N = map(int, input().split())
query = [list(map(int, input().split())) for i in range(N)]
list_star = defaultdict(set)
H_max = 0
W_max = 0
for y, x in query:
    H_max = max(H_max, y)
    W_max = max(W_max, x)
    list_star[y - 1].add(x - 1)

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


lista = [0] * 10

def counter(x, y):
    if x <= 0 or W - 1 <= x or y <= 0 or H - 1 <= y:
        return 0
    cnt = 0
    for i in range(9):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0 <= nx < W and 0 <= ny < H:
            if nx in list_star[ny]:
                cnt += 1
    return cnt

star_list = set()
for y, x in query:
    x -= 1
    y -= 1
    for l in range(9):
        nx = x + dx[l]
        ny = y + dy[l]
        if (nx, ny) in star_list:
            continue
        opt = counter(nx, ny)
        if opt:
            lista[opt] += 1
            star_list.add((nx, ny))

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

Submission status: Memory Limit Exceeded

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

H, W, N = getNM()
query = [getList() for i in range(N)]
list_star = defaultdict(set)
H_max = 0
W_max = 0
for y, x in query:
    H_max = max(H_max, y)
    W_max = max(W_max, x)
    list_star[y - 1].add(x - 1)

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


lista = [0] * 10

def counter(x, y):
    if x <= 0 or W - 1 <= x or y <= 0 or H - 1 <= y:
        return 0
    cnt = 0
    for i in range(9):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0 <= nx < W and 0 <= ny < H:
            if nx in list_star[ny]:
                cnt += 1
    return cnt

star_list = set()
for y, x in query:
    x -= 1
    y -= 1
    for l in range(9):
        nx = x + dx[l]
        ny = y + dy[l]
        if nx <= 0 or W - 1 <= nx or ny <= 0 or H - 1 <= ny:
            continue
        if (nx, ny) in star_list:
            continue
        opt = counter(nx, ny)
        if opt:
            lista[opt] += 1
            star_list.add((nx, ny))

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

Submission status: Memory Limit Exceeded

Solution code:
from collections import defaultdict
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: Memory Limit Exceeded

Solution code:
from collections import defaultdict
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 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: Memory Limit Exceeded

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

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

from collections import defaultdict

H, W, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
SIZE = 10 ** 9 + 1

arr = []
for a, b in AB:
  for aa in range(a - 1, a + 2):
    for bb in range(b - 1, b + 2):
      if 1 < aa < H and 1 < bb < W:
        arr.append((aa, bb))
arr = list(set(arr))

counter = defaultdict(int)
for a, b in AB:
  counter[a * SIZE + b] += 1  

arr2 = [[] for _ in range(10)]
for a, b in arr:
  tmp = 0
  for aa in range(a - 1, a + 2):
    for bb in range(b - 1, b + 2):
      tmp += counter[aa * SIZE + bb]
  arr2[tmp].append(aa * SIZE + bb)

answer = []
for i in range(1, 10):
  answer.append(len(set(arr2[i])))
answer = [(H - 2) * (W - 2) - sum(answer)] + answer

for a in answer:
  print(a)

Submission status: Memory Limit Exceeded

Solution code:
import collections

h, w, n = map(int, input().split())
pos = collections.defaultdict(lambda: collections.defaultdict(bool))
squares = collections.defaultdict(set)
for index in range(n):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    pos[a][b] = True
    for i in range(-2, 1):
        for j in range(-2, 1):
            y = a + i
            x = b + j
            if 0 <= x < w - 2 and 0 <= y < h - 2:
                squares[y].add(x)
counter = collections.Counter()
for y, xs in squares.items():
    for x in xs:
        count = 0
        for i in range(3):
            for j in range(3):
                if pos[y + i][x + j]:
                    count += 1
        counter[count] += 1
print((h - 2) * (w - 2) - sum(counter.values()))
for i in range(1, 10):
    print(counter[i])

Submission status: Memory Limit Exceeded

Solution code:
inp=input().split(" ")
H=int(inp[0])
W=int(inp[1])
N=int(inp[2])
square=[]
plot=[]
times=[0 for i in range(10)]
times[0]=(H-2)*(W-2)
from collections import defaultdict
count=defaultdict(lambda:0)
def check(a,b,square):
    if a-2>=0 and b-2>=0:
        square.append([a-2,b-2])
    if a-2>=0 and b-1>=0 and b+1<=W-1:
        square.append([a-2,b-1])
    if a-2>=0 and b+2<=W-1:
        square.append([a-2,b])
    if a-1>=0 and b-2>=0 and a+1<=H-1:
        square.append([a-1,b-2])
    if a-1>=0 and b-1>=0 and a+1<=H-1 and b+1<=W-1:
        square.append([a-1,b-1])
    if a-1>=0 and a+1<=H-1 and b+2<=W-1:
        square.append([a-1,b])
    if a+2<=H-1 and b-2>=0:
        square.append([a,b-2])
    if a+2<=H-1 and b+1<=W-1 and b-1>=0:
        square.append([a,b-1])
    if  a+2<=H-1 and b+2<=W-1:
        square.append([a,b])
for i in range(N):
    plot.append(list(map(int,input().split(" "))))
    check(plot[i][0]-1,plot[i][1]-1,square)
for i in range(len(square)):
    count[str(square[i])]+=1
for i in count.values():
    times[i]+=1
    times[0]-=1
for i in range(10):
  print(times[i])

Submission status: Memory Limit Exceeded

Solution code:
import collections 
def solve():
  h,w,n = (int(i) for i in input().split())
  
  query = []
  for i in range(n):
    a,b = (int(i) for i in input().split())
    d = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,0),(0,1),(1,-1),(1,0),(1,1)]
    for dx,dy in d:
      if 2 <= a+dx <= h-1 and 2 <= b+dy <= w-1:
        query.append((a+dx,b+dy))
  ans = [0]*10
  if query:
   query = collections.Counter(query)
   values, counts = zip(*query.most_common())
   for i in range(10):
     ans[i] = counts.count(i)
  tp = sum(ans)
  ans[0] = (h-2)*(w-2)-tp
  
  for i in ans:
    print(i)
solve()

Submission status: Memory Limit Exceeded

Solution code:
import collections 
def solve():
  h,w,n = (int(i) for i in input().split())
  
  query = []
  for i in range(n):
    a,b = (int(i) for i in input().split())
    d = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,0),(0,1),(1,-1),(1,0),(1,1)]
    for dx,dy in d:
      if 2 <= a+dx <= h-1 and 2 <= b+dy <= w-1:
        query.append((a+dx,b+dy))
  ans = [0]*10
  if query:
   c = collections.Counter(query)
   values, counts = zip(*c.most_common())
   for i in range(10):
     ans[i] = counts.count(i)
  tp = sum(ans)
  ans[0] = (h-2)*(w-2)-tp
  
  for i in ans:
    print(i)
solve()

Submission status: Memory Limit Exceeded

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

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

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



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




if __name__ == '__main__':
    main()

Submission status: Memory Limit Exceeded

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

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

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

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




if __name__ == '__main__':
    main()

Submission status: Memory Limit Exceeded

Solution code:
h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
x=[]
di=[0,0,0,1,1,1,2,2,2]
dj=[0,1,2,0,1,2,0,1,2]
for a,b in ab:
    for ti,tj in zip(di,dj):
        if 3<=a+ti<=h and 3<=b+tj<=w:
            x.append(str(a+ti)+'-'+str(b+tj))
from collections import Counter
c=list(Counter(x).values())
x=[0 for _ in range(10)]
for t in c:
    x[t]+=1
x[0]=(h-2)*(w-2)-sum(x)
for t in x:
    print(t)

Submission status: Memory Limit Exceeded

Solution code:
h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
x=[]
di=[0,0,0,1,1,1,2,2,2]
dj=[0,1,2,0,1,2,0,1,2]
for a,b in ab:
    for ti,tj in zip(di,dj):
        if 3<=a+ti<=h and 3<=b+tj<=w:
            x.append(str(a+ti)+'-'+str(b+tj))
from collections import Counter
c=Counter(list(Counter(x).values()))
print((h-2)*(w-2)-sum(list(c.values())))
for i in range(1,10):
    print(c[i])

Submission status: Memory Limit Exceeded

Solution code:
h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
x=[]
di=[0,0,0,1,1,1,2,2,2]
dj=[0,1,2,0,1,2,0,1,2]
for a,b in ab:
    for ti,tj in zip(di,dj):
        if 3<=a+ti<=h and 3<=b+tj<=w:
            x.append(str(a+ti)+'-'+str(b+tj))
from collections import Counter
c1=Counter(x)
c2=list(c1.values())
del x
c1=Counter(c2)
print((h-2)*(w-2)-sum(list(c1.values())))
for i in range(1,10):
    print(c1[i])

Submission status: Memory Limit Exceeded

Solution code:
h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
x=[]
di=[0,0,0,1,1,1,2,2,2]
dj=[0,1,2,0,1,2,0,1,2]
for a,b in ab:
    for ti,tj in zip(di,dj):
        if 3<=a+ti<=h and 3<=b+tj<=w:
            x.append(str(a+ti)+'-'+str(b+tj))
from collections import Counter
c1=Counter(x)
c2=list(c1.values())
c3=Counter(c2)
print((h-2)*(w-2)-sum(list(c3.values())))
for i in range(1,10):
    print(c3[i])

Submission status: Memory Limit Exceeded

Solution code:
# 参考url: https://beta.atcoder.jp/contests/abc045/submissions/2365068

from collections import Counter

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

squares = []
for i in range(N):
    h, w = map(int, input().split())
    for hh in range(3):
        for ww in range(3):
            th, tw = h-hh, w-ww
            # th, twを左上とする3×3の正方形は与えられたグリッドに収まるか
            if 1 <= th <= H-2 and 1 <= tw <= W-2:
                squares.append((th, tw))

ans = [0] * 10
C = dict(Counter(squares).most_common())
for v in C.values():
    ans[v] += 1

# 黒マスが0 = 正方形の総数-黒マスが1個以上の正方形
ans[0] = (H-2)*(W-2) - sum(ans)

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

Submission status: Accepted

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

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


    H,W,N = LI()

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

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


    H,W,N = LI()

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h, w, n = map(int,input().split())
 
xy_pos = dict()
 
for i in range(n):
    a, b = map(int, input().split())
    for k in range(-2,1):
        for l in range(-2,1):
            x = (a-1) + k
            y = (b-1) + l
            if (0 <= x <= h-3 and 0 <= y <= w-3):
                xy = str(x) + "x" + str(y)
                if xy in xy_pos:
                    xy_pos[xy] += 1
                else:
                    xy_pos[xy] = 1
 
ans = [0]*10                    
for v in xy_pos.values():
    ans[v] += 1
ans[0] = (h-2)*(w-2) - sum(ans)
for i in range(10):
    print(ans[i])

Submission status: Accepted

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

d = {}
ab = []

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

memo = [0] * 10

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

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

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

for memoi in memo:
    print(memoi)

Submission status: Accepted

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

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

Submission status: Accepted

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


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

Submission status: Accepted

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

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

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

for a in ans:
    print(a)

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

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

#############
# Functions #
#############

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


#####Shorten#####
def DD(arg): return defaultdict(arg)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#############
# Main Code #
#############
H,W,N = IL()
data = ILL(N)

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

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

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

Submission status: Accepted

Solution code:
import sys

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


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

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

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

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


if __name__ == '__main__':
    resolve()