#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000, inf = 0x3fffffff;
bool pic[maxn][maxn];
bool vis[maxn][maxn];
int n;
int mini, maxi, minj, maxj;
int di[] = {0, 1, 0, -1};
int dj[] = {1, 0, -1, 0};
inline bool legal(int x) { return x >= 0 && x < n; }
void dfs(int i, int j) {
  mini = min(mini, i);
  maxi = max(maxi, i);
  minj = min(minj, j);
  maxj = max(maxj, j);
  vis[i][j] = true;
  for (int k = 0; k < (4); ++k) {
    int ni = i + di[k], nj = j + dj[k];
    if (legal(ni) && legal(nj) && !vis[ni][nj] && pic[ni][nj]) dfs(ni, nj);
  }
}
int sq = 0, cir = 0;
int main(void) {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (n); ++j) cin >> pic[i][j];
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (n); ++j)
      if (pic[i][j] && !vis[i][j]) {
        mini = maxi = i;
        minj = maxj = j;
        dfs(i, j);
        if (pic[mini][minj] && pic[maxi][maxj])
          ++sq;
        else
          ++cir;
      }
  cout << cir << ' ' << sq << endl;
  return 0;
}
