题库练习 Jeff and Permutation
← 上一题 下一题 →

A9250 | Jeff and Permutation

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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
C++ 编辑器
输入
输出