import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
import std.math;
 
auto solve(string s_)
{
    immutable N = s_.to!int();
    auto AS = new int[N];
    foreach(ref a;AS) a=readln.chomp().to!int();
    int[2][int] c;
    foreach(i;0..N)
    {
        immutable v=AS[i];
        if(v !in c) c[v]=[0,0];
        c[v][i&1]++;
    }
    immutable bs = sort(AS.dup).array();
    foreach(i;0..N)
    {
        immutable v=bs[i];
        if(v !in c) c[v]=[0,0];
        c[v][i&1]--;
    }
    int p=0;
    foreach(ref a;c) p+=(abs(a[0])+abs(a[1]))/2;
    return (p+1)/2;
}

void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }