#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1, 0};
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
const int inf = 1 << 30;
const int N = 2001;
int x1, y1, x2, y2, cnt, i, j, sq, cr, n;
bool was[N][N], a[N][N];
void dfs(int i, int j) {
  was[i][j] = 1;
  cnt++;
  x1 = min(x1, i);
  y1 = min(y1, j);
  x2 = max(x2, i);
  y2 = max(y2, j);
  int pair<int, int>, jj, k;
  for (int k = 0; k < 8; k++) {
    pair<int, int> = i + dx[k];
    jj = j + dy[k];
    if (a[pair<int, int>][jj] == 1 && !was[pair<int, int>][jj])
      dfs(pair<int, int>, jj);
  }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) scanf("%d", &a[i][j]);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      if (!was[i][j] && a[i][j]) {
        x1 = y1 = inf;
        x2 = y2 = -inf;
        cnt = 0;
        dfs(i, j);
        if (cnt == (x2 - x1 + 1) * (y2 - y1 + 1))
          sq++;
        else
          cr++;
      }
  cout << cr << " " << sq;
  return 0;
}
