#include <iostream>
#include <algorithm>

using namespace std;

void Swap(long *a, long *b)
{
	long temp = *a;
	*a = *b;
	*b = temp;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long n, m;
    cin >> n;
    m = n;
    long sec [n];
    queue<long> q ;
    int j = 0, temp, times = 0;
    bool enable = true;
    while(n--)
    {
        cin >> temp;
        sec[j] = temp;
        j++;
    }
    j = 0, temp = m;
    q.push(m - 1);
    while(enable)
    {
        enable = false;
       if (j + 2 < m && sec[j] > sec[j + 2])
       {
           Swap(&sec[j], &sec[j + 2]);
           q.push(j);
           j = j + 2;
           if (j == m - 1) j--;
           enable = true;
           continue;
       }
       if (j <= m - 2 && sec[j] > sec[j + 1])
       {
           if (j > 0 && sec[j - 1] > sec[j])
           {
               q.push(j);
               j = j - 1;
               enable = true;
               continue;
           }
           Swap(&sec[j], &sec[j + 1]);
           times++;
           enable = true;
       }
       if (j > 1 && sec[j] < sec[j - 2])
       {
           Swap(&sec[j], &sec[j - 2]);
           q.push(j);
           j = j - 2;
           if (j == 0) j++;
           enable = true;
           continue;
       }
       if (j > 0 && sec[j] < sec[j - 1])
       {
           if (j < m - 1 && sec[j] > sec[j + 1])
           {
               q.push(j);
               j = j + 1;
               enable = true;
               continue;
           }
           Swap(&sec[j], &sec[j - 1]);
           times++;
           enable = true;
       }
       if (!enable && !q.empty()){
        j = q.front();
        q.pop();
        enable = true;
       }
    }
    /*j = 0;
    while(temp--)
    {
        cout << sec[j] << " ";
        j++;
    }
    cout << endl;*/
    cout << times << endl;
    return 0;
}
