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;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
inline unsigned long long rnd() {
  return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;
}
const int N = 2005;
int n, cnt[1 << 6 | 2], d[N], e[N], ans[10], sum;
char ch[N];
bitset<N> s[N];
bool check(int *a) {
  static int jb[N];
  memset((jb), 0, sizeof(jb));
  for (int i = (int)(0); i <= (int)(n - 1); i++) jb[a[i]]++;
  int sum = 0, cnt = 0;
  for (int i = (int)(n); i >= (int)(0); i--) {
    for (int j = (int)(1); j <= (int)(jb[i]); j++) {
      sum += i;
      cnt++;
      if (cnt < n && sum == cnt * (cnt - 1) / 2 + cnt * (n - cnt)) return 0;
    }
  }
  return 1;
}
int main() {
  n = read();
  for (int i = (int)(0); i <= (int)(n - 1); i++) {
    scanf("%s", ch);
    for (int j = (int)(0); j <= (int)(n - 1); j++)
      d[i] += (s[i][j] = (ch[j] == '1'));
  }
  if (n <= 6) {
    for (int i = (int)(0); i <= (int)((1 << n) - 1); i++) {
      memset((d), 0, sizeof(d));
      cnt[i] = cnt[i >> 1] + (i & 1);
      for (int j = (int)(0); j <= (int)(n - 1); j++)
        for (int k = (int)(0); k <= (int)(n - 1); k++)
          d[j] += s[j][k] ^ (i >> j & 1) ^ (i >> k & 1);
      ans[cnt[i]] += check(d);
    }
    for (int i = (int)(0); i <= (int)(n); i++)
      if (ans[i]) {
        for (int j = (int)(1); j <= (int)(i); j++) ans[i] = ans[i] * j;
        cout << i << " " << ans[i] << endl;
        exit(0);
      }
    puts("-1");
  } else {
    if (check(d)) {
      puts("0 1");
      exit(0);
    }
    for (int i = (int)(0); i <= (int)(n - 1); i++) {
      memcpy(e, d, sizeof(d));
      for (int j = (int)(0); j <= (int)(n - 1); j++)
        if (s[j][i])
          e[j]--;
        else
          e[j]++;
      e[i] = n - 1 - d[i];
      sum += check(e);
    }
    cout << 1 << " " << sum << endl;
  }
}