#include <bits/stdc++.h>
using namespace std;
int n;
int deg[2010];
int a[2010][2010];
void work(int u) {
  for (int v = 1; v <= n; v++)
    if (v != u) {
      if (a[u][v]) {
        deg[u]--;
        deg[v]++;
      } else {
        deg[u]++;
        deg[v]--;
      }
      swap(a[u][v], a[v][u]);
    }
  return;
}
int d[2010];
bool check() {
  for (int i = 1; i <= n; i++) d[i] = deg[i];
  sort(d + 1, d + n + 1);
  int sum = 0;
  for (int i = 1; i < n; i++) {
    sum += d[i];
    if (sum <= i * (i - 1) / 2) return false;
  }
  return true;
}
char st[2010];
void input() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", st + 1);
    for (int j = 1; j <= n; j++) {
      a[i][j] = st[j] - '0';
      deg[i] += a[i][j];
    }
  }
  return;
}
int ans, cnt;
void solve1() {
  ans = n + 1;
  cnt = 0;
  for (int s = 0; s < (1 << n); s++) {
    int num = 0;
    for (int i = 0; i < n; i++)
      if (s & (1 << i)) {
        num++;
        work(i + 1);
      }
    if (check()) {
      if (num < ans) {
        ans = num;
        cnt = 1;
      } else if (num == ans)
        cnt++;
    }
    for (int i = 0; i < n; i++)
      if (s & (1 << i)) work(i + 1);
  }
  return;
}
void solve2() {
  if (check()) {
    ans = 0;
    cnt = 1;
    return;
  }
  ans = 1;
  cnt = 0;
  for (int i = 1; i <= n; i++) {
    work(i);
    cnt += check();
    work(i);
  }
  return;
}
int main() {
  input();
  if (n <= 6)
    solve1();
  else
    solve2();
  if (ans > n)
    printf("-1\n");
  else {
    for (int i = 1; i <= ans; i++) cnt *= i;
    printf("%d %d\n", ans, cnt);
  }
  return 0;
}
