#d2876. pSort

pSort

pSort

Problem Source

Original problem: CF28B pSort | Luogu

Problem Description

There is a sequence a1,a2,…,ana_1, a_2, \dots, a_n of nn elements. Initially, every element satisfies ai=ia_i = i.

In one operation, you may swap the ii-th and jj-th elements if and only if ∣i−j∣=di|i - j| = d_i.

You are given the sequences b1,b2,…,bnb_1, b_2, \dots, b_n and d1,d2,…,dnd_1, d_2, \dots, d_n. Determine whether, after several swaps, the sequence aa can be made exactly equal to bb.

Input Format

The first line contains a positive integer nn, as described above.

The second line contains nn positive integers giving b1,b2,…,bnb_1, b_2, \dots, b_n.

The third line contains nn positive integers giving d1,d2,…,dnd_1, d_2, \dots, d_n.

Output Format

If possible, output YES; otherwise output NO.

Sample Input 1

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

Sample Output 1

YES

Sample Input 2

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

Sample Output 2

NO

Constraints

1≤n,di≤1001 \le n, d_i \le 100. The elements of bb are guaranteed to be distinct.