#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
const int mod = 998244353;
int n;
int s[N][N], g[N], f[N], cnt[6], a[N], b[N], c[N][N], ans[N], d[N], nxt[N],
    fac[N];
bool vis[N];
void init(int n) {
  int i, j;
  c[0][0] = s[0][0] = fac[0] = 1;
  for (i = 1; i <= n; i++) {
    c[i][0] = 1;
    for (j = 1; j <= i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= i; j++)
      s[i][j] = (s[i - 1][j - 1] + 1ll * s[i - 1][j] * (i - 1) % mod) % mod;
  }
  for (i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
}
void dfs(int k, int col, int st) {
  int j, u;
  vis[k] = 1;
  if (nxt[k]) {
    if (!vis[nxt[k]])
      dfs(nxt[k], col ^ 1, st);
    else
      cnt[4]++;
  } else
    cnt[(st << 1) | col]++;
}
int main() {
  int i, j;
  scanf("%d", &n);
  init(n + n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (i = 1; i <= n; i++) {
    if (!b[i]) continue;
    nxt[i] = b[i] + n;
    d[b[i] + n]++;
  }
  for (i = 1; i <= n; i++) {
    if (!a[i]) continue;
    nxt[a[i] + n] = i;
    d[i]++;
  }
  for (i = 1; i <= n + n; i++)
    if (!vis[i] && !d[i]) dfs(i, i > n, i > n);
  for (i = 1; i <= n + n; i++)
    if (!vis[i]) dfs(i, i > n, i > n);
  for (i = 0; i <= n; i++)
    g[i] = 1ll * fac[cnt[0]] * fac[i] % mod *
           (cnt[0] == 0 ? (i == 0 ? 1 : 0) : c[i + cnt[0] - 1][cnt[0] - 1]) %
           mod;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= cnt[2]; j++)
      (f[i] += 1ll * g[j] * c[cnt[2]][j] % mod * s[cnt[2] - j][i] % mod) %= mod;
  }
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= i; j++)
      (ans[i] += 1ll * f[j] * s[cnt[0] + cnt[1]][i - j] % mod) %= mod;
  }
  for (i = n; i >= 0; i--)
    if (i >= cnt[4])
      ans[i] = ans[i - cnt[4]];
    else
      ans[i] = 0;
  for (i = 1; i <= n; i++) printf("%d ", ans[n - i + 1]);
  return 0;
}
