#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair ll_i; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int u, v; ll w; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; int main() { int N; cin >> N; vector D(N), W(N); for (int i = 0; i < N; i++) cin >> D[i]; for (int i = 0; i < N; i++) cin >> W[i]; for (int t = 0; t < 1000000; t++) { int sum = 0; for (int i = 0; i < N; i++) sum += W[i]; if (sum == N) { cout << "Yes" << endl; return 0; } for (;;) { int i = rand() % N; int next = (i + D[i]) % N, prev = ((i - D[i]) % N + N) % N; if (W[next] && W[prev]) continue; W[next] = !W[next]; if (next != prev) W[prev] = !W[prev]; break; } } cout << "No" << endl; }