#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
const int mod = (int)1e9 + 7;
const long long INF64 = 3e18;
void smxl(long long &a, long long b) {
  if (a < b) a = b;
}
void smnl(long long &a, long long b) {
  if (a > b) a = b;
}
void adsl(long long &a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
}
void misl(long long &a, long long b) {
  a -= b;
  if (a >= mod) a -= mod;
  if (a < 0) a += mod;
}
void smx(long long &a, long long b) {
  if (a < b) a = b;
}
void smn(long long &a, long long b) {
  if (a > b) a = b;
}
void ads(long long &a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
}
void mis(long long &a, long long b) {
  a -= b;
  if (a >= mod) a -= mod;
  if (a < 0) a += mod;
}
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long egcd(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  long long d = egcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
long long mbinp(long long a, long long b) {
  a %= mod;
  if (b == 0) return 1;
  long long ans = mbinp(a, b / 2);
  long long tmp = (ans * ans) % mod;
  if (b % 2) return ((tmp * a) % mod);
  return ((tmp) % mod);
}
long long binp(long long a, long long b) {
  if (b == 0) return 1;
  long long ans = binp(a, b / 2);
  long long tmp = (ans * ans);
  if (b % 2) return ((tmp * a));
  return ((tmp));
}
long long C(int n, int m) {
  long long ret = 1;
  for (int i = 1; i <= m; i++) {
    ret *= (n - i + 1);
    ret /= i;
  }
  return ret;
}
long long overbinp(long long a, int b) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      if (res < INF64 / a)
        res *= a;
      else
        return INF64;
    }
    if (b > 1) {
      if (a < INF64 / a)
        a *= a;
      else
        return INF64;
    }
    b >>= 1;
  }
  return res;
}
const int nax = 105;
int par[nax];
int siize[nax];
int get(int x) { return (x == par[x] ? x : par[x] = get(par[x])); }
void merge(int a, int b) {
  int x = get(a);
  int y = get(b);
  if (x == y) return;
  if (siize[x] < siize[y]) swap(x, y);
  par[y] = x;
  siize[x] += siize[y];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> all(n);
  for (int i = 0; i < n; i++) cin >> all[i];
  vector<int> d(n);
  for (int i = 0; i < n; i++) cin >> d[i];
  for (int i = 0; i < n; i++) {
    par[i] = i;
    siize[i] = 1;
  }
  set<int> pr;
  for (int i = 0; i < n; i++) {
    if ((i - d[i] >= 0 && i - d[i] < n ? 1 : 0)) merge(i, i - d[i]);
    if ((i + d[i] >= 0 && i + d[i] < n ? 1 : 0)) merge(i, i + d[i]);
  }
  for (int i = 0; i < n; i++) pr.insert(get(i));
  int kk = pr.size();
  int k = 0;
  map<int, int> mp;
  for (int i = 0; i < n; i++)
    if (!mp.count(get(i))) mp[get(i)] = k++;
  vector<vector<int> > ss(kk);
  vector<int> pos(kk, 0);
  for (int i = 0; i < n; i++) ss[mp[get(i)]].push_back(all[i]);
  for (int i = 0; i < kk; i++) sort(ss[i].begin(), ss[i].end());
  vector<int> out(n);
  for (int i = 0; i < n; i++) {
    out[i] = ss[mp[get(i)]][pos[mp[get(i)]]];
    pos[mp[get(i)]]++;
  }
  for (int i = 0; i < n - 1; i++)
    if (out[i] > out[i + 1]) {
      cout << "NO";
      return 0;
    }
  cout << "YES";
}

### Prompt

Please create a solution in Cpp 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;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
const int mod = (int)1e9 + 7;
const long long INF64 = 3e18;
void smxl(long long &a, long long b) {
  if (a < b) a = b;
}
void smnl(long long &a, long long b) {
  if (a > b) a = b;
}
void adsl(long long &a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
}
void misl(long long &a, long long b) {
  a -= b;
  if (a >= mod) a -= mod;
  if (a < 0) a += mod;
}
void smx(long long &a, long long b) {
  if (a < b) a = b;
}
void smn(long long &a, long long b) {
  if (a > b) a = b;
}
void ads(long long &a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
}
void mis(long long &a, long long b) {
  a -= b;
  if (a >= mod) a -= mod;
  if (a < 0) a += mod;
}
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long egcd(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  long long d = egcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
long long mbinp(long long a, long long b) {
  a %= mod;
  if (b == 0) return 1;
  long long ans = mbinp(a, b / 2);
  long long tmp = (ans * ans) % mod;
  if (b % 2) return ((tmp * a) % mod);
  return ((tmp) % mod);
}
long long binp(long long a, long long b) {
  if (b == 0) return 1;
  long long ans = binp(a, b / 2);
  long long tmp = (ans * ans);
  if (b % 2) return ((tmp * a));
  return ((tmp));
}
long long C(int n, int m) {
  long long ret = 1;
  for (int i = 1; i <= m; i++) {
    ret *= (n - i + 1);
    ret /= i;
  }
  return ret;
}
long long overbinp(long long a, int b) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      if (res < INF64 / a)
        res *= a;
      else
        return INF64;
    }
    if (b > 1) {
      if (a < INF64 / a)
        a *= a;
      else
        return INF64;
    }
    b >>= 1;
  }
  return res;
}
const int nax = 105;
int par[nax];
int siize[nax];
int get(int x) { return (x == par[x] ? x : par[x] = get(par[x])); }
void merge(int a, int b) {
  int x = get(a);
  int y = get(b);
  if (x == y) return;
  if (siize[x] < siize[y]) swap(x, y);
  par[y] = x;
  siize[x] += siize[y];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> all(n);
  for (int i = 0; i < n; i++) cin >> all[i];
  vector<int> d(n);
  for (int i = 0; i < n; i++) cin >> d[i];
  for (int i = 0; i < n; i++) {
    par[i] = i;
    siize[i] = 1;
  }
  set<int> pr;
  for (int i = 0; i < n; i++) {
    if ((i - d[i] >= 0 && i - d[i] < n ? 1 : 0)) merge(i, i - d[i]);
    if ((i + d[i] >= 0 && i + d[i] < n ? 1 : 0)) merge(i, i + d[i]);
  }
  for (int i = 0; i < n; i++) pr.insert(get(i));
  int kk = pr.size();
  int k = 0;
  map<int, int> mp;
  for (int i = 0; i < n; i++)
    if (!mp.count(get(i))) mp[get(i)] = k++;
  vector<vector<int> > ss(kk);
  vector<int> pos(kk, 0);
  for (int i = 0; i < n; i++) ss[mp[get(i)]].push_back(all[i]);
  for (int i = 0; i < kk; i++) sort(ss[i].begin(), ss[i].end());
  vector<int> out(n);
  for (int i = 0; i < n; i++) {
    out[i] = ss[mp[get(i)]][pos[mp[get(i)]]];
    pos[mp[get(i)]]++;
  }
  for (int i = 0; i < n - 1; i++)
    if (out[i] > out[i + 1]) {
      cout << "NO";
      return 0;
    }
  cout << "YES";
}

```