#include <bits/stdc++.h>
using namespace std;
template <class T>
T gi() {
  T x = 0;
  bool f = 0;
  char c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') f = 1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return f ? -x : x;
}
const int N = 310, Mod = 998244353;
int C[N][N], S[N][N], p[N], q[N], f[N], g[N], h[N], ans[N * 3];
int pla[N], plb[N], fac[N << 1], ifac[N << 1];
int fpow(int a, int b) {
  int res = 1;
  for (; b; b >>= 1, a = 1ll * a * a % Mod)
    if (b & 1) res = 1ll * res * a % Mod;
  return res;
}
bool dfs(int x) {
  if (!q[x]) return 0;
  if (!pla[q[x]]) return q[x];
  return dfs(pla[q[x]]);
}
int xjm(int n, int m) {
  if (!m) return 1;
  return 1ll * fac[n] * ifac[n - m] % Mod;
}
int fa[N];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int main() {
  int n = gi<int>();
  for (int i = 1; i <= n; i++) p[i] = gi<int>(), pla[p[i]] = i;
  for (int i = 1; i <= n; i++) q[i] = gi<int>(), plb[q[i]] = i;
  fac[0] = 1;
  for (int i = 1; i <= 2 * n; i++) fac[i] = 1ll * fac[i - 1] * i % Mod;
  ifac[2 * n] = fpow(fac[2 * n], Mod - 2);
  for (int i = 2 * n; i >= 1; i--) ifac[i - 1] = 1ll * ifac[i] * i % Mod;
  S[0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= i; j++)
      S[i][j] = (S[i - 1][j - 1] + 1ll * S[i - 1][j] * (i - 1) % Mod) % Mod;
  for (int i = 0; i <= n; i++) C[i][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % Mod;
  int a = 0, b = 0, c = 0;
  for (int i = 1; i <= n; i++)
    if (!p[i])
      dfs(i) ? b++ : a++;
    else {
      if (!plb[p[i]] && !dfs(i)) c++;
    }
  int cnt = 0;
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= n; i++) {
    if (!p[i] || !q[i]) continue;
    int x = find(p[i]), y = find(q[i]);
    if (x == y) cnt++;
    fa[x] = y;
  }
  for (int i = 0; i <= b; i++)
    for (int j = i; j <= b; j++)
      (f[i] +=
       1ll * C[b][j] * S[j][i] % Mod * xjm(b - j + a - 1, b - j) % Mod) %= Mod;
  for (int i = 0; i <= c; i++)
    for (int j = i; j <= c; j++)
      (g[i] +=
       1ll * C[c][j] * S[j][i] % Mod * xjm(c - j + a - 1, c - j) % Mod) %= Mod;
  for (int i = 0; i <= a; i++) h[i] = 1ll * S[a][i] * fac[a] % Mod;
  for (int i = 0; i <= a; i++)
    for (int j = 0; j <= b; j++)
      for (int k = 0; k <= c; k++)
        (ans[i + j + k] += 1ll * h[i] * f[j] % Mod * g[k] % Mod) %= Mod;
  for (int i = 0; i < n; i++) printf("%d ", ans[n - i - cnt]);
  return 0;
}
