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)

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

use std::cmp::max;
use std::collections::BTreeMap;

fn main() {
    let n: usize = read();
    let v: Vec<u32> = read_vec();

    let mut odd: BTreeMap<u32, u32> = BTreeMap::new();
    let mut even: BTreeMap<u32, u32> = BTreeMap::new();

    for i in 0..(n / 2) {
        let e = 2 * i;
        let tmp: u32;
        if let Some(x) = even.get(&v[e]) {
            tmp = x + 1;
        } else {
            tmp = 1;
        }
        even.insert(v[e], tmp);

        let o = 2 * i + 1;
        let tmp: u32;
        if let Some(x) = odd.get(&v[o]) {
            tmp = x + 1;
        } else {
            tmp = 1;
        }
        odd.insert(v[o], tmp);
    }

    let mut fste: (u32, u32) = (0, 0);
    let mut snde: (u32, u32) = (0, 0);
    for (key, val) in even.iter() {
        if *val > fste.1 {
            snde = fste;
            fste = (*key, *val);
        } else if *val > snde.1 {
            snde = (*key, *val);
        }
    }

    let mut fsto: (u32, u32) = (0, 0);
    let mut sndo: (u32, u32) = (0, 0);
    for (key, val) in odd.iter() {
        if *val > fsto.1 {
            sndo = fsto;
            fsto = (*key, *val);
        } else if *val > sndo.1 {
            sndo = (*key, *val);
        }
    }

    let n: u32 = n as u32;

    if fste.0 != fsto.0 {
        println!("{}", n - fste.1 - fsto.1);
    } else {
        println!("{}", n - max(fste.1 + sndo.1, fsto.1 + snde.1));
    }
}