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>
#pragma comment(linker, "/STACK:1000000000")
#pragma GCC optimize("Ofast,no-stack-protector")
using namespace std;
const int maxn = 2001;
const int mag = 30;
int ed[2][maxn][maxn / mag + 1];
int n;
void change(int tp, int a, int b) { ed[tp][a][b / mag] ^= (1 << (b % mag)); }
void flip(int v) {
  for (int i = 0; i < n; i++) {
    if (v == i) {
      continue;
    }
    for (int j = 0; j < 2; j++) {
      change(j, i, v);
      change(j, v, i);
    }
  }
}
int used[maxn / mag + 1];
int fir[1 << 16];
void clear() {
  for (int i = 0; i < maxn / mag + 1; i++) {
    used[i] = (1 << mag) - 1;
  }
}
int gg = (1 << 16) - 1;
int ctz(int mask) {
  if (mask & gg) {
    return fir[mask & gg];
  }
  return 16 + fir[mask >> 16];
}
int dfs(int tp, int v) {
  used[v / mag] ^= (1 << (v % mag));
  int ans = 1;
  for (int i = 0; i <= n / mag; i++) {
    int mask = used[i] & ed[tp][v][i];
    if (mask == 0) {
      continue;
    }
    int u = i * mag + ctz(mask);
    ans += dfs(tp, u);
    i--;
  }
  return ans;
}
bool check() {
  clear();
  if (dfs(0, 0) == n) {
    clear();
    if (dfs(1, 0) == n) {
      return true;
    }
  }
  return false;
}
int ans, cnt = 0;
void build(int pos, int num) {
  if (num > ans) {
    return;
  }
  if (pos == n) {
    if (check()) {
      if (ans > num) {
        ans = num;
        cnt = 1;
      } else {
        cnt++;
      }
    }
  } else {
    build(pos + 1, num);
    flip(pos);
    build(pos + 1, num + 1);
    flip(pos);
  }
}
int main() {
  for (int i = 1; i < (1 << 16); i++) {
    if (i & 1) {
      fir[i] = 0;
    } else {
      fir[i] = fir[i >> 1] + 1;
    }
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    char c;
    for (int j = 0; j < n; j++) {
      scanf(" %c", &c);
      if (i != j) {
        if (c == '1') {
          change(0, i, j);
        } else {
          change(1, i, j);
        }
      }
    }
  }
  if (check()) {
    cout << "0 1\n";
    return 0;
  }
  ans = n;
  if (n <= 6) {
    build(0, 0);
    if (ans == n) {
      cout << -1 << '\n';
      return 0;
    }
    for (int i = 1; i <= ans; i++) {
      cnt *= i;
    }
    cout << ans << ' ' << cnt << '\n';
    return 0;
  }
  ans = 1;
  cnt = 0;
  for (int i = 0; i < n; i++) {
    flip(i);
    if (check()) {
      cnt++;
    }
    flip(i);
  }
  cout << ans << ' ' << cnt << '\n';
}