#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

vvi g;
vector<set<int>> ch;
vi a, p, pos, dep;
vi res;

void rot(int v) {
  res.push_back(v);
  int val = a[v], cur = p[v];
  while (cur >= 0) {
    swap(a[cur], val);
    pos[a[cur]] = cur;
    cur = p[cur];
  }
  a[v] = val;
  pos[a[v]] = v;
}

void rem(set<int>& v, int a) {
  v.erase(a);
}

const int DEBUG = 0;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n = 2000;
  if (!DEBUG) cin >> n;
  g.resize(n);
  ch.resize(n);
  a.resize(n);
  p.assign(n, -1);
  dep.assign(n, 0);
  pos.assign(n, 0);
  for (int i = 1; i < n; ++i) {
    if (!DEBUG) cin >> p[i];
    else p[i] = rand() % i;
    g[p[i]].push_back(i);
    dep[i] = dep[p[i]] + 1;
  }
  for (int i = 0; i < n; ++i) {
    if (!DEBUG) cin >> a[i];
    else a[i] = n-i-1;
  }
  if (DEBUG) random_shuffle(a.begin(), a.end());
  for (int i = 0; i < n; ++i) {
    pos[a[i]] = i;
  }
  for (int i = n-1; i >= 0; --i) {
    if (ch[i].empty() && a[i] == i) continue;
    int cur = p[i];
    while (cur >= 0) {
      ch[cur].insert(i);
      cur = p[cur];
    }
  }
  while (!ch[0].empty()) {
    int v = a[0];
    if (ch[v].empty()) {
      rot(v);
      int cur = p[v];
      while (cur >= 0) {
        rem(ch[cur], v);
        cur = p[cur];
      }
    } else {
      int u = -1, ma = -1;
      for (int x : ch[v]) {
        if (ma < dep[pos[x]]) {
          u = pos[x];
          ma = dep[u];
        }
      }
      assert(u >= 0);
      rot(u);
    }
    assert(res.size() <= 25000);
  }
  cout << res.size() << endl;
  for (int x : res) cout << x << endl;
  return 0;
}
### Prompt

Please create a solution in cpp to the following problem:

You are given a rooted tree with N vertices. The vertices are numbered 0, 1, ..., N-1. The root is Vertex 0, and the parent of Vertex i (i = 1, 2, ..., N-1) is Vertex p_i.

Initially, an integer a_i is written in Vertex i. Here, (a_0, a_1, ..., a_{N-1}) is a permutation of (0, 1, ..., N-1).

You can execute the following operation at most 25 000 times. Do it so that the value written in Vertex i becomes i.

* Choose a vertex and call it v. Consider the path connecting Vertex 0 and v.
* Rotate the values written on the path. That is, For each edge (i, p_i) along the path, replace the value written in Vertex p_i with the value written in Vertex i (just before this operation), and replace the value of v with the value written in Vertex 0 (just before this operation).
* You may choose Vertex 0, in which case the operation does nothing.

Constraints

* 2 \leq N \leq 2000
* 0 \leq p_i \leq i-1
* (a_0, a_1, ..., a_{N-1}) is a permutation of (0, 1, ..., N-1).

Input

Input is given from Standard Input in the following format:


N
p_1 p_2 ... p_{N-1}
a_0 a_1 ... a_{N-1}


Output

In the first line, print the number of operations, Q. In the second through (Q+1)-th lines, print the chosen vertices in order.

Examples

Input

5
0 1 2 3
2 4 0 1 3


Output

2
3
4


Input

5
0 1 2 2
4 3 1 2 0


Output

3
4
3
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

vvi g;
vector<set<int>> ch;
vi a, p, pos, dep;
vi res;

void rot(int v) {
  res.push_back(v);
  int val = a[v], cur = p[v];
  while (cur >= 0) {
    swap(a[cur], val);
    pos[a[cur]] = cur;
    cur = p[cur];
  }
  a[v] = val;
  pos[a[v]] = v;
}

void rem(set<int>& v, int a) {
  v.erase(a);
}

const int DEBUG = 0;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n = 2000;
  if (!DEBUG) cin >> n;
  g.resize(n);
  ch.resize(n);
  a.resize(n);
  p.assign(n, -1);
  dep.assign(n, 0);
  pos.assign(n, 0);
  for (int i = 1; i < n; ++i) {
    if (!DEBUG) cin >> p[i];
    else p[i] = rand() % i;
    g[p[i]].push_back(i);
    dep[i] = dep[p[i]] + 1;
  }
  for (int i = 0; i < n; ++i) {
    if (!DEBUG) cin >> a[i];
    else a[i] = n-i-1;
  }
  if (DEBUG) random_shuffle(a.begin(), a.end());
  for (int i = 0; i < n; ++i) {
    pos[a[i]] = i;
  }
  for (int i = n-1; i >= 0; --i) {
    if (ch[i].empty() && a[i] == i) continue;
    int cur = p[i];
    while (cur >= 0) {
      ch[cur].insert(i);
      cur = p[cur];
    }
  }
  while (!ch[0].empty()) {
    int v = a[0];
    if (ch[v].empty()) {
      rot(v);
      int cur = p[v];
      while (cur >= 0) {
        rem(ch[cur], v);
        cur = p[cur];
      }
    } else {
      int u = -1, ma = -1;
      for (int x : ch[v]) {
        if (ma < dep[pos[x]]) {
          u = pos[x];
          ma = dep[u];
        }
      }
      assert(u >= 0);
      rot(u);
    }
    assert(res.size() <= 25000);
  }
  cout << res.size() << endl;
  for (int x : res) cout << x << endl;
  return 0;
}
```