#include <bits/stdc++.h>
using namespace std;
const int N = 18;
string s[N];
int sz[1 << N];
long long dp[1 << N][N], ct[N][1 << N], tmp[N + 1][1 << N], w[1 << N];
int n, len = 0;
vector<int> v;
map<vector<int>, long long> mp;
void calc_sum_over_subsets(long long a[1 << N]) {
  memset(tmp, 0, sizeof(tmp));
  for (int i = 0; i < (1 << n); i++) {
    tmp[0][i] = a[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < (1 << n); j++) {
      tmp[i + 1][j] = tmp[i][j];
      if ((j >> i) & 1) tmp[i + 1][j] += tmp[i][j ^ (1 << i)];
    }
  }
  for (int i = 0; i < (1 << n); i++) {
    a[i] = tmp[n][i];
  }
}
void rec(int rem, int k) {
  if (rem == 0) {
    long long ans = 0;
    for (int i = 1; i < (1 << n); i++) {
      long long cur = 1;
      for (int j = 0; j < v.size(); j++) {
        cur *= ct[v[j] - 1][i];
      }
      if ((n - sz[i]) & 1)
        ans -= cur;
      else
        ans += cur;
    }
    mp[v] = ans;
  } else {
    for (int i = 1; i <= min(rem, k); i++) {
      v.push_back(i);
      rec(rem - i, i);
      v.pop_back();
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    sz[1 << i] = 1;
  }
  for (int i = 1; i < (1 << n); i++) {
    sz[i] = sz[i & -i] + sz[i ^ (i & -i)];
  }
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < n; i++) {
    dp[1 << i][i] = 1;
  }
  for (int i = 1; i < (1 << n); i++) {
    for (int j = 0; j < n; j++) {
      if (dp[i][j]) {
        for (int k = 0; k < n; k++) {
          if (!((i >> k) & 1) && s[j][k] == '1') {
            dp[i | (1 << k)][k] += dp[i][j];
          }
        }
      }
    }
  }
  for (int i = 1; i < (1 << n); i++) {
    for (int j = 0; j < n; j++) {
      ct[sz[i] - 1][i] += dp[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    calc_sum_over_subsets(ct[i]);
  }
  rec(n, n);
  for (int i = 0; i < (1 << (n - 1)); i++) {
    vector<int> cur;
    int bl = 0;
    for (int j = 0; j < n; j++) {
      bl++;
      if (!((i >> j) & 1)) {
        cur.push_back(bl);
        bl = 0;
      }
    }
    sort(cur.rbegin(), cur.rend());
    if (sz[i] & 1)
      w[(1 << (n - 1)) - 1 - i] = mp[cur];
    else
      w[(1 << (n - 1)) - 1 - i] = -mp[cur];
  }
  calc_sum_over_subsets(w);
  for (int i = 0; i < (1 << (n - 1)); i++) {
    cout << abs(w[(1 << (n - 1)) - 1 - i]) << " ";
  }
  return 0;
}
