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: Runtime Error

Solution code:
H, W , N = map(int,input().split())
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
    for x_r in [-2, -1 , 0]:
        for y_r in [-2, -1 , 0]:
            nowx = l[0] + x_r
            nowy = l[1] + y_r
            if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
                continue
            #ここで起点(左上)nowx, nowy として　 9マスに着目する
            name = str(nowx) + str(nowy)
            print(nowx,nowy,name)
            try: cand[name] += 1
            except: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in cand.values():
    if x == 9:
        while True:
            print(W)
    ans[x] += 1
    tmp -= 1
ans[0] = tmp
for x in ans:
    print(x)

Submission status: Runtime Error

Solution code:
H, W , N = map(int,input().split())
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
from bisect import bisect_left
cand = {}
try:
    for l in matrix:
        for x_r in [-2, -1 , 0]:
            for y_r in [-2, -1 , 0]:
                nowx = l[0] + x_r
                nowy = l[1] + y_r
                if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
                    continue
                #ここで起点(左上)nowx, nowy として　 9マスに着目する
                name = str(nowx) + str(nowy)
                try: cand[name] += 1
                except: cand[name] = 1
except: pass
tmp = ((H - 2) * (W - 2))
for x in cand.values():
    ans[x] += 1
    tmp -= 1
ans[0] = tmp
for x in ans:
    print(x)

Submission status: Runtime Error

Solution code:
H, W , N = map(int,input().split())
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
from bisect import bisect_left

cand = {}
for l in matrix:
    for x_r in [-2, -1 , 0]:
        for y_r in [-2, -1 , 0]:
            nowx = l[0] + x_r
            nowy = l[1] + y_r
            if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
                continue
            #ここで起点(左上)nowx, nowy として　 9マスに着目する
            name = str(nowx) + str(nowy)
            try: cand[name] += 1
            except: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in cand.values():
    ans[x] += 1
    tmp -= 1
ans[0] =tmp
for x in ans:
    print(x)

Submission status: Runtime Error

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

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)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################


h,w,n = list(map(int, input().split()))
painted = []
for i in range(n):
    t = list(map(int, input().split()))
    for j in range(3):
        for k in range(3):
            painted.append([t[0]-2+j, t[1]-2+k])
    
painted.sort(key = lambda x : x[1])
painted.sort(key = lambda x : x[0])

p2 = []

for i in painted:
    if(i[0]>=1 and i[0]<h-1 and i[1]>=1 and i[1]<w-1):
        p2.append(i)

#print(p2)
ans = [0 for i in range(10)]
before = p2[0]
chain = 1
for ii in range(len(p2)-1):
    i = ii+1
    if(p2[i][0] == before[0] and p2[i][1] == before[1]):
        chain += 1
    else:
        ans[chain]+=1
        chain=1
        before[0],before[1] = p2[i]
ans[chain]+=1

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

Submission status: Runtime Error

Solution code:

h,w,n = list(map(int, input().split()))
painted = []
for i in range(n):
    t = list(map(int, input().split()))
    for j in range(3):
        for k in range(3):
            painted.append([t[0]-2+j, t[1]-2+k])
    
painted.sort(key = lambda x : x[1])
painted.sort(key = lambda x : x[0])

p2 = []

for i in painted:
    if(i[0]>=1 and i[0]<h-1 and i[1]>=1 and i[1]<w-1):
        p2.append(i)

#print(p2)
ans = [0 for i in range(10)]
before = p2[0]
chain = 1
for ii in range(len(p2)-1):
    i = ii+1
    if(p2[i][0] == before[0] and p2[i][1] == before[1]):
        chain += 1
    else:
        ans[chain]+=1
        chain=1
        before[0],before[1] = p2[i]
ans[chain]+=1

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

Submission status: Runtime Error

Solution code:
import math
import fractions
#import sys
#input = sys.stdin.readline

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)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################


h,w,n = list(map(int, input().split()))
painted = []
for i in range(n):
    t = list(map(int, input().split()))
    for j in range(3):
        for k in range(3):
            painted.append([t[0]-2+j, t[1]-2+k])
    
painted.sort(key = lambda x : x[1])
painted.sort(key = lambda x : x[0])

p2 = []

for i in painted:
    if(i[0]>=1 and i[0]<h-1 and i[1]>=1 and i[1]<w-1):
        p2.append(i)

#print(p2)
ans = [0 for i in range(10)]
before = p2[0]
chain = 1
for ii in range(len(p2)-1):
    i = ii+1
    if(p2[i][0] == before[0] and p2[i][1] == before[1]):
        chain += 1
    else:
        ans[chain]+=1
        chain=1
        before = list(p2[i])
ans[chain]+=1

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

Submission status: Runtime Error

Solution code:
h,w,n = list(map(int, input().split()))
painted = []
for i in range(n):
    t = list(map(int, input().split()))
    for j in range(3):
        for k in range(3):
            painted.append([t[0]-2+j, t[1]-2+k])
    
painted.sort(key = lambda x : x[1])
painted.sort(key = lambda x : x[0])

p2 = []

for i in painted:
    if(i[0]>=1 and i[0]<h-1 and i[1]>=1 and i[1]<w-1):
        p2.append(i)

#print(p2)
ans = [0 for i in range(10)]
before = p2[0]
chain = 1
for ii in range(len(p2)-1):
    i = ii+1
    if(p2[i][0] == before[0] and p2[i][1] == before[1]):
        chain += 1
    else:
        ans[chain]+=1
        chain=1
        before = list(p2[i])
ans[chain]+=1

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

ini_state=np.zeros((h, w))

for i in range(n):
    a, b=map(int, input().split())
    ini_state[a-1, b-1]=1
  
counts=[]

for i in range(h-2):
    for j in range(w-2):
        square=ini_state[i:i+3, j:j+3]
        counts.append(np.sum(square))
    
def count_num(x, a):
  
  count=0
  for y in x:
      if y==a:
          count+=1
  
  return count
    
for j in range(10):
    res=count_num(counts, j)
    print(res)

Submission status: Runtime Error

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

painted = []
for i in range(h):
    l = [0] * w
    painted.append(l)

first_painted = []
last_painted = []
for i in range(n):
    y,x = map(int, input().split())
    y,x = y-1,x-1
    if (i == 0):
        first_painted = [y,x]
    if (i == n-1):
        last_painted = [y,x]
    for n in range(y-1, y+2):
        if(n < 0 or n > h-1):
            continue
        for m in range(x-1, x+2):
            if(m < 0 or m > w-1):
                continue
            painted[n][m] += 1

for j in range(9):
    count = 0
    if (len(first_painted) > 0):
        y_start = max(1, first_painted[y]-1)
        y_end = min(h-1, last_painted[y]+1)
        x_start = max(1, first_painted[x]-1)
        x_end = min(w-1, last_painted[x]+1)
        for n in range(y_start, y_end+1):
            for m in range(x_start, x_end+1):
                if(painted[n][m] == j):
                    count += 1
    print(count)

Submission status: Runtime Error

Solution code:
H, W, N = map(int,input().split())
ans = [0] * 10
points = []
MAP = [[0] * W for _ in range(H)]
for _ in range(N):
    a, b = map(int,input().split())
    MAP[a-1][b-1] = 1
    points.append([a-1, b-1])
for i in range(N):
    a, b = points[i]
    for p in range(-1, 2):
        for q in range(-1, 2):
            cnt = 0
            if 1 <= a + p <= H - 2 and 1 <= b + q <= W - 2:
                for h in range(-1, 2):
                    cnt += sum(MAP[a + p + h][b + q - 1: b + q + 2])
            ans[cnt] += 1
for i in range(1,10):
    ans[i] //= i
SUM = sum(ans[1:])
ans[0] = (H-2) * (W-2) - SUM
for i in ans:
    print(i)

Submission status: Runtime Error

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


dp=[0]*10
for h in range(1,H-1):
    for w in range(1,W-1):
        s = 0
        for i in range(0,N):
            if ab[i][0] >= h and ab[i][0] <= h+2 and ab[i][1] >= w and ab[i][1] <=w+2:
                s = s+1
        dp[s] += 1

for i in dp:
    print(dp[i])

Submission status: Runtime Error

Solution code:
import numpy as np

def ABC045D(h, w, n, ab):
    board = np.zeros((h, w), dtype=int)
    for a, b in ab:
        board[a-1, b-1] = 1
    ans = np.zeros(10, dtype=int)
    if h >= 3 and w >= 3:
        for i in range(1, h-1):
            for j in range(1, w-1):
                count = board[i-1, j-1] + board[i, j-1] + board[i+1, j-1] +\
                        board[i-1, j]   + board[i, j]   + board[i+1, j]   +\
                        board[i-1, j+1] + board[i, j+1] + board[i+1, j+1]
                ans[count] += 1
    for i in ans:
        print(i)

h, w, n = map(int, input().split())
ab = [0] * n
for i in range(n):
    ab[i] = list(map(int, input().split()))
ABC045D(h, w, n, ab)

Submission status: Runtime Error

Solution code:
H, W, N = input().split(" ")
H, W, N = int(H), int(W), int(N)
A = [input().split(" ") for i in range(N)]
A = [[int(l[0])-1, int(l[1])-1] for l in A]


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

import numpy as np
field = np.array([np.array([1 if [i, j] in A else 0 for j in range(W)]) for i in range(H)])

for h in range(H - 3 + 1):
    for w in range(W - 3 + 1):
        black_num[np.sum(field[h:h+3].T[w:w+3].T)] += 1
for i in black_num:
    print(i)

Submission status: Runtime Error

Solution code:
h, w, n = map(int, input().split())
mat = []
for i in range(h+1):
    mat += [[0] * (w + 1)]
blacks = []
for i in range(n):
    a, b = map(int, input().split())
    mat[a][b] = 1
    blacks.append([a, b])
d = dict()
def count_blacks(x, y):
    b = 0
    if mat[x][y] == 1:
        b += 1
    if mat[x + 1][y] == 1:
        b += 1
    if mat[x + 2][y] == 1:
        b += 1
    if mat[x][y+1] == 1:
        b += 1
    if mat[x + 1][y+1] == 1:
        b += 1
    if mat[x + 2][y+1] == 1:
        b += 1
    if mat[x][y+2] == 1:
        b += 1
    if mat[x + 1][y+2] == 1:
        b += 1
    if mat[x + 2][y+2] == 1:
        b += 1
    return b
for i in blacks:
    x = i[0]
    y = i[1]
    if 3 <= y + 2 <= w and 1 <= x <= h - 2:
        d[(x, y)] = count_blacks(x, y)
    if 3 <= y + 2 <= w and 2 <= x <= h - 1:
        d[(x - 1, y)] = count_blacks(x-1, y)
    if 3 <= y + 2 <= w and 3 <= x <= h:
        d[(x - 2, y)] = count_blacks(x - 2, y)

    if 3<=y + 1 <= w and 1 <= x <= h - 2:
        d[(x, y - 1)] = count_blacks(x, y - 1)
    if 3 <= y + 1 <= w and 2 <= x <= h - 1:
        d[(x - 1, y - 1)] = count_blacks(x - 1, y - 1)
    if 3 <= y + 1 <= w and 3 <= x <= h:
        d[(x - 2, y - 1)] = count_blacks(x - 2, y - 1)

    if 3<=y<= w and 1 <= x <= h - 2:
        d[(x, y - 2)] = count_blacks(x, y - 2)
    if 3 <= y <= w and 2 <= x <= h - 1:
        d[(x - 1, y - 2)] = count_blacks(x - 1, y - 2)
    if 3 <= y <= w and 3 <= x <= h:
        d[(x - 2, y - 2)] = count_blacks(x - 2, y - 2)
l = [0]
sums = 0
for i in range(1, 10):
    t = 0
    for x in d:
        if d[x] == i:
            t += 1
    sums += t
    l.append(t)
l[0] = (h - 2) * (w - 2) - sums
for x in l:
    print(x)

Submission status: Runtime Error

Solution code:
h, w, n = map(int, input().split())
mat = []
for i in range(h+1):
    mat += [[0] * (w + 1)]
blacks = []
for i in range(n):
    a, b = map(int, input().split())
    mat[a][b] = 1
    blacks.append([a, b])
d = dict()
def count_blacks(x, y):
    b = 0
    if mat[x][y] == 1:
        b += 1
    if mat[x + 1][y] == 1:
        b += 1
    if mat[x + 2][y] == 1:
        b += 1
    if mat[x][y+1] == 1:
        b += 1
    if mat[x + 1][y+1] == 1:
        b += 1
    if mat[x + 2][y+1] == 1:
        b += 1
    if mat[x][y+2] == 1:
        b += 1
    if mat[x + 1][y+2] == 1:
        b += 1
    if mat[x + 2][y+2] == 1:
        b += 1
    return b
for i in blacks:
    x = i[0]
    y = i[1]
    if 3 <= y + 2 <= w and 1 <= x <= h - 2:
        d[(x, y)] = count_blacks(x, y)
    if 3 <= y + 2 <= w and 2 <= x <= h - 1:
        d[(x - 1, y)] = count_blacks(x-1, y)
    if 3 <= y + 2 <= w and 3 <= x <= h:
        d[(x - 2, y)] = count_blacks(x - 2, y)

    if 3<=y + 1 <= w and 1 <= x <= h - 2:
        d[(x, y - 1)] = count_blacks(x, y - 1)
    if 3 <= y + 1 <= w and 2 <= x <= h - 1:
        d[(x - 1, y - 1)] = count_blacks(x - 1, y - 1)
    if 3 <= y + 1 <= w and 3 <= x <= h:
        d[(x - 2, y - 1)] = count_blacks(x - 2, y - 1)

    if 3<=y<= w and 1 <= x <= h - 2:
        d[(x, y - 2)] = count_blacks(x, y - 2)
    if 3 <= y <= w and 2 <= x <= h - 1:
        d[(x - 1, y - 2)] = count_blacks(x - 1, y - 2)
    if 3 <= y <= w and 3 <= x <= h:
        d[(x - 2, y - 2)] = count_blacks(x - 2, y - 2)
l = [0]
for i in range(1, 10):
    t = 0
    for x in d:
        if d[x] == i:
            t += 1
    l.append(t)
sums = sum(l)
l[0] = (h - 2) * (w - 2) - sums
for x in l:
    print(x)

Submission status: Runtime Error

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

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

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


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

Submission status: Runtime Error

Solution code:
def sub_matrix(i, j):
    list_ = []
    for n in [i, i+1, i+2]:
        for m in [j, j+1, j+2]:
            list_.append((n, m))
        
    return list_

inp = input().split(' ')

H = int(inp[0])
W = int(inp[1])
N = int(inp[2])

matrix = [[0]*W for i in range(H)]

for _ in range(N):
    i, j = [int(inp) for inp in input().split(' ')]
    matrix[i-1][j-1] = 1

counter = [0]*10
for i in range(H-2):
    for j in range(W-2):
        sum_ = 0
        square = sub_matrix(i, j)
        for coord in square:
            if matrix[coord[0]][coord[1]] == 1:
                sum_ += 1
            else:
                pass
                
        counter[sum_] += 1
        
for i in counter:
    print(i)

Submission status: Runtime Error

Solution code:
#in1 = '10 10 20'
#in2 = ['1 1', '1 4', '1 9', '2 5', '3 10', '4 2', '4 7', '5 9', '6 4', '6 6', '6 7', '7 1', '7 3', '7 7', '8 1', '8 5', '8 10', '9 2', '10 4', '10 9']
#in1 = '1000000000 1000000000 0'
h, w, n = map(int, input().split())
#h, w, n = map(int, in1.split())

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

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

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

    for idx1 in range(len(in2)):
        if ab[idx1][0] < 3:
            s = 0
        else:
            s = ab[idx1][0] - 3
        if ab[idx1][0] > h - 2:
            l = h - 2
        else:
            l = ab[idx1][0]
        Rrange = range(s, l)
        if ab[idx1][1] < 3:
            s = 0
        else:
            s = ab[idx1][1] - 3
        if ab[idx1][1] > w - 2:
            l = h - 2
        else:
            l = ab[idx1][1]
        Crange = range(s, l)

        for nowRow in Rrange:
            for nowCol in Crange:
                w_black = 0
                for idx2 in range(idx1):
                    if nowRow < ab[idx2][0] <= nowRow + 3 and nowCol < ab[idx2][1] <= nowCol + 3:
                        w_black += 1
                black_cnt[w_black]     -= 1
                black_cnt[w_black + 1] += 1

for idx1 in range(len(black_cnt)):
    print(black_cnt[idx1])

Submission status: Runtime Error

Solution code:
#in1 = '10 10 20'
#in2 = ['1 1', '1 4', '1 9', '2 5', '3 10', '4 2', '4 7', '5 9', '6 4', '6 6', '6 7', '7 1', '7 3', '7 7', '8 1', '8 5', '8 10', '9 2', '10 4', '10 9']
h, w, n = map(int, input().split())
#h, w, n = map(int, in1.split())

idx1 = 0
ab = [[0 for i in range(2)] for j in range(n)]
while idx1 < n:
    x = input().split()
    #x = in2[idx1].split()
    ab[idx1][0] = int(x[0])
    ab[idx1][1] = int(x[1])
    idx1 += 1

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

for idx1 in range(len(in2)):
    if ab[idx1][0] < 3:
        s = 0
    else:
        s = ab[idx1][0] - 3
    if ab[idx1][0] > h - 2:
        l = h - 2
    else:
        l = ab[idx1][0]
    Rrange = range(s, l)
    if ab[idx1][1] < 3:
        s = 0
    else:
        s = ab[idx1][1] - 3
    if ab[idx1][1] > w - 2:
        l = h - 2
    else:
        l = ab[idx1][1]
    Crange = range(s, l)

    for nowRow in Rrange:
        for nowCol in Crange:
            w_black = 0
            for idx2 in range(idx1):
                if nowRow < ab[idx2][0] <= nowRow + 3 and nowCol < ab[idx2][1] <= nowCol + 3:
                    w_black += 1
            black_cnt[w_black]     -= 1
            black_cnt[w_black + 1] += 1

for idx1 in range(len(black_cnt)):
    print(black_cnt[idx1])

Submission status: Runtime Error

Solution code:
#in1 = '10 10 20'
#in2 = ['1 1', '1 4', '1 9', '2 5', '3 10', '4 2', '4 7', '5 9', '6 4', '6 6', '6 7', '7 1', '7 3', '7 7', '8 1', '8 5', '8 10', '9 2', '10 4', '10 9']
h, w, n = lambda:map(int, input().split())
h, w, n = map(int, in1.split())

idx1 = 0
ab = [[0 for i in range(2)] for j in range(n)]
while idx1 < n:
    x = input().split()
    #x = in2[idx1].split()
    ab[idx1][0] = int(x[0])
    ab[idx1][1] = int(x[1])
    idx1 += 1

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

for idx1 in range(len(in2)):
    if ab[idx1][0] < 3:
        s = 0
    else:
        s = ab[idx1][0] - 3
    if ab[idx1][0] > h - 2:
        l = h - 2
    else:
        l = ab[idx1][0]
    Rrange = range(s, l)
    if ab[idx1][1] < 3:
        s = 0
    else:
        s = ab[idx1][1] - 3
    if ab[idx1][1] > w - 2:
        l = h - 2
    else:
        l = ab[idx1][1]
    Crange = range(s, l)

    for nowRow in Rrange:
        for nowCol in Crange:
            w_black = 0
            for idx2 in range(idx1):
                if nowRow < ab[idx2][0] <= nowRow + 3 and nowCol < ab[idx2][1] <= nowCol + 3:
                    w_black += 1
            black_cnt[w_black]     -= 1
            black_cnt[w_black + 1] += 1

for idx1 in range(len(black_cnt)):
    print(black_cnt[idx1])

Submission status: Runtime Error

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: Runtime Error

Solution code:
H,W,N = map(int,input().split())
g = [[0]*(W+2) for _ in range(H+2)] # 0:white 1:black
a = [0]*N
b = [0]*N
seen = [[False]*(W+2) for _ in range(H+2)]
ans = [0]*10
for i in range(N):
    a[i], b[i] = map(int,input().split())
    g[a[i]][b[i]] = 1
# 黒マスの周り9領域を探索する
for y,x in zip(a,b):
    for dy in range(-1,2):
        for dx in range(-1,2):
            if 2 <= x + dx <= W-1 and 2 <= y + dy <= H-1:
                cy = y+dy # 中心を決める
                cx = x+dx
                if seen[cy][cx]:
                    continue
                seen[cy][cx] = True
                black_cnt = 0
                for ddx in range(-1,2):
                    for ddy in range(-1,2):
                        black_cnt += g[cy+ddy][cx+ddx]
                ans[black_cnt] += 1
ans[0] = (H-2)*(W-2) - sum(ans[1:])

# for i in range(H+2):
#     print(g[i])
for i in range(10):
    print(ans[i])

Submission status: Runtime Error

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

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

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

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

        if f((a)*dg + b-1):
            if (a)*dg + b-1 in d:
                d[(a)*dg + b-1] += 1
            else:
                d[(a)*dg + b-1] = 1
        
        if f(a*dg + b):
            if a*dg + b in d:
                d[a*dg + b] += 1
            else:
                d[a*dg + b] = 1
        
        if f((a)*dg + b+1):
            if (a)*dg + b+1 in d:
                d[(a)*dg + b+1] += 1
            else:
                d[(a)*dg + b+1] = 1
        
        if f((a+1)*dg + b+1):
            if (a+1)*dg + b+1 in d:
                d[(a+1)*dg + b+1] += 1
            else:
                d[(a+1)*dg + b+1] = 1
        
        if f((a+1)*dg + b):
            if (a+1)*dg + b in d:
                d[(a+1)*dg + b] += 1
            else:
                d[(a+1)*dg + b] = 1
        
        if f((a+1)*dg + b-1):
            if (a+1)*dg + b-1 in d:
                d[(a+1)*dg + b-1] += 1
            else:
                d[(a+1)*dg + b-1] = 1
        
        
        
        
    res = [0]*10
    cnt = 0
    for e in d:
        cnt += 1
    
    if cnt > 65535:
        d[-1] += 1
        

    else:
        print(10)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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

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

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

        if f((a)*dg + b-1):
            d[(a)*dg + b-1] += 1
        
        if f(a*dg + b):
            d[a*dg + b] += 1
        
        if f((a)*dg + b+1):
			d[(a)*dg + b+1] += 1
        
        if f((a+1)*dg + b+1):
			d[(a+1)*dg + b+1] += 1
        
        if f((a+1)*dg + b):
			d[(a+1)*dg + b] += 1

        if f((a+1)*dg + b-1):
			d[(a+1)*dg + b-1] += 1
        
        
        
        
    res = [0]*10

    for e in d:
        res[d[e]] += 1

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

    for e in res:
        print(e)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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

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

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

    if f((a)*dg + b-1):
        if (a)*dg + b-1 in d:
            d[(a)*dg + b-1] += 1
        else:
            d[(a)*dg + b-1] = 1
    
    if f((a+1)*dg + b+1):
        if (a+1)*dg + b+1 in d:
            d[(a+1)*dg + b+1] += 1
        else:
            d[(a+1)*dg + b+1] = 1
    
    if f((a+1)*dg + b):
        if (a+1)*dg + b in d:
            d[(a+1)*dg + b] += 1
        else:
            d[(a+1)*dg + b] = 1
    
    if f((a)*dg + b+1):
        if (a)*dg + b+1 in d:
            d[(a)*dg + b+1] += 1
        else:
            d[(a)*dg + b+1] = 1
    
    if f((a-1)*dg + b+1):
        if (a-1)*dg + b+1 in d:
            d[(a-1)*dg + b+1] += 1
        else:
            d[(a-1)*dg + b+1] = 1
    
    if f((a+1)*dg + b-1):
        if (a+1)*dg + b-1 in d:
            d[(a+1)*dg + b-1] += 1
        else:
            d[(a+1)*dg + b-1] = 1
    
res = [0]*9

for e in d:
    res[d[e]] += 1

for e in res:
    print(e)

Submission status: Runtime Error

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

d = {}
c = [0] * 9

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

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

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

for x in c:
    print(x)