import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.conv, std.stdio, std.typecons; class UnionFind { int[] par; this(int n) { par = new int[](n); par[] = -1; } int find(int i) { if (par[i] < 0) { return i; } else { par[i] = find(par[i]); return par[i]; } } void unite(int i, int j) { auto pi = find(i), pj = find(j); if (pi != pj) par[pj] = pi; } } void main() { auto n = readln.chomp.to!int; auto di = readln.split.map!(to!int); auto wi = readln.split.map!(a => a.to!int == 0 ? false : true); auto uf = new UnionFind(n); int[] isolateds; foreach (i; 0..n) { auto j1 = (i + di[i]) % n; auto j2 = (i - (di[i] % n) + n) % n; if (j1 == j2) isolateds ~= j1; else uf.unite(j1, j2); } int[][int] h; foreach (i; 0..n) h[uf.find(i)] ~= i; auto r = true; foreach (pi; h.byValue) { if (pi.length == 1) { if (!wi[pi.front]) { r = false; break; } } else { auto c = pi.count!(p => !wi[p]); if (c % 2 != 0 && !isolateds.any!(a => pi.canFind(a))) { r = false; break; } } } writeln(r ? "Yes" : "No"); }