#B3965. Mystical Sequence Check
Mystical Sequence Check
Mystical Sequence Check
A sequence \(a_1, a_2, \ldots, a_n\) is called a mystical sequence if and only if it satisfies the following conditions:
- The sequence is a permutation of the integers \(1, 2, \ldots, n\). That is, every integer from \(1\) to \(n\) appears exactly once in the sequence.
- Let \(p_x\) denote the position (index) at which the integer \(x\) appears in the sequence (i.e. if \(a_j = x\), then \(p_x=j\) with \(1 \le j \le n\)). Then, for every integer \(i\) from \(1\) to \(n\), the sequence must satisfy \(p_i = a_i\).
For example, consider the sequence \(3, 5, 2, 1, 4\). The number \(1\) appears in the 4th position (i.e. \(p_1=4\)). However, \(a_1=3\) which is not equal to \(4\). Hence, this sequence is not mystical.
Your task is to determine whether a given sequence \(a_1, a_2, \ldots, a_n\) is a mystical sequence.
inputFormat
The input consists of two lines:
- The first line contains a single integer \(n\) (the length of the sequence).
- The second line contains \(n\) space-separated integers \(a_1, a_2, \ldots, a_n\) representing the sequence.
outputFormat
Output a single line containing YES
if the sequence is mystical; otherwise, output NO
.
sample
1
1
YES
</p>