Problem:
Score : 300 points

Problem Statement

A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:

For each i = 1,2,..., n-2, a_i = a_{i+2}.

Exactly two different numbers appear in the sequence.

You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

Print the minimum number of elements that needs to be replaced.

Sample Input 1

4
3 1 3 2

Sample Output 1

1

The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

The sequence 105,119,105,119,105,119 is /\/\/\/.

Sample Input 3

4
1 1 1 1

Sample Output 3

2

The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.

Solution in Rust (1.15.1) (judge verdict: Accepted)

use std::cmp;

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<::std::cmp::Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> ::std::cmp::Ordering {
        other.0.cmp(&self.0)
    }
}

#[allow(dead_code)]
pub struct Scanner<'a> {
    _buf: &'a str,
    iter: ::std::str::SplitWhitespace<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    pub fn new(buf: &'a str) -> Self {
        Scanner {
            _buf: buf,
            iter: buf.split_whitespace(),
        }
    }

    pub fn array<T>(&mut self, n: usize) -> Vec<T>
        where T: ::std::str::FromStr,
              T::Err: ::std::fmt::Debug,
    {
        let mut res = Vec::with_capacity(n);
        for _ in 0..n {
            res.push(self.value());
        }
        res
    }

    pub fn value<T>(&mut self) -> T
        where T: ::std::str::FromStr,
              T::Err: ::std::fmt::Debug,
    {
        self.next().parse().unwrap()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.next().chars().collect()
    }

    fn next(&mut self) -> &str {
        self.iter.next().unwrap()
    }
}

fn cnt(v: &[i64]) -> Vec<i64> {
    let mut res = vec![0; 100001];
    for &e in v {
        res[e as usize] += 1;
    }
    res
}

fn top2(cnt: &[i64]) -> ((i64,i64),(i64,i64)) {
    let mut v: Vec<_> = cnt.iter().enumerate().map(|(i,&e)| (e,i as i64)).collect();
    v.sort_by_key(|&e| Rev(e));
    (v[0], v[1])
}

fn main() {
    let mut _input = String::new();
    {
        use ::std::io::Read;
        ::std::io::stdin().read_to_string(&mut _input).unwrap();
    }
    let mut sc = Scanner::new(&_input);

    let n = sc.value::<usize>();
    let m = (n/2) as i64;
    let (mut a, mut b) = (Vec::with_capacity(m as usize), Vec::with_capacity(m as usize));
    for _ in 0..m {
        a.push(sc.value::<i64>());
        b.push(sc.value::<i64>());
    }

    let cnt_a = cnt(&a);
    let cnt_b = cnt(&b);
    let top2_a = top2(&cnt_a);
    let top2_b = top2(&cnt_b);
    //eprintln!("{:?}", top2_a);
    //eprintln!("{:?}", top2_b);

    let ans = if (top2_a.0).1 != (top2_b.0).1 {
        m - (top2_a.0).0 + m - (top2_b.0).0
    }
    else {
        cmp::min(
            m - (top2_a.0).0 + m - (top2_b.1).0,
            m - (top2_a.1).0 + m - (top2_b.0).0
        )
    };

    println!("{}", ans);
}