#include <bits/stdc++.h>
using namespace std;
const long long maxn = 4000 + 5, mod = 998244353;
long long n, m, cycle;
long long cnt[2];
long long a[maxn], b[maxn];
long long p[maxn][maxn];
long long jc[maxn], inv[maxn];
inline long long ksm(long long x, long long k) {
  long long ans = 1;
  while (k) {
    if (k & 1) ans = ans * x % mod;
    x = x * x % mod;
    k >>= 1;
  }
  return ans;
}
inline void prestirling(long long n) {
  p[0][0] = 1;
  for (long long i = (1); i <= (n); i++)
    for (long long j = (1); j <= (n); j++) {
      p[i][j] = (p[i - 1][j] * (i - 1) % mod + p[i - 1][j - 1]) % mod;
    }
  jc[0] = 1;
  for (long long i = (1); i <= (n); i++) jc[i] = jc[i - 1] * i % mod;
  inv[n] = ksm(jc[n], mod - 2);
  for (long long i = (n - 1); i >= (0); i--)
    inv[i] = inv[i + 1] * (i + 1) % mod;
}
inline long long P(long long n, long long m) {
  return jc[n] * inv[n - m] % mod;
}
inline long long C(long long n, long long m) {
  return jc[n] * inv[m] % mod * inv[n - m] % mod;
}
long long pd[maxn], to[maxn];
long long deg[maxn];
inline void dfs(long long x, long long last) {
  pd[x] = 1;
  if (to[x]) {
    if (!pd[to[x]])
      dfs(to[x], last);
    else
      cycle++;
  } else {
    if (x > n && last > n)
      m++;
    else if (x <= n && last > n)
      cnt[0]++;
    else if (x > n && last <= n)
      cnt[1]++;
  }
}
inline void work(long long *f, long long n) {
  for (long long i = (0); i <= (n); i++)
    for (long long j = (i); j <= (n); j++)
      f[i] = (f[i] + C(n, j) * p[j][i] % mod * P(m + n - j, n - j) % mod) % mod;
  for (long long i = (0); i <= (n); i++) {
    long long sum = 0;
    for (long long j = (i); j <= (n); j++)
      sum = (sum + ((j - i) & 1 ? -1 : 1) * f[j] * C(j, i) % mod + mod) % mod;
    f[i] = sum;
  }
}
long long dp[maxn], ans[maxn], f[maxn], g[maxn];
signed main() {
  scanf("%lld", &n);
  prestirling(n + 10);
  for (long long i = (1); i <= (n); i++) scanf("%lld", &a[i]);
  for (long long i = (1); i <= (n); i++) scanf("%lld", &b[i]);
  for (long long i = (1); i <= (n << 1); i++) pd[i] = 1;
  for (long long i = (1); i <= (n); i++) {
    long long x = a[i] ? a[i] : i + n, y = b[i] ? b[i] : i + n;
    pd[x] = pd[y] = 0;
    if (x <= n || y <= n) to[x] = y, deg[y]++;
  }
  for (long long i = (1); i <= (n << 1); i++)
    if (!pd[i] && !deg[i]) dfs(i, i);
  for (long long i = (1); i <= (n << 1); i++)
    if (!pd[i]) dfs(i, i);
  work(f, cnt[0]);
  work(g, cnt[1]);
  for (long long i = (0); i <= (n); i++)
    for (long long j = (0); j <= (i); j++)
      dp[i] = (dp[i] + f[j] * g[i - j] % mod) % mod;
  for (long long i = (0); i <= (n); i++)
    for (long long j = (0); j <= (i); j++)
      ans[i] = (ans[i] + dp[j] * p[m][i - j] % mod) % mod;
  for (long long i = (0); i <= (n - 1); i++)
    printf("%lld ",
           n - i - cycle >= 0 ? ans[n - i - cycle] * jc[m] % mod : 0ll);
  return 0;
}
