# 2019/10/03

import sys

inpt=sys.stdin.readline
n=int(input())
a=[]
for i in range(n):
    a.append((int(input()),i+1))
a.sort()

cnt=0
for idx,aa in enumerate(a,1):
    if aa[1]%2==idx%2:continue
    cnt+=1
print(cnt//2)
f8cb6a2e51ff824cc4459ad1ecbfc533fbddd780
<mask token>

<mask token>
for i in range(n):
    a.append((int(input()), i + 1))
a.sort()
<mask token>
for idx, aa in enumerate(a, 1):
    if aa[1] % 2 == idx % 2:
        continue
    cnt += 1
print(cnt // 2)

<mask token>
inpt = sys.stdin.readline
n = int(input())
a = []
for i in range(n):
    a.append((int(input()), i + 1))
a.sort()
cnt = 0
for idx, aa in enumerate(a, 1):
    if aa[1] % 2 == idx % 2:
        continue
    cnt += 1
print(cnt // 2)

import sys
inpt = sys.stdin.readline
n = int(input())
a = []
for i in range(n):
    a.append((int(input()), i + 1))
a.sort()
cnt = 0
for idx, aa in enumerate(a, 1):
    if aa[1] % 2 == idx % 2:
        continue
    cnt += 1
print(cnt // 2)

# 2019/10/03

import sys

inpt=sys.stdin.readline
n=int(input())
a=[]
for i in range(n):
    a.append((int(input()),i+1))
a.sort()

cnt=0
for idx,aa in enumerate(a,1):
    if aa[1]%2==idx%2:continue
    cnt+=1
print(cnt//2)