#include <bits/stdc++.h>
const int N = 18, S = 1 << N, C = 400;
struct array {
  long long val;
  int a[N];
};
int n, s, cnt;
char mp[N + 1][N + 1];
long long h[S];
long long f[N][S];
long long g[N + 1][S], cur[N + 1][S];
array now;
array p[C];
bool cmp(const array &x, const array &y) {
  for (int i = 0; i != n; ++i) {
    if (x.a[i] != y.a[i]) {
      return x.a[i] < y.a[i];
    }
  }
  return false;
}
void dfs(const int &x, const int &l, const int &v) {
  if (!l) {
    for (int i = 0; i != x; ++i) p[cnt].a[i] = now.a[i];
    for (int i = 0; i != s; ++i) p[cnt].val += cur[x][i];
    ++cnt;
    return;
  }
  for (int i = v; i <= l; ++i) {
    now.a[x] = i;
    for (int j = 0; j != s; ++j) cur[x + 1][j] = cur[x][j] * g[i][j];
    dfs(x + 1, l - i, i);
  }
}
int main() {
  scanf("%d", &n);
  s = 1 << n;
  for (int i = 0; i != n; ++i) {
    scanf("%s", mp[i]);
    f[i][1 << i] = 1;
  }
  for (int i = 1; i != s; ++i) {
    int c = 0;
    for (int j = 0; j != n; ++j) {
      if (i >> j & 1) {
        ++c;
        for (int k = 0; k != n; ++k) {
          if ((~i >> k & 1) && mp[j][k] == '1') {
            f[k][i | 1 << k] += f[j][i];
          }
        }
      }
    }
    for (int j = 0; j != n; ++j) {
      if (i >> j & 1) {
        g[c][i] += f[j][i];
      }
    }
    cur[0][i] = (((n ^ c) & 1) ? -1 : 1);
  }
  for (int i = 0; i != n; ++i) {
    for (int j = 0; j != n; ++j) {
      for (int k = 0; k != s; ++k) {
        if (~k >> j & 1) {
          g[i][k | 1 << j] += g[i][k];
        }
      }
    }
  }
  dfs(0, n, 1);
  std::sort(p, p + cnt, cmp);
  for (int i = 0; i != (s >> 1); ++i) {
    int l = -1, c = 0;
    for (int j = 0; j != n - 1; ++j) {
      if (~i >> j & 1) {
        now.a[c++] = j - l;
        l = j;
      }
    }
    now.a[c++] = n - 1 - l;
    std::sort(now.a, now.a + c);
    while (c < n) now.a[c++] = 0;
    h[i] = std::lower_bound(p, p + cnt, now, cmp)->val;
  }
  for (int i = 0; i != n - 1; ++i) {
    for (int j = 0; j != (s >> 1); ++j) {
      if (~j >> i & 1) {
        h[j] -= h[j | 1 << i];
      }
    }
  }
  for (int i = 0; i != (s >> 1); ++i) {
    printf("%lld ", h[i]);
  }
  return 0;
}
