#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 2010
int bad[N], bad2[N];
vector<int> g[N];
int n;
int p[N], a[N];

void dfs_init(int u){
	for(auto v: g[u]){
		dfs_init(v);
		bad[u] += bad[v];
	}
	if(bad[u]==1 && a[u]==u) bad[u] = 0;
}

int search(int u){

	for(auto v: g[u]){
		if(bad2[v]) return search(v);
	}
	{
		int u2 = u;
		while(u2>=0){
			bad2[u2]--;
			u2 = p[u2];
		}
	}
	return u;
}

int search2(int u){
	if(g[u].empty()) return u;
	int mn = 0;
	for(auto v: g[u]){
		if(!bad[v]) continue;
		int w = search2(v);
		if(a[w]<a[mn]) mn = w;
	}
	if(mn==0) return u;
	return mn;
}

void rot(int u, int x){
	if(u<0) return;
	rot(p[u], a[u]);
	a[u] = x;
}

void update_bad(int u){
	bad[u] = 0;
	for(auto v: g[u]){
		update_bad(v);
		bad[u] += bad[v];
	}
	if(bad[u]||u!=a[u]) bad[u]++;
}

int main(){
	cin>>n;
	p[0] = -1;
	rep(i, n-1) cin>>p[i+1];
	rep(i, n) cin>>a[i];
	rep(i, n-1) g[p[i+1]].pb(i+1);
	fill(bad, bad+n, 1);
	dfs_init(0);
	vector<int> res;
	memcpy(bad2, bad, sizeof(bad));
	int cnt = 0;
	while(bad[0]){
		if(bad2[0]==1) memcpy(bad2, bad, sizeof(bad));
		/*if(cnt>20) break;
		rep(i, n) cerr<<a[i]<<" "; cerr<<endl;
		rep(i, n) cerr<<bad[i]<<" "; cerr<<endl;
		rep(i, n) cerr<<bad2[i]<<" "; cerr<<endl;
		cerr<<endl;*/
		int v = a[0];
		if(bad2[v]){
			v = search(v);
		}
		v = search2(v);
		rot(v, a[0]);
		update_bad(0);
		/*if(bad[v]==1&&v==a[v]){
			int u2 = v;
			while(u2>=0){
				bad[u2]--;
				u2 = p[u2];
			}
		}*/
		res.pb(v);
		cnt++;
		if(cnt>=30000) return -1;
	}
	cout<<res.size()<<endl;
	rep(i, res.size()) cout<<res[i]<<endl;
	//rep(i, n) cerr<<a[i]<<" ";
	return 0;
}

### Prompt

Develop a solution in cpp to the problem described below:

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 <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 2010
int bad[N], bad2[N];
vector<int> g[N];
int n;
int p[N], a[N];

void dfs_init(int u){
	for(auto v: g[u]){
		dfs_init(v);
		bad[u] += bad[v];
	}
	if(bad[u]==1 && a[u]==u) bad[u] = 0;
}

int search(int u){

	for(auto v: g[u]){
		if(bad2[v]) return search(v);
	}
	{
		int u2 = u;
		while(u2>=0){
			bad2[u2]--;
			u2 = p[u2];
		}
	}
	return u;
}

int search2(int u){
	if(g[u].empty()) return u;
	int mn = 0;
	for(auto v: g[u]){
		if(!bad[v]) continue;
		int w = search2(v);
		if(a[w]<a[mn]) mn = w;
	}
	if(mn==0) return u;
	return mn;
}

void rot(int u, int x){
	if(u<0) return;
	rot(p[u], a[u]);
	a[u] = x;
}

void update_bad(int u){
	bad[u] = 0;
	for(auto v: g[u]){
		update_bad(v);
		bad[u] += bad[v];
	}
	if(bad[u]||u!=a[u]) bad[u]++;
}

int main(){
	cin>>n;
	p[0] = -1;
	rep(i, n-1) cin>>p[i+1];
	rep(i, n) cin>>a[i];
	rep(i, n-1) g[p[i+1]].pb(i+1);
	fill(bad, bad+n, 1);
	dfs_init(0);
	vector<int> res;
	memcpy(bad2, bad, sizeof(bad));
	int cnt = 0;
	while(bad[0]){
		if(bad2[0]==1) memcpy(bad2, bad, sizeof(bad));
		/*if(cnt>20) break;
		rep(i, n) cerr<<a[i]<<" "; cerr<<endl;
		rep(i, n) cerr<<bad[i]<<" "; cerr<<endl;
		rep(i, n) cerr<<bad2[i]<<" "; cerr<<endl;
		cerr<<endl;*/
		int v = a[0];
		if(bad2[v]){
			v = search(v);
		}
		v = search2(v);
		rot(v, a[0]);
		update_bad(0);
		/*if(bad[v]==1&&v==a[v]){
			int u2 = v;
			while(u2>=0){
				bad[u2]--;
				u2 = p[u2];
			}
		}*/
		res.pb(v);
		cnt++;
		if(cnt>=30000) return -1;
	}
	cout<<res.size()<<endl;
	rep(i, res.size()) cout<<res[i]<<endl;
	//rep(i, n) cerr<<a[i]<<" ";
	return 0;
}

```