#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
bool a[2010][2010];
int n;
int kp;
short x[4000010], y[4000010];
bool u[2010][2010];
void dfs(int cx, int cy) {
  x[kp] = cx;
  y[kp] = cy;
  u[cx][cy] = true;
  kp++;
  for (int q = 0; q < (int)(4); q++) {
    int nx = cx + dx[q];
    int ny = cy + dy[q];
    if (nx >= 0 && ny >= 0 && nx < n && ny < n)
      if (a[nx][ny] && !u[nx][ny]) dfs(nx, ny);
  }
}
int main() {
  scanf("%d", &n);
  int z;
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(n); j++) {
      scanf("%d", &z);
      a[i][j] = z;
    }
  int ci = 0, sq = 0;
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(n); j++)
      if (a[i][j] && !u[i][j]) {
        kp = 0;
        dfs(i, j);
        int minX = 3000, maxX = -1, minY = 3000, maxY = -1;
        for (int i = 0; i < (int)(kp); i++) {
          if (x[i] < minX) minX = x[i];
          if (y[i] < minY) minY = y[i];
          if (x[i] > maxX) maxX = x[i];
          if (y[i] > maxY) maxY = y[i];
        }
        if (a[minX][minY] + a[minX][maxY] + a[maxX][minY] + a[maxX][maxY] > 2)
          sq++;
        else
          ci++;
      }
  printf("%d %d\n", ci, sq);
  return 0;
}
