#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")

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

typedef long double ld;
typedef long long int ll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;

#define ff first
#define ss second
#define pb push_back
#define int long long   // Make sure to use ll everywhere while commenting this, to avoid overflow
#define sz(v) (int)v.size()
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define f(i,l,r) for(long long i=l;i<=r;i++)
#define rf(i,r,l) for(long long i=r;i>=l;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }


const int N = 16385, mod = 1e9 + 7, bit = 61;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
	uniform_int_distribution<int> uid(l, r);
	return uid(rng);
}



signed main()
{
	fast;

	int t = 1;
	// cin>>t;
	f(tc, 1, t)
	{
		int n;
		cin >> n;
		int a[n + 1], b[n + 1], c[n + 1];
		map<int, int> mp;
		int ans = 0;
		f(i, 1, n)
		{
			cin >> a[i];
		}
		f(i, 1, n)
		{
			cin >> b[i];
		}
		f(i, 1, n)
		{
			cin >> c[i];
			mp[b[c[i]]]++;
		}
		f(i, 1, n)
		{
			ans += mp[a[i]];
		}
		cout << ans << endl;
	}
	return 0;
}
#include<bits/stdc++.h>
#define rep(i, n) for (Int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(Int i=(n)-1;i>=0;i--)
#define FOR(i,a,b) for(Int i=a;i<=Int(b);i++)
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);
//#include <atcoder/all>
//using namespace atcoder;
typedef long long Int;
const long long INF = 1ll << 60;
using namespace std;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
  __MAGIC__
  int n; cin >> n;
  int A[n], B[n];

  rep(i,n)cin >> A[i];
  rep(i,n)cin >> B[i];
  Int sums = 0;
  rep(i,n){
    sums += A[i]*B[i];
  }
  if(sums == 0)cout << "Yes" <<endl;
  else cout << "No" <<endl;

//  cout << ans << endl;
//  cout << (ans ? "Yes" : "No") << endl;

  return 0;
}