func_code_string: #include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + c - 48;       c = getchar();     }     return x * f;   }   const int N = 510;   const int mod = 998244353;   int n, cnt1, cnt2, cnt3, cnt4;   int s[N][N], A[N][N], C[N][N];   int a[N], b[N];   int f[N], g[N], G[N];   int tmp[N], ans[N];   int vis[N << 1], nxt[N];   int ru[N];   void dfs(int u, int fa) {     vis[u] = 1;     if (nxt[u]) {       if (!vis[nxt[u]])         dfs(nxt[u], fa);       else         cnt3++;     } else {       if (fa > n && u > n)         cnt4++;       else if (fa <= n && u > n)         cnt1++;       else if (fa > n && u <= n)         cnt2++;     }   }   void init() {     s[0][0] = C[0][0] = A[0][0] = 1;     for (int i = 1; i <= n; i++) {       C[i][0] = A[i][0] = 1;       for (int j = 1; j <= i; j++) {         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;         A[i][j] = (A[i - 1][j] + 1ll * j * A[i - 1][j - 1] % mod) % mod;         s[i][j] = (1ll * (i - 1) * s[i - 1][j] % mod + s[i - 1][j - 1]) % mod;       }     }   }   void getans(int n, int *f) {     for (int i = 0; i <= n; i++) {       for (int j = i; j <= n; j++) {         f[i] = (f[i] +                 1ll * C[n][j] * s[j][i] % mod * A[n - j + cnt4][n - j] % mod) %                mod;       }     }     memset(G, 0, sizeof G);     for (int i = 0; i <= n; i++) {       for (int j = i, fz = 1; j <= n; j++, fz = -fz)         G[i] = (G[i] + 1ll * C[j][i] * f[j] % mod * fz + mod) % mod;     }     memcpy(f, G, sizeof(G));   }   int main() {     n = read();     for (int i = 1; i <= n + n; i++) vis[i] = 1;     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++) b[i] = read();     for (int i = 1; i <= n; i++) {       int x = a[i] ? a[i] : i + n;       int y = b[i] ? b[i] : i + n;       vis[x] = vis[y] = 0;       if (x <= n || y <= n) nxt[x] = y, ru[y]++;     }     for (int i = 1; i <= n + n; i++)       if (!vis[i] && !ru[i]) dfs(i, i);     for (int i = 1; i <= n + n; i++)       if (!vis[i]) dfs(i, i);     init();     getans(cnt1, f);     getans(cnt2, g);     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= i; j++) {         tmp[i] = (tmp[i] + 1ll * f[j] * g[i - j] % mod) % mod;       }     }     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= i; j++) {         ans[i] = (ans[i] + 1ll * tmp[j] * s[cnt4][i - j] % mod) % mod;       }       ans[i] = 1ll * ans[i] * A[cnt4][cnt4] % mod;     }     for (int i = 0; i < n; i++)       printf( %d  , (n - i - cnt3 < 0) ? 0 : ans[n - i - cnt3]);     return 0;   }   