#define _GLIBCXX_DEBUG #include using namespace std; int main() { int N; cin >> N; vector A(N, 0), T(N, 0); for(int i = 0; i < N; i++) cin >> A[i]; for(int i = 0; i < N; i++){ int B; cin >> B; if(B == 0) T[0] += A[i]; else T[B] += A[i]; } int maxP = -1; for(int i = 0; i < N; i++) maxP = max(maxP, T[i]); if(maxP == T[0]) cout << "YES" << endl; else cout << "NO" << endl; }