#include <bits/stdc++.h>
using namespace std;
const int N = 2020;
int n, Edge[N][N], deg[N], tmp[N], cnt, Min = 7;
char s[N];
bool Check() {
  for (int i = 1; i <= n; ++i) tmp[i] = deg[i];
  sort(tmp + 1, tmp + 1 + n);
  int sum = 0;
  for (int i = 1; i < n; ++i) {
    sum += tmp[i];
    if (sum == i * (i - 1) / 2) return false;
  }
  return true;
}
int rev(int x) {
  deg[x] = n - 1 - deg[x];
  for (int i = 1; i <= n; ++i) {
    if (i == x) continue;
    if (Edge[i][x])
      deg[i]--;
    else
      deg[i]++;
    Edge[i][x] ^= 1;
    Edge[x][i] ^= 1;
  }
}
void DFS(int now, int c) {
  if (c > Min) return;
  if (now == n + 1) {
    if (Check()) {
      Min = c;
      cnt++;
    }
    return;
  }
  DFS(now + 1, c);
  rev(now);
  DFS(now + 1, c + 1);
  rev(now);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s + 1);
    for (int j = 1; j <= n; ++j) Edge[i][j] = s[j] - '0', deg[i] += Edge[i][j];
  }
  if (Check()) return 0 * puts("0 1");
  for (int i = 1; i <= n; ++i) {
    rev(i);
    cnt += Check();
    rev(i);
  }
  if (cnt) return 0 * printf("1 %d\n", cnt);
  DFS(1, 0);
  if (!cnt) return 0 * puts("-1");
  for (int i = 1; i <= Min; ++i) cnt = (1LL * cnt * i) % 998244353;
  printf("%d %d\n", Min, cnt);
  return 0;
}
