#include <bits/stdc++.h>
const double eps = 1e-9;
const int oo = 1000000000;
const double E = 2.7182818284590452353602874713527;
const double pi = 3.1415926535897932384626433832795;
using namespace std;
int a[2005][2005], d[4000001][2], l[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main() {
  int n, a1 = 0, a2 = 0;
  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]) {
        int minx = i, maxx = i, miny = j, maxy = j, st = 1, en = 1;
        d[1][0] = i;
        d[1][1] = j;
        a[i][j] = 0;
        while (st <= en) {
          int x = d[st][0], y = d[st++][1];
          maxx = max(maxx, x);
          minx = min(minx, x);
          maxy = max(maxy, y);
          miny = min(miny, y);
          for (int k = 0; k < 4; k++)
            if (a[x + l[k][0]][y + l[k][1]]) {
              a[x + l[k][0]][y + l[k][1]] = 0;
              d[++en][0] = x + l[k][0];
              d[en][1] = y + l[k][1];
            }
        }
        if ((maxx - minx + 1) * (maxy - miny + 1) == en)
          a2++;
        else
          a1++;
      }
  cout << a1 << ' ' << a2 << endl;
  return 0;
}
