program main
  implicit none
  integer::n,i,cnt,t,chk
  integer,allocatable::a(:)
  read*,n
  allocate(a(n))
  read*,a
  chk=0
  do
     do i=1,n-2
        if(a(i).gt.a(i+2))then
           t=a(i)
           a(i)=a(i+2)
           a(i+2)=t
           chk=1
        endif
     enddo
     if(chk==0)exit
     chk=0
  end do
  cnt=0
!  print*,"a",a
  do i=1,n-1
     if(a(i).gt.a(i+1))then
        t=a(i)
        a(i)=a(i+1)
        a(i+1)=t
        cnt=cnt+1
     endif
  enddo
  print*,cnt
end program main
