#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
namespace ywy {
inline long long mi(int a, int b) {
  long long ans = 1, tmp = a;
  while (b) {
    if (b & 1) ans = (ans * tmp) % 998244353;
    tmp = (tmp * tmp) % 998244353;
    b >>= 1;
  }
  return (ans);
}
long long jc[600], jcny[600], f[600], g[600], h[600], s[300][300];
inline long long xjm(int n, int m) {
  if (m == 0) return (1);
  if (n - m < 0 || n <= 0 || m < 0) return (0);
  return ((jc[n] * jcny[n - m]) % 998244353);
}
int a[300], b[300], pla[300], plb[300];
int dfs(int pos) {
  if (!b[pos]) return (0);
  if (!pla[b[pos]]) return (b[pos]);
  return (dfs(pla[b[pos]]));
}
inline long long cnm(int n, int m) {
  if (n < m || m < 0) return (0);
  long long cjr = jc[n];
  cjr *= jcny[m];
  cjr %= 998244353;
  cjr *= jcny[n - m];
  return (cjr % 998244353);
}
long long ans[1000];
int ints[600];
int find(int n) {
  if (ints[n] == n) return (n);
  return (ints[n] = find(ints[n]));
}
void ywymain() {
  int n;
  cin >> n;
  for (register int i = 1; i <= n; i++) cin >> a[i], pla[a[i]] = i;
  for (register int i = 1; i <= n; i++) cin >> b[i], plb[b[i]] = i;
  jc[0] = 1;
  for (register int i = 1; i <= n * 2; i++) jc[i] = (jc[i - 1] * i) % 998244353;
  jcny[n * 2] = mi(jc[n * 2], 998244353 - 2);
  for (register int i = n * 2 - 1; i >= 0; i--)
    jcny[i] = (jcny[i + 1] * (i + 1)) % 998244353;
  s[0][0] = 1;
  for (register int i = 1; i <= n; i++) {
    for (register int j = 1; j <= i; j++)
      s[i][j] = (s[i - 1][j - 1] + s[i - 1][j] * (i - 1)) % 998244353;
  }
  int A = 0, B = 0, C = 0;
  for (register int i = 1; i <= n; i++) {
    if (a[i] == 0) {
      if (dfs(i))
        B++;
      else
        A++;
    } else {
      if (!plb[a[i]]) {
        if (!dfs(i)) C++;
      }
    }
  }
  for (register int i = 0; i <= B; i++) {
    for (register int j = i; j <= B; j++) {
      long long cjr = cnm(B, j);
      cjr *= s[j][i];
      cjr %= 998244353;
      cjr *= xjm(A + B - j - 1, B - j);
      f[i] = (f[i] + cjr) % 998244353;
    }
  }
  for (register int i = 0; i <= C; i++) {
    for (register int j = i; j <= C; j++) {
      long long cjr = cnm(C, j);
      cjr *= s[j][i];
      cjr %= 998244353;
      cjr *= xjm(A + C - j - 1, C - j);
      g[i] = (g[i] + cjr) % 998244353;
    }
  }
  for (register int i = 0; i <= A; i++) {
    h[i] = (s[A][i] * jc[A]) % 998244353;
  }
  for (register int i = 0; i <= B; i++) {
    for (register int j = 0; j <= C; j++) {
      for (register int k = 0; k <= A; k++) {
        long long cjr = f[i];
        cjr *= g[j];
        cjr %= 998244353;
        ans[i + j + k] = (ans[i + j + k] + cjr * h[k]) % 998244353;
      }
    }
  }
  int cnt = 0;
  for (register int i = 1; i <= n; i++) ints[i] = i;
  for (register int i = 1; i <= n; i++) {
    if (!(a[i] && b[i])) continue;
    int aa = find(a[i]), ab = find(b[i]);
    if (aa == ab) cnt++;
    ints[aa] = ab;
  }
  for (register int i = 0; i < n; i++) {
    printf("%lld ", ans[n - i - cnt]);
  }
}
}  // namespace ywy
int main() {
  ywy::ywymain();
  return (0);
}
