#include <bits/stdc++.h>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ') {
  while (!isdigit(ch = getchar()))
    if (ch == '-') f = -1;
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f * x;
}
const int N = 2e3 + 5, P = 998244353;
int n, a[N], b[N], vis[N << 1], to[N << 1], cnt[4], d[N << 1];
long long S[N][N], A[N][N], C[N][N], f[N], g[N], h[N];
void dfs(int x, int y) {
  vis[x] = 1;
  if (to[x]) {
    if (!vis[to[x]])
      dfs(to[x], y);
    else
      ++cnt[0];
  } else if (x > n || y > n)
    ++cnt[(x > n) * 2 + (y > n)];
}
void solve(long long *f, int n) {
  for (int i = 0; i <= n; ++i) {
    f[i] = 0;
    for (int j = i; j <= n; ++j)
      f[i] = (f[i] + C[n][j] * S[j][i] % P * A[n + cnt[3] - j][n - j] % P) % P;
  }
  for (int i = 0; i <= n; ++i) {
    long long w = 0;
    for (int j = i, k = 1; j <= n; ++j, k = P - k)
      w = (w + k * C[j][i] % P * f[j] % P) % P;
    f[i] = w;
  }
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i)
    a[i] = read(), a[i] = a[i] ? a[i] : i + n, vis[i] = 1;
  for (int i = 1; i <= n; ++i)
    b[i] = read(), b[i] = b[i] ? b[i] : i + n, vis[i + n] = 1;
  for (int i = 1; i <= n; ++i) {
    vis[a[i]] = vis[b[i]] = 0;
    if (a[i] <= n || b[i] <= n) to[a[i]] = b[i], ++d[b[i]];
  }
  for (int i = 1; i <= n << 1; ++i)
    if (!vis[i] && !d[i]) dfs(i, i);
  for (int i = 1; i <= n << 1; ++i)
    if (!vis[i]) dfs(i, i);
  for (int i = 0; i <= n; ++i) {
    S[i][0] = i == 0, C[i][0] = 1, A[i][0] = 1;
    for (int j = 1; j <= i; ++j)
      S[i][j] = (S[i - 1][j - 1] + (i - 1) * S[i - 1][j] % P) % P,
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % P,
      A[i][j] = A[i][j - 1] * (i - j + 1) % P;
  }
  solve(f, cnt[1]), solve(g, cnt[2]);
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= i; ++j) h[i] = (h[i] + f[j] * g[i - j] % P) % P;
  for (int i = 0; i <= n; ++i) {
    f[i] = 0;
    for (int j = 0; j <= i; ++j)
      f[i] = (f[i] + S[cnt[3]][j] * h[i - j] % P) % P;
    f[i] = f[i] * A[cnt[3]][cnt[3]] % P;
  }
  for (int i = 0; i < n; ++i)
    printf("%lld ", n - cnt[0] - i >= 0 ? f[n - cnt[0] - i] : 0);
  puts("");
  return 0;
}
