#include <bits/stdc++.h>
using namespace std;
const int MAXN = 20;
const int MAXS = 524288;
int n, mS, tot;
char s[MAXN][MAXN];
int G[MAXN][MAXN];
inline void FWT_or(long long *F, int t) {
  for (int j = 0; j < n; ++j) {
    for (int S = 0; S < mS; ++S) {
      if (S >> j & 1) {
        F[S] = F[S] + 1ll * F[S ^ (1 << j)] * t;
      }
    }
  }
  return;
}
long long f[MAXS][MAXN];
long long g[MAXN][MAXS];
inline void init() {
  for (int i = 0; i < n; ++i) f[1 << i][i] = 1;
  for (int S = 0; S < mS; ++S) {
    int qwq = 0;
    for (int j = 0; j < n; ++j) {
      if (!(S >> j & 1)) continue;
      for (int p = 0; p < n; ++p) {
        if (S >> p & 1) continue;
        if (!G[j][p]) continue;
        f[S ^ (1 << p)][p] += f[S][j];
      }
      qwq++;
    }
    for (int i = 0; i < n; ++i) {
      if (S >> i & 1) {
        g[qwq][S] += f[S][i];
      }
    }
  }
  for (int i = 0; i <= n; ++i) FWT_or(g[i], 1);
  return;
}
vector<int> rc[MAXN];
vector<int> v;
map<vector<int>, int> mp;
inline void dfs(int u, int B) {
  if (u == n) {
    mp[v] = ++tot;
    rc[tot] = v;
    return;
  }
  for (int i = B; i <= n - u; ++i) {
    v.push_back(i);
    dfs(u + i, i);
    v.pop_back();
  }
}
long long t[MAXS], ans[MAXS], a[MAXS];
inline void init2() {
  for (int i = 1; i <= tot; ++i) {
    for (int S = 0; S < mS; ++S) t[S] = 1;
    for (auto q : rc[i]) {
      for (int S = 0; S < mS; ++S) {
        t[S] = t[S] * g[q][S];
      }
    }
    FWT_or(t, -1);
    ans[i] = t[mS - 1];
  }
  return;
}
inline void getans() {
  for (int S = 0; S < mS; ++S) {
    v.clear();
    int lst = 1;
    for (int i = 0; i < n - 1; ++i) {
      if (S >> i & 1) {
        lst++;
      } else {
        if (lst) v.push_back(lst);
        lst = 1;
      }
    }
    v.push_back(lst);
    sort(v.begin(), v.end());
    a[S] = ans[mp[v]];
  }
  return;
}
int main() {
  scanf("%d", &n);
  mS = (1 << n);
  for (int i = 0; i < n; ++i) scanf("%s", s[i]);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) G[i][j] = s[i][j] - '0';
  init();
  dfs(0, 1);
  init2();
  getans();
  mS = (1 << n - 1);
  --n;
  for (int j = 0; j < n; ++j) {
    for (int S = mS - 1; S >= 0; --S)
      if (!(S >> j & 1)) a[S] = a[S] - a[S | (1 << j)];
  }
  for (int S = 0; S < mS; ++S) printf("%lld ", a[S]);
  puts("");
  return 0;
}
