跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F2301. Jeff and Permutation

    ID: 2307 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>贪心算法思想提高难度共享题库Codeforces英文题面题目来源题面语言

Jeff and Permutation

题目描述

E. Jeff and Permutation
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p1,p2,...,pn for his birthday.

Jeff hates inversions in sequences. An inversion in sequence a1,a2,...,an is a pair of indexes i,j (1≤i<jn), such that an inequality ai>aj 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.

Input

The first line contains integer n (1≤n≤2000). The next line contains n integers − sequence p1, p2, ..., pn (|pi|≤105). The numbers are separated by spaces.

Output

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

Examples
Input
2
2 1
Output
0
Input
9
-2 0 -1 0 -1 2 1 0 -1
Output
6

题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 1914 题。保留原作者与原赛事署名。