#include using namespace std; struct UnionFind { vector data; UnionFind(int n) { data.assign(n, -1); } bool unite(int x, int y) { x = root(x), y = root(y); if (x == y) return (false); if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return (true); } int root(int k) { if (data[k] < 0) return (k); return (data[k] = root(data[k])); } bool same(int x, int y) { return root(x) == root(y); } int size(int k) { return (-data[root(k)]); } }; int rem(int a, int b) { return ((a %= b) += b) %= b; } int main() { int N, D[110], W[110]; cin >> N; for (int i = 0; i < N; i++) { cin >> D[i + 1]; } for (int i = 0; i < N; i++) { cin >> W[i + 1]; } int ok[110] = {}; UnionFind uf(N + 1); for (int i = 1; i <= N; i++) { uf.unite(rem(i + D[i] - 1, N) + 1, rem(i - D[i] - 1, N) + 1); if (rem(i + D[i] - 1, N) + 1 == rem(i - D[i] - 1, N) + 1) { ok[rem(i + D[i] - 1, N) + 1] = 1; } } map> mp; for (int i = 1; i <= N; i++) { mp[uf.root(i)].push_back(i); } bool ans = true; for (auto& p : mp) { auto& V = p.second; int cnt = 0; for (auto& x : V) { cnt += !W[x]; if (ok[x]) { cnt = 0; break; } } if (cnt & 1) ans = false; } cout << (ans ? "Yes" : "No") << endl; }