n = int(input())
mat = [list(map(int, input().split())) for _ in range(n)]
st = [[0] * n for _ in range(n)]
dxs, dys = [-1, -1, 0, 1, 1, 1, 0, -1], [0, -1, -1, -1, 0, 1, 1, 1]
def bfs(x, y):
has_higher = has_lower = False
que = [(x, y)]
hh = tt = 0
st[x][y] = True
while hh <= tt:
x, y = que[hh]
hh += 1
cv = mat[x][y]
for dx, dy in zip(dxs, dys):
nx, ny = x + dx, y + dy
if 0 <= nx < n and 0 <= ny < n:
nv = mat[nx][ny]
if nv != cv:
if nv > cv:
has_higher = True
else:
has_lower = True
elif not st[nx][ny]:
tt += 1
que.append((nx, ny))
st[nx][ny] = True
return has_higher, has_lower
def count():
peak = valley = 0
for i in range(n):
for j in range(n):
if not st[i][j]:
has_higher, has_lower = bfs(i, j)
if not has_higher: peak += 1
if not has_lower: valley += 1
print(peak, valley)
count()