#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
const int X[] = {-1, 1, 0, 0};
const int Y[] = {0, 0, -1, 1};
bool a[N][N], use[N][N];
int n, mxx, mxy, mnx, mny;
void dfs(int x, int y) {
  use[x][y] = true;
  mxx = max(mxx, x);
  mnx = min(mnx, x);
  mxy = max(mxy, y);
  mny = min(mny, y);
  for (int c = 0; c < 4; c++) {
    int nx = x + X[c];
    int ny = y + Y[c];
    if (nx >= 0 && nx < n && ny >= 0 && ny < n && !use[nx][ny] && a[nx][ny])
      dfs(nx, ny);
  }
}
int main() {
  cin >> n;
  int sq = 0, cir = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) scanf("%d", &a[i][j]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (a[i][j] && !use[i][j]) {
        mxx = mxy = -N;
        mnx = mny = N;
        dfs(i, j);
        bool all = true;
        for (int ki = mnx; ki <= mxx; ki++)
          for (int kj = mny; kj <= mxy; kj++) all &= a[ki][kj];
        if (all)
          sq++;
        else
          cir++;
      }
  cout << cir << " " << sq;
  return 0;
}
