program BBuBBBlesort
  implicit none
  integer :: n, a(100000,2), i, j, m
  a = 0
  read(*,*) n
  do i = 1, n
    read(*,*) a(i,1)
    a(i,2) = i
  end do
  call quick_sort(a(1:n,1:2),1)
  m = 0
  do i = 1, n
    if (mod(i+a(i,2),2).eq.1) m = m+1
  end do
  write(*,'(i0)') m/2
  stop
contains
  recursive subroutine quick_sort(a,i)
    implicit none
    integer, intent(inout) :: a(:,:)
    integer, intent(in) :: i
    integer :: p, c(size(a(1,:)))
    integer :: n, l, r
    n = size(a(:,1))
    l = 1
    r = n
    p = a((l+r)/2,i)+a(l,i)+a(r,i)-max(a((l+r)/2,i),a(l,i),a(r,i))-min(a((l+r)/2,i),a(l,i),a(r,i))
    do
      do while (a(l,i).lt.p)
        l = l+1
      end do
      do while (a(r,i).gt.p)
        r = r-1
      end do
      if (l.ge.r) exit
      c = a(l,:)
      a(l,:) = a(r,:)
      a(r,:) = c
      l = l+1
      r = r-1
    end do
    if (l.gt.2) call quick_sort(a(1:l-1,:),i)
    if (n.gt.r+1) call quick_sort(a(r+1:n,:),i)
    return
  end subroutine quick_sort
end program BBuBBBlesort