#include <bits/stdc++.h>
using namespace std;
int n, a[2002][2002], u[2002][2002], cnt1, cnt2, cnt;
pair<int, int> Maxx, Maxy, Minx, Miny;
inline void dfs(int i, int j) {
  u[i][j] = true;
  Minx = min(Minx, make_pair(i, j));
  Maxx = max(Maxx, make_pair(i, j));
  Miny = min(Miny, make_pair(j, i));
  Maxy = max(Maxy, make_pair(j, i));
  if (i > 1 && !u[i - 1][j] && a[i - 1][j]) dfs(i - 1, j);
  if (i < n && !u[i + 1][j] && a[i + 1][j]) dfs(i + 1, j);
  if (j > 1 && !u[i][j - 1] && a[i][j - 1]) dfs(i, j - 1);
  if (j < n && !u[i][j + 1] && a[i][j + 1]) dfs(i, j + 1);
}
int main() {
  scanf("%d", &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] && !u[i][j]) {
        Miny = make_pair(1e9, 1e9);
        Minx = Miny;
        Maxy = make_pair(0, 0);
        Maxx = Maxy;
        dfs(i, j);
        if (Minx.first == Miny.second && Miny.first == Minx.second &&
            Maxx.first == Maxy.second && Maxx.second == Maxy.first)
          cnt2++;
        else
          cnt1++;
      }
    }
  }
  printf("%d %d", cnt1, cnt2);
  return 0;
}
