#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 18), M = 20;
int n, k, lim, ch[M], st[M], og[N][M];
long long ans[N], sum[N], g[M][N], p[M][N], dp[N][M];
bool fl[M][M];
char s[M];
inline void fwt(long long *s) {
  for (int d = 1; d < lim; d = d << 1)
    for (int i = 0, r = d << 1; i < lim; i += r)
      for (int j = 0; j < d; j++) {
        long long a = s[i + j], b = s[i + j + d];
        s[i + j] = a, s[i + j + d] = a + b;
      }
}
inline void dfs(int u, int c) {
  if (ch[0] == n) {
    for (int i = 0; i < lim; i++)
      if (__builtin_popcount(i) % 2 == n % 2)
        sum[c] += p[u - 1][i];
      else
        sum[c] -= p[u - 1][i];
    return;
  }
  for (int i = max(ch[u - 1], 1); i + ch[0] <= n; i++) {
    for (int x = 0; x < lim; x++) p[u][x] = p[u - 1][x] * g[i][x];
    ch[0] += i, ch[u] = i, dfs(u + 1, og[c][i] = ++k), ch[0] -= i;
  }
}
int main() {
  cin >> n, lim = (1 << n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    dp[(1 << (i - 1))][i] = 1;
    for (int j = 1; j <= n; j++) fl[i][j] = s[j] - 48;
  }
  for (int i = 1; i < (1 << n); i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++)
        if (((1 << (j - 1)) & i) && (!((1 << (k - 1)) & i)) && fl[j][k])
          dp[i | (1 << (k - 1))][k] += dp[i][j];
  for (int i = 1; i < (1 << n); i++)
    for (int j = 1; j <= n; j++) g[__builtin_popcount(i)][i] += dp[i][j];
  g[0][0] = 1;
  for (int i = 0; i <= n; i++) fwt(g[i]);
  for (int i = 0; i < lim; i++) p[0][i] = g[0][i];
  dfs(1, 0);
  for (int i = 0; i < (1 << (n - 1)); i++) {
    int x = 1;
    st[0] = 0;
    for (int j = 1; j < n; j++)
      if (i & (1 << (j - 1)))
        x++;
      else
        st[++st[0]] = x, x = 1;
    st[++st[0]] = x;
    sort(st + 1, st + st[0] + 1);
    int u = 0;
    for (int j = 1; j <= st[0]; j++) u = og[u][st[j]];
    ans[i] = sum[u];
  }
  for (int i = 0; i < n - 1; ++i)
    for (int j = 0; j < 1 << (n - 1); ++j)
      if (j >> i & 1) ans[j - (1 << i)] -= ans[j];
  for (int i = 0; i < 1 << (n - 1); ++i) printf("%lld ", ans[i]);
  return 0;
}
