#define _GLIBCXX_DEBUG #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef ll li; typedef pair PI; #define rep(i,n) for(int i=0;i<(int)(n);++i) #define REP(i, n) rep (i, n) #define F first #define S second #define mp(a,b) make_pair(a,b) #define pb(a) push_back(a) #define SZ(a) (int)((a).size()) #define ALL(a) (a).begin(),(a).end() #define FLL(a,b) memset((a),b,sizeof(a)) #define CLR(a) memset((a),0,sizeof(a)) #define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it) #define FORR(it,a) for(__typeof(a.rbegin())it=a.rbegin();it!=a.rend();++it) template ostream& operator<< (ostream& out, const pair& val){return out << "(" << val.F << ", " << val.S << ")";} template ostream& operator<< (ostream& out, const vector& val){out << "{";rep(i,SZ(val)) out << (i?", ":"") << val[i];return out << "}";} #define declare(a,it) __typeof(a) it=a const double EPS = 1e-8; const int dx[]={1,0,-1,0,1,1,-1,-1,0}; const int dy[]={0,1,0,-1,-1,1,-1,1,0}; #define endl '\n' typedef vector arr; typedef vector mat; bool sol(mat A,arr y){//Ax=y, return x int n = A.size(); mat B(n,arr(n)); mat ab = A; for(int i = 0; i < n; ++i) B[i][i] = 1; for(int i = 0; i < n; ++i){ for(int j=i+1;j < n; ++j){ if(abs(A[j][i]) > abs(A[i][i])){ swap(A[j],A[i]); swap(B[j],B[i]); } } for(int j = 0; j < n; ++j){ if(i==j) continue; int m = A[j][i]; if(!m) continue; for(int k = 0; k < n; ++k){ A[j][k] -= A[i][k] * m; B[j][k] -= B[i][k] * m; A[j][k] &= 1; B[j][k] &= 1; } } } arr ret(n); for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j) ret[i] += B[i][j] * y[j]; arr cy(n); rep(i,n)rep(j,n) (cy[i] += ab[i][j] * ret[j]) &= 1; return y == cy; } int main(int argc, char *argv[]) { int n; cin >> n; mat A(n,arr(n)); rep(i,n){ int d; cin >> d; A[(i+d)%n][i] = 1; //A[i][i] = 1; A[((i-d)%n+n)%n][i] = 1; } arr x(n); rep(i,n) cin >> x[i]; rep(i,n) x[i] = 1 - x[i]; cout << (sol(A,x)?"Yes":"No") << endl; /* 0 1 0 0 1 1 0 0 1 = 0 1 1 0 1 0 */ }