#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

#define ll long long
#define ull unsigned ll

void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(double *x){scanf("%lf",x);}
int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);}
template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);}

void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(double x, char c){printf("%.15f",x);mypc(c);}
void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}
template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');}
template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');}

char memarr[17000000]; void *mem = memarr;
#define MD 1000000007

template<class T>
struct fenwick{
  int size, memory; T *data;
  void malloc(int mem){memory=mem;data=(T*)std::malloc(sizeof(T)*mem);}
  void *malloc(int mem, void *workMemory){memory=mem;data=(T*)workMemory;return (void*)(data+mem);}
  void free(void){memory=0;free(data);}
  void init(int N){size=N;memset(data,0,sizeof(T)*N);}
  void add(int k, T val){while(k<size)data[k]+=val,k|=k+1;}
  T get(int k){T res=0;while(k>=0)res+=data[k],k=(k&(k+1))-1;return res;}
  T range(int a, int b){if(b==-1)b=size-1;return get(b)-get(a-1);}
  int kth(T k){int i=0,j=size,c;T v;while(i<j){c=(i+j)/2;v=get(c);if(v<=k)i=c+1;else j=c;}return i==size?-1:i;}
};

template<class T> int coordinateCompress(int n, T arr[], int res[], void *mem){int i,k=0;pair<T,int>*r=(pair<T,int>*)mem;rep(i,n)r[i].first=arr[i],r[i].second=i;sort(r,r+n);if(res!=NULL){rep(i,n){if(i&&r[i].first!=r[i-1].first)k++;res[r[i].second]=k;}}else{rep(i,n){if(i&&r[i].first!=r[i-1].first)k++;arr[r[i].second]=k;}}return k+1;}
template<class T> int coordinateCompress(int n1, T arr1[], int n2, T arr2[], int res1[], int res2[], void *mem){int i,k=0;pair<T,int>*r =(pair<T,int>*)mem;rep(i,n1)r[i].first=arr1[i],r[i].second=i;rep(i,n2)r[n1+i].first=arr2[i],r[n1+i].second=n1+i;sort(r,r+n1+n2);rep(i,n1+n2){if(i&&r[i].first!=r[i-1].first) k++;if(r[i].second<n1){if(res1!=NULL)res1[r[i].second]=k;else arr1[r[i].second]=k;}else{if(res2!=NULL)res2[r[i].second-n1]=k;else arr2[r[i].second-n1]=k;}}return k+1;}

ll inversion(int N, int A[], void *mem){
  int i;
  int *arr;
  fenwick<int> t;
  ll res = 0;

  arr = (int*)mem;
  mem = t.malloc(N, arr+N);
  coordinateCompress(N, A, arr, mem);

  t.init(N);
  for(i=N-1;i>=0;i--){
    res += t.get(arr[i]-1);
    t.add(arr[i], 1);
  }

  return res;
}


int N;
int A[100000];

int Bs, Cs;
int B[100000], C[100000];

int main(){
  int i, j, k;
  int res = 0;

  reader(&N);
  rep(i,N) reader(A+i);

  Bs = Cs = 0;
  for(i=0;i<N;i+=2) B[Bs++] = A[i];
  sort(B, B+Bs);

  sort(A, A+N);
  for(i=0;i<N;i+=2) C[Cs++] = A[i];

  i=j=0;
  while(i < Bs && j < Cs){
    if(B[i] == C[j]){ i++; j++; continue; }
    if(B[i] < C[j]) i++, res++;
    else            j++;
  }
  while(i < Bs) res++, i++;
  while(j < Cs) j++;

  writerLn(res);

  return 0;
}


Measured memory_bytes: 1024