#define _USE_MATH_DEFINES #include #include #include #include #include #include //#include #include #include #include #include #include #include ///////// #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define P(p) cout<<(p)< ///////// typedef long long LL; typedef long double LD; typedef unsigned long long ULL; ///////// using namespace::std; ///////// vector< pair > v; int main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed;// cout << setprecision(16);// int N; cin>>N; int D[100]; bool W[100]; int ww; rep(i,N)cin>>D[i]; rep(i,N){ cin>>ww; W[i] = ww?true:false; } int tr,tl; ULL L,R; pair Start,Goal; v.reserve(N); rep(i,N){ L = 0; R = 0; tr = (i+D[i])%N; tl = (N+i+(-D[i])%N)%N; if(tr>64){ L |= (ULL)1<<(tr%64); }else{ R |= (ULL)1<<(tr%64); } if(tl>64){ L |= (ULL)1<<(tl%64); }else{ R |= (ULL)1<<(tl%64); } v.push_back( pair(L,R) ); } for(int i=0; i<64 && i> AllSet[2],prevSet[2],nextSet[2]; AllSet[0].insert(Start); if( binary_search(AllSet[0].begin(),AllSet[0].end(),Goal) ){ P("Yes"); return 0; } AllSet[1].insert(Goal); prevSet[0].insert(Start); prevSet[1].insert(Goal); set>::iterator itr; vector>::iterator itrX; pair temp; int endCount = 0; for(;;){ endCount = 0; rep(turn,2){ for( itr = prevSet[turn].begin();itr != prevSet[turn].end(); ++itr ){ for(itrX = v.begin(); itrX != v.end(); ++itrX){ temp = pair(itr->second ^ itrX->second,itr->first ^ itrX->first); if( binary_search( AllSet[(turn+1)%2].begin(),AllSet[(turn+1)%2].end(),temp) ){ P("Yes"); return 0; } if( AllSet[turn].insert(temp).second ){ nextSet[turn].insert(temp); } } } prevSet[turn] = nextSet[turn]; nextSet[turn].clear(); if(prevSet[turn].size() == 0){ ++endCount; } } if( endCount == 2){ break; } } P("No"); return 0; }