#include <bits/stdc++.h>
using namespace std;
long long int adj[101][101], vis[101], tot = 0, ss[101][101];
void init() {
  long long int i;
  for (i = 0; i < 101; i++) {
    vis[i] = 0;
  }
}
long long int modexpo(long long int x, long long int p) {
  long long int res = 1;
  x = x % 1000000007;
  while (p) {
    if (p % 2) res = res * x;
    p >>= 1;
    x = x * x % 1000000007;
    res %= 1000000007;
  }
  return res;
}
long long int binSearch(long long int a[], long long int l, long long int h,
                        long long int x) {
  long long int c = -1;
  while (l <= h) {
    long long int m = (l + h) / 2;
    if (a[m] < x) {
      c = m;
      l = m + 1;
    } else
      h = m - 1;
  }
  return c;
}
long long int isPrime(long long int n) {
  if (n < 2) return 0;
  if (n < 4) return 1;
  if (n % 2 == 0 or n % 3 == 0) return 0;
  for (long long int i = 5; i * i <= n; i += 6)
    if (n % i == 0 or n % (i + 2) == 0) return 0;
  return 1;
}
void bfs(long long int s, long long int n) {
  long long int i;
  queue<long long int> q;
  q.push(s);
  ss[s][s] = 1;
  vis[s] = 1;
  while (!q.empty()) {
    long long int x = q.front();
    q.pop();
    for (i = 0; i < n; i++) {
      if (adj[x][i] == 1 && vis[i] == 0) {
        q.push(i);
        vis[i] = 1;
        ss[s][i] = 1;
        ss[i][s] = 1;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, t, i, q, m, ans = 0, j, k = 1, g = 0, h = 0;
  ;
  cin >> n;
  long long int a[n], f[n];
  ;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) cin >> f[i];
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (abs(i - j) == f[i] || abs(i - j) == f[j]) {
        adj[i][j] = 1;
        adj[j][i] = 1;
      }
    }
  }
  for (i = 0; i < n; i++) {
    init();
    bfs(i, n);
  }
  for (i = 0; i < n; i++) {
    if (ss[i][a[i] - 1] == 0) g = 1;
  }
  if (g)
    cout << "NO";
  else
    cout << "YES";
  return 0;
}

### Prompt

Your challenge is to write a CPP solution to the following problem:

One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited.

The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state.

Input

The first line contains positive integer n (1 ≤ n ≤ 100) — the number of cells in the array. The second line contains n distinct integers from 1 to n — permutation. The last line contains n integers from 1 to n — favourite numbers of the cells.

Output

If the given state is reachable in the described game, output YES, otherwise NO.

Examples

Input

5
5 4 3 2 1
1 1 1 1 1


Output

YES


Input

7
4 3 5 1 2 7 6
4 6 6 1 6 6 1


Output

NO


Input

7
4 2 5 1 3 7 6
4 6 6 1 6 6 1


Output

YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int adj[101][101], vis[101], tot = 0, ss[101][101];
void init() {
  long long int i;
  for (i = 0; i < 101; i++) {
    vis[i] = 0;
  }
}
long long int modexpo(long long int x, long long int p) {
  long long int res = 1;
  x = x % 1000000007;
  while (p) {
    if (p % 2) res = res * x;
    p >>= 1;
    x = x * x % 1000000007;
    res %= 1000000007;
  }
  return res;
}
long long int binSearch(long long int a[], long long int l, long long int h,
                        long long int x) {
  long long int c = -1;
  while (l <= h) {
    long long int m = (l + h) / 2;
    if (a[m] < x) {
      c = m;
      l = m + 1;
    } else
      h = m - 1;
  }
  return c;
}
long long int isPrime(long long int n) {
  if (n < 2) return 0;
  if (n < 4) return 1;
  if (n % 2 == 0 or n % 3 == 0) return 0;
  for (long long int i = 5; i * i <= n; i += 6)
    if (n % i == 0 or n % (i + 2) == 0) return 0;
  return 1;
}
void bfs(long long int s, long long int n) {
  long long int i;
  queue<long long int> q;
  q.push(s);
  ss[s][s] = 1;
  vis[s] = 1;
  while (!q.empty()) {
    long long int x = q.front();
    q.pop();
    for (i = 0; i < n; i++) {
      if (adj[x][i] == 1 && vis[i] == 0) {
        q.push(i);
        vis[i] = 1;
        ss[s][i] = 1;
        ss[i][s] = 1;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, t, i, q, m, ans = 0, j, k = 1, g = 0, h = 0;
  ;
  cin >> n;
  long long int a[n], f[n];
  ;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) cin >> f[i];
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (abs(i - j) == f[i] || abs(i - j) == f[j]) {
        adj[i][j] = 1;
        adj[j][i] = 1;
      }
    }
  }
  for (i = 0; i < n; i++) {
    init();
    bfs(i, n);
  }
  for (i = 0; i < n; i++) {
    if (ss[i][a[i] - 1] == 0) g = 1;
  }
  if (g)
    cout << "NO";
  else
    cout << "YES";
  return 0;
}

```