func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx2 )   using namespace std;   const int MX = 1005;   int n, a, b;   vector<int> adj[2 * MX][2];   int leaf[MX][2];   int pos[2 * MX][2];   int siz[2 * MX][2];   int best[MX][MX][2];   int ans[MX][2];   pair<int, int> rang[2 * MX][2];   void dfs(int v, int p, int d) {     if (pos[v][d] != -1) rang[v][d] = {pos[v][d], pos[v][d]};     siz[v][d] = 1;     for (int to : adj[v][d]) {       if (to != p) {         dfs(to, v, d);         siz[v][d] += siz[to][d];         rang[v][d].first = min(rang[v][d].first, rang[to][d].first);         rang[v][d].second = max(rang[v][d].second, rang[to][d].second);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> a;     for (int i = 0; i < a; i++) pos[i][0] = -1, rang[i][0] = {1e9, -1e9};     for (int i = 0; i < a - 1; i++) {       int p;       cin >> p;       adj[p - 1][0].push_back(i + 1);     }     for (int i = 0; i < n; i++) {       cin >> leaf[i][0], leaf[i][0]--;       pos[leaf[i][0]][0] = i;     }     cin >> b;     for (int i = 0; i < b; i++) pos[i][1] = -1, rang[i][1] = {1e9, -1e9};     for (int i = 0; i < b - 1; i++) {       int p;       cin >> p;       adj[p - 1][1].push_back(i + 1);     }     for (int i = 0; i < n; i++) {       cin >> leaf[i][1], leaf[i][1]--;       pos[leaf[i][1]][1] = i;     }     dfs(0, -1, 0);     dfs(0, -1, 1);     for (int i = 0; i < a; i++) {       auto cur = rang[i][0];       best[cur.first][cur.second][0] =           max(best[cur.first][cur.second][0], siz[i][0] - (i == 0));     }     for (int i = 0; i < b; i++) {       auto cur = rang[i][1];       best[cur.first][cur.second][1] =           max(best[cur.first][cur.second][1], siz[i][1] - (i == 0));     }     for (int c = 0; c < 2; c++) {       for (int len = 2; len < n + 1; len++) {         for (int st = 0; st < n; st++) {           if (st + len - 1 < n) {             int l = st, r = st + len - 1;             for (int k = l; k < r + 1; k++) {               if (k < r)                 best[l][r][c] =                     max(best[l][r][c], best[l][k][c] + best[k + 1][r][c]);             }           }         }       }     }     for (int i = 0; i < n + 1; i++) ans[i][0] = -1e9, ans[i][1] = -1e9;     ans[0][0] = 0, ans[0][1] = 0;     for (int i = 1; i < n + 1; i++) {       for (int j = 0; j < i; j++) {         ans[i][0] = max(ans[i][0], ans[j][1] + best[j][i - 1][1]);         ans[i][1] = max(ans[i][1], ans[j][0] + best[j][i - 1][0]);       }     }     cout << max(ans[n][0], ans[n][1]) <<   n ;   }   