# Original solution
# coding: utf-8
import copy

def count_sort_count(numbers):
    count = 0
    for index_of_a in range(len(numbers)-1):
        for index_of_b in range(index_of_a + 1, len(numbers)):
            if numbers[index_of_a] > numbers[index_of_b]:
                numbers[index_of_a], numbers[index_of_b] = (numbers[index_of_b], numbers[index_of_a])
                count += 1
    return count, numbers

def different_positions(answer, numbers):
    different_positions = [-1 for index in range(len(numbers))]
    index = 0
    for answer_value in answer:
        for position in range(len(numbers)):
            if numbers[position] == answer_value:
                different_positions[index] = abs(index - position)
        index += 1
    return different_positions

def find_best_swap_position(answer, numbers, differents, max_different_position):
    min_sum = 1000000
    min_pattern = None
    for i in range(len(numbers)):
        if differents[i] == 0:
            continue
        if i != max_different_position:
            pattern = copy.deepcopy(numbers)
            pattern[i], pattern[max_different_position] = (pattern[max_different_position], pattern[i])
            sum_different = sum(different_positions(answer, pattern))
            if min_sum > sum_different:
                min_sum = sum_different
                min_pattern = pattern
    return min_pattern

numbers = [-1 for i in range(int(eval(input())))]
numbers = list([int(eval(input())) for x in numbers])
base_sort_count, answer = count_sort_count(copy.deepcopy(numbers))
if base_sort_count == 0:
    print((1))
else:
    differents = different_positions(answer, numbers)
    max_different_position = differents.index(max(differents))
    swaped = find_best_swap_position(answer, numbers, differents, max_different_position)
    print((count_sort_count(swaped)[0]))

# Optimized solution
# coding: utf-8
import copy

def count_sort_count(numbers):
    count = 0
    for index_of_a in range(len(numbers)-1):
        for index_of_b in range(index_of_a + 1, len(numbers)):
            if numbers[index_of_a] > numbers[index_of_b]:
                numbers[index_of_a], numbers[index_of_b] = (numbers[index_of_b], numbers[index_of_a])
                count += 1
    return count, numbers

def different_positions(answer, numbers):
    different_positions = [index for index in range(len(numbers))]
    different_positions = list([abs(answer.index(numbers[x]) - x) for x in different_positions])
    return different_positions

def find_best_swap_position(answer, numbers, differents, max_different_position):
    min_sum = 1000000
    min_pattern = None
    for i in range(len(numbers)):
        if differents[i] == 0:
            continue
        if i != max_different_position:
            pattern = copy.deepcopy(numbers)
            pattern[i], pattern[max_different_position] = (pattern[max_different_position], pattern[i])
            sum_different = sum(different_positions(answer, pattern))
            if min_sum > sum_different:
                min_sum = sum_different
                min_pattern = pattern
    return min_pattern

numbers = [-1 for i in range(int(eval(input())))]
numbers = list([int(eval(input())) for x in numbers])
base_sort_count, answer = count_sort_count(copy.deepcopy(numbers))
if base_sort_count == 0:
    print((1))
else:
    differents = different_positions(answer, numbers)
    max_different_position = differents.index(max(differents))
    swaped = find_best_swap_position(answer, numbers, differents, max_different_position)
    print((count_sort_count(swaped)[0]))