stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

#define For(i,n) for(int i =0; i<n;i++)

#define ll long long

using namespace std;



int main(){

    #ifdef magUNbos

    freopen("in","r",stdin);

    freopen("out","w",stdout);

    #endif // magUNbos

    int n;

    cin>>n;

    ll a[n];

    map <ll, ll> m;

    For(i,n){

        cin>>a[i];

        m[a[i]]=i;

    }

    sort(a,a+n);

    ll ans = 0;

    For(i,n){

        if((abs(i-m[a[i]]) % 2)){

            ans++;

           // cerr<<i<<" : "<<m[a[i]]<<endl;

        }

    }

    cout<<ans/2<<endl;









}


// Faster C++ solution for the same problem (measured speedup: 5.290880079964516x):
#include <cstdio>

#include <cmath>

#include <cstring>

#include <algorithm>

using namespace std;

int  a,b,c,d,i,j,k,x,y,z,ans,gay;

int f[100005],h[10010][1005][2],g[10010];

int main(){

	gay=0;

	ans=0;

	scanf("%d",&a);

	for (i=1;i<=a;i++) 	{

		scanf("%d",&f[i]);

		c=f[i]%10007;

		g[c]++;

		h[c][g[c]][0]=f[i];

		h[c][g[c]][1]=i;

	}

	sort(f+1,f+a+1);

	for (i=1;i<=a;i++){

		c=f[i]%10007;

		//printf("D%d\n",g[c]);

		for (j=1;j<=g[c];j++){

			if (h[c][j][0]==f[i]){

				//printf("E%d %d\n",h[c][j][0],h[c][j][1]);

				if (abs((h[c][j][1]-i)%2)==1) ans++;

				break;

			}

		}

	}

	printf("%d\n",(ans)/2);

}
// Slower C++ solution:
#include <algorithm>

#include <iostream>

#include <map>

using namespace std;



int main() {

	int n; cin >> n;

	int arr[n];

	map<int, int> index;

	for (int i = 0; i < n; i++) {

		cin >> arr[i];

		index[arr[i]] = i;

	}

	sort(arr, arr+n);



	int ans = 0;

	for (int i = 0; i < n; i++) {

		ans += (i%2 != index[arr[i]]%2);

	}

	cout << ans/2 << '\n';

}


// Faster C++ solution for the same problem (measured speedup: 5.272891160065189x):
#include <cstdio>

#include <cmath>

#include <cstring>

#include <algorithm>

using namespace std;

int  a,b,c,d,i,j,k,x,y,z,ans,gay;

int f[100005],h[10010][1005][2],g[10010];

int main(){

	gay=0;

	ans=0;

	scanf("%d",&a);

	for (i=1;i<=a;i++) 	{

		scanf("%d",&f[i]);

		c=f[i]%10007;

		g[c]++;

		h[c][g[c]][0]=f[i];

		h[c][g[c]][1]=i;

	}

	sort(f+1,f+a+1);

	for (i=1;i<=a;i++){

		c=f[i]%10007;

		//printf("D%d\n",g[c]);

		for (j=1;j<=g[c];j++){

			if (h[c][j][0]==f[i]){

				//printf("E%d %d\n",h[c][j][0],h[c][j][1]);

				if (abs((h[c][j][1]-i)%2)==1) ans++;

				break;

			}

		}

	}

	printf("%d\n",(ans)/2);

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

using namespace std;



int main()

{

    int N;

    pair<int, int> A[100000];

    cin >> N;

    for (int i = 0; i < N; i++)

    {

        pair<int, int> temp;

        temp.second = i;

        cin >> temp.first;

        A[i] = temp;

    }

    sort(A, A + N);

    int result = 0;

    for(int i = 0; i < N; i++)

        if(abs(A[i].second - i) % 2 != 0)

            result++;

    cout << result / 2 << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.7717472836876567x):
#include <bits/stdc++.h>



using namespace std;



int main() {

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;

	cin >> n;

	vector<int> A(n);

	for (auto &i: A)cin >> i;



	vector<int> B = A;

	sort(B.begin(), B.end());

	int odd = 0;

	for (int i = 0; i < A.size(); ++i) {

	  int j = lower_bound(B.begin(), B.end(), A[i]) - B.begin();

	  if ((i - j) % 2)

		++odd;

	}

	cout << odd / 2 << '\n';



  return 0;

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

using namespace std;



int main()

{

    int N;

    pair<int, int> A[100000];

    cin >> N;

    for (int i = 0; i < N; i++)

    {

        pair<int, int> temp;

        temp.second = i;

        cin >> temp.first;

        A[i] = temp;

    }

    sort(A, A + N);

    int result = 0;

    for(int i = 0; i < N; i++)

        if(abs(A[i].second - i) % 2 != 0)

            result++;

    cout << result / 2 << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.8340618837639513x):
#include <bits/stdc++.h>

using namespace std;

const int maxn=100000;

struct _node{

	int A;

	int p;

	static bool cmp(_node &a,_node &b){

		return a.A<b.A;

	}

};

_node l[maxn+1];

int n;

int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;++i){

		scanf("%d",&l[i].A);

		l[i].p=i;

	}

	sort(l+1,l+1+n,_node::cmp);

	int cnt=0;

	for(int i=1;i<=n;++i){

		cnt+=abs(l[i].p-i)%2;

	}

	printf("%d",cnt/2);

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

using namespace std;



int main()

{

    int N;

    pair<int, int> A[100000];

    cin >> N;

    for (int i = 0; i < N; i++)

    {

        pair<int, int> temp;

        temp.second = i;

        cin >> temp.first;

        A[i] = temp;

    }

    sort(A, A + N);

    int result = 0;

    for(int i = 0; i < N; i++)

        if(abs(A[i].second - i) % 2 != 0)

            result++;

    cout << result / 2 << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.807791640405974x):
#include <algorithm>

#include <iostream>

#include <vector>

#include <set>

using namespace std;



int n, tmp, ans;

vector<int> a;

set<int> s;



int main() {

	cin >> n;

	for (int i = 0; i < n; i++) {

		cin >> tmp;

		a.push_back(tmp);

		if (i % 2 == 0)

			s.insert(tmp);

	}

	sort(a.begin(), a.end());

	for (int i = 0; i < n; i += 2)

		if (s.find(a[i]) == s.end())

			ans++;

	cout << ans;

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

using namespace std;



int main()

{

    int N;

    pair<int, int> A[100000];

    cin >> N;

    for (int i = 0; i < N; i++)

    {

        pair<int, int> temp;

        temp.second = i;

        cin >> temp.first;

        A[i] = temp;

    }

    sort(A, A + N);

    int result = 0;

    for(int i = 0; i < N; i++)

        if(abs(A[i].second - i) % 2 != 0)

            result++;

    cout << result / 2 << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.810989376041108x):
#include <iostream>

#include <algorithm>



using namespace std;

const int N = 1e6 + 10;

typedef pair <int, int> pii;



int n;

pii a[N];



int main() {

	cin >> n;

	for (int i = 0; i < n; i++) {

		cin >> a[i].first;

		a[i].second = i;

	}



	int ans = 0;

	sort (a, a + n);

	for (int i = 0; i < n; i += 2)

		if ((i % 2) != (a[i].second % 2))

			ans ++;



	cout << ans << endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



bool even(int a, int b) {

    return (a%2 == 0) && (b%2 == 0);

}



bool odd(int a, int b) {

    return (a%2 != 0) && (b%2 != 0);

}



int main() {



    int n, k, cont = 0;

    cin >> n;



    vector<int> arr(n);

    map<int, int> idx;



    for(int i=0; i<n; i++) {

        cin >> k;

        idx[k] = i;

        arr[i] = k;

    }



    sort(arr.begin(), arr.end());

    /*for(int i=0; i<n; i++)cout << arr[i] << ' ';

    cout << endl;*/



    for(int i=0; i<n; i++) {



        if(even(i, idx[arr[i]]) || odd(i, idx[arr[i]])) {

            //cont++;

            //cout << "here\n";

        } else {

            cont++;

        }





    }



    cout << (int)cont/2 << '\n';

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.275572711966364x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=3e5+5;

int a[N];

int b[N],bn;

int n;

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++){

        scanf("%d",&a[i]);

        b[i]=a[i];

    }

    sort(b+1,b+n+1);

    bn=unique(b+1,b+n+1)-b;

    for(int i=1;i<=n;i++)

        a[i]=lower_bound(b+1,b+bn+1,a[i])-b;

    int ans=0;

    for(int i=1;i<=n;i++){

        if(i%2!=a[i]%2)

            ans++;

    }

    ans/=2;

    printf("%d\n",ans);

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define PB          push_back

#define PF          push_front

#define MP          make_pair

#define FI          first

#define SE          second

#define SIZE( A )   int( ( A ).size( ) )

#define ALL( A )    ( A ).begin( ), ( A ).end( )

#define ALLR( A )   ( A ).rbegin( ), ( A ).rend( )



using namespace std;



typedef long long           ll;

typedef unsigned long long  ull;

typedef long double         lf;

typedef pair< int, int >    pii;

typedef pair< ll, ll >      pll;

typedef vector< bool >      vb;

typedef vector< lf >        vd;

typedef vector< ll >        vll;

typedef vector< int >       vi;

typedef vector< pii >       vpii;



const int MAXN = int( 2e5 );

const int MOD  = int( 360 );

const int oo   = INT_MAX;



int n;

int arr[ MAXN ], cp[ MAXN ];

int tp[ MAXN ];



int main( ) {



  #ifdef LOCAL

    freopen( "input", "r", stdin );

    //freopen( "output", "w", stdout );

  #else

    //freopen( "attack.in", "r", stdin );

    //freopen( "attack.out", "w", stdout );

    ios_base::sync_with_stdio( 0 );

    cin.tie( 0 );

  #endif



  while( cin >> n ) {

    for( int i = 0; i < n; ++i ) {

      cin >> arr[ i ];

    }

    memcpy( cp, arr, sizeof( int )*n );

    sort( cp, cp+n );

    int ans = 0;

    for( int i = 0; i < n; ++i ) {

      int pos = lower_bound( cp, cp+n, arr[ i ] )-cp;

      if( pos%2 != i%2 ) {

        ++ans;

      }

    }

    cout << ans/2 << '\n';

  }



  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.286888985334775x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=3e5+5;

int a[N];

int b[N],bn;

int n;

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++){

        scanf("%d",&a[i]);

        b[i]=a[i];

    }

    sort(b+1,b+n+1);

    bn=unique(b+1,b+n+1)-b;

    for(int i=1;i<=n;i++)

        a[i]=lower_bound(b+1,b+bn+1,a[i])-b;

    int ans=0;

    for(int i=1;i<=n;i++){

        if(i%2!=a[i]%2)

            ans++;

    }

    ans/=2;

    printf("%d\n",ans);

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define For(i,n) for(int i =0; i<n;i++)

#define ll long long

using namespace std;



int main(){

    #ifdef magUNbos

    freopen("in","r",stdin);

    freopen("out","w",stdout);

    #endif // magUNbos

    int n;

    cin>>n;

    ll a[n];

    map <ll, ll> m;

    For(i,n){

        cin>>a[i];

        m[a[i]]=i;

    }

    sort(a,a+n);

    ll ans = 0;

    For(i,n){

        if((abs(i-m[a[i]]) % 2)){

            ans++;

           // cerr<<i<<" : "<<m[a[i]]<<endl;

        }

    }

    cout<<ans/2<<endl;









}


// Faster C++ solution for the same problem (measured speedup: 5.2884946996719115x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=3e5+5;

int a[N];

int b[N],bn;

int n;

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++){

        scanf("%d",&a[i]);

        b[i]=a[i];

    }

    sort(b+1,b+n+1);

    bn=unique(b+1,b+n+1)-b;

    for(int i=1;i<=n;i++)

        a[i]=lower_bound(b+1,b+bn+1,a[i])-b;

    int ans=0;

    for(int i=1;i<=n;i++){

        if(i%2!=a[i]%2)

            ans++;

    }

    ans/=2;

    printf("%d\n",ans);

}
// Slower C++ solution:
#include <algorithm>

#include <iostream>

#include <map>

using namespace std;



int main() {

	int n; cin >> n;

	int arr[n];

	map<int, int> index;

	for (int i = 0; i < n; i++) {

		cin >> arr[i];

		index[arr[i]] = i;

	}

	sort(arr, arr+n);



	int ans = 0;

	for (int i = 0; i < n; i++) {

		ans += (i%2 != index[arr[i]]%2);

	}

	cout << ans/2 << '\n';

}


// Faster C++ solution for the same problem (measured speedup: 5.270513890032951x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=3e5+5;

int a[N];

int b[N],bn;

int n;

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++){

        scanf("%d",&a[i]);

        b[i]=a[i];

    }

    sort(b+1,b+n+1);

    bn=unique(b+1,b+n+1)-b;

    for(int i=1;i<=n;i++)

        a[i]=lower_bound(b+1,b+bn+1,a[i])-b;

    int ans=0;

    for(int i=1;i<=n;i++){

        if(i%2!=a[i]%2)

            ans++;

    }

    ans/=2;

    printf("%d\n",ans);

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<algorithm>

using namespace std;

int n,o;

pair<int,bool> a[100005];

int main()

{

	scanf("%d",&n);

	for (int i=1;i<=n;i++)

	{

		scanf("%d",&a[i].first);

		if (i%2==0) a[i].second=true;

	}

	sort(a+1,a+n+1);

	for (int i=1;i<=n;i++)

	{

		if ((i%2==0)!=a[i].second) 

		++o;

	}

	printf("%d",o/2);

}

// Faster C++ solution for the same problem (measured speedup: 5.1529594866233115x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=3e5+5;

int a[N];

int b[N],bn;

int n;

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++){

        scanf("%d",&a[i]);

        b[i]=a[i];

    }

    sort(b+1,b+n+1);

    bn=unique(b+1,b+n+1)-b;

    for(int i=1;i<=n;i++)

        a[i]=lower_bound(b+1,b+bn+1,a[i])-b;

    int ans=0;

    for(int i=1;i<=n;i++){

        if(i%2!=a[i]%2)

            ans++;

    }

    ans/=2;

    printf("%d\n",ans);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define FOR(i, s, e) for(int i = (s); i < (e); i++)

#define FOE(i, s, e) for(int i = (s); i <= (e); i++)

#define FOD(i, s, e) for(int i = (s); i >= (e); i--)

#define ll long long



int A[100005], B[100005], n;



map<int, int> M;



int main ()

{

	scanf("%d", &n);

	FOR(i, 0, n) { scanf("%d", &A[i]); B[i] = A[i]; }

	

	sort(B, B + n);

	

	FOR(i, 0, n) M.insert(make_pair(A[i], i % 2));

	

	int ans = 0;

	FOR(i, 0, n)

	{

		if (i % 2 != M.find(B[i]) -> second) ans++;

	}

	

	printf("%d\n", ans / 2);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.2106270640340675x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=3e5+5;

int a[N];

int b[N],bn;

int n;

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++){

        scanf("%d",&a[i]);

        b[i]=a[i];

    }

    sort(b+1,b+n+1);

    bn=unique(b+1,b+n+1)-b;

    for(int i=1;i<=n;i++)

        a[i]=lower_bound(b+1,b+bn+1,a[i])-b;

    int ans=0;

    for(int i=1;i<=n;i++){

        if(i%2!=a[i]%2)

            ans++;

    }

    ans/=2;

    printf("%d\n",ans);

}
// Slower C++ solution:
#include <iostream>

#include <sstream>

#include <iomanip>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cctype>

#include <cstring>

#include <vector>

#include <list>

#include <queue>

#include <deque>

#include <stack>

#include <map>

#include <set>

#include <algorithm>

#include <iterator>

#include <bitset>

#include <ctime>

using namespace std;



#define FOR(i,a,b) for (int i = (a); i < (b); i++)

#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)

#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a,value) memset(a, value, sizeof(a))



#define SZ(a) (int)a.size()

#define ALL(a) a.begin(), a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const int INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL) INF;

const int MOD = 1000 * 1000 * 1000 + 7;



const int MAX = 111*1000;



PII A[MAX];



int main()

{

    int n;

    scanf("%d", &n);

    FOR(i, 0, n)

    {

        scanf("%d", &A[i].first);

        A[i].second = i;

    }

    sort(A, A + n);

    int ans = 0;

    FOR(i, 0, n)

    {

        if (!(i & 1) && (A[i].second & 1))

            ans++;

    }

    cout << ans << endl;

    

}


// Faster C++ solution for the same problem (measured speedup: 5.172222485045525x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=3e5+5;

int a[N];

int b[N],bn;

int n;

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++){

        scanf("%d",&a[i]);

        b[i]=a[i];

    }

    sort(b+1,b+n+1);

    bn=unique(b+1,b+n+1)-b;

    for(int i=1;i<=n;i++)

        a[i]=lower_bound(b+1,b+bn+1,a[i])-b;

    int ans=0;

    for(int i=1;i<=n;i++){

        if(i%2!=a[i]%2)

            ans++;

    }

    ans/=2;

    printf("%d\n",ans);

}
// Slower C++ solution:
#include<iostream>

#include <bits/stdc++.h>

using namespace std;



class par

{

 public:

 int value;

 int pos;

};

bool comp(par a, par b)

{

if(a.value<b.value)return true;

return false;

};

int main()

{

    int n;

    cin>>n;

    vector<par>v (n);

    for(int i=0 ; i<n;i++)

        {

            int temp;

            cin>>temp;

            v[i].pos=i;

            v[i].value=temp;

        }

    sort(v.begin(), v.end(), comp);

     int times=0;



     for(int i=0 ; i<n;i+=2)

     {

      {

          if(i%2!=v[i].pos%2)

            times++;

      }



     }

     cout<<times<<endl;

     

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.265246320127807x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=3e5+5;

int a[N];

int b[N],bn;

int n;

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++){

        scanf("%d",&a[i]);

        b[i]=a[i];

    }

    sort(b+1,b+n+1);

    bn=unique(b+1,b+n+1)-b;

    for(int i=1;i<=n;i++)

        a[i]=lower_bound(b+1,b+bn+1,a[i])-b;

    int ans=0;

    for(int i=1;i<=n;i++){

        if(i%2!=a[i]%2)

            ans++;

    }

    ans/=2;

    printf("%d\n",ans);

}
// Slower C++ solution:
#include <iostream>

#include <bits/stdc++.h>

#define endl '\n'

#define MAXN 1000010

#define vi vector<int>

#define pii pair<int, int>

#define vii vector<pii>

using namespace std;



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int n; cin >> n;

    vi num;

    vii ordered;

    int index = 0;

    int n1 = n;

    while (n1--){

        int x; cin >> x;

        num.push_back(x);

        ordered.emplace_back(x, index);

        index++;

    }

    sort(ordered.begin(), ordered.end());

    int count = 0;

    for (int i = 0; i < n; ++i) {

        if(ordered[i].second % 2 != i % 2) ++count;

    }

    cout << (count >> 1) << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.338992373916037x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=3e5+5;

int a[N];

int b[N],bn;

int n;

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++){

        scanf("%d",&a[i]);

        b[i]=a[i];

    }

    sort(b+1,b+n+1);

    bn=unique(b+1,b+n+1)-b;

    for(int i=1;i<=n;i++)

        a[i]=lower_bound(b+1,b+bn+1,a[i])-b;

    int ans=0;

    for(int i=1;i<=n;i++){

        if(i%2!=a[i]%2)

            ans++;

    }

    ans/=2;

    printf("%d\n",ans);

}
// Slower C++ solution:
#include <bits/stdc++.h>

#include <ext/algorithm>

#include <ext/numeric>

#define endl '\n'

using namespace std;

using namespace __gnu_cxx;



int main()

{

	ios_base::sync_with_stdio(0);

	cin.tie(0);



/**************************************************************/



	int N;

	cin >> N;

	pair<int,int> array[N];



	int count;

	for(int i = 0; i < N; i++)

	{

		cin >> count;

		array[i] = {count,i};

	}



	sort(array, array+N);

	count = 0;

	for(int i = 0; i < N; i++)

		if(i%2 != array[i].second%2)

			count++;



	cout << (count >> 1) << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.282640547215043x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=3e5+5;

int a[N];

int b[N],bn;

int n;

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++){

        scanf("%d",&a[i]);

        b[i]=a[i];

    }

    sort(b+1,b+n+1);

    bn=unique(b+1,b+n+1)-b;

    for(int i=1;i<=n;i++)

        a[i]=lower_bound(b+1,b+bn+1,a[i])-b;

    int ans=0;

    for(int i=1;i<=n;i++){

        if(i%2!=a[i]%2)

            ans++;

    }

    ans/=2;

    printf("%d\n",ans);

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

using namespace std;



int main()

{

    int N;

    pair<int, int> A[100000];

    cin >> N;

    for (int i = 0; i < N; i++)

    {

        pair<int, int> temp;

        temp.second = i;

        cin >> temp.first;

        A[i] = temp;

    }

    sort(A, A + N);

    int result = 0;

    for(int i = 0; i < N; i++)

        if(abs(A[i].second - i) % 2 != 0)

            result++;

    cout << result / 2 << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 9.44813635985392x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=3e5+5;

int a[N];

int b[N],bn;

int n;

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++){

        scanf("%d",&a[i]);

        b[i]=a[i];

    }

    sort(b+1,b+n+1);

    bn=unique(b+1,b+n+1)-b;

    for(int i=1;i<=n;i++)

        a[i]=lower_bound(b+1,b+bn+1,a[i])-b;

    int ans=0;

    for(int i=1;i<=n;i++){

        if(i%2!=a[i]%2)

            ans++;

    }

    ans/=2;

    printf("%d\n",ans);

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



int main() {

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;

	cin >> n;

	vector<int> A(n);

	for (auto &i: A)cin >> i;



	vector<int> B = A;

	sort(B.begin(), B.end());

	int odd = 0;

	for (int i = 0; i < A.size(); ++i) {

	  int j = lower_bound(B.begin(), B.end(), A[i]) - B.begin();

	  if ((i - j) % 2)

		++odd;

	}

	cout << odd / 2 << '\n';



  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.332665920722553x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=3e5+5;

int a[N];

int b[N],bn;

int n;

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++){

        scanf("%d",&a[i]);

        b[i]=a[i];

    }

    sort(b+1,b+n+1);

    bn=unique(b+1,b+n+1)-b;

    for(int i=1;i<=n;i++)

        a[i]=lower_bound(b+1,b+bn+1,a[i])-b;

    int ans=0;

    for(int i=1;i<=n;i++){

        if(i%2!=a[i]%2)

            ans++;

    }

    ans/=2;

    printf("%d\n",ans);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

const int maxn=100000;

struct _node{

	int A;

	int p;

	static bool cmp(_node &a,_node &b){

		return a.A<b.A;

	}

};

_node l[maxn+1];

int n;

int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;++i){

		scanf("%d",&l[i].A);

		l[i].p=i;

	}

	sort(l+1,l+1+n,_node::cmp);

	int cnt=0;

	for(int i=1;i<=n;++i){

		cnt+=abs(l[i].p-i)%2;

	}

	printf("%d",cnt/2);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.151481770322817x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=3e5+5;

int a[N];

int b[N],bn;

int n;

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++){

        scanf("%d",&a[i]);

        b[i]=a[i];

    }

    sort(b+1,b+n+1);

    bn=unique(b+1,b+n+1)-b;

    for(int i=1;i<=n;i++)

        a[i]=lower_bound(b+1,b+bn+1,a[i])-b;

    int ans=0;

    for(int i=1;i<=n;i++){

        if(i%2!=a[i]%2)

            ans++;

    }

    ans/=2;

    printf("%d\n",ans);

}