#include <bits/stdc++.h>
using namespace std;

void solve(vector<int> &a, vector<int> &b, vector<int> &c) {
    sort(a.begin(), a.end());
    int64_t ans = 0;
    for (auto &&i : c) {
        int value = b[i - 1];
        ans += upper_bound(a.begin(), a.end(), value) - lower_bound(a.begin(), a.end(), value);
    }
    cout << ans << endl;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for (auto &&i : a) cin >> i;
    for (auto &&i : b) cin >> i;
    for (auto &&i : c) cin >> i;
    solve(a, b, c);
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define int long long
#define uint unsigned int
#define reg register
#define db double
#define il inline
#define gc getchar
#define pc putchar
#define len 200000
il int umax(int a,int b){return a>b?a:b;}
il int umin(int a,int b){return a<b?a:b;}
il int rd()
{
	reg int res=0;
	reg char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')
		res=(res<<3)+(res<<1)+(ch&15),ch=getchar();
	return res;
}
il void prt(int x,char t)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)prt(x/10,0),x%=10;
	putchar(x|48);
	if(t)putchar(t);
}
int n,a[len+5],b[len+5],mxa[len+5],mxb[len+5],ans;
signed main()
{
	n=rd();
	for(int i=1;i<=n;++i)
		a[i]=rd(),mxa[i]=umax(mxa[i-1],a[i]);
	for(int i=1;i<=n;++i)
		b[i]=rd(),mxb[i]=umax(mxb[i-1],b[i]);
	for(int i=1;i<=n;++i)
		prt((ans=umax(ans,mxa[i]*b[i])),'\n');
	return 0;
}