#include <bits/stdc++.h>
using namespace std;
const int N = 20;
const int M = (1 << 18) + 69;
int n, m, g[N][N];
vector<int> _partition;
map<vector<int>, long long> f;
long long dp[N][M], path[N][M], ans[M];
void backtrack(int rem = n, int last = 1) {
  if (!rem) {
    long long cur = 0;
    for (int mask = 0; mask < m; ++mask) {
      long long sup = 1;
      for (int x : _partition) sup *= path[x][mask];
      (__builtin_popcount(mask) & 1) ? cur -= sup : cur += sup;
    }
    f[_partition] = cur;
    return;
  }
  _partition.emplace_back(rem);
  backtrack(0, rem);
  _partition.pop_back();
  for (int i = last; i + i <= rem; ++i) {
    _partition.emplace_back(i);
    backtrack(rem - i, i);
    _partition.pop_back();
  }
}
int main() {
  cin >> n;
  m = 1 << n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < n; ++j) g[i][j] = s[j] - '0';
  }
  for (int mask = 1; mask < m; ++mask) {
    for (int i = 0; i < n; ++i)
      if (mask & 1 << i) {
        if (__builtin_popcount(mask) == 1) {
          dp[i][mask] = 1;
          continue;
        }
        for (int j = 0; j < n; ++j)
          if ((mask & 1 << j) and g[i][j]) {
            dp[i][mask] += dp[j][mask ^ 1 << i];
          }
      }
    int pop = __builtin_popcount(mask);
    for (int i = 0; i < n; ++i) path[pop][mask] += dp[i][mask];
  }
  for (int i = 1; i <= n; ++i) {
    reverse(path[i], path[i] + m);
    for (int j = 0; j < n; ++j) {
      for (int mask = 0; mask < m; ++mask) {
        if (~mask & 1 << j) path[i][mask] += path[i][mask ^ 1 << j];
      }
    }
  }
  backtrack();
  for (int mask = 0; mask < m >> 1; ++mask) {
    int last = 1;
    vector<int> cur;
    for (int i = 0; i < n - 1; ++i) {
      if (~mask & 1 << i) {
        cur.emplace_back(last);
        last = 1;
        continue;
      }
      ++last;
    }
    cur.emplace_back(last);
    sort(cur.begin(), cur.end());
    ans[mask] = f[cur];
  }
  for (int i = 0; i < n - 1; ++i) {
    for (int mask = 0; mask < m >> 1; ++mask) {
      if (~mask & 1 << i) ans[mask] = ans[mask ^ 1 << i] - ans[mask];
    }
  }
  for (int mask = 0; mask < m >> 1; ++mask) {
    if (__builtin_popcount(mask) & 1) ans[mask] = -ans[mask];
  }
  if (~n & 1)
    for (int mask = 0; mask < m >> 1; ++mask) ans[mask] = -ans[mask];
  for (int mask = 0; mask < m >> 1; ++mask) printf("%lld ", ans[mask]);
  cout << '\n';
  return 0;
}
