Problem: You are given a tournament — complete directed graph.

In one operation you can pick any vertex v and change the direction of all edges with v on one of the ends (i.e all edges u → v change their orientation to v → u and vice versa).

You want to make the tournament strongly connected with the smallest possible number of such operations if it is possible. 

Also, if it is possible, you need to find the number of ways to make this number of operations to make graph strongly connected (two ways are different if for some i vertex that we chose on i-th operation in one way is different from vertex that we chose on i-th operation in another way). You only need to find this value modulo 998 244 353.

Input

The first line of input contains one integer n (3 ≤ n ≤ 2000): the number of vertices in the tournament.

Following n lines contain a description of the given tournament, each of them contains a binary string of length n. If j-th character of i-th string is equal to '1', then the graph has an edge i → j.

It is guaranteed that there are no edges i → i and the graph has exactly one edge among i → j and j → i for different i and j.

Output

If it is not possible to convert tournament to strongly connected with the given operations, output "-1".

Otherwise, output two integers: the smallest number of operations that you need to make the given graph strongly connected and the number of ways to do this number of operations to make graph strongly connected, modulo 998 244 353.

Examples

Input


3
010
001
100


Output


0 1


Input


4
0010
1000
0100
1110


Output


-1


Input


6
010000
001000
100000
111001
111100
111010


Output


2 18

Solution (in CPP):

Solution:
#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;
}