#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#define mymalloc(p,n) {p = malloc((n)*sizeof(*p));if ((p)==NULL) {printf("not enough memory?\n"); exit(1);};}

typedef struct{
	int key;
	int root;
}obj;

void merge(obj *A,int left,int mid,int right){
	int n1,n2,i,j,k;
	obj *L,*R;
	n1=mid-left;
	n2=right-mid;
	mymalloc(L,n1+1);
	mymalloc(R,n2+1);
	for(i=0;i<n1;i++){
		L[i]=A[left+i];
	}
	for(j=0;j<n2;j++){
		R[j]=A[mid+j];
	}
	L[n1].key=INT_MAX;R[n2].key=INT_MAX;
	i=0;j=0;
	for(k=left;k<right;k++){
		if(L[i].key<=R[j].key){
			A[k]=L[i];
			i++;
		}
		else{
			A[k]=R[j];
			j++;
		}
	}
	free(L);free(R);
}

void mergeSort(obj *A,int left,int right){
	int mid;
	if(left+1<right){
		mid=(right-left)/2+left;
		mergeSort(A,left,mid);
		mergeSort(A,mid,right);
		merge(A,left,mid,right);
	}
}

int pos(int n){
	if(n<0){
		return 0;
	}
	else{
		return n;
	}
}


main(){
	int i,j,swap,n,*B;
	obj *A;
	scanf("%d",&n);
	mymalloc(A,n);
	for(i=0;i<n;i++){
		scanf(" %d",&(A[i].key));
		A[i].root=i;
	}
	mergeSort(A,0,n);
	mymalloc(B,n);
	for(i=0;i<n;i++){
		B[A[i].root]=i;
	}
	swap=0;
	for(i=0;i<n;i++){
		swap+=pos(A[i].root);
		/*printf("%d %d\n",i,A[i].root);*/
		for(j=A[i].root+1;j<n;j++){
			A[B[j]].root--;
		}
	}
	printf("%d\n",swap);
	free(A);free(B);
	return 0;
}