unittest
{
	assert( [ "4", "2", "4", "3", "1" ].parse.expand.solve == 1 );
	assert( [ "5", "10", "8", "5", "3", "2" ].parse.expand.solve == 0 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto as = new long[ n ];
	foreach( ref a; as )
	{
		input.popFront;
		a = input.front.to!( long );
	}
	return tuple( as );
}

auto solve( long[] as )
{
	// 並べ替え前の位置を整理
	long[ long ] ps;
	foreach( i, a; as )
	{
		ps[ a ] = i;
	}
	
	// 並べ替え前と並べ替え後の位置の偶奇が不一致だったら操作1が必要
	auto ans = 0L;
	foreach( i, a; ps.keys.sort().enumerate( 0 ) )
	{
		ans += ( ps[ a ] % 2 != i % 2 );
	}
	return ans / 2;
}
