Problem:
Score : 600 points

Problem Statement

Snuke got an integer sequence of length N from his mother, as a birthday present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are pairwise distinct.
He is sorting this sequence in increasing order.
With supernatural power, he can perform the following two operations on the sequence in any order:

Operation 1: choose 2 consecutive elements, then reverse the order of those elements.

Operation 2: choose 3 consecutive elements, then reverse the order of those elements.

Snuke likes Operation 2, but not Operation 1. Find the minimum number of Operation 1 that he has to perform in order to sort the sequence in increasing order.

Constraints

1 ≦ N ≦ 10^5

0 ≦ A_i ≦ 10^9

If i ≠ j, then A_i ≠ A_j.

All input values are integers.

Input

The input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print the minimum number of times Operation 1 that Snuke has to perform.

Sample Input 1

4
2
4
3
1

Sample Output 1

1

The given sequence can be sorted as follows:

First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.

Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.

In this sequence of operations, Operation 1 is performed once. It is not possible to sort the sequence with less number of Operation 1, thus the answer is 1.

Sample Input 2

5
10
8
5
3
2

Sample Output 2

0

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <sstream>
#include <cmath>
#include <functional>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cout << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int64 gcd(int64 a, int64 b) {
    if (a < b) a, b = b, a;
    if (a % b == 0) return b;
    return gcd(b, a % b);
}

int64 modinv(int64 a, int64 m) {
    int64 b = m, u = 1, v = 0;
    while (b) {
        int64 t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// https://en.wikipedia.org/wiki/Trial_division
#define M map<int64, int64>
M f(int64 n) {
    M m;

    while (n % 2 == 0) {
        m[2]++;
        n = n / 2;
    }

    int64 c = 3;
    while (c * c <= n) {
        if (n % c == 0) {
            n = n / c;
            m[c]++;
        } else {
            c += 2;
        }
    }
    if (n != 1) m[n]++;
    return m;
}

template <typename T>
class SegmentTree {
private:
    int n;
    vector<T> data;
    function<T(T, T)> operation;
    function<T(T, T)> change;
public:
    SegmentTree(vector<T> d, function<T(T, T)> _operation, function<T(T, T)> _change)
        : operation(_operation), change(_change) {
        n = 1;
        while (n < d.size()) n *= 2;
        data.resize(n * 2 - 1, INF);

        rep(i, d.size()) data[data.size() - n + i] = d[i];
        rev(i, data.size() - n) data[i] = operation(data[i*2+1], data[i*2+2]);
    }

    void update(int index, T val) {
        index += n - 1;
        data[index] = change(data[index], val);
        while (index != 0) {
            index = (index - 1) / 2;
            data[index] = operation(data[index*2+1], data[index*2+2]);
        }
    }

    T query(int a, int b, int k=0, int l=0, int r=-1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return INF;
        if (a <= l && r <= b) return data[k];

        T left = query(a, b, k*2+1, l, (l+r)/2);
        T right = query(a, b, k*2+2, (l+r)/2, r);

        return operation(left, right);
    }

    T operator[](int index) {
        return data[index + n - 1];
    }
};

int main() {
    int N;
    cin >> N;

    vector<int> L(N);
    rep(i, N) cin >> L[i];

    vector<int> A, B;
    rep(i, N) {
        if (i % 2 == 0) A.push_back(L[i]);
        else B.push_back(L[i]);
    }
    sort(all(A));
    sort(all(B));

    rep(i, N) {
        if (i % 2 == 0) L[i] = A[i/2];
        else L[i] = B[i/2];
    }

    int ans = 0;
    int index = 0;
    // cout << L << endl;
    while (index < N - 1) {
        if (L[index] > L[index+1]) {
            index += 2;
            ans++;
        } else {
            index += 1;
        }
    }

    cout << ans << endl;
}