#include <bits/stdc++.h>
using namespace std;
const int N = 20;
const int M = 120000;
int n;
int m;
int tot;
long long I[M];
long long t[M];
long long ans[M];
long long f[M][N];
long long g[N][M];
long long res[N * N];
int know[N][N];
map<vector<int>, int> Id;
vector<int> part[N * N], now;
void fmt_or(long long *f, int g) {
  int i, j;
  for (i = 0; i < n; ++i)
    for (j = 0; j <= m; ++j)
      if (j >> i & 1) f[j] = f[j] + (long long)g * f[j ^ (1 << i)];
}
void fmt_and(long long *f, int g) {
  int i, j;
  for (i = 0; i < n; ++i)
    for (j = m; j >= 0; --j)
      if (~j >> i & 1) f[j] = f[j] + (long long)g * f[j | (1 << i)];
}
void dfs_part(int st, int big) {
  if (st == n + 1) return void(part[Id[now] = ++tot] = now);
  if (n - st + 1 >= big) {
    for (int i = big; i <= n - st + 1; ++i)
      now.push_back(i), dfs_part(st + i, i), now.pop_back();
  }
}
int main() {
  cin >> n;
  m = (1 << n) - 1;
  I[0] = 1;
  fmt_or(I, 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) scanf("%1d", &know[i][j]);
  for (int i = 0; i < n; ++i) f[1 << i][i + 1] = 1;
  for (int i = 1; i <= m; ++i) {
    int len = 0;
    for (int j = 1; j <= n; ++j) {
      if (1 << (j - 1) & ~i) continue;
      for (int k = 1; k <= n; ++k) {
        if (!know[j][k]) continue;
        if (1 << (k - 1) & i) continue;
        f[i | (1 << (k - 1))][k] += f[i][j];
      }
      ++len;
    }
    for (int j = 1; j <= n; ++j)
      if (1 << (j - 1) & i) g[len][i] += f[i][j];
  }
  for (int i = 1; i <= n; ++i) fmt_or(g[i], 1);
  dfs_part(1, 1);
  for (int i = 1; i <= tot; ++i) {
    memcpy(t, I, sizeof(I));
    int o = (int)part[i].size();
    for (int j = 0; j < o; ++j)
      for (int k = 0; k <= m; ++k) t[k] *= g[part[i][j]][k];
    fmt_or(t, -1);
    res[i] = t[m];
  }
  for (int i = 0; i <= m; ++i) {
    now.clear();
    for (int l = 0, r; l < n; l = r + 1) {
      r = l;
      while ((1 << r) & i && r < n) ++r;
      now.push_back(r - l + 1);
    }
    sort(now.begin(), now.end());
    ans[i] = res[Id[now]];
  }
  ((m += 1) >>= 1) -= 1;
  fmt_and(ans, -1);
  for (int i = 0; i <= m; ++i) cout << ans[i] << " \n"[i == m];
  return 0;
}
