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::io::Read;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr;
}

impl<'a> Parse for std::str::SplitWhitespace<'a> {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn group_by_same(v: Vec<u32>) -> Vec<Vec<u32>> {
    let mut groups = Vec::new();
    let mut group = Vec::new();
    group.push(v[0]);
    for i in 1..v.len() {
        if v[i - 1] != v[i] {
            groups.push(group);
            group = Vec::new();
        }
        group.push(v[i]);
    }
    if !group.is_empty() {
        groups.push(group);
    }
    groups
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n = iter.to();
    let v = (0..n).map(|_| iter.to()).collect::<Vec<_>>();
    let mut v1: Vec<u32> = v.iter()
        .enumerate()
        .filter(|&x| x.0 % 2 == 0)
        .map(|x| x.1)
        .cloned()
        .collect();
    v1.sort();
    let mut c1 = group_by_same(v1)
        .into_iter()
        .map(|group| (group.len(), group[0]))
        .collect::<Vec<_>>();
    let mut v2: Vec<u32> = v.iter()
        .enumerate()
        .filter(|&x| x.0 % 2 == 1)
        .map(|x| x.1)
        .cloned()
        .collect();
    v2.sort();
    let mut c2 = group_by_same(v2)
        .into_iter()
        .map(|group| (group.len(), group[0]))
        .collect::<Vec<_>>();

    c1.sort();
    c2.sort();
    let l1 = c1.last().unwrap();
    let l2 = c2.last().unwrap();
    let ans = if l1.1 == l2.1 {
        let l12 = if c1.len() >= 2 { c1[c1.len() - 2].0 } else { 0 };
        let l22 = if c2.len() >= 2 { c2[c2.len() - 2].0 } else { 0 };
        n - std::cmp::max(l1.0 + l22, l2.0 + l12)
    } else {
        n - l1.0 - l2.0
    };

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