#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 18;
const long long mod = 998244353;
long long dp[N][18], val[N], ans[N], f[19][N], cur[19][N];
char s[20][20];
int n;
map<vector<int>, vector<int> > ok;
vector<int> g;
inline void dfs(int s, int x) {
  if (s == n) {
    int op = (1 << n) - 1;
    long long res = 0;
    for (int i = (0); i < (1 << n); ++i) {
      if (__builtin_popcount(i) & 1)
        res -= val[op ^ i];
      else
        res += val[op ^ i];
    }
    for (auto v : ok[g]) ans[v] += res;
  }
  for (int i = (0); i < (1 << n); ++i) cur[s][i] = val[i];
  for (int i = x; s + i <= n; ++i) {
    if (s + i != n && s + i + i > n) continue;
    for (int mask = (0); mask < (1 << n); ++mask) val[mask] *= f[i][mask];
    g.push_back(i);
    dfs(s + i, i);
    for (int mask = (0); mask < (1 << n); ++mask) val[mask] = cur[s][mask];
    g.pop_back();
  }
}
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) {
    scanf("%s", s[i]);
    for (int j = (0); j < (n); ++j) s[i][j] -= 48;
  }
  for (int mask = (0); mask < (1 << (n - 1)); ++mask) {
    vector<int> a;
    a.clear();
    int pos = 0, num = 0;
    while (pos < n - 1) {
      if ((mask >> pos) & 1)
        ++num;
      else
        a.push_back(num + 1), num = 0;
      ++pos;
    }
    a.push_back(num + 1);
    sort(a.begin(), a.end());
    ok[a].push_back(mask);
  }
  for (int i = (0); i < (n); ++i) dp[1 << i][i] = 1;
  for (int mask = (0); mask < (1 << n); ++mask) {
    for (int i = (0); i < (n); ++i) {
      if (mask & (1 << i)) {
        for (int j = (0); j < (n); ++j)
          if (((~mask >> j) & 1) && s[i][j])
            dp[mask | (1 << j)][j] += dp[mask][i];
      }
      f[__builtin_popcount(mask)][mask] += dp[mask][i];
    }
  }
  for (int len = (1); len < (n + 1); ++len) {
    for (int i = (0); i < (n); ++i) {
      for (int mask = (0); mask < (1 << n); ++mask) {
        if ((~mask >> i) & 1) f[len][mask | (1 << i)] += f[len][mask];
      }
    }
  }
  for (int i = (0); i < (1 << n); ++i) val[i] = 1;
  dfs(0, 1);
  for (int i = (0); i < (n - 1); ++i) {
    for (int mask = (0); mask < (1 << (n - 1)); ++mask) {
      if ((~mask >> i) & 1) ans[mask] -= ans[mask | (1 << i)];
    }
  }
  for (int i = (0); i < (1 << n - 1); ++i) printf("%lld ", ans[i]);
}
