import java.util.Arrays;
import java.util.Scanner;
public class chexiangchongzu {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int [] num = new int [n];
int [] shu = new int [n];
for (int i = 0; i < shu.length; i++) {
num[i]=sc.nextInt();
shu[i]=num[i];
}
Arrays.sort(shu);
int sum = 0;int temp = 0;int a = 0;
for (int i = n-1; i >=0; i--) {
for (int j = 0; j < shu.length; j++) {
if(shu[i]==num[j]){
temp=j;
sum+=(Math.abs(j-i));
break;
}
}
if(temp>i)
for (int j = i; j <temp; j++) {
a=num[j];
num[j]=num[j+1];
num[j+1]=a;
}
if(temp<i){
for (int j = temp; j <i; j++){
a=num[j];
num[j]=num[j+1];
num[j+1]=a;
}
}
}
System.out.println(sum);
}
}