Snuke received an integer sequence of length N as a birthday present from his mother. He wants to sort the sequence in increasing order. He can perform two operations: Operation 1 reverses the order of 2 consecutive elements, and Operation 2 reverses the order of 3 consecutive elements. Snuke prefers Operation 2 over Operation 1. The task is to find the minimum number of times Operation 1 needs to be performed to sort the sequence in increasing order. The constraints are 1 ≤ N ≤ 10^5, 0 ≤ A_i ≤ 10^9, A_i ≠ A_j if i ≠ j, and all input values are integers. The input is given in the format N followed by the elements of the sequence. The output should be the minimum number of times Operation 1 needs to be performed. Two sample inputs and their corresponding outputs are provided.

# Buggy version:
from collections import Counter
n=int(input())
a=[int(input()) for i in range(n)]
b=Counter(a[::2])
a.sort()
c=Counter(a[::2])

ans=0
for i in b:
	if i in c:
		ans+=abs(b[i])-c[i])
	else:
		ans+=b[i]
print(ans)

# Fixed version:
from collections import Counter
n=int(input())
a=[int(input()) for i in range(n)]
b=Counter(a[::2])
a.sort()
c=Counter(a[::2])

ans=0
for i in b:
	if i in c:
		ans+=abs(b[i]-c[i])
	else:
		ans+=b[i]
print(ans)

# Buggy version:
n=int(input())
a =[int(input()) for i in range(n)]
res = [[a[i],i]for i in range(n)]
res.sort()
ret =0
for i in range(n):
    if res[i][1]%2 != i%2:ret+=1
print(ret)

# Fixed version:
n=int(input())
a =[int(input()) for i in range(n)]
res = [[a[i],i]for i in range(n)]
res.sort()
ret =0
for i in range(n):
    if res[i][1]%2 != i%2:ret+=1
print(ret//2)

# Buggy version:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n = int(input())
a = [None] * n
for i in range(n):
    a[i] = (i,int(input()))
    
a.sort()
ans = 0
for i in range(n):
    if a[i][0]%2 != i%2:
        ans += 1
print(ans)

# Fixed version:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = [None] * n
for i in range(n):
    a[i] = (i,int(input()))
    
a.sort(key=lambda x: x[1])
ans = 0
for i in range(n):
    if a[i][0]%2 != i%2:
        ans += 1
print(ans//2)

# Buggy version:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(100000)
# mod = 10 ** 9 + 7
mod = 998244353


def read_values():
    return map(int, input().split())


def read_index():
    return map(lambda x: int(x) - 1, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v

    def __str__(self):
        return str(self.v)

    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n)


def main():
    N = int(input())
    A = [(int(input()), n % 2) for n in range(N)]

    print(A)
    res = 0
    t = 0
    for i, (_, j) in enumerate(A):
        if j == 0:
            res += abs(i - (t * 2))
            t += 1

    print(res)


if __name__ == "__main__":
    main()


# Fixed version:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(100000)
# mod = 10 ** 9 + 7
mod = 998244353


def read_values():
    return map(int, input().split())


def read_index():
    return map(lambda x: int(x) - 1, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v

    def __str__(self):
        return str(self.v)

    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n)


def main():
    N = int(input())
    A = [(int(input()), n % 2) for n in range(N)]
    A.sort()

    res = 0
    for i, (_, j) in enumerate(A):
        if i % 2 != j:
            res += 1

    print(res // 2)


if __name__ == "__main__":
    main()

# Buggy version:
N = int(input())
A = [int(input()) * N + i for i in range(N)]
A.sort()
cnt = 0
for i in range(N):
  d = (A[i] % N) % 2
  if d % 2 == i % 2:
    cnt += 1
print(cnt//2)

# Fixed version:
N = int(input())
A = [int(input()) * N + i for i in range(N)]
A.sort()
cnt = 0
for i in range(N):
  d = (A[i] % N) % 2
  if d % 2 != i % 2:
    cnt += 1
print(cnt//2)

# Buggy version:
N, *A = map(int, open(0))
print(len(set(A[1::2] + sorted(A)[::2])))

# Fixed version:
N, *A = map(int, open(0))
print(len(set(A[1::2]) & set(sorted(A)[::2])))

# Buggy version:
import sys
#import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
A = [ri() for _ in range(N)]
x_to_i = {x:i for i, x in enumerate(sorted(A))}
rank = [x_to_i[x] for x in A]
answer = sum((i^x)&1 for i,x in enumerate(rank)) // 2
print(B)


# Fixed version:
import sys
#import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
A = [ri() for _ in range(N)]
x_to_i = {x:i for i, x in enumerate(sorted(A))}
rank = [x_to_i[x] for x in A]
answer = sum(i&1 and (i^x)&1 for i,x in enumerate(rank))
print(answer)

# Buggy version:
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    b = sorted(a)
    c = b[::2]
    d = a[::2]
    set_c = set(c)
    set_d = set(d)
    print(len(set_c & set_d))

main()

# Fixed version:
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    b = sorted(a)
    c = b[::2]
    d = a[::2]
    set_c = set(c)
    set_d = set(d)
    print(len(set_c - set_d))
main()

# Buggy version:
n = int(input())
a = [[int(input()),i] for i in range(n)]
a.sort()
ans = 0
for i,tmp in enumerate(a):
  x,j = tmp
  ans += abs(i-j) % 2
print(ans-1)
#print(a)


# Fixed version:
n = int(input())
a = [[int(input()),i] for i in range(n)]
a.sort()
ans = 0
for i,tmp in enumerate(a):
  x,j = tmp
  ans += abs(i-j) % 2
print(ans//2)
#print(a)

# Buggy version:
n=int(input())
a=[(int(input()),i) for i in range(n)]
#print(a)
a.sort()
#print(a)
ans=0

for i in range(n):
    ans+=(a[i][1]-i)%2
print(ans,ans//2)


# Fixed version:
n = int(input())
a = [(int(input()), i) for i in range(n)]
a.sort()
ans = 0
for i in range(n):
    if (i-a[i][1])%2:
        ans += 1
print(ans//2)

# Buggy version:
a=sorted([[int(input()),i]for i in range(int(input()))]);print(sum([(a[i][1]-i)%2for i in range(len(a))]))

# Fixed version:
a=sorted([[int(input()),i]for i in range(int(input()))]);print(sum([(a[i][1]-i)%2for i in range(len(a))])//2)

# Buggy version:
N=int(input())
A=[]
B=[]
for i in range(N):
	if i%2==0:
		A.append(int(input()))
	else:
		B.append(int(input()))
		
A=sorted(A)
B=sorted(B)
C=sorted(A+B)
#ここまでNlogN
c=0
j=0
for i in range(C):
	if A[j]==C[i]:
		if i%2==1:
			c+=1
		j+=1
print(c)

# Fixed version:
N=int(input())
A=[]
B=[]
for i in range(N):
	if i%2==0:
		A.append(int(input()))
	else:
		B.append(int(input()))
		
A=sorted(A)
B=sorted(B)
C=sorted(A+B)
#ここまでNlogN
c=0
j=0
for i in range(N):
	if j>=len(A):
		break
	if A[j]==C[i]:
		if i%2==1:
			c+=1
		j+=1
print(c)

# Buggy version:
from collections import defaultdict as d
a=[int(input()) for i in range(int(input()))]
b=sorted(a)
c=d(int)
e=0
for i in range(0,n,2):
    d[b[i]]=1
for i in a[1::2]:
    e+=d[i]
print(e)

# Fixed version:
from collections import defaultdict as d
a=[int(input()) for i in range(int(input()))]
b=sorted(a)
c=d(int)
e=0
for i in b[::2]:
    c[i]=1
for i in a[1::2]:
    e+=c[i]
print(e)