CF351E.Jeff and Permutation

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

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

Jeff can multiply some numbers of the sequence pp 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 nn (1<=n<=2000)(1<=n<=2000) . The next line contains nn integers — sequence p1p_{1} , p2p_{2} , ...... , pnp_{n} (pi<=105)(|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
    
首页