#1294. Problem A. 逆序对染色

Problem A. 逆序对染色

We know the definition of reverse pairs: for a permutation a1,a2,,ana_1,a_2,\dots,a_n of length nn, if there exists i<ji<j and ai>aja_i>a_j, then ai,aja_i,a_j form a reverse pair. A permutation of length nn contains each of the numbers 11 to nn exactly once.

Finding the number of reverse pairs should not be a difficult task for you. Now, you are given a permutation a1,a2,,ana_1,a_2,\dots,a_n of length nn. For each pair satisfying i<ji<j and ai>aja_i>a_j of reverse pairs, color the cell in the n×nn \times n grid at row ii and column aja_j. Please determine how many colored connected components are there in the final grid. Connected means that if two colored cells share an edge, then we consider these two cells to be connected.

Input

The first line contains an integer nn (1n3×1051 \le n \le 3 \times 10^5), representing the length of the permutation.

The second line contains nn integers a1,a2,,ana_1,a_2,\dots,a_n, representing a permutation of length nn.

Output

Output an integer, representing the number of four-connected components in the final grid.

Examples

9
5 9 1 8 2 6 4 7 3
5
2
1 2
0