#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
inline unsigned long long rnd() {
  return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;
}
const int N = 18;
vector<int> Q[400];
map<vector<int>, int> Map;
int tot, n, bit[1 << 18 | 2], q[20];
char e[20][20];
long long f[1 << (N - 1) | 2], jdb[400], dp[20][20], sum[20];
void dfs(int rest, int dq, vector<int> v) {
  if (!rest) {
    Q[++tot] = v;
    Map[v] = tot;
    return;
  }
  for (int i = (int)(dq); i <= (int)(rest); i++) {
    v.push_back(i);
    dfs(rest - i, i, v);
    v.pop_back();
  }
}
int main() {
  n = read();
  for (int i = (int)(0); i <= (int)(n - 1); i++) {
    scanf("%s", e[i]);
    for (int j = (int)(0); j <= (int)(n - 1); j++) e[i][j] -= '0';
  }
  vector<int> v;
  dfs(n, 1, v);
  memset((jdb), 0, sizeof(jdb));
  for (int i = (int)(0); i <= (int)((1 << n) - 1); i++) {
    bit[i] = bit[i >> 1] + (i & 1);
    memset((dp), 0, sizeof(dp));
    memset((sum), 0, sizeof(sum));
    int tt = 0;
    for (int j = (int)(0); j <= (int)(n - 1); j++)
      if (i >> j & 1) q[tt++] = j;
    for (int j = (int)(0); j <= (int)(tt - 1); j++) dp[0][j] = 1;
    for (int j = (int)(0); j <= (int)(n - 1); j++)
      for (int k = (int)(0); k <= (int)(tt - 1); k++)
        for (int l = (int)(0); l <= (int)(tt - 1); l++)
          if (e[q[k]][q[l]]) dp[j + 1][l] = dp[j + 1][l] + dp[j][k];
    for (int i = (int)(0); i <= (int)(n - 1); i++)
      for (int j = (int)(0); j <= (int)(tt - 1); j++) sum[i] += dp[i][j];
    for (int j = (int)(1); j <= (int)(tot); j++) {
      long long ans = 1;
      for (auto k : Q[j]) ans *= sum[k - 1];
      if ((n - bit[i]) & 1) ans = -ans;
      jdb[j] += ans;
    }
  }
  for (int i = (int)(0); i <= (int)((1 << (n - 1)) - 1); i++) {
    int dq = 1;
    vector<int> vv;
    for (int j = (int)(0); j <= (int)(n - 1); j++)
      if (i >> j & 1) {
        dq++;
      } else {
        vv.push_back(dq);
        dq = 1;
      }
    sort(vv.begin(), vv.end());
    f[i] = jdb[Map[vv]];
  }
  for (int i = (int)(0); i <= (int)(n - 2); i++)
    for (int j = (int)(0); j <= (int)((1 << (n - 1)) - 1); j++)
      if (j >> i & 1) f[j - (1 << i)] -= f[j];
  for (int i = (int)(0); i <= (int)((1 << (n - 1)) - 1); i++) wri(f[i]);
}
