Line Town

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

The NN residents of Line Town have arranged themselves in a line. Initially, the residents have happiness values of h_1,h_2,,h_Nh\_{1}, h\_{2}, \ldots, h\_{N} from left to right along the line.

Since you are the mayor of Line Town, you are implementing the third pillar of your plan entitled "Community, Candy, and Organization" (CCO). As such, you have taken the mayoral power to swap the residents' locations. In one swap, you may tell two adjacent residents to swap their positions in the line. However, this swap will cause both residents to negate their happiness values.

You would like to perform some swaps so that the residents' happiness values are in nondecreasing order from left to right in the line. Determine whether this is possible, and if so, the minimum number of swaps needed.

입력

The first line of input contains a single integer NN.

The next line of input contains NN integers h_1,,h_Nh\_{1}, \ldots, h\_{N} (109h_i109)(-10^{9} \le h\_{i} \le 10^{9}), the happiness values of the residents from left to right.

출력

On a single line, output the minimum number of swaps, or -1 if the task is impossible.

제한

  • 1N500,0001 \le N \le 500\\,000