#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
int n, a[2020][2020], square, circle, d[2020][2020];
void bfs(int x, int y) {
  int maxX = x, minX = x, maxY = y, minY = y, cnt = 1;
  queue<pair<int, int> > q;
  q.push(make_pair(x, y));
  d[x][y] = 1;
  while (!q.empty()) {
    pair<int, int> u = q.front();
    q.pop();
    x = u.first;
    y = u.second;
    for (int i = 0; i < 4; i++) {
      int xx = x + dx[i], yy = y + dy[i];
      if (xx && yy && xx <= n && yy <= n && a[xx][yy] && !d[xx][yy]) {
        d[xx][yy] = 1;
        cnt++;
        q.push(make_pair(xx, yy));
        minX = min(minX, xx);
        maxX = max(maxX, xx);
        minY = min(minY, yy);
        maxY = max(maxY, yy);
      }
    }
  }
  if (cnt == (maxX - minX + 1) * (maxY - minY + 1))
    square++;
  else
    circle++;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (a[i][j] && !d[i][j]) bfs(i, j);
  cout << circle << ' ' << square << endl;
}
