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 setmax(T& x, T y) {
  x = max(x, y);
}
template <typename T>
void setmin(T& x, T y) {
  x = min(x, y);
}
const double PI = acos(-1.0);
const int INF = 1e9 + 47;
const long long LINF = 1LL * INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int a[1 << 11][1 << 11];
int deg[1 << 11];
bool SCC(int n) {
  vector<int> tmp(n);
  for (int i = (0); i < (n); ++i) tmp[i] = deg[i];
  sort(tmp.begin(), tmp.end());
  int sum = 0;
  for (int k = (1); k < (n); ++k) {
    sum += tmp[k - 1];
    if (2 * sum == k * (k - 1)) return 0;
  }
  return 1;
}
const int MOD = 998244353;
int fact(int n) {
  if (!n) return 1;
  return (n * (long long)fact(n - 1)) % MOD;
}
int main() {
  int n;
  cin >> n;
  for (int i = (0); i < (n); ++i) {
    string s;
    cin >> s;
    for (int j = (0); j < (n); ++j) {
      a[i][j] = s[j] - '0';
    }
  }
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j) deg[i] += a[i][j];
  if (n < 10) {
    int cnt[10];
    memset(cnt, 0, sizeof(cnt));
    for (int mask = (0); mask < (1 << n); ++mask) {
      for (int i = (0); i < (n); ++i) {
        if (mask & (1 << i)) {
          for (int j = (0); j < (n); ++j) {
            deg[i] -= a[i][j];
            a[i][j] ^= 1;
            deg[i] += a[i][j];
            deg[j] -= a[j][i];
            a[j][i] ^= 1;
            deg[j] += a[j][i];
          }
        }
      }
      cnt[__builtin_popcount(mask)] += SCC(n);
      for (int i = (0); i < (n); ++i) {
        if (mask & (1 << i)) {
          for (int j = (0); j < (n); ++j) {
            deg[i] -= a[i][j];
            a[i][j] ^= 1;
            deg[i] += a[i][j];
            deg[j] -= a[j][i];
            a[j][i] ^= 1;
            deg[j] += a[j][i];
          }
        }
      }
    }
    for (int i = (0); i < (n); ++i) {
      if (cnt[i]) {
        cout << i << " " << (cnt[i] * (long long)fact(i)) % MOD << endl;
        return 0;
      }
    }
    cout << -1 << endl;
    return 0;
  }
  if (SCC(n)) {
    cout << "0 1" << endl;
    return 0;
  }
  int ans = 0;
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (n); ++j) {
      deg[i] -= a[i][j];
      a[i][j] ^= 1;
      deg[i] += a[i][j];
      deg[j] -= a[j][i];
      a[j][i] ^= 1;
      deg[j] += a[j][i];
    }
    ans += SCC(n);
    for (int j = (0); j < (n); ++j) {
      deg[i] -= a[i][j];
      a[i][j] ^= 1;
      deg[i] += a[i][j];
      deg[j] -= a[j][i];
      a[j][i] ^= 1;
      deg[j] += a[j][i];
    }
  }
  cout << 1 << " " << ans << endl;
  cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
  return 0;
}