#include <bits/stdc++.h>
using namespace std;
long long n, A[255], B[255], X[255], Y[255], fac[255], C[255][255],
    stl[255][255], cnt[5], cyc = 0, vis[255], g[255], G[255], Ans[255];
int main() {
  scanf("%d", &n), memset(X, -1, sizeof X), memset(Y, -1, sizeof Y);
  for (long long i = 1; i <= n; i++) scanf("%d", &A[i]);
  for (long long i = 1; i <= n; i++)
    scanf("%d", &B[i]), X[B[i]] = A[i], Y[A[i]] = B[i];
  for (long long i = 0; i <= n; i++)
    fac[i] = i == 0 ? 1 : (long long)fac[i - 1] * i % 998244353;
  for (long long i = 0; i <= n; i++)
    for (long long j = 0; j <= i; j++)
      C[i][j] = !j ? 1 : (C[i - 1][j - 1] + C[i - 1][j]) % 998244353,
      stl[i][j] =
          !j ? !i
             : (stl[i - 1][j - 1] + (long long)stl[i - 1][j] * (i - 1)) %
                   998244353;
  for (long long i = 1, tmp; i <= n; i++)
    if (i && X[i] <= 0 && !(X[i] == -1 && Y[i] == -1)) {
      for (long long j = i;; j = Y[j])
        if (Y[j] > 0)
          vis[j] = 1;
        else {
          tmp = Y[j], vis[j] = 1;
          break;
        }
      cnt[X[i] * 2 + tmp + 3]++;
    }
  for (long long i = 1; i <= n; i++)
    if (A[i] == 0 && B[i] == 0) cnt[3]++;
  for (long long i = 1; i <= n; i++)
    if (A[i] && !vis[A[i]]) {
      vis[A[i]] = 1, cyc++;
      for (long long j = Y[A[i]]; j != A[i]; j = Y[j]) vis[j] = 1;
    }
  long long a = cnt[1], b = cnt[2], c = cnt[3];
  for (long long i = 0; i <= b; i++)
    g[i] =
        (i + c == 0 ? 1ll : (long long)C[i + c - 1][i] * fac[i] % 998244353) *
        fac[c] % 998244353;
  for (long long i = 0; i <= n - cyc; i++)
    for (long long j = 0; j <= i; j++)
      for (long long k = 0; k <= b; k++)
        Ans[n - (i + cyc)] =
            (Ans[n - (i + cyc)] + (long long)g[k] * stl[b - k][j] % 998244353 *
                                      stl[a + c][i - j] % 998244353 * C[b][k]) %
            998244353;
  for (long long i = 0; i < n; i++) printf("%d ", Ans[i]);
  return putchar('\n'), 0;
}
