#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 7;
int n, c[N], p[N], f[N][N];
char s[N][N];
inline bool solve() {
  for (int i = 1; i <= n; i++) p[i] = c[i];
  sort(p + 1, p + n + 1);
  int sum = 0;
  for (int i = 1; i < n; i++) {
    sum += p[i];
    if (sum == i * (i - 1) / 2) return 0;
  }
  return 1;
}
inline void rev(int u) {
  for (int i = 1; i <= n; i++)
    c[i] -= f[i][u], c[u] -= f[u][i], swap(f[u][i], f[i][u]), c[i] += f[i][u],
        c[u] += f[u][i];
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) f[i][j] = s[i][j] - '0', c[i] += f[i][j];
  if (solve()) {
    cout << 0 << " " << 1 << endl;
    return 0;
  }
  if (n <= 6) {
    int ans = 114514, sum = 1919810;
    for (int i = 0; i < (1 << n); i++) {
      for (int x = 1; x <= n; x++)
        if ((1 << (x - 1)) & i) rev(x);
      if (solve()) {
        if (ans > __builtin_popcount(i)) ans = __builtin_popcount(i), sum = 0;
        if (ans == __builtin_popcount(i)) sum++;
      }
      for (int x = 1; x <= n; x++)
        if ((1 << (x - 1)) & i) rev(x);
    }
    if (ans == 114514) {
      puts("-1");
      return 0;
    }
    for (int i = 1; i <= ans; i++) sum *= i;
    cout << ans << " " << sum << endl;
    return 0;
  }
  int sum = 0;
  for (int x = 1; x <= n; x++) {
    rev(x);
    if (solve()) sum++;
    rev(x);
  }
  cout << 1 << " " << sum << endl;
  return 0;
}
