#include <bits/stdc++.h>
using namespace std;
int cnt, n, lim, bc[1 << 19];
long long f[1 << 19][19], F[19][1 << 19], I[1 << 19];
long long ans[1 << 19], t[1 << 19], res[1 << 19];
char G[25][25];
vector<int> num[450], now;
map<vector<int>, int> id;
inline void FWTOR(long long *a, int type) {
  for (int mid = 1; mid < lim; mid <<= 1)
    for (int i = 0; i < lim; i += (mid << 1))
      for (int j = 0; j < mid; j++) a[i + mid + j] += type * a[i + j];
}
inline void dfs(int sum, int last) {
  if (sum == n) {
    id[now] = ++cnt;
    num[cnt] = now;
    return;
  }
  for (int i = last; i <= n - sum; i++)
    now.push_back(i), dfs(sum + i, i), now.pop_back();
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", G[i] + 1);
  lim = (1 << n);
  for (int s = 0; s < lim; s++) bc[s] = bc[s >> 1] + (s & 1);
  for (int i = 1; i <= n; i++) f[1 << i - 1][i] = 1;
  for (int s = 1; s < lim; s++)
    for (int i = 1; i <= n; i++) {
      if (!(s & (1 << i - 1)) || !f[s][i]) continue;
      for (int j = 1; j <= n; j++) {
        if ((s & (1 << j - 1)) || G[i][j] == '0') continue;
        f[s | (1 << j - 1)][j] += f[s][i];
      }
      F[bc[s]][s] += f[s][i];
    }
  for (int i = 1; i <= n; i++) FWTOR(F[i], 1);
  dfs(0, 1);
  I[0] = 1;
  FWTOR(I, 1);
  for (int k = 1; k <= cnt; k++) {
    memcpy(t, I, sizeof(I));
    for (int i = 0; i < num[k].size(); i++)
      for (int s = 0; s < lim; s++) t[s] *= F[num[k][i]][s];
    FWTOR(t, -1);
    res[k] = t[lim - 1];
  }
  lim = (1 << n - 1);
  for (int s = 0; s < lim; s++) {
    now.clear();
    for (int i = 0, j = 0; i < n; i = j + 1) {
      j = i;
      while (s & (1 << j)) j++;
      now.push_back(j - i + 1);
    }
    sort(now.begin(), now.end());
    ans[s] = res[id[now]];
  }
  for (int j = 0; j < n - 1; j++)
    for (int i = 0; i < lim; i++)
      if (!(i & (1 << j))) ans[i] -= ans[i | (1 << j)];
  for (int s = 0; s < lim; s++) printf("%lld ", ans[s]);
  return 0;
}
