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 Rust (1.15.1) (judge verdict: Wrong Answer)

#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}


#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


#[allow(unused_imports)]
use std::f64;

#[allow(dead_code)]
fn min<T: PartialOrd>(a:T, b:T) -> T {
    if a < b { a }
    else { b }
}
#[allow(dead_code)]
fn max<T: PartialOrd>(a:T, b:T) -> T {
    if a < b { b }
    else { a }
}

use std::hash::Hash;
#[allow(dead_code)]
fn inc<T: Hash+Ord>(map:&mut BTreeMap<T,i64>, key:T) {
    let count = map.entry(key).or_insert(0);
    *count += 1;
}

#[allow(dead_code)]
fn digit(ch: char) -> i64 {
    return (ch as u8 - b'0') as i64
}

#[allow(dead_code)]
const MAX:usize = 1000007;
#[allow(dead_code)]
const INF:i64 = std::i64::MAX;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;


struct BIT {
    n: usize,
    bit: Vec<i64>
}

impl BIT {
    fn new(n: usize) -> BIT {
        BIT {
            n: n,
            bit: vec![0;MAX],
        }
    }

    fn add(&mut self, a:i64, w:i64) {
        let mut x = a;
        while x <= self.n as i64 {
            self.bit[x as usize] += w;
            x += x & (-x);
        }
    }

    fn sum(&self, a:i64) -> i64 {
        let mut ret = 0;
        let mut x = a;
        while x > 0 {
            ret += self.bit[x as usize];
            x -= x & (-x);
        }
        ret
    }
}

fn main() {
    input!{n:usize, a:[i64;n]};
    let mut a = a;
    let mut map = HashMap::new();
    let mut b = a.clone();
    b.sort();
    for i in 0..n {
        map.insert(b[i], i);
    }
    for i in 0..n {
        a[i] = *map.get(&a[i]).unwrap() as i64 + 1;
    }
    //debug!(a);

    let mut ae = vec![];
    let mut ao = vec![];
    for i in 0..n {
        if i%2==0 { ae.push(a[i]); }
        else { ao.push(a[i]); }
    }
    ae.sort();
    ao.sort();

    let mut a = vec![];
    let mut j = 0;
    let mut k = 0;
    for i in 0..n {
        if i%2==0 {
            a.push(ae[j]);
            j+=1;
        } else {
            a.push(ao[k]);
            k+=1;
        }
    }
    //debug!(a);

    let mut ans = 0;
    /*
    let mut bit = BIT::new(n);

    for i in 0..n {
        //debug!(i, a[i], bit.sum(a[i]));
        ans += i as i64 - bit.sum(a[i]);
        bit.add(a[i],1);
    }
    */

    for i in 0..n-1 {
        if a[i] > a[i+1] {
            ans += 1;
        }
    }

    println!("{}", ans);

}

/*

操作２はいくらでもやっていい、操作１を最小にする
操作２は１個先の数を反転する操作
貪欲に操作２を先頭から行っていき、反転数が答え？

2 4 3 1
2 1 3 4

10 8 5 3 2
5 8 10 3 2
5 3 10 8 2
5 3 2 8 10

１回だとここまでしかならない

2 3 5 8 10

0 1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
8 9 10 7 6 5 4 3 2 1
8 7 10 9 6 5 4 3 2 1
8 7 6 9 10 5 4 3 2 1

偶奇独立でソートしたものが操作２でできる限界なので、
そこから反転数を求める
ただ、a[i]がでかいので、圧縮する必要がある
最初に全体をソートして、ソートしたもののインデックスと結びつける



*/