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

Solution code:
Blist = {}
chkedSquare = {}
result = {}
#sA,sBを左上にもつ３×３の四角に■が何個あるか
#■は{'a,b',四角の数}であらわされている
def chkAreaCount(sA,sB):
	count = 0
	if str(sA) + ',' + str(sB) not in chkedSquare:
		for i in range(3):
			chkA = sA + i
			for j in range(3):
				chkB = sB + j
				if str(chkA) + ',' + str(chkB) in Blist:
					count = count + 1
					#print('check' + str(chkA) + ':' + str(chkB) + ':' + str(count))
		#print(str(sA) + ':' + str(sB) + ':' + str(count))
		chkedSquare[str(sA) + ',' + str(sB)] = count

def chkOneBlackSquare(a,b):
	#print('PARENT' + str(a) +','+ str(b))
	for i in range(3):
		sA = a - i
		if sA < 1 :
			continue
		if sA + 2 > H:
			continue
		for j in range(3):
			sB = b - j
			if sB < 1:
				continue
			if sB + 2 > W:
				continue
			#print(str(sA) +','+ str(sB))
			chkAreaCount(sA,sB)
				
	
if __name__ == '__main__':
	H,W,N = map(int,list(input().split())) 
	for i in range(N):
		a,b = map(int,list(input().split())) 
		Blist[str(a) + ',' + str(b)] = 0
	for key in Blist.keys():
		#print(key)
		a,b = key.split(',')
		chkOneBlackSquare(int(a),int(b))
	for v in chkedSquare.values():
		if v in result:
			result[v] = result[v] + 1
		else:
			result[v] = 1
	for i in range(10):
		if i == 0:
			wholeS = (H-2)*(W-2)
			ZeroS = wholeS - len(chkedSquare)
			print(str(ZeroS))
		elif i in result:
			print(str(result[i]))
			#print('')
		else:
			print('0')
			#print('')

Submission status: Time Limit Exceeded

Solution code:
h, w, n = [int(i) for i in input().split()]
board = [[False for _ in range(w)] for _ in range(h)]
for _ in range(n):
    y, x = [int(i)-1 for i in input().split()]
    board[y][x] = True

anss = [0 for _ in range(10)]
for i in range(1, w-1):
    for j in range(1, h-1):
        sum_black = 0
        for x in range(i-1, i+2):
            sum_black += sum(board[y][x] for y in range(j-1, j+2))
        anss[sum_black] += 1

for ans in anss:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

count = [0] * 10
count[0] = (H - 2) * (W - 2)
drawed = {}

def check(x, y):
    cnt = 0
    for i in range(-1, 2):
        for j in range(-1, 2):
            if (x + i, y + j) in drawed:
                cnt += 1
    return cnt


def draw(x, y):
    cnt = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    for i in range(-1, 2):
        if x + i <= 0 or x + i >= H-1:
            continue
        for j in range(-1, 2):
            if y + j <= 0 or y + j >= W-1:
                continue
            cnt[check(x + i, y + j)] += 1
    for i in range(9):
        count[i] -= cnt[i]
        count[i + 1] += cnt[i]
    drawed[(x, y)] = None

for i in range(N):
    x, y = map(int, input().split(" "))
    draw(x-1, y-1)

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

Submission status: Time Limit Exceeded

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

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

for i in range(n):
    m[a[i][0]-1][a[i][1]-1] = 1

count = [0] * 10

for i in range(h-2):
        for j in range(w-2):
            kuro = 0
            for s in range(3):
                for t in range(3):
                    kuro += m[i+s][j+t]
            count[kuro] += 1

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

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

# 升目の高さ、幅、塗りつぶし回数
height, width, n = map(int,raw_input().split())

# 升目の生成処理
mass = {}
# 升目の塗りつぶし処理
for i in xrange(n):
	a, b = map(int,raw_input().split())
	if mass.has_key(a-1):
		mass[a-1].append(b-1)
	else:
		mass.update({a-1:[b-1]})

# 計算
result = 0
j = [0]*10

for y in xrange(height-2):
	for x in xrange(width-2):
		for n_y in xrange(y,y+3):
			try:
				for n_x in mass[n_y]:
					if n_x >= x and n_x < x+3:
						result = result + 1
			except:
				pass
		j[result] = j[result] + 1
		result = 0

for i in j:
	print i

# # 升目の生成処理
# mass = [[] for i in xrange(height)]

# # 升目の塗りつぶし処理
# for i in xrange(n):
# 	a, b = map(int, raw_input().split())
# 	if len(mass[a-1]) < b-1:
# 		for i in xrange(b-2-len(mass[a-1])+1):
# 			mass[a-1].append(0)
# 	mass[a-1].append(1)

# # jとresultを定義
# j = [0]*10
# result = 0

# # 塗りつぶした升目をカウント
# for y in xrange(height-2):
# 	for x in xrange(width-2):
# 		for n_y in xrange(y,y+3):
# 			for n_x in xrange(x,x+3):
# 				try:
# 					result = result + mass[n_y][n_x]
# 				except:
# 					pass
# 		j[result] = j[result]+1
# 		result = 0

# for i in j:
# 	print i

# 
# mass = [[0 for i in xrange(width)] for j in xrange(height)]
# for list_ in mass:
# 	print list_
# j = [0]*10

# for i in xrange(n):
# 	y, x = map(int,raw_input().split())
# 	mass[y-1][x-1] = 1
# 	for list_ in mass:
# 		print list_

# result = 0
# for x in xrange(width-2):
# 	for y in xrange(height-2):
# 		for n_x in xrange(x,x+3):
# 			for n_y in xrange(y,y+3):
# 				result = result + mass[n_y][n_x]
# 		j[result] = j[result]+1
# 		result = 0

# for i in j:
# 	print i

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

# 升目の高さ、幅、塗りつぶし回数
height, width, n = map(int,raw_input().split())

if n == 0:
	for i in xrange(10):
		print 0

# 升目の生成処理
mass = {}
# 升目の塗りつぶし処理
for i in xrange(n):
	a, b = map(int,raw_input().split())
	if mass.has_key(a-1):
		mass[a-1].append(b-1)
	else:
		mass.update({a-1:[b-1]})

# 計算
result = 0
j = [0]*10

for y in xrange(height-2):
	for x in xrange(width-2):
		for n_y in xrange(y,y+3):
			if mass.has_key(n_y):
				for n_x in mass[n_y]:
					if n_x >= x and n_x < x+3:
						result = result + 1
		j[result] = j[result] + 1
		result = 0

for i in j:
	print i

# # 升目の生成処理
# mass = [[] for i in xrange(height)]

# # 升目の塗りつぶし処理
# for i in xrange(n):
# 	a, b = map(int, raw_input().split())
# 	if len(mass[a-1]) < b-1:
# 		for i in xrange(b-2-len(mass[a-1])+1):
# 			mass[a-1].append(0)
# 	mass[a-1].append(1)

# # jとresultを定義
# j = [0]*10
# result = 0

# # 塗りつぶした升目をカウント
# for y in xrange(height-2):
# 	for x in xrange(width-2):
# 		for n_y in xrange(y,y+3):
# 			for n_x in xrange(x,x+3):
# 				try:
# 					result = result + mass[n_y][n_x]
# 				except:
# 					pass
# 		j[result] = j[result]+1
# 		result = 0

# for i in j:
# 	print i

# 
# mass = [[0 for i in xrange(width)] for j in xrange(height)]
# for list_ in mass:
# 	print list_
# j = [0]*10

# for i in xrange(n):
# 	y, x = map(int,raw_input().split())
# 	mass[y-1][x-1] = 1
# 	for list_ in mass:
# 		print list_

# result = 0
# for x in xrange(width-2):
# 	for y in xrange(height-2):
# 		for n_x in xrange(x,x+3):
# 			for n_y in xrange(y,y+3):
# 				result = result + mass[n_y][n_x]
# 		j[result] = j[result]+1
# 		result = 0

# for i in j:
# 	print i

Submission status: Time Limit Exceeded

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

cs = [[0 for i in range(W)] for j in range(H)]
for tup in ab:
	a = tup[0]
	b = tup[1]
	cs[a-1][b-1] = 1


a = [0 for i in range(10)]
for k in range(H-2):
	for l in range(W-2):
		c = cs[k][l] + cs[k][l+1] + cs[k][l+2] + cs[k+1][l] + cs[k+1][l+1] + cs[k+1][l+2] + cs[k+2][l] + cs[k+2][l+1] + cs[k+2][l+2]
		a[c] += 1
for i in range(10):
	print(a[i])

Submission status: Time Limit Exceeded

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

ab = [list(map(lambda x:(int(x)-1),input().split())) for _ in range(N)]
d= defaultdict(int)

def get_near(x,y):
    return [(x+i,y+j) for i,j in itertools.product(range(-1,2),repeat=2)\
            if 1<=x+i<H-1 and 1<=y+j<W-1 ]

for x,y in ab:
    for p,q in get_near(x,y):
        d[(p,q)] +=1
    #print(d)


#ans= [ for _ in range(10)]
ans = Counter(d.values())
ans[0]= (H-2)*(W-2) - sum(ans[i] for i in range(1,10))

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

Submission status: Time Limit Exceeded

Solution code:
import sys

#sys.stdin = open('input1.txt', 'r')

H, W , N = map(int, raw_input().split())
squares = {}
results = [0 for _ in range(10)]
for _ in range(N):
	h, w = map(int, raw_input().split())
	for x in [(0, 0), (0, -1), (0, -2), (-1, 0), (-1, -1), (-1, -2), (-2, 0), (-2, -1), (-2, -2)]:
		nh, nw = h + x[0], w + x[1]
		if ((nh < 1) or (nw < 1) or (nh + 2 > H) or (nw + 2 > W)):
			pass
		else:
			if (nh, nw) in squares:
				squares[(nh, nw)] += 1
			else:
				squares[(nh, nw)] = 1

for v in squares.values():
	results[v] += 1

subtotal = 0
for x in range(1, 10, 1):
	subtotal += results[x]
results[0] = (H - 2) * (W - 2) - subtotal

for x in range(10):
	print str(results[x])

Submission status: Time Limit Exceeded

Solution code:
import sys

#sys.stdin = open('input1.txt', 'r')

H, W , N = map(int, raw_input().split())
squares = {}
results = [0 for _ in range(10)]
for _ in range(N):
	h, w = map(int, raw_input().split())
	for x in [(0, 0), (0, -1), (0, -2), (-1, 0), (-1, -1), (-1, -2), (-2, 0), (-2, -1), (-2, -2)]:
		nh, nw = h + x[0], w + x[1]
		if ((nh < 1) or (nw < 1) or (nh + 2 > H) or (nw + 2 > W)):
			pass
		else:
			if (nh, nw) in squares:
				squares[(nh, nw)] += 1
			else:
				squares[(nh, nw)] = 1

for k in squares.keys():
	results[squares[k]] += 1

subtotal = 0
for x in range(1, 10, 1):
	subtotal += results[x]
results[0] = (H - 2) * (W - 2) - subtotal

for x in range(10):
	print str(results[x])

Submission status: Time Limit Exceeded

Solution code:
import sys

#sys.stdin = open('input3.txt', 'r')

H, W , N = map(int, raw_input().split())
squares = []
results = [0 for _ in range(10)]
for _ in range(N):
	h, w = map(int, raw_input().split())
	for x in [(0, 0), (0, -1), (0, -2), (-1, 0), (-1, -1), (-1, -2), (-2, 0), (-2, -1), (-2, -2)]:
		nh, nw = h + x[0], w + x[1]
		if ((nh < 1) or (nw < 1) or (nh + 2 > H) or (nw + 2 > W)):
			pass
		else:
			squares.append((nh, nw))
squares.sort()

current = ()
count = 0
for s in squares:
	if s != current:
		results[count] = results[count] + 1
		current = s
		count = 1
	else:
		count = count + 1
results[count] = results[count] + 1


subtotal = 0
for x in range(1, 10, 1):
	subtotal += results[x]
results[0] = (H - 2) * (W - 2) - subtotal

for x in range(10):
	print str(results[x])

Submission status: Time Limit Exceeded

Solution code:
import sys

#sys.stdin = open('input1.txt', 'r')

H, W, N = map(int, raw_input().split())
points = []
for _ in range(N):
	a, b = map(int, raw_input().split())
	points.append((a,b))

searched = {}
for p in points:
	searched[p] = 0
results = {}
for x in range(10):
	results[x] = 0

def get_points(h, w):
	if ((h + 2 >  H) or (w + 2 > W) or (h < 1) or (w < 1)):
		return 0
	else:
		count = 0
		for x in range(3):
			for y in range(3):
				if ( (h + x, w + y) in searched ):
					if searched[(h + x, w + y)] == 0:
						count = count + 1
					else:
						return 0
		return count

def search_three_by_three_square(pt):
	h, w = pt[0], pt[1]
	possibles = [(h , w), (h - 1, w), (h - 2 , w), (h , w - 1), (h - 1, w - 1), (h - 2, w - 1), (h, w - 2), (h - 1, w - 2), (h - 2, w - 2)]

	for p in possibles:
		v = get_points(p[0], p[1])
		results[v] = results[v] + 1

	searched[pt] = 1

for p in points:
	search_three_by_three_square(p)

zero = (W - 2) * (H - 2)
for x in range(1, 10, 1):
	zero = zero - results[x]
results[0] = zero
for x in range(10):
	print str(results[x])

Submission status: Time Limit Exceeded

Solution code:
import sys

#sys.stdin = open('input3.txt', 'r')

H, W, N = map(int, raw_input().split())
points = []
for _ in range(N):
	a, b = map(int, raw_input().split())
	points.append((a,b))

points.sort(key=lambda x:x[0])
searched = {}
for p in points:
	searched[p] = 0
results = {}
for x in range(10):
	results[x] = 0

def get_points(h, w):
	if ((h + 2 >  H) or (w + 2 > W) or (h < 1) or (w < 1)):
		return 0
	else:
		count = 0
		for x in range(3):
			for y in range(3):
				if ( (h + x, w + y) in searched ):
					if searched[(h + x, w + y)] == 0:
						count = count + 1
					else:
						return 0
		return count

def search_three_by_three_square(pt):
	h, w = pt[0], pt[1]
	results[get_points(h, w)] = results[get_points(h, w)] + 1
	results[get_points(h - 1, w)] = results[get_points(h - 1, w)] + 1
	results[get_points(h - 2, w)] = results[get_points(h - 2, w)] + 1

	results[get_points(h, w - 1)] = results[get_points(h, w - 1)] + 1
	results[get_points(h - 1, w - 1)] = results[get_points(h - 1, w - 1)] + 1
	results[get_points(h - 2, w - 1)] = results[get_points(h - 2, w - 1)] + 1

	results[get_points(h, w - 2)] = results[get_points(h, w - 2)] + 1
	results[get_points(h - 1, w - 2)] = results[get_points(h - 1, w - 2)] + 1
	results[get_points(h - 2, w - 2)] = results[get_points(h - 2, w - 2)] + 1

	searched[pt] = 1

for p in points:
	search_three_by_three_square(p)

zero = (W - 2) * (H - 2)
for x in range(1, 10, 1):
	zero = zero - results[x]
results[0] = zero
for x in range(10):
	print str(results[x])

Submission status: Time Limit Exceeded

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

while True:
    ab = input()
    if not ab:
        break
    a, b = map((lambda n: int(n)-1), ab.split())
    board[a][b] = 1

result = [0 for i in range(10)]
for i in range(h-2):
    lines = board[i:i+3]
    for j in range(w-2):
        num = 0
        for line in lines:
            num += line[j:j+3].count(1)
        result[num] += 1

print('\n'.join(map(str, result)))

Submission status: Time Limit Exceeded

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

bs = set()

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

cnts = [0] * 10

looked = set()

from itertools import product

for a, b in bs:
    for pa, pb in product(range(3), repeat = 2):
        fa = a - pa
        fb = b - pb
        if fa < 1 or fb < 1 or fa + 2 > H or fb + 2 > W or (fa, fb) in looked:
            continue

        looked.add((fa, fb))
        
        cnt = 0
        for da in range(3):
            for db in range(3):
                if (fa + da, fb + db) in bs:
                    cnt += 1
        cnts[cnt] += 1

cnts[0] += (H - 2) * (W - 2) - len(looked)

for c in cnts:
    print(c)

Submission status: Time Limit Exceeded

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

bs = set()

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

cnts = [0] * 10

looked = set()

from itertools import product

for a, b in bs:
    for pa, pb in product(range(3), repeat = 2):
        fa = a - pa
        fb = b - pb
        if fa < 1 or fb < 1 or fa + 2 > H or fb + 2 > W or (fa, fb) in looked:
            continue

        looked.add((fa, fb))
        
        cnt = 0
        for da, db in product(range(3), repeat = 2):
            if (fa + da, fb + db) in bs:
                cnt += 1
        cnts[cnt] += 1

cnts[0] += (H - 2) * (W - 2) - len(looked)

for c in cnts:
    print(c)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env pypy3

import collections
import itertools


MAX_J = 9
SQUARE_SIZE = 3


class Board(object):

    def __init__(self, height, width):
        self.height = height
        self.width = width
        self.squares = collections.Counter()

    def inside_board(self, r, c):
        return 0 <= r < self.height - 2 and 0 <= c < self.width - 2

    def paint_cell(self, r, c):
        for k, l in itertools.product(range(SQUARE_SIZE), repeat=2):
            sr, sc = r - k, c - l
            if self.inside_board(sr, sc):
                self.squares[(sr, sc)] += 1

    def summarize(self):
        ans = [0 for _ in range(MAX_J + 1)]
        for v in self.squares.values():
            if 1 <= v <= MAX_J:
                ans[v] += 1
        ans[0] = (self.height - 2) * (self.width - 2) - sum(ans[1:])
        return ans


def main():
    h, w, n = map(int, input().split())
    board = Board(h, w)
    for _ in range(n):
        a, b = map(lambda x: int(x) - 1, input().split())
        board.paint_cell(a, b)
    ans = board.summarize()
    print(*ans, sep="\n")


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

import collections
import itertools


MAX_J = 9
SQUARE_SIZE = 3


class Board(object):

    def __init__(self, height, width):
        self.height = height
        self.width = width
        self.squares = collections.Counter()

    def inside_board(self, r, c):
        return 0 <= r < self.height - 2 and 0 <= c < self.width - 2

    def paint_cell(self, r, c):
        for k, l in itertools.product(range(SQUARE_SIZE), repeat=2):
            sr, sc = r - k, c - l
            if self.inside_board(sr, sc):
                self.squares[(sr, sc)] += 1

    def summarize(self):
        ans = [0 for _ in range(MAX_J + 1)]
        for v in self.squares.values():
            if 1 <= v <= MAX_J:
                ans[v] += 1
        ans[0] = (self.height - 2) * (self.width - 2) - sum(ans[1:])
        return ans


def main():
    h, w, n = map(int, input().split())
    board = Board(h, w)
    for _ in range(n):
        a, b = map(lambda x: int(x) - 1, input().split())
        board.paint_cell(a, b)
    ans = board.summarize()
    print(*ans, sep="\n")


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
h, w, n = map(lambda x: int(x), input().split())
x = [[0 for i in range(w)] for j in range(h)]
for i in range(n):
        a, b = map(lambda x: int(x), input().split())
        x[a-1][b-1] = 1

if (n == 0):
        for i in range(10):
                print (0)
else:
        ans = [[0 for i in range(w-2)] for j in range(h-2)]
        for j in range(w-2):
                for i in range(h-2):
                        ans[i][j] = x[i][j]+x[i][j+1]+x[i][j+2]+x[i+1][j]+x[i+1][j+1]+x[i+1][j+2]+x[i+2][j]+x[i+2][j+1]+x[i+2][j+2]
        for i in range(10):
                temp = 0
                for j in range(h-2):
                        temp += ans[j].count(i)
                print(temp)

Submission status: Time Limit Exceeded

Solution code:
h,w,n=map(int,input().split())
d={}
for _ in range(n):
    a,b=map(int,input().split()) 
    for i in (-1,0,1):
        for j in (-1,0,1):
            if 2<=a+i<=h-1 and 2<=b+j<=w-1:
                d.setdefault((a+i,b+j),0)
                d[a+i,b+j]+=1
r=[0]*10
for i in d.values():
    r[i]+=1
r[0]=(h-2)*(w-2)-sum(r)
for i in r:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
h,w,n=map(int,input().split())
s={tuple(map(int,input().split())) for _ in range(n)}
p=[(i,j) for i in (-1,0,1) for j in (-1,0,1)]
t={(a+i,b+j) for a,b in s for i,j in p}
c=[0]*10
for a,b in t:
    if 2<=a<=h-1 and 2<=b<=w-1:
        c[sum((a+i,b+j) in s for i,j in p)]+=1
c[0]=(h-2)*(w-2)-sum(c)
for i in c:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
class nSnukes_Coloring:
	def returnEachNumber(self,H,W,N,r):
		HWMap = [[0 for i in range(W+2)] for j in range(H+2)]
		points = [0 for i in range(10)]
		for cord in range(len(r)):
			y,x = r[cord][0],r[cord][1]
			for i in range(3):
				for j in range(3):
					HWMap[y-i+1][x-j+1] += 1
		for i in range(H-2):
			for j in range(W-2):
				points[HWMap[i+2][j+2]] += 1
		for i in range(len(points)):
			print points[i]

if __name__ == "__main__":
	H, W, N = map(int, raw_input().split())
	if H < 3 or W < 3:
		l = [0 for i in range(10)]
		for i in range(10):
			print l[i]
	elif N == 0:
		l = [0 for i in range(10)]
		l[0] = (H-2)*(W-2)
		for i in range(10):
			print l[i]
	else:
		r = [[int(i) for i in raw_input().split()] for j in range(N)]
		s = nSnukes_Coloring()
		s.returnEachNumber(H,W,N,r)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
dd=defaultdict(int)
h,w,n=map(int,input().split())
for i in range(n):
    a,b=map(int,input().split())
    for hh in range(-1,2):
        for ww in range(-1,2):
            if 1<a+hh and a+hh<h and 1<b+ww and b+ww<w:
                dd[(a+hh,b+ww)]+=1
ans=[0]*10
for k in dd.keys():
    ans[dd[k]]+=1

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

Submission status: Time Limit Exceeded

Solution code:
class nSnukes_Coloring:
	def returnEachNumber(self,H,W,N,r):
		HWMap = [[0 for i in range(W+2)] for j in range(H+2)]
		points = [0 for i in range(10)]
		for cord in range(len(r)):
			y,x = r[cord][0],r[cord][1]
			for i in range(3):
				for j in range(3):
					HWMap[y-i+1][x-j+1] += 1
		for i in range(H-2):
			for j in range(W-2):
				points[HWMap[i+2][j+2]] += 1
		for i in range(len(points)):
			print points[i]

if __name__ == "__main__":
	H, W, N = map(int, raw_input().split())
	if N == 0:
		l = [0 for i in range(10)]
		l[0] = (H-2)*(W-2)
		for i in range(10):
			print l[i]
	else:
		r = [[int(i) for i in raw_input().split()] for j in range(N)]
		s = nSnukes_Coloring()
		s.returnEachNumber(H,W,N,r)

Submission status: Time Limit Exceeded

Solution code:
class nSnukes_Coloring:
	def returnEachNumber(self,H,W,N,r):
		HWMap = [[0 for i in range(W+2)] for j in range(H+2)]
		points = [0 for i in range(10)]
		for cord in range(len(r)):
			y,x = r[cord][0],r[cord][1]
			for i in range(3):
				for j in range(3):
					HWMap[y-i+1][x-j+1] += 1
		for i in range(H-2):
			for j in range(W-2):
				points[HWMap[i+2][j+2]] += 1
		for i in range(len(points)):
			print points[i]

if __name__ == "__main__":
	H, W, N = map(int, raw_input().split())
	r = [[int(i) for i in raw_input().split()] for i in range(N)]
	s = nSnukes_Coloring()
	s.returnEachNumber(H,W,N,r)

Submission status: Time Limit Exceeded

Solution code:
class Snukes_Coloring:
	def returnEachNumber(self,H,W,N,r):
		HWMap = [[0 for i in range(W)] for j in range(H)]
		points = [0 for i in range(10)]
		for cord in range(len(r)):
			y,x = r[cord][0],r[cord][1]
			HWMap[y-1][x-1] = 1
		for tri_row in range(H-2):
			for tri_col in range(W-2):
				point = 0
				for base_row in range(3):
					for base_col in range(3):
						if HWMap[tri_row+base_row][tri_col+base_col] == 1:
							point += 1
				points[point] += 1
		for i in range(len(points)):
			print points[i]

if __name__ == "__main__":
	H, W, N = map(int, raw_input().split())
	r = [[int(i) for i in raw_input().split()] for i in range(N)]
	s = Snukes_Coloring()
	s.returnEachNumber(H,W,N,r)

Submission status: Time Limit Exceeded

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

    board = [[0 for i in range(W)] for j in range(H)]
    for x in a:
        board[x[0]-1][x[1]-1] = 1


    count = [0]*10
    for i in range(H-2):
        for j in range(W-2):
            x = sum(board[i][j:j+3]) + sum(board[i+1][j:j+3]) + sum(board[i+2][j:j+3])
            count[x] += 1

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

solve()

Submission status: Time Limit Exceeded

Solution code:
import collections


def read_nums():
    return map(int, raw_input().split(' '))


H, W, N = read_nums()
As = [0 for _ in range(N)]
Bs = [0 for _ in range(N)]
vs = []
for i in range(-1, 2):
    for j in range(-1, 2):
        vs.append((i, j))

cnt = []
for i in range(N):
    a, b = read_nums()
    for v in vs:
        i, j = v
        x = a + i
        y = b + j
        if x >= 2 and x <= H-1 and y >= 2 and y <= W-1:
            cnt.append(x * W + y)
cnt = collections.Counter(cnt)
cnt2 = [0] * 10
cnt2[0] = (H - 2) * (W - 2)
for k, v in cnt.items():
    cnt2[v] += 1
    cnt2[0] -= 1
for c in cnt2:
    print c

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
def solve():
    H, W, N = list(map(int, input().split()))
    a = []
    for i in range(N):
        a.append(list(map(int, input().split())))

    board = np.zeros((H,W))
    for x in a:
        board[x[0]-1][x[1]-1] = 1


    count = [0]*10
    for i in range(H-2):
        for j in range(W-2):
            count[int( np.sum(board[i:i+3,j:j+3]) )] += 1

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

solve()

Submission status: Time Limit Exceeded

Solution code:
def read_nums():
    return map(int, raw_input().split(' '))


def is_in_the_map(x, y):
    return x < H-1 and x > 0 and y < W-1 and y > 0


def solve():
    res = [0 for _ in range(10)]
    for i in range(N):
        a = As[i]
        b = Bs[i]
        for j in [-1, 0, 1]:
            for k in [-1, 0, 1]:
                x_mid = a + j
                y_mid = b + k
                if not is_in_the_map(x_mid, y_mid) or memo[x_mid][y_mid] == 1:
                    continue
                memo[x_mid][y_mid] = 1
                count = 0
                for x_pad in [-1, 0, 1]:
                    for y_pad in [-1, 0, 1]:
                        x = x_mid + x_pad
                        y = y_mid + y_pad
                        if Map[x][y] == 1:
                            count += 1
                res[count] += 1
    res[0] = (H-2) * (W-2) - sum(res)
    return res


H, W, N = read_nums()
As = [0 for _ in range(N)]
Bs = [0 for _ in range(N)]
Map = [[0 for _ in range(W)] for _ in range(H)]
for i in range(N):
    a, b = read_nums()
    As[i] = a - 1
    Bs[i] = b - 1
    Map[a - 1][b - 1] = 1
memo = [[0 for _ in range(W)] for _ in range(H)]
res = solve()
for i in res:
    print i

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
import sys
import io
import re
import math
import itertools
import collections
import bisect
#sys.stdin=file('input.txt')
#sys.stdout=file('output.txt','w')
#10**9+7
mod=1000000007
#mod=1777777777
pi=3.141592653589
IS=float('inf')
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
def niten(a,b): return abs(a-b) if a>=0 and b>=0 else  a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b))
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)
def euclid_dis(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5
def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0

#n=int(raw_input())
h,w,n=map(int,raw_input().split())
ans=[0]*10
b=[[0 for i in range(w)] for j in range(h)]
for i in range(n):
    y,x=map(int,raw_input().split())
    b[y-1][x-1]=1
for i in range(h-2):
    for j in range(w-2):
        tmp=(b[i][j]+b[i+1][j]+b[i+2][j]+b[i][j+1]+b[i+1][j+1]+b[i+2][j+1]+b[i][j+2]+b[i+1][j+2]+b[i+2][j+2])
        ans[tmp]+=1
for i in ans:
    print i

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

def inside(x, y):    
    return 0 <= x <= h - 3 and 0 <= y <= w - 3

h, w, n = (int(_) for _ in input().split())
black = defaultdict(int)
for i in range(n):
    a, b = (int(_) - 1 for _ in input().split())
    for j in range(3):
        for k in range(3):
            x, y = a - j, b - k
            if not inside(x, y):
                continue
            black[(x, y)] += 1
ans = [0 for i in range(10)]
ans[0] = (h-2)*(w-2) - len(black)
for k in black:
    ans[black[k]] += 1
for i in range(10):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
H, W, N = map(int, raw_input().split())

board = np.zeros((H, W))
for _ in xrange(N):
    a, b = map(int, raw_input().split())
    board[a - 1, b - 1] = 1

hist = np.zeros(10, dtype=np.int)
for row in xrange(H - 2):
    for col in xrange(W - 2):
        patch = board[row:row + 3, col:col + 3]
        hist[patch.sum()] += 1

for i in xrange(10):
    print hist[i]

Submission status: Time Limit Exceeded

Solution code:
def read_nums():
    return map(int, raw_input().split(' '))


def solve(H,W, Map):
    res = [0 for _ in range(10)]
    for x in range(1, H-1):
        for y in range(1, W-1):
            count = 0
            for i in range(-1, 2):
                for j in range(-1, 2):
                    if Map[x+i][y+j] == 1:
                        count += 1
            res[count] += 1
    return res


H, W, N = read_nums()
As = []
Bs = []
Map = [[0 for _ in range(W)] for _ in range(H)]
for i in range(N):
    a, b = read_nums()
    Map[a-1][b-1] = 1
res = solve(H, W, Map)
for i in res:
    print i

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Here your code !
def scan(sx, sy, mp):
    cnt = 0
    for y in range(sy, sy + 3):
        for x in range(sx, sx + 3):
            if mp[y][x] == 1:
                cnt += 1
    return cnt

H, W, N = map(int, input().split())
mp = [[0 for i in range(W)] for j in range(H)]

for i in range(N):
    a, b = map(int, input().split())
    mp[a-1][b-1] = 1
ans_list = [0 for i in range(10)]

sx = 0
sy = 0
for y in range(H-2):
    for x in range(W-2):
        sx = x
        sy = y
        cnt = scan(sx, sy, mp)
        ans_list[cnt] += 1
for i in ans_list:
    print(i)

Submission status: Time Limit Exceeded

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

cs = [[0 for i in range(W)] for j in range(H)]
for tup in ab:
	a = tup[0]
	b = tup[1]
	cs[a-1][b-1] = 1

for j in range(10):
	a = 0
	for k in range(H-2):
		for l in range(W-2):
			if cs[k][l] + cs[k][l+1] + cs[k][l+2] + cs[k+1][l] + cs[k+1][l+1] + cs[k+1][l+2] + cs[k+2][l] + cs[k+2][l+1] + cs[k+2][l+2] == j:
				a += 1
	print(a)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
h, w, n = [int(i) for i in input().split()]
cnt = Counter()

vs = []
for i in range(-1, 2):
	for j in range(-1, 2):
		vs.append((i,j))

for _ in range(n):
	a, b = [int(i) for i in input().split()]
	for v in vs:
		aa = a + v[0]
		bb = b + v[1]
		if 2<=aa<=h-1 and 2<=bb<=w-1:
			cnt.update([(aa, bb)])


cnt2 = [0] * 10
cnt2[0] = (h-2)*(w-2)
for k in cnt:
	c = cnt[k]
	cnt2[c] += 1
	cnt2[0] -= 1

for i in cnt2:
	print(i)

Submission status: Time Limit Exceeded

Solution code:
H, W, N = input().split()
ba = []
for i in range(int(N)):
    ba.append(list(map(int,input().split())))
# print(ba)
dic = {1:0,
       2:0,
       3:0,
       4:0,
       5:0,
       6:0,
       7:0,
       8:0,
       9:0,
       0:0 }
for h in range(int(H)-2):
    for w in range(int(W)-2):
        tmp = 0
        # print("h,w")
        # print(h)
        # print(w)
        for i in range(1,4):
            for j in range(1,4):
                # print([h+i,w+j])
                if([h+i,w+j] in ba):
                    # print(" ")
                    tmp+=1
        # print(tmp)
        dic[tmp] += 1
for i in range(10):
    print(dic[i])