#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace::std;
//struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
__attribute__((constructor))
void init(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
}
// random_device rd;
// mt19937 mt(rd());
// #include <boost/numeric/interval.hpp>
// #include <boost/numeric/interval/io.hpp>
// #include <boost/intrusive/rbtree.hpp>
// #include <boost/dynamic_bitset.hpp>
// #include <boost/geometry.hpp>
// #include <boost/geometry/geometries/linestring.hpp>
// #include <boost/geometry/geometries/polygon.hpp>
// #include <boost/geometry/geometries/point_xy.hpp>
// #include <boost/math/tools/minima.hpp>
// using boost::math::tools::brent_find_minima;
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<256>> cdouble;
// typedef mp::cpp_int cint;
// #include <boost/unordered_map.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
template<typename T=long long>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T=long long>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T=long long>using pqueue =__gnu_pbds::priority_queue<T, less<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
typedef vector<pair<lint,lint>> pvec;
typedef vector<vector<pair<lint,lint>>> pmat;
typedef vector<vector<vector<pair<lint,lint>>>> pmat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
//#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define SUM(v) accumulate(all(v),0LL)
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define LINF 9223372036854775807
//#define MOD 998244353LL
#define MOD 1000000007LL
#define endl "\n"
//struct in{template<class T>operator T(){T t;cin>>t;return t;}};
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(int i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(int i=0;i<t.size();i++)output(t[i]);}
auto Y=[&](auto f){return[&](auto... args){return f(f, args...);};};
template<typename T=lint>T in(){return *istream_iterator<T>(cin);}
template<typename T=lint>inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T=lint>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<typename T>inline T minq(T a,T b){return min(a,b);}
template<typename T>inline T maxq(T a,T b){return max(a,b);}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};

class dinamic_connectivity{
    using DC=dinamic_connectivity*;
    class euler_tour_tree{
        unsigned long rnd() {
            static unsigned long x=123456789, y=362436069, z=521288629, w=88675123;
            unsigned long t=(x^(x<<11));
            x=y; y=z; z=w;
            return ( w=(w^(w>>19))^(t^(t>>8)) );
        }
        struct node;
        using np=node*;
        struct node{
            np par=nullptr;
            np ch[2]={nullptr,nullptr};
            int l,r,cnt=1;
            node(int l,int r):l(l),r(r){}
        };
        inline int count(np t){return !t?0:t->cnt;}
        np update(np& t){
            if(!t)return t;
            if(t->ch[0])t->ch[0]->par=t;
            if(t->ch[1])t->ch[1]->par=t;
            t->cnt=count(t->ch[0])+count(t->ch[1])+1;
            return t;
        }
        int sz;
        unordered_map<int,unordered_map<int,np>> ptr;
        public:
        euler_tour_tree(){}
        np get_node(const int& l,const int& r){
            if(!ptr[l].count(r))ptr[l][r]=new node(l,r);
            return ptr[l][r];
        }
        inline bool same(const int& s,const int& t){
            return root(get_node(s,s))==root(get_node(t,t));
        }
        bool link(const int& l,const int r){
            if(same(l,r))return 0;
            merge(reroot(get_node(l,l)),get_node(l,r),reroot(get_node(r,r)),get_node(r,l));
            return 1;
        }
        bool cut(const int& l,const int& r){
			if(!ptr[l].count(r))return 0;
			np s,t,u;
            tie(s,t,u)=split(get_node(l,r),get_node(r,l));
			split(t,1);
			merge(s,split(u,1).second);
            delete(get_node(l,r));
            delete(get_node(r,l));
			ptr[l].erase(r);
			ptr[r].erase(l);
            return 1;
        }
        inline int size(int t){
            return root(ptr[t][t])->cnt;
        }
        vector<pair<int,int>> upgrade_edge(const int& s,euler_tour_tree& next){
            vector<pair<int,int>>res;
            stack<np> stk;
            stk.emplace(root(get_node(s,s)));
            while(!stk.empty()){
                auto t=stk.top();
                stk.pop();
                if(!t)continue;
                if(t->l<t->r)next.link(t->l,t->r);
                stk.emplace(t->ch[0]);
                stk.emplace(t->ch[1]);
            };
            return res;
        }
        pair<int,int> try_reconnect(const int& s,const int& t,const int& layer,DC dc){
            stack<np> stk;
            unordered_set<int>tmp;
            stk.emplace(root(get_node(s,s)));
            while(!stk.empty()){
                auto s=stk.top();
                stk.pop();
                if(!s)continue;
                if(!tmp.count(s->l)){
                    auto d=dc->reconnect(s->l,t,layer);
                    if(d.first!=-1)return d;
                }
                else tmp.emplace(s->l);
                stk.emplace(s->ch[0]);
                stk.emplace(s->ch[1]);
            }
            return {-1,-1};
        }
        private:
        inline np reroot(np t){
            auto s=split(t);
            return merge(s.second,s.first);
        }
        inline np root(np t){
            while(t->par)t=t->par;
            return t;
        }
        inline np merge(const np& p,const np& q,const np& r,const np& s){
            return merge(merge(p,q),merge(r,s));
        }
        np merge(np l,np r){
            if(!l||!r)return !l?r:l;
            if((unsigned long)count(l)>rnd()%(unsigned long)(count(l)+count(r))){
                if(l->ch[1])l->ch[1]->par=nullptr;
                l->ch[1]=merge(l->ch[1],r);
                return update(l);
            }else{
                if(r->ch[0])r->ch[0]->par=nullptr;
                r->ch[0]=merge(l,r->ch[0]);
                return update(r);
            }
        }
		tuple<np,np,np> split(np s,np t){
			int si=count(s->ch[0]);
            while(s->par){
                if(s->par->ch[1]==s)si+=count(s->par->ch[0])+1;
                s=s->par;
            }
            int ti=count(t->ch[0]);
            while(t->par){
                if(t->par->ch[1]==t)ti+=count(t->par->ch[0])+1;
                t=t->par;
            }
			if(ti<si)swap(si,ti);
            return split(t,si,ti);
        }
        pair<np,np> split(np t){
            if(!t)return {nullptr,nullptr};
            pair<np,np>res={t->ch[0],t};
            if(t->ch[0])t->ch[0]->par=nullptr;
            t->ch[0]=nullptr;
            update(t);
            while(t->par){
                if(t->par->ch[0]=t){
                    res.second=t->par;
                }else{
                    np s=res.first;
                    res.first=t->par;
                    if(t->par->ch[1])t->par->ch[1]->par=nullptr;
                    t->par->ch[1]=s;
                    update(t->par);
                }
                t=t->par;
            }
            return res;
        }
        //0-indexed [-INF,l),[l,r),[r,INF)
        tuple<np,np,np> split(np t,int l,int r){
            auto p=split(t,l);
            auto q=split(p.second,r-l);
            return make_tuple(p.first,q.first,q.second);
        }
        //0-indexed [-INF,k),[k,INF)
        pair<np,np> split(np t,int k){
            if(!t)return make_pair(nullptr,nullptr);
            bool b=k>count(t->ch[0]);
            auto s=split(t->ch[b],k-(b?(count(t->ch[0])+1):0));
            if(t->ch[b])t->ch[b]->par=nullptr;
            t->ch[b]=b?s.first:s.second;
            return b?make_pair(update(t),s.second):make_pair(s.first,update(t));
        }

    };
    unordered_map<int,euler_tour_tree> ett;
    unordered_map<int,unordered_map<int,unordered_map<int,int>>> edgeList;
    int sz,log=0;
    public:
    dinamic_connectivity(int sz):sz(sz){}
    inline bool link(int s,int t){
        if(!ett[0].link(s,t)){
			edgeList[0][s][t]++;
			edgeList[0][t][s]++;
            return 0;
        }
        return 1;
    }
    inline bool same(int s,int t){
        return ett[0].same(s,t);
    }
    inline bool cut(int s,int t){
        int layer=-1;
        for(int i=0;i<=log;i++){
            if(ett[i].same(s,t)){
                ett[i].cut(s,t);
				layer=i;
            }else{
				if(edgeList[i][s].count(t)){
					edgeList[i][s][t]--;
					if(edgeList[i][s][t]==0)edgeList[i][s].erase(t);
				}
				if(edgeList[i][t].count(s)){
					edgeList[i][t][s]--;
					if(edgeList[i][t][s]==0)edgeList[i][t].erase(s);
				}
			}
        }
        for(int i=layer;i>=0;i--){
			if(ett[i].size(s)>ett[i].size(t))swap(s,t);
            chmax(log,i+1);
        	ett[i].upgrade_edge(s,ett[i+1]);
            pair<int,int>d;
			if((d=ett[i].try_reconnect(s,t,i,this)).first!=-1){
				ett[0].link(d.first,d.second);
				return 0;
			}
		}
		return 1;
    }
 
    pair<int,int> reconnect(const int& s,const int& t,const int& layer){
		pair<int,int> res={-1,-1};
		vector<pair<int,int>>eraseList;
        for(auto d:edgeList[layer][s]){
            int es=s,et=d.first,cnt=d.second;
            if(ett[layer].same(et,t)){
                if(res==pair<int,int>{-1,-1}){
                    res={es,et};
                    edgeList[layer][es][et]--;
                    edgeList[layer][et][es]--;
                    if(edgeList[layer][es][et]==0)eraseList.emplace_back(es,et);
                    if(edgeList[layer][et][es]==0)eraseList.emplace_back(et,es);
                    goto last;
                }
            }else{
                eraseList.emplace_back(es,et);
                edgeList[layer][es][et]=0;
                chmax(log,layer+1);
                edgeList[layer+1][es][et]+=cnt;
            }
        }
        last:;
		for(auto d:eraseList)edgeList[layer][d.first].erase(d.second);
		return res;
    }
};


 
int main(){
    lint n;
    cin>>n;
    vec a(n);
    rep(i,n)cin>>a[i];
    auto v=a;
    sort(all(v));
    set<lint>s,t;
    rep(i,n){
        if(i%2)s.insert(v[i]);
        else t.insert(v[i]);
    }
    lint ans=0;
    rep(i,n){
        if(i%2)ans+=!s.count(a[i]);
        else ans+=!t.count(a[i]);
    }
    cout<<ans/2<<endl;
}


Measured memory_bytes: 6528