#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair ll_i; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int u, v; ll w; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; struct union_find { vector v; union_find(int n) : v(n, -1) {} int find(int x) { return (v[x] < 0) ? x : (v[x] = find(v[x])); } void unite(int x, int y) { x = find(x); y = find(y); if (x != y) { if (-v[x] < -v[y]) swap(x, y); v[x] += v[y]; v[y] = x; } } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return -v[find(x)]; } }; 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]; union_find uf(N); for (int i = 0; i < N; i++) uf.unite((i + D[i]) % N, ((i - D[i]) % N + N) % N); vector a(N); for (int i = 0; i < N; i++) if (!W[i]) a[uf.find(i)]++; bool flag = true; for (int i = 0; i < N; i++) if (a[i] % 2) flag = true; cout << (flag ? "Yes" : "No") << endl; }