#include "bits/stdc++.h" using namespace std; #define MAX 500 int dp[MAX]; bool check[MAX]; int finduni(int a){ if (dp[a] < 0) return a; else return dp[a] = finduni(dp[a]); } bool connect(int a, int b){ a = finduni(a); b = finduni(b); if (a == b) return false; dp[a] += dp[b] + 1; check[a] |= check[b]; dp[b] = a; return true; } int main(){ int N; cin >> N; vector D(N), W(N); for (int i = 0; i < N; i++) { cin >> D[i]; } for (int i = 0; i < N; i++) { cin >> W[i]; } for (int i = 0; i < N; i++) { dp[i] = -1; if (!W[i]) dp[i]--; check[i] = false; } for (int i = 0; i < N; i++) { int a = (i + D[i]) % N; int b = (i - D[i]) % N; if (b < 0) b += N; if (a == b) check[finduni(a)] = true; else connect(a, b); } for (int i = 0; i < N; i++) { if (dp[i] >= 0) continue; if (!check[i] && dp[i] % 2 == 0){ cout << "No" << endl; return 0; } } cout << "Yes" << endl; }