#include using namespace std; class UnionFind { private: vector data; public: UnionFind(const int& N) : data(vector(N, -1)) {} int root(const int& x) { if (data[x] < 0) { return x; } else { return data[x] = root(data[x]); } } int size(const int& x) { return -data[root(x)]; } bool same(const int& x, const int& y) { return root(x) == root(y); } void unite(int x, int y) { if (same(x, y)) return; x = root(x); y = root(y); if (size(x) < size(y)) { data[y] += data[x]; data[x] = y; } else { data[x] += data[y]; data[y] = x; } } }; int main() { int N; cin >> N; int D[N], W[N]; bool flag[N] = {}; for (size_t i = 0; i < N; i++) cin >> D[i]; for (size_t i = 0; i < N; i++) cin >> W[i]; UnionFind UF(N); for (size_t i = 0; i < N; i++) { int x = (i + D[i]) % N; int y = ((i - D[i]) % N + N) % N; UF.unite(x, y); if (x == y) { flag[x] = true; } } map> sets; for (size_t i = 0; i < N; i++) { sets[UF.root(i)].push_back(i); } for (const auto& s : sets) { int cnt = s.second.size(); bool is_flaged = false; for (const auto& x : s.second) { is_flaged |= flag[x]; cnt -= W[x]; } if (is_flaged) continue; if (cnt % 2) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; }