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;
using ll = long long;
bool ck(vector<int> &degs, vector<int> &vals, int size) {
  sort(degs.begin(), degs.end());
  reverse(degs.begin(), degs.end());
  int sum = 0;
  for (int i = 0; i < size - 1; i++) {
    sum += degs[i];
    if (sum >= vals[i]) {
      return false;
    }
  }
  return true;
}
bool check(vector<vector<int>> &matr, int size) {
  vector<int> degs(size), vals(size);
  for (int i = 0; i < size; i++) {
    vals[i] = (i + 1) * (size - i - 1) + (i * (i + 1)) / 2;
  }
  for (int i = 0; i < size; i++) {
    for (int j = 0; j < size; j++) {
      if (matr[i][j] == 1) {
        degs[i]++;
      }
    }
  }
  for (int i = 0; i < size; i++) {
  }
  return ck(degs, vals, size);
}
int ibit(int mask, int i) { return (mask >> i) % 2; }
pair<int, int> ans(vector<int> &trs, vector<vector<int>> &bs) {
  for (int i = 0; i < 20; i++) {
    int val = 0;
    for (int j = 0; j < trs.size(); j++) {
      int jj = trs[j];
      if (bs[jj].size() == i) {
        val++;
      }
    }
    if (val > 0) {
      return make_pair(i, val);
    }
  }
  return make_pair(-1, -1);
}
int check_one(vector<vector<int>> &matr, int size) {
  vector<int> degs(size), vals(size);
  for (int i = 0; i < size; i++) {
    vals[i] = (i + 1) * (size - i - 1) + (i * (i + 1)) / 2;
  }
  for (int i = 0; i < size; i++) {
    for (int j = 0; j < size; j++) {
      if (matr[i][j] == 1) {
        degs[i]++;
      }
    }
  }
  int cur = 0;
  for (int i = 0; i < size; i++) {
    vector<int> degs1 = degs;
    for (int h = 0; h < size; h++) {
      if (h != i) {
        if (matr[h][i] == 0) {
          degs1[h]++;
          degs1[i]--;
        } else {
          degs1[h]--;
          degs1[i]++;
        }
      }
    }
    if (ck(degs1, vals, size)) {
      cur++;
    }
  }
  return cur;
}
ll facts[228];
void solve(istream &cin = std::cin, ostream &cout = std::cout) {
  facts[0] = 1;
  for (int i = 0; i < 100; i++) {
    facts[i + 1] = facts[i] * (i + 1);
    facts[i + 1] %= 998244353;
  }
  int n;
  cin >> n;
  vector<vector<int>> matr(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      char x;
      cin >> x;
      matr[i][j] = x - '0';
    }
  }
  if (n < 15) {
    vector<vector<int>> bs(1 << n);
    vector<int> trs;
    for (int mask = 0; mask < (1 << n); mask++) {
      for (int j = 0; j < n; j++) {
        if (ibit(mask, j) == 1) {
          bs[mask].push_back(j);
        }
      }
      vector<vector<int>> m1 = matr;
      for (int i = 0; i < bs[mask].size(); i++) {
        int vl = bs[mask][i];
        for (int h = 0; h < n; h++) {
          if (h != vl) {
            m1[h][vl] ^= 1;
            m1[vl][h] ^= 1;
          }
        }
      }
      if (check(m1, n)) {
        trs.push_back(mask);
      }
    }
    pair<int, int> bv = ans(trs, bs);
    if (bv.first == -1) {
      cout << -1 << endl;
    } else {
      ll h = bv.second;
      h *= facts[bv.first];
      h %= 998244353;
      cout << bv.first << ' ' << h << endl;
    }
  } else {
    if (check(matr, n)) {
      cout << 0 << ' ' << 1 << endl;
    } else {
      cout << 1 << ' ' << check_one(matr, n) << endl;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed;
  solve();
  int n;
  cin >> n;
  return 0;
}