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;                                                                                                                      
                                                                                                                                                    
fn AAA() -> Result<i64, &'static str> {                                                                                                             
    let mut input = String::new();                                                                                                                  
    std::io::stdin().read_line(&mut input)                                                                                                          
        .map_err(|_| "input error");                                                                                                                
    let n = input.trim_right()                                                                                                                      
        .parse::<usize>()                                                                                                                           
        .map_err(|_| "parse error")?;                                                                                                               
                                                                                                                                                    
    let mut input = String::new();                                                                                                                  
    std::io::stdin().read_line(&mut input)                                                                                                          
        .map_err(|_| "input error");                                                                                                                
    let v: Vec<i64> = input.split_whitespace()                                                                                                      
        .map(|s| s.parse::<i64>().unwrap())                                                                                                         
        .collect();                                                                                                                                 
                                                                                                                                                    
    let mut odd : HashMap<i64, i64> = HashMap::with_capacity(n / 2);                                                                                
    let mut even : HashMap<i64, i64> = HashMap::with_capacity(n / 2);                                                                               
    for i in 0..n {                                                                                                                                 
        if i % 2 == 0 {
            *even.entry(v[i]).or_insert(0) += 1;
        }
        else {
            *odd.entry(v[i]).or_insert(0) += 1;
        }
    }

    let mut odd_entry = [(0i64, 0i64); 2];
    let mut even_entry = [(0i64, 0i64); 2];
    let mut odd_sum = 0;
    let mut even_sum = 0;

    for (odd_key, odd_value) in odd.iter() {
        if *odd_value > odd_entry[0].1 {
            odd_entry[1] = odd_entry[0];
            odd_entry[0] = (*odd_key, *odd_value);
        }
        odd_sum += *odd_value;
    }
    for (even_key, even_value) in even.iter() {
        if *even_value > even_entry[0].1 {
            even_entry[1] = even_entry[0];
            even_entry[0] = (*even_key, *even_value);
        }
        even_sum += *even_value;
    }
    if odd_entry[0].0 != even_entry[0].0 {
        let odd_count : i64 = odd_sum - odd_entry[0].1;
        let even_count: i64 = even_sum - even_entry[0].1;
        return Ok(odd_count + even_count);
    }
    else if odd_entry[0].1 >= even_entry[0].1 {
        let odd_count: i64 = odd_sum - odd_entry[0].1;
        let even_count: i64 = even_sum - even_entry[1].1;
        return Ok(odd_count + even_count);
    }
    else {
        let odd_count: i64 = odd_sum - odd_entry[1].1;
        let even_count: i64 = even_sum - even_entry[0].1;
        return Ok(odd_count + even_count);
    }
}

fn main() {
    println!("{}", AAA().unwrap());
}