#include typedef long long ll; typedef unsigned long long ull; #define FOR(i,a,b) for(int (i)=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define RANGE(vec) (vec).begin(),(vec).end() using namespace std; class BoredomOfSavingsBox { public: void solve(void) { int N; cin>>N; vector D(N); REP(i,N) cin>>D[i]; vector W(N); REP(i,N) cin>>W[i]; // O(N^3) REP(i, N) { bool all_ok = false; vector w(W); int d = D[i]; int l = (d+i)%N; int r = (N*1000-d+i)%N; w[i] ^= 1; // d による周期は最大 N REP(j, N) { bool ok = true; REP(i, N) ok &= (w[i]==1); if (ok) { all_ok = true; break; } if (l == r) w[l] ^= 1; else { w[l] ^= 1; w[r] -= 1; } l = (l+d)%N; r = (N*1000-d+r)%N; } if (all_ok) { cout<<"Yes"<solve(); delete obj; return 0; } #endif