#d2876. pSort
pSort
pSort
Problem Source
Original problem: CF28B pSort | Luogu
Problem Description
There is a sequence of elements. Initially, every element satisfies .
In one operation, you may swap the -th and -th elements if and only if .
You are given the sequences and . Determine whether, after several swaps, the sequence can be made exactly equal to .
Input Format
The first line contains a positive integer , as described above.
The second line contains positive integers giving .
The third line contains positive integers giving .
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
. The elements of are guaranteed to be distinct.