#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &u) {
  u = 0;
  char c = getchar();
  int flag = 0;
  while (c < '0' || c > '9') flag |= (c == '-'), c = getchar();
  while (c >= '0' && c <= '9')
    u = (u << 3) + (u << 1) + (c ^ 48), c = getchar();
  if (flag) u = -u;
}
template <class T>
bool checkmin(T &a, T b) {
  return (b < a ? a = b, 1 : 0);
}
template <class T>
bool checkmax(T &a, T b) {
  return (b > a ? a = b, 1 : 0);
}
template <class T>
T _min(T a, T b) {
  return (a < b ? a : b);
}
template <class T>
T _max(T a, T b) {
  return (a > b ? a : b);
}
const int N = 255, mod = 998244353;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int n, a[N], b[N], aa = 0, bb = 0, cc = 0, dd = 0;
int S[N][N], C[N][N], frac[N];
int nxt[N], pre[N], is_pre_zero[N], is_nxt_zero[N], cnt[N];
int f[N], g[N], h[N], tmp[N << 1], ans[N];
void init() {
  read(n);
  for (int i = 1; i <= n; ++i) read(a[i]);
  for (int i = 1; i <= n; ++i) read(b[i]);
  frac[0] = 1;
  for (int i = 1; i <= n; ++i) {
    frac[i] = (long long)frac[i - 1] * i % mod;
  }
  S[0][0] = 1;
  C[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
    }
    for (int j = 1; j <= i; ++j) {
      add(S[i][j], (1LL * S[i - 1][j] * (i - 1) + S[i - 1][j - 1]) % mod);
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (!a[i] && !b[i])
      ++dd;
    else if (a[i] && b[i]) {
      nxt[a[i]] = b[i];
      pre[b[i]] = a[i];
    } else if (a[i] && !b[i])
      is_nxt_zero[a[i]] = 1;
    else
      is_pre_zero[b[i]] = 1;
  }
  for (int i = 1; i <= n; ++i) {
    if (!cnt[i]) {
      cnt[i] = 1;
      int l = i, r = i;
      for (; pre[l] && !cnt[pre[l]];) l = pre[l], cnt[l] = 1;
      for (; nxt[r] && !cnt[nxt[r]];) r = nxt[r], cnt[r] = 1;
      if (pre[l] == r)
        ++aa;
      else if (is_pre_zero[l] && is_nxt_zero[r])
        ++dd;
      else if (is_pre_zero[l] && !is_nxt_zero[r])
        ++bb;
      else if (!is_pre_zero[l] && is_nxt_zero[r])
        ++cc;
    }
  }
}
void mul(int *f, int *g) {
  for (int i = 0; i <= n; ++i) tmp[i] = 0;
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      add(tmp[i + j], 1LL * f[i] * g[j] % mod);
    }
  }
  for (int i = 0; i <= n; ++i) {
    f[i] = tmp[i];
  }
}
void solve() {
  for (int i = 0; i <= bb; ++i) {
    for (int j = i; j <= bb; ++j) {
      int tmp = 0;
      if (bb == j)
        tmp = 1;
      else
        tmp = C[bb - j + dd - 1][bb - j];
      add(g[i], ((long long)S[j][i] * C[bb][j] % mod) *
                    ((long long)frac[bb - j] * tmp % mod) % mod);
    }
  }
  for (int i = 0; i <= cc; ++i) {
    for (int j = i; j <= cc; ++j) {
      int tmp = 0;
      if (cc == j)
        tmp = 1;
      else
        tmp = C[cc - j + dd - 1][cc - j];
      add(h[i], ((long long)S[j][i] * C[cc][j] % mod) *
                    ((long long)frac[cc - j] * tmp % mod) % mod);
    }
  }
  for (int i = 0; i <= dd; ++i) {
    f[i] = (long long)S[dd][i] * frac[dd] % mod;
  }
  mul(f, g);
  mul(f, h);
  for (int i = 0; i <= bb + cc + dd; ++i) {
    ans[n - i - aa] = f[i];
  }
  for (int i = 0; i < n; ++i) printf("%d%c", ans[i], " \n"[i == n - 1]);
}
int main() {
  init();
  solve();
  return 0;
}
