#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int dx[8] = {0, 0, -1, -1, -1, 1, 1, 1};
int dy[8] = {-1, 1, -1, 0, 1, -1, 0, 1};
bool vis[maxn][maxn];
int dit[maxn][maxn];
int ret0, ret1;
int lx, rx, cnt;
int n;
void init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &dit[i][j]);
}
void dfs(int x, int y) {
  if (x < 1 || x > n || y < 1 || y > n || !dit[x][y] || vis[x][y]) return;
  cnt++;
  if (x < lx) lx = x;
  if (x > rx) rx = x;
  vis[x][y] = 1;
  for (int i = 0; i < 8; i++) dfs(x + dx[i], y + dy[i]);
}
void work() {
  ret0 = ret1 = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (!vis[i][j] && dit[i][j]) {
        lx = n + 1;
        rx = 0;
        cnt = 0;
        dfs(i, j);
        if ((rx - lx + 1) * (rx - lx + 1) == cnt)
          ret1++;
        else
          ret0++;
      }
}
void print() { printf("%d %d\n", ret0, ret1); }
int main() {
  init();
  work();
  print();
  return 0;
}
