#include "stdio.h"
#include "string.h"
const int maxn = 5005;
int n;
int a[maxn],c[maxn];
int lowbit( int x )
{
return x&(-x);
}
void add( int x )
{
while( x<=maxn )
{
c[x] += 1;
x += lowbit(x);
}
}
int sum( int x )
{
int ans = 0;
while( x>=1 )
{
ans += c[x];
x -= lowbit(x);
}
return ans;
}
int main()
{
int i,j;
while( scanf("%d",&n)!=EOF )
{
int ans = 0,Min=1<<30;
memset( c,0,sizeof(c) );
for( i=1;i<=n;i++ )
{
scanf("%d",&a[i]);
a[i]++;
add( a[i] );
ans += i - sum( a[i] );
}
for( i=1; i<=n; i++ )
{
ans = ans +n - a[i]*2 + 1; //ans - (a[i]-1) + n - a[i];
if( ans < Min )
Min = ans;
}
printf("%d\n",Min);
}
return 0;
}