#include #define show(x) cout << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template constexpr T INF = numeric_limits::max() / 100; struct Graph { Graph(int n) { edge.resize(n); } void addEdge(int from, int to) { edge[from].push_back(to); edge[to].push_back(from); } void print() { show(edge); } vector> edge; }; int main() { int N; cin >> N; Graph g(N); for (ll i = 0; i < N; i++) { int d; cin >> d; const int s1 = (i + N - (d % N)) % N; const int s2 = (i + (d % N)) % N; g.addEdge(s1, s2); } vector side(N); for (ll i = 0; i < N; i++) { bool w; cin >> w; side[i] = w; } vector checked(N, false); for (int i = 0; i < N; i++) { if (not checked[i]) { queue q; q.push(i); checked[i] = true; int s[2] = {0, 0}; bool flag = false; while (not q.empty()) { const int p = q.front(); q.pop(); s[side[p]]++; for (const int to : g.edge[p]) { if (to == p) { flag = true; } if (not checked[to]) { q.push(to); checked[to] = true; } } } if ((not flag) and s[0] % 2 == 1) { cout << "No" << endl; return 0; } } } cout << "Yes" << endl; return 0; }