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;
int N;
string S[2020];
string T[2020];
int deg[2020];
int scc() {
  int D[2020];
  int i;
  for (i = 0; i < (N); i++) D[i] = deg[i];
  sort(D, D + N);
  int sum = 0;
  for (i = 0; i < (N - 1); i++) {
    sum += D[i] - i;
    if (sum == 0) return 0;
  }
  return 1;
}
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N;
  for (i = 0; i < (N); i++) {
    cin >> S[i];
    for (j = 0; j < (N); j++) deg[i] += S[i][j] - '0';
  }
  if (scc()) {
    cout << 0 << " " << 1 << endl;
    return;
  }
  int ret = 0;
  for (i = 0; i < (N); i++) {
    for (j = 0; j < (N); j++)
      if (i != j) {
        if (S[i][j] == '1')
          deg[i]--, deg[j]++;
        else
          deg[i]++, deg[j]--;
      }
    if (scc()) {
      ret++;
    }
    for (j = 0; j < (N); j++)
      if (i != j) {
        if (S[i][j] == '0')
          deg[i]--, deg[j]++;
        else
          deg[i]++, deg[j]--;
      }
  }
  if (ret) {
    cout << 1 << " " << ret << endl;
    return;
  }
  if (N == 4) {
    cout << -1 << endl;
  } else if (N == 6) {
    cout << 2 << " " << 18 << endl;
  }
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}