#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
string direc = "URDL";
const long long MOD2 = (long long)998244353 * (long long)998244353;
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  x += y;
  if (x >= mod) x -= mod;
  if (x < 0) x += mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
int mp[2035][2035], dg[2035], dgc[2035];
char s[2035];
bool ck() {
  int cnt = 0, ps = 0;
  for (int i = 0; i <= n; i++) {
    for (int(j) = 0; (j) < (int)(dgc[i]); (j)++) {
      cnt++;
      if (cnt == n) return 1;
      ps += i;
      if (ps == cnt * (cnt - 1) / 2) {
        return 0;
      }
    }
  }
  return 1;
}
void changeD(int x, int v) {
  dgc[dg[x]]--;
  dg[x] += v;
  dgc[dg[x]]++;
}
void rev(int x) {
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    if (x != i) {
      if (mp[i][x] == 1) {
        changeD(i, -1);
        changeD(x, 1);
      } else {
        changeD(i, 1);
        changeD(x, -1);
      }
      mp[i][x] ^= 1;
      mp[x][i] ^= 1;
    }
}
void fmain(int tid) {
  scanf("%d", &n);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    scanf("%s", s + 1);
    for (int(j) = 1; (j) <= (int)(n); (j)++) mp[i][j] = s[j] - '0';
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    for (int(j) = 1; (j) <= (int)(n); (j)++)
      if (mp[i][j] == 1) {
        dg[i]++;
      }
  for (int(i) = 1; (i) <= (int)(n); (i)++) dgc[dg[i]]++;
  if (ck()) {
    puts("0 1");
    return;
  }
  if (n > 6) {
    int cc = 0;
    for (int(i) = 1; (i) <= (int)(n); (i)++) {
      rev(i);
      if (ck()) cc++;
      rev(i);
    }
    printf("1 %d\n", cc);
    return;
  }
  int cc = (1 << 30), ans = 0;
  for (int i = 1; i < (1 << n); i++) {
    int tmp = 0;
    for (int(j) = 0; (j) < (int)(n); (j)++)
      if (i & (1 << j)) {
        tmp++;
        rev(j + 1);
      }
    if (ck()) {
      if (tmp < cc) {
        cc = tmp;
        ans = 1;
      } else if (tmp == cc)
        ans++;
    }
    for (int(j) = 0; (j) < (int)(n); (j)++)
      if (i & (1 << j)) {
        rev(j + 1);
      }
  }
  if (cc == (1 << 30)) et();
  for (int(i) = 1; (i) <= (int)(cc); (i)++) ans *= i;
  printf("%d %d\n", cc, ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
