from collections import deque
grid = []
n = int(input())
for i in range(n):
grid.append(list(map(int, input().split())))
# 波峰返回1, 波谷返回-1, 既是波峰又是波谷返回2,其他返回0
def bfs(i, j) -> int:
que = deque()
que.append((i, j))
min_val, max_val = 0x7fffffff, -0x7fffffff
while len(que) > 0:
ii, jj = que.popleft()
for new_i, new_j in [ [ii-1, jj-1], [ii-1, jj], [ii-1, jj+1], [ii, jj-1], [ii, jj+1], [ii+1, jj-1], [ii+1, jj], [ii+1, jj+1]]:
if new_i < 0 or new_i >= n or new_j < 0 or new_j >= n:
continue
if grid[new_i][new_j] == grid[i][j]:
if visited[new_i][new_j] == 0:
#print(i, j, new_i, new_j)
visited[new_i][new_j] = 1
que.append((new_i, new_j))
else:
min_val = min(min_val, grid[new_i][new_j])
max_val = max(max_val, grid[new_i][new_j])
if max_val == -0x7fffffff and min_val == 0x7fffffff:
return 2
if max_val < grid[i][j]:
return 1
if min_val > grid[i][j]:
return -1
return 0
visited = [[0]*n for _ in range(n)]
ans1, ans2 = 0, 0
for i in range(n):
for j in range(n):
if visited[i][j] == 0:
val = bfs(i, j)
if val == -1:
ans2 += 1
elif val == 1:
ans1 += 1
elif val == 2:
ans1 += 1
ans2 += 1
print(ans1, ans2)