#include <bits/stdc++.h>
using namespace std;
const long long N = 550, mod = 998244353, inv2 = 499122177, g = 3;
long long mul[N], inv[N];
long long ksm(long long f, long long x) {
  long long tot = 1;
  while (x) {
    if (x & 1ll) tot = tot * f % mod;
    f = f * f % mod;
    x >>= 1ll;
  }
  return tot;
}
void pre() {
  long long lim = N - 5;
  mul[0] = inv[0] = 1;
  for (long long i = 1; i <= lim; i++) mul[i] = mul[i - 1] * i % mod;
  inv[lim] = ksm(mul[lim], mod - 2);
  for (long long i = lim - 1; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
}
namespace NTT {
void solve(long long* s, long long* f, long long* g, long long n, long long m) {
  long long A[N];
  for (long long i = 0; i <= n + m; i++) A[i] = 0;
  for (long long i = 0; i <= n; i++) {
    for (long long j = 0; j <= m; j++) {
      A[i + j] = (A[i + j] + 1ll * f[i] * g[j] % mod) % mod;
    }
  }
  for (long long i = 0; i <= n + m; i++) s[i] = A[i];
  return;
}
}  // namespace NTT
long long A(long long m, long long n) {
  if (n == 0) return 1;
  if (m == -1) return ksm(-1, n) * mul[n] % mod;
  if (m < n) return 0;
  return mul[m] * inv[m - n] % mod;
}
long long n;
long long p[N], q[N], mp[N];
long long cnt1, cnt2, cnt0, cntcir;
long long S[N][N], C[N][N], F[N], G[N], H[N];
bool vis[N];
int main() {
  pre();
  cin >> n;
  S[0][0] = C[0][0] = 1;
  for (long long i = 1; i <= n; i++) {
    C[i][0] = 1;
    for (long long j = 1; j <= i; j++) {
      S[i][j] = (S[i - 1][j - 1] + S[i - 1][j] * (i - 1) % mod) % mod;
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
    }
  }
  for (long long i = 1; i <= n; i++) cin >> p[i], mp[p[i]] = i;
  for (long long i = 1; i <= n; i++) cin >> q[i];
  for (long long i = 1; i <= n; i++) {
    if (!p[i]) {
      long long x = i;
      while (1) {
        vis[x] = 1;
        if (!q[x]) {
          cnt0++;
          break;
        }
        if (!mp[q[x]]) {
          cnt1++;
          break;
        }
        x = mp[q[x]];
      }
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (p[i] && !vis[i]) {
      long long x = i;
      while (1) {
        if (vis[x]) {
          if (x == i) cntcir++;
          break;
        }
        vis[x] = 1;
        if (!q[x]) {
          cnt2++;
          break;
        }
        if (!mp[q[x]]) break;
        x = mp[q[x]];
      }
    }
  }
  for (long long i = 0; i <= n; i++) {
    for (long long j = i; j <= cnt1; j++) {
      F[i] = (F[i] + C[cnt1][j] * S[j][i] % mod *
                         A(cnt0 + cnt1 - j - 1, cnt1 - j) % mod) %
             mod;
    }
  }
  for (long long i = 0; i <= n; i++) {
    for (long long j = i; j <= cnt2; j++) {
      G[i] = (G[i] + C[cnt2][j] * S[j][i] % mod *
                         A(cnt0 + cnt2 - j - 1, cnt2 - j) % mod) %
             mod;
    }
  }
  for (long long i = 0; i <= n; i++) {
    H[i] = S[cnt0][i] * mul[cnt0] % mod;
  }
  NTT::solve(F, F, G, n, n);
  NTT::solve(F, F, H, n, n);
  for (long long i = 0; i < n; i++) cout << F[n - cntcir - i] << " ";
}
