Codeforces Round 204 (Div. 1)
E
Jeff and Permutation
Codeforces
2200
原题
← D→
翻译中…

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.

翻译中…

Input

翻译中…

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.

翻译中…

Output

翻译中…

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

翻译中…

样例

Input #1
2
2 1
Output #1
0
InputCopy OutputCopy
Input #2
9
-2 0 -1 0 -1 2 1 0 -1
Output #2
6
InputCopy OutputCopy
题目信息
题号
351E
时间限制
2 s
内存限制
256 MB
标签
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。