#include<bits/stdc++.h>usingnamespacestd;intN;vector<vector<int>>adj;vector<int>prevnum,rating,ans,parent;intcountval=0;vector<int>bit;// bit functionsvoidupdateBIT(inta,intb){while(a<=N){bit[a]+=b;a+=(a&(-a));}}intquery(inta){intr=0;while(a>0){r+=bit[a];a=a-(a&(-a));}returnr;}voiddfs(intnode){prevnum[node]=query(N)-query(rating[node]);for(autochild:adj[node]){countval++;dfs(child);}ans[node]=query(N)-query(rating[node])-prevnum[node];updateBIT(rating[node],1);}intmain(){ifstreamcin("promote.in");ofstreamcout("promote.out");cin>>N;adj.resize(N+1);rating.resize(N+1);bit.resize(N+1);parent.resize(N+1,-1);prevnum.resize(N+1);ans.resize(N+1);vector<pair<int,int>>old(N+1);for(inti=1;i<N+1;i++){cin>>old[i].first;old[i].second=i;}for(inti=2;i<N+1;i++){intp;cin>>p;adj[p].push_back(i);}// compressionsort(old.begin(),old.end());for(inti=1;i<N+1;i++){rating[old[i].second]=i;}dfs(1);for(inti=1;i<=N;i++){cout<<ans[i]<<endl;}}