测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A9250. Jeff and Permutation

编程题 普及/提高-

题目描述

Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence $p_{1},p_{2},...,p_{n}$ for his birthday.

Jeff hates inversions in sequences. An inversion in sequence $a_{1},a_{2},...,a_{n}$ is a pair of indexes $i,j$ $(1<=i<j<=n)$ , such that an inequality $a_{i}>a_{j}$ holds.

Jeff can multiply some numbers of the sequence $p$ by -1. At that, he wants the number of inversions in the sequence to be minimum. Help Jeff and find the minimum number of inversions he manages to get.

输入格式

The first line contains integer $n$ $(1<=n<=2000)$ . The next line contains $n$ integers — sequence $p_{1}$ , $p_{2}$ , $...$ , $p_{n}$ $(|p_{i}|<=10^{5})$ . The numbers are separated by spaces.

输出格式

In a single line print the answer to the problem — the minimum number of inversions Jeff can get.

输入输出样例

输入 #1
2
2 1
输出 #1
0
输入 #2
9
-2 0 -1 0 -1 2 1 0 -1
输出 #2
6
上一题 去做题 下一题