#include <bits/stdc++.h>
using namespace std;
typedef long long int ll ; 
ll dp[500000+5];
int b[500000+5];
int a[500000+5];
void DFS(int node,vector <int> G[],int used[],int parent[]){
    
    used[node] = 1 ; 
    
    for(auto u: G[node]){ //iterating all children "u" of "node"
        
        if(used[u]==0){
            //if this node/branch has never been visited before 
            //just go into it and search it using dfs in recursion
            parent[u] = node ; 
            DFS(u,G,used,parent);
            
        }
    }
    
    
    //print(node)--->parent
    //----> bottom up traversal 
    ll s = 0 ; 
    for(auto child: G[node]){
        
        if(child==parent[node]){
            //it means the child node is parent of the node
            //it is not the child
            //ignore it
        }
        
        else{
            s = s + dp[child]; 
        }
    }
    dp[node] = s + 1; 
    
    
}

int main(){
    int n ; 
    cin>>n ; 
    vector <int> G[n+1];
    int i = 1 ; 
    while(i<=n){
        cin>>a[i] ; 
        i++;
    }
    
    i = 1 ; 
    while(i<=n){
        cin>>b[i] ; 
        i++;
    }
    
    i = 1 ; 
    while(i<=n){
        int u,v;
        u = a[i],v = b[i]; 
        G[u].push_back(v);
        G[v].push_back(u); 
        i++;
    }
    int used[n+1] = {0};
    int parent[n+1] = {0};
    DFS(0,G,used,parent); //starts from node 1  
    
    ll answer = 0;    
    i = 1;
    while(i <= n){
    	answer += (dp[i] + 4) / 5; // ceil division
    	i++;
    }

    cout<<(answer); 
    return 0 ; 
}

