#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int MN = 1 << 8;
int exp(int x, int n) {
  int ret = 1;
  while (n) {
    if (n & 1) ret = 1LL * ret * x % mod;
    x = 1LL * x * x % mod;
    n >>= 1;
  }
  return ret;
}
int inv(int x) { return exp(x, mod - 2); }
int fact[MN], invf[MN];
int comb(int n, int k) {
  return 1LL * fact[n] * invf[k] % mod * invf[n - k] % mod;
}
int fa[MN];
void init() {
  for (int i = 0; i < MN; i++) fa[i] = i;
}
int find(int u) {
  if (fa[u] == u)
    return u;
  else
    return fa[u] = find(fa[u]);
}
void mrg(int u, int v) {
  u = find(u);
  v = find(v);
  if (u == v) return;
  fa[v] = u;
}
int cc[MN][MN];
int dp(int n, int k) {
  int &ret = cc[n][k];
  if (ret != -1) return ret;
  if (k == 0) return ret = n == 0;
  ret = 0;
  for (int i = 1; i <= n; i++) {
    ret +=
        1LL * comb(n - 1, i - 1) * fact[i - 1] % mod * dp(n - i, k - 1) % mod;
    ret %= mod;
  }
  return ret;
}
int N;
int A[MN], B[MN], del[MN], chk[MN], tcnt[3], ans[MN];
int main() {
  fact[0] = 1;
  for (int i = 1; i < MN; i++) {
    fact[i] = 1LL * fact[i - 1] * i % mod;
  }
  for (int i = 0; i < MN; i++) {
    invf[i] = inv(fact[i]);
  }
  memset(cc, -1, sizeof(cc));
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    A[i]--;
  }
  for (int i = 0; i < N; i++) {
    scanf("%d", &B[i]);
    B[i]--;
  }
  int ccnt = 0;
  init();
  for (int i = 0; i < N; i++) {
    if (A[i] != -1 && B[i] != -1) {
      if (find(A[i]) == find(B[i])) {
        del[find(A[i])] = 1;
        ccnt++;
      } else
        mrg(A[i], B[i]);
    }
  }
  vector<int> V;
  for (int i = 0; i < N; i++)
    if (!del[i] && fa[i] == i) V.push_back(i);
  if (V.size() == 0) {
    for (int i = 0; i < N; i++) {
      printf("%d ", (N - i == ccnt));
    }
    return 0;
  }
  for (int i = 0; i < N; i++) {
    if (A[i] != -1 && B[i] == -1) {
      chk[find(A[i])] |= 1;
    }
    if (A[i] == -1 && B[i] != -1) {
      chk[find(B[i])] |= 2;
    }
  }
  for (int i = 0; i < V.size(); i++) {
    tcnt[chk[V[i]]]++;
  }
  for (int i = 1; i <= (int)V.size() - tcnt[3]; i++) {
    int tmp = 0;
    for (int j = 0; j <= min(tcnt[1], tcnt[2]); j++) {
      if (j % 2)
        tmp += mod - 1LL * comb(tcnt[1], j) * comb(tcnt[2], j) % mod * fact[j] %
                         mod * dp((int)V.size() - tcnt[3] - j, i) % mod;
      else
        tmp += 1LL * comb(tcnt[1], j) * comb(tcnt[2], j) % mod * fact[j] % mod *
               dp((int)V.size() - tcnt[3] - j, i) % mod;
      tmp %= mod;
    }
    ans[ccnt + i] = tmp;
  }
  for (int i = 0; i < N; i++) {
    printf("%d ", 1LL * ans[N - i] * fact[tcnt[0]] % mod);
  }
}
