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 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}

typedef struct node_t{
	int data;
	struct node_t *left,*right;
	int pri;
	int cnt;
	int sum;
}Node;
typedef struct{
	Node *n1,*n2;
}Node_pair;
Node *make_node(int a){
	Node *n=(Node*)malloc(sizeof(Node));
	n->left=n->right=NULL;
	n->data=a,n->sum=a;
	n->cnt=1,n->pri=rand();
	return n;
}
int count(Node *n){return n==NULL?0:n->cnt;}
int sum(Node *n){return n==NULL?0:n->sum;}
Node *update(Node *n){
	n->cnt=count(n->left)+count(n->right)+1;
	n->sum=sum(n->left)+sum(n->right)+n->data;
	return n;
}
Node *merge(Node *l,Node *r){
	if(l==NULL) return r;
	if(r==NULL) return l;
	if(l->pri > r->pri){
		l->right=merge(l->right,r);
		return update(l);
	}else{
		r->left=merge(l,r->left);
		return update(r);
	}
}
Node_pair split(Node *n,int k){
	Node_pair s,res;
	if(n==NULL) res.n1=res.n2=NULL;
	else if(k<=count(n->left)){
		s=split(n->left,k);
		n->left=s.n2;
		res.n1=s.n1; res.n2=update(n);
	}else{
		s=split(n->right,k-count(n->left)-1);
		n->right=s.n1;
		res.n1=update(n); res.n2=s.n2;
	}
	return res;
}
Node *insert(Node *n,int k,int a){
	Node *t;
	Node_pair s;
	t=make_node(a);
	s=split(n,k);
	return merge(merge(s.n1,t),s.n2);
}
Node *erase(Node *n,int k){
	Node_pair sl,sr;
	sr=split(n,k+1);
	sl=split(sr.n1,k);
	return merge(sl.n1,sr.n2);
}
int find(Node *n,int a){
	if(n==NULL) return 0;
	if(n->data==a) return 1;
	if(n->data<a) return find(n->right,a);
	else return find(n->left,a);
}
int a[100000];
int main(void)
{
	srand((unsigned)time(NULL));
	int n,res=0,i;
	Node *k=NULL;
	scanf("%d",&n);
	FOR(i,0,n){
		scanf("%d",&a[i]);
		if(i%2) k=insert(k,0,a[i]);
	}
	qsort(a,n,sizeof(int),comp);
	for(i=0;i<n;i+=2){
		if(find(k,a[i])) res++;
	}
	printf("%d\n",res);
	return 0;
}