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 main() {
    let mut buf = String::new();
    std::io::stdin().read_line(& mut buf).ok();
    let buf = buf.trim();
    let n: i32 = buf.trim().parse().ok().unwrap();
    //println!{"{}", n};

    let mut buf = String::new();
    std::io::stdin().read_line(& mut buf).ok();
    let buf = buf.trim();
    let v: Vec<i32> = buf.split_whitespace().map(|x| x.parse().ok().unwrap()).collect();

    let mut v1: Vec<i32> = Vec::new();
    let mut v2: Vec<i32> = Vec::new();
    for i in 0..v.len() {
        if i % 2 == 0 {v1.push(v[i]);}
        else {v2.push(v[i]);}
    }
    /*
    for i in 0..v.len() {
        println!{"{}", v[i]};
    }
    println!{"------------"};
    for i in 0..v1.len() {
        println!{"{}", v1[i]};
    }
    println!{"------------"};

    for i in 0..v2.len() {
        println!{"{}", v2[i]};
    }
    println!{"------------"};

    */
    let mut cnt1: Vec<(i32, i32)> = Vec::new();
    let mut cnt2: Vec<(i32, i32)> = Vec::new();
    for i in 0..100000+1 {
        cnt1.push((0, i));
        cnt2.push((0, i));
    }
    //println!{"{}", cnt1[100].0};
    //println!{"{}", cnt[100]};
    for i in  0..v1.len() {
        let idx1:usize = v1[i] as usize;
        let idx2:usize = v2[i] as usize;
        cnt1[idx1].0 += 1;
        cnt2[idx2].0 += 1;
    }
    //println!{"{}", cnt1[3].0};
    cnt1.sort();
    //cnt1.sort_by_key(|&(a,b)| a);
    cnt1.reverse();
    //println!{"{} {}", cnt1[0].0, cnt1[0].1};
    //cnt2.sort_by_key(|&(a,b)| a);
    cnt2.sort();
    cnt2.reverse();
    //println!{"{} {}", cnt2[0].0, cnt2[0].1};
    let ans;
    if cnt1[0].1 != cnt2[0].1 {
        ans = n - cnt1[0].0 - cnt2[0].0;
    }
    else {
        ans = std::cmp::min(n - cnt1[0].0 - cnt2[1].0, n - cnt1[1].0 - cnt2[0].0);
    }
    println!{"{}", ans};
}