#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define BET(a,b,c) ((a)<=(b)&&(b)<(c)) #define FOR(i,n) for(int i=0,i##_end=(int(n));i VI; typedef vector VVI; struct QuickFindWeighted { vector to_main; vector > groups; QuickFindWeighted(int n) : to_main(n), groups(n) { FOR(i,n) to_main[i] = i ; FOR(i,n) groups[i].push_back(i); } void merge(int large, int small){ FOR(i,SZ(groups[small])) { int e = groups[small][i]; groups[large].push_back(e); to_main[e] = large; } groups[small].clear(); } bool unionSet(int x, int y) { x = root(x); y = root(y); if(x == y) return false; if(size(x) >= size(y)) merge(x, y); else merge(y, x); return true; } bool is_sameSet(int x, int y) { return root(x) == root(y); } int root(int x) { return to_main[x]; } int size(int x) { return groups[x].size(); } }; int main() { int N; cin>>N; VI D(N); VI W(N); FOR(i,N) cin>>D[i]; FOR(i,N) cin>>W[i]; VI canFlip(N), Flip1(N); QuickFindWeighted u(N); FOR(i,N){ int a = (i + D[i]) % N; int b = (i - D[i] % N + N) % N; canFlip[a] = canFlip[b] = true; if(a != b) { u.unionSet(a,b); }else{ Flip1[a] = true; } } bool ok = true; FOR(i,N) if(W[i] == 0 && !canFlip[i]) ok = false; FOR(i,N) { int cnt =0 ; for(auto g : u.groups[i]){ if(W[g]==0) cnt++; if(Flip1[g]){ cnt = 0 ; break; } } if(cnt % 2 == 1) ok = false; } puts(ok ? "Yes" : "No"); return 0; }