#include <bits/stdc++.h>
using namespace std;
int mnI, mnJ, mxI, mxJ, a[3000][3000], used[3000][3000], n;
void Dfs(int i, int j) {
  if (used[i][j]) return;
  if (a[i][j] == 0) return;
  used[i][j] = true;
  mxI = max(mxI, i);
  mnI = min(mnI, i);
  mxJ = max(mxJ, j);
  mnJ = min(mnJ, j);
  if (i - 1 >= 0) Dfs(i - 1, j);
  if (i + 1 < n) Dfs(i + 1, j);
  if (j - 1 >= 0) Dfs(i, j - 1);
  if (j + 1 < n) Dfs(i, j + 1);
}
int main() {
  scanf("%d\n", &n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) scanf("%d", &a[i][j]);
  }
  int rec = 0, cir = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (!used[i][j] && a[i][j] == 1) {
        mnI = mnJ = (1 << 30);
        mxI = mxJ = -(1 << 30);
        Dfs(i, j);
        bool ok = true;
        for (int x = mnI; ok && x <= mxI; ++x)
          for (int y = mnJ; ok && y <= mxJ; ++y)
            if (a[x][y] != 1) ok = false;
        if (ok)
          rec++;
        else
          cir++;
      }
  cout << cir << " " << rec << endl;
  return 0;
}
