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::io;
use std::collections::HashSet;

fn read_line() -> String {
    let mut line = String::new();

    io::stdin().read_line(&mut line)
        .expect("Failed to read line");
    return line;
}
fn to_i(s: &str) -> i64 {
    return s.trim().parse()
        .expect("Please type a number!");
}
fn check(nums: &Vec<i64>, i: i32, count: i32, data: &HashSet<i64>) -> i32 {
    if i+2==nums.len() as i32 {
        if data.len()==2 {
            return count;
        } else {
            return 9999999;
        }
    }
    if data.len() >=3 {
        return 9999999;
    }
    let x = nums[i as usize];
    let x2 = nums[(i+2) as usize];
    //println!("{} {} {} {} {}", i, x, x2, count, data.len());
    if x==x2 {
        let mut data1 = data.clone();
        data1.insert(x);
        if data.len()==2 {
            if data.contains(&x) {
                //println!("# {} {} ", i+1+2, nums.len());
                
                return check(nums, i+1, count, &data1);
            }else{
                return check(nums, i+1, count+2, &data1);
            }
        }else{
            /*if data.include?(x) {

            }else{

            }*/
            if i+1+2==nums.len() as i32 {
                    
                    
                        return count+2;
                    
            }
            return check(nums, i+1, count, &data1);
        }
        
    }

    if data.len()==2 {
        if data.contains(&x) || data.contains(&x2) { 
            if data.contains(&x) {
                let mut data3 = data.clone();
                data3.insert(x2);
                return check(nums, i+1, count+1, &data3);
            }else{
                let mut data2 = data.clone();
                data2.insert(x);
                return check(nums, i+1, count+1, &data2);
            }
        }else{
            return check(nums, i+1, count+2, &data);
        }
    }else{
        //nums[(i+2) as usize] = x;
        let mut data2 = data.clone();
        data2.insert(x);
        let a = check(nums, i+1, count+1, &data2);
        //println!("a {} {} ",a, data2.len());
        //nums[(i+0) as usize] = x2;
        let mut data3 = data.clone();
        data3.insert(x2);
        let b = check(nums, i+1, count+1, &data3);

        //println!("b {} {}", b, data3.len());
        if a>b {
            return b;
        }else {
            return a;
        }
    }
    
}
fn main() {
     let l = read_line();
    let n = to_i(&l);

    let line = read_line();
    let items: Vec<&str> = line.split(' ').collect();

    let mut nums: Vec<i64> = Vec::new();

    for item in items {
        nums.push(to_i(item));
    }
    let mut data = HashSet::new();
    /*
    let mut count = 0;
    println!("---");
    let mut data = HashSet::new();
    for i in 0..n/2 {
        let x = nums[i as usize];
        let x2 = nums[(i+2) as usize];
        //println!("{} {} {} ", i, x, x2);
        if x != x2 {
            //println!("diff");
            //count += 1;
            if data.len() == 0 {

            }
        } else {
            //println!("same");
            /*
            if data.contains(&x) {
                println!("used");
                count += 1;
            }*/
        }

        data.insert(x);
    }
    
    
    println!("len:{}",data.len());
    */
    
    let result = check(&nums, 0, 0, &data);
    print!("{}", result);


}