"""
https://www.acmicpc.net/problem/1780
시작: 21.05.17 23:21
끝: 21.05.17 23:35
디버깅: 21.05.18 00:01
성공:
[아이디어]
이거야말로... 9개로 분할해서 9번 재귀 도는 문제다!!
[시간복잡도]
[실수]
[검색]
[개선/추가사항]
"""
global paper_count
global arr
paper_count : list = [0, 0, 0]
def solve(size: int, x: int, y: int) -> None:
global paper_count
global arr
first_num: int = arr[x][y]
if size == 1:
paper_count[first_num] += 1
return
all_same_num = True
i: int = 0
while all_same_num and i < size:
for j in range(size):
if (first_num != arr[x+i][y+j]):
all_same_num = False
break
i += 1
if all_same_num:
paper_count[first_num] += 1
return
else:
next_size = int(size/3)
solve(next_size, x, y)
solve(next_size, x + next_size, y)
solve(next_size, x + next_size * 2, y)
solve(next_size, x, y + next_size)
solve(next_size, x + next_size, y + next_size)
solve(next_size, x + next_size * 2, y + next_size)
solve(next_size, x, y + next_size * 2)
solve(next_size, x + next_size, y + next_size * 2)
solve(next_size, x + next_size * 2, y + next_size * 2)
import sys
input = sys.stdin.readline
N = int(input())
arr = [list(map(lambda x: int(x) + 1, input().split())) for _ in range(N)]
solve(N, 0, 0)
for answer in paper_count:
print(answer)