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: Wrong Answer)

use std::collections::HashMap;
use std::io;
/// 一行を読み込んで、空白で区切ったベクタにして返す
#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

/// n行を読み込んで、数字を空白で区切って二次元のベクタにして返す
#[allow(dead_code)]
fn read_table<T>(n: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut ret: Vec<Vec<T>> = Vec::new();
    for _ in 0..n {
        ret.push(read::<T>());
    }
    ret
}

/// n行を読み込んで、1文字ずつを二次元のベクタにして返す
#[allow(dead_code)]
fn read_char_table(n: usize) -> Vec<Vec<char>> {
    let mut ret: Vec<Vec<char>> = Vec::new();
    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let chr = buf.trim().chars().collect();
        ret.push(chr);
    }
    ret
}

/// n行を読み込んで、一次元のベクタにして返す
#[allow(dead_code)]
fn read_array<T>(n: usize) -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut array = Vec::new();

    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        array.push(buf.trim().parse().unwrap());
    }
    array
}

fn mode(vec: &Vec<u64>) -> u64 {
    let mut times = HashMap::new();

    // count
    for x in vec {
        let cnt = times.entry(*x as u64).or_insert(0);
        *cnt += 1;
    }

    let mut best: (u64, u64) = (
        *times.iter().nth(0).expect("Fatal.").0 as u64,
        *times.iter().nth(0).expect("Fatal.").1 as u64,
    );

    for x in times.iter() {
        if *x.1 > best.1 {
            best = (*x.0 as u64, *x.1);
        }
    }
    best.0
}

fn main() {
    // 数値
    let n = {
        let i = read::<u64>();
        i[0]
    };
    let a = read::<u64>();
    let mut i = 0;

    let mut vec1: Vec<u64> = Vec::new();
    let mut vec2: Vec<u64> = Vec::new();

    for ai in a {
        if i % 2 == 0 {
            vec1.push(ai);
        } else {
            vec2.push(ai);
        }
        i += 1;
    }

    let mut mode1 = mode(&vec1);
    let mut mode2 = mode(&vec2);

    let mut ans = 0;
    for v in &vec1 {
        if *v != mode1 {
            ans += 1;
        }
    }

    if ans == n / 2 - 1 {
        mode1 = 0;
    }

    for v in &vec2 {
        if *v != mode2 || *v == mode1 {
            ans += 1;
        }
    }

    let mut ans2 = 0;
    for v in &vec2 {
        if *v != mode2 {
            ans2 += 1;
        }
    }
    if ans2 == n / 2 - 1 {
        mode2 = 0;
    }

    for v in &vec1 {
        if *v != mode1 || *v == mode2 {
            ans2 += 1;
        }
    }

    println!("{}", std::cmp::min(ans, ans2));
}