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;
const int MAXN = 2010;
class SCC {
 public:
  SCC(int _n) : n(_n), x(_n), y(_n) {}
  void AddEdge(int a, int b) {
    x[a].push_back(b);
    y[b].push_back(a);
  }
  void FDfs(int a, int& cnt, vector<bool>& z) {
    z[a] = true;
    for (int i : x[a]) {
      if (!z[i]) FDfs(i, cnt, z);
    }
    list[--cnt] = a;
  }
  void RDfs(int a, vector<bool>& z, vector<int>& ans) {
    z[a] = true;
    ans.push_back(a);
    for (int i : y[a]) {
      if (!z[i]) RDfs(i, z, ans);
    }
  }
  vector<vector<int>> GetScc() {
    list = vector<int>(n);
    vector<bool> z(n);
    int cnt = n;
    for (int i = 0; i < n; ++i) {
      if (!z[i]) FDfs(i, cnt, z);
    }
    z = vector<bool>(n);
    vector<vector<int>> ans;
    for (int i = 0; i < n; ++i) {
      if (!z[list[i]]) {
        vector<int> temp;
        RDfs(list[i], z, temp);
        ans.push_back(temp);
      }
    }
    return ans;
  }
  int n;
  vector<vector<int>> x;
  vector<vector<int>> y;
  vector<int> list;
};
SCC BuildScc(const vector<vector<bool>>& f) {
  int n = f.size();
  SCC scc(n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (f[i][j]) scc.AddEdge(i, j);
    }
  }
  return scc;
}
bool Check(SCC& scc) { return scc.GetScc().size() == 1; }
void Reverse(vector<vector<bool>>& f, vector<int>& out, int a, int n) {
  for (int i = 0; i < n; ++i) {
    swap(f[i][a], f[a][i]);
    if (f[i][a]) {
      ++out[i];
      --out[a];
    } else {
      ++out[a];
      --out[i];
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<bool>> f(n, vector<bool>(n));
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < n; ++j) {
      if (s[j] == '1') f[i][j] = true;
    }
  }
  SCC scc = BuildScc(f);
  if (Check(scc)) {
    cout << "0 1" << endl;
    return 0;
  }
  if (n <= 6) {
    vector<set<vector<int>>> cnt(7);
    vector<int> x;
    for (int i = 0; i < n; ++i) x.push_back(i);
    do {
      auto g = f;
      vector<int> change;
      for (int i : x) {
        change.push_back(i);
        for (int j = 0; j < n; ++j) {
          g[i][j] = !g[i][j];
          g[j][i] = !g[j][i];
        }
        scc = BuildScc(g);
        if (Check(scc)) {
          cnt[change.size()].insert(change);
          break;
        }
      }
    } while (next_permutation(x.begin(), x.end()));
    for (int i = 1; i <= n; ++i) {
      if (cnt[i].size() > 0) {
        cout << i << " " << cnt[i].size() << endl;
        return 0;
      }
    }
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  vector<int> out(n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (f[i][j]) ++out[i];
    }
  }
  for (int i = 0; i < n; ++i) {
    Reverse(f, out, i, n);
    vector<int> cnt(n);
    for (int j = 0; j < n; ++j) ++cnt[out[j]];
    int sum = 0, cc = 0;
    bool flag = true;
    for (int j = n - 1; j >= 0; --j) {
      if (!flag) break;
      for (int k = 0; k < cnt[j]; ++k) {
        ++cc;
        if (cc == n) break;
        sum += j;
        if ((cc - 1) * cc / 2 + cc * (n - cc) == sum) {
          flag = false;
          break;
        }
      }
    }
    if (flag) ++ans;
    Reverse(f, out, i, n);
  }
  cout << 1 << " " << ans << endl;
  return 0;
}