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>
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = false;
  while (!isdigit(c)) {
    if (c == '-') flag = true;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
  if (flag) x = -x;
}
using namespace std;
const int P = 998244353;
int n;
char s[2010][2010];
int outd[2010];
int h[2010];
inline bool cmp(const int x, const int y) { return outd[x] < outd[y]; }
inline bool check() {
  for (int i = 1; i <= n; ++i) h[i] = i;
  sort(h + 1, h + 1 + n, cmp);
  int cnt = 0;
  for (int i = 1; i < n; ++i) {
    cnt += outd[h[i]];
    if (cnt * 2 == i * (i - 1)) return false;
  }
  return true;
}
namespace jzpforce {
char str[22][22], bkups[22][22];
int bkupd[22], siz[2010];
inline void Cpy(int *a, int *b) {
  for (int i = 1; i <= n; ++i) a[i] = b[i];
}
inline void cg(int cur) {
  for (int i = 1; i <= n; ++i)
    if (i != cur) {
      if (str[cur][i] == '1')
        --outd[cur], ++outd[i], str[cur][i] = '0', str[i][cur] = '1';
      else
        ++outd[cur], --outd[i], str[cur][i] = '1', str[i][cur] = '0';
    }
}
int jie[8];
inline void sol() {
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      bkups[i][j] = str[i][j] = ::s[i][j];
    }
  }
  jie[0] = 1;
  for (int i = 1; i <= 6; ++i) jie[i] = jie[i - 1] * i;
  Cpy(bkupd, outd);
  int mn = n + 1, mncnt = -1;
  const int All = (1 << n) - 1;
  for (int s = 0; s <= All; ++s) {
    memcpy(str, bkups, sizeof(str));
    Cpy(outd, bkupd);
    if (s) siz[s] = siz[s >> 1] + (s & 1);
    for (int i = 0; i < n; ++i)
      if ((s >> i) & 1) {
        cg(i + 1);
      }
    if (check()) {
      if (siz[s] < mn)
        mn = siz[s], mncnt = jie[mn];
      else if (siz[s] == mn)
        mncnt += jie[mn];
    }
  }
  if (mncnt == -1)
    puts("-1");
  else
    printf("%d %d\n", mn, mncnt);
}
}  // namespace jzpforce
namespace jzpcheat {
int bkupd[2010];
inline void cg(int cur) {
  for (int i = 1; i <= n; ++i)
    if (i != cur) {
      if (s[cur][i] == '1')
        --outd[cur], ++outd[i];
      else
        ++outd[cur], --outd[i];
    }
}
inline void sol() {
  if (check()) return puts("0 1"), void();
  memcpy(bkupd, outd, sizeof(outd));
  int res = 0;
  for (int i = 1; i <= n; ++i) {
    memcpy(outd, bkupd, sizeof(bkupd));
    cg(i);
    if (check()) ++res;
  }
  printf("1 %d\n", res);
}
}  // namespace jzpcheat
int main() {
  read(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)
      if (s[i][j] == '1') ++outd[i];
  if (n <= 6)
    jzpforce::sol();
  else
    jzpcheat::sol();
  return 0;
}