#include <bits/stdc++.h>
using namespace std;
const int N = 18;
long long f[1 << N][N], g[N + 1][1 << N], ans[1 << N], m[1 << N];
char a[N][N];
int n;
long long solve(vector<int> &v, int x) {
  if (m[x] != -1) return m[x];
  long long r = 0;
  for (int i = 0; i < 1 << n; i++) {
    long long t = 1;
    for (int j : v) t *= g[j][i];
    if ((n - __builtin_popcount(i)) & 1)
      r -= t;
    else
      r += t;
  }
  return m[x] = r;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) f[1 << i][i] = 1;
  for (int i = 1; i < 1 << n; i++)
    for (int j = 0; j < n; j++)
      if (f[i][j]) {
        for (int k = 0; k < n; k++)
          if (!(i >> k & 1) && a[j][k] == '1') {
            f[i | (1 << k)][k] += f[i][j];
          }
        g[__builtin_popcount(i)][i] += f[i][j];
      }
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < 1 << n; k++)
        if (k >> j & 1) g[i][k] += g[i][k ^ (1 << j)];
  memset(m, -1, sizeof(m));
  for (int i = 0; i < 1 << (n - 1); i++) {
    int t = 1;
    vector<int> v;
    for (int j = 0; j < n; j++) {
      if (i >> j & 1)
        t++;
      else
        v.push_back(t), t = 1;
    }
    sort(v.begin(), v.end());
    int x = 0;
    for (int j : v) {
      x = x << 1 | 0;
      j--;
      while (j--) x = x << 1 | 1;
    }
    ans[i] = solve(v, x);
  }
  for (int i = 0; i < n - 1; i++)
    for (int j = 0; j < 1 << (n - 1); j++)
      if (!(j >> i & 1)) ans[j] -= ans[j | (1 << i)];
  for (int i = 0; i < 1 << (n - 1); i++) cout << ans[i] << ' ';
  cout << endl;
}
