#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
int n, deg[N], a[N];
bool ed[N][N];
void change(int u) {
  for (int v = 0; v < n; v++) {
    deg[u] -= ed[u][v], deg[u] += ed[u][v] ^= true;
    deg[v] -= ed[v][u], deg[v] += ed[v][u] ^= true;
  }
}
bool check() {
  copy(deg, deg + n, a);
  sort(a, a + n, greater<int>());
  for (int i = 1, sum = a[0]; i < n; sum += a[i++])
    if (sum == i * (i - 1) / 2 + i * (n - i)) return false;
  return true;
}
void read_input() {
  cin >> n;
  for (int u = 0; u < n; u++)
    for (int v = 0; v < n; v++) {
      char c;
      cin >> c;
      deg[u] += ed[u][v] = c - '0';
    }
}
void solve() {
  if (check()) {
    cout << "0 1";
    return;
  }
  int ans = n, ted = 0;
  for (int u = 0; u < n; change(u++)) change(u), ted += check();
  if (ted) {
    cout << "1 " << ted;
    return;
  }
  for (int msk = 0; msk < 1 << n; msk++) {
    for (int u = 0; u < n; u++)
      if (msk >> u & 1) change(u);
    if (check()) {
      int k = __builtin_popcount(msk);
      k < ans ? ans = k, ted = 1 : ted += k == ans;
    }
    for (int u = 0; u < n; u++)
      if (msk >> u & 1) change(u);
  }
  if (ans < n) {
    for (int i = ans; i; i--) ted *= i;
    cout << ans << ' ' << ted;
    return;
  }
  cout << -1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  read_input(), solve();
  return 0;
}
