#include <bits/stdc++.h>
using namespace std;
template <class T>
void write(T x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const int N = 18;
int n;
int a[N];
long long res[1 << N], mul[1 << N];
long long f[N][1 << N], dp[N + 1][1 << N];
map<vector<int>, vector<int>> remap;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    string inp;
    cin >> inp;
    for (int j = 0; j < n; j++) a[i] |= (inp[j] - '0') * (1 << j);
    f[i][1 << i] = 1;
  }
  for (int mask = 0; mask < (1 << n); mask++)
    for (int i = 0; i < n; i++)
      if (mask >> i & 1) {
        for (int j = 0; j < n; j++)
          if (!(mask >> j & 1) && (a[i] >> j & 1))
            f[j][mask | (1 << j)] += f[i][mask];
        dp[__builtin_popcount(mask)][mask] += f[i][mask];
      }
  for (int i = 0; i < n; i++)
    for (int mask = 0; mask < (1 << n); mask++)
      if (mask >> i & 1)
        for (int len = 1; len <= __builtin_popcount(mask); len++)
          dp[len][mask] += dp[len][mask ^ (1 << i)];
  for (int mask = 0; mask < (1 << n - 1); mask++) {
    int len = 1;
    vector<int> stat;
    for (int i = 0; i < n; i++)
      if (mask >> i & 1)
        len++;
      else
        stat.push_back(len), len = 1;
    if (len > 1) stat.push_back(len);
    sort(stat.begin(), stat.end());
    assert(accumulate(stat.begin(), stat.end(), 0) == n);
    remap[stat].push_back(mask);
  }
  for (auto it : remap) {
    fill(mul, mul + (1 << n), 1);
    for (int x : it.first)
      for (int mask = 0; mask < (1 << n); mask++) mul[mask] *= dp[x][mask];
    long long total = 0;
    for (int mask = 0; mask < (1 << n); mask++)
      total +=
          (__builtin_popcount(mask) % 2 ? -1 : 1) * mul[((1 << n) - 1) ^ mask];
    assert(total >= 0);
    for (int mask : it.second) res[mask] = total;
  }
  for (int i = 0; i < n - 1; i++)
    for (int mask = 0; mask < (1 << (n - 1)); mask++)
      if (!(mask >> i & 1)) res[mask] -= res[mask ^ (1 << i)];
  for (int i = 0; i < (1 << n - 1); i++) write(res[i]), putchar(' ');
}
