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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int evenV[] = new int[n/2];
        int oddV[] = new int[n/2];
        HashSet<Integer> evenNum = new HashSet<>();
        HashMap<Integer,Integer> evenCount = new HashMap<>();
        HashSet<Integer> oddNum = new HashSet<>();
        HashMap<Integer,Integer> oddCount = new HashMap<>();

        for(int i=0;i<n;i++){
            if(i%2==0)evenV[i/2]=sc.nextInt();
            else oddV[i/2]=sc.nextInt();
        }
        
        for(int i=0;i<evenV.length;i++){
            if(evenNum.contains(evenV[i])){
                int temp = evenCount.get(evenV[i]);
                evenCount.remove(evenV[i]);
                evenCount.put(evenV[i],temp+1);
            }else{
                evenNum.add(evenV[i]);
                evenCount.put(evenV[i],1);
            }
        }
        for(int i=0;i<evenV.length;i++){
            if(oddNum.contains(oddV[i])){
                int temp = oddCount.get(oddV[i]);
                oddCount.remove(oddV[i]);
                oddCount.put(oddV[i],temp+1);
            }else{
                oddNum.add(oddV[i]);
                oddCount.put(oddV[i],1);
            }
        }

        int even1 = mode(evenNum,evenCount);
        evenNum.remove(even1);
        int even2 = mode(evenNum,evenCount);

        int odd1 = mode(oddNum,oddCount);
        oddNum.remove(odd1);
        int odd2 = mode(oddNum,oddCount);

        int conf = 0;

        //System.out.println(even1 +" "+ even2 +" "+ odd1+" "+odd2);

        if(even1==odd1){
            if(evenCount.get(even1)>=oddCount.get(odd1)){
                if(oddCount.get(odd2)==null){
                    conf = evenCount.get(even1);
                }else {
                    conf = evenCount.get(even1)+oddCount.get(odd2);
                }
            } else {
                if(evenCount.get(even2)==null){
                    conf = oddCount.get(odd1);
                }else{
                    conf = evenCount.get(even2)+oddCount.get(odd1);
                }
            }
        } else {
            conf = evenCount.get(even1)+ oddCount.get(odd1);
        }

        System.out.println(n-conf);


        
    }
    private static int mode(HashSet<Integer> num,HashMap<Integer,Integer> count){
        int max=0;
        int mode = 0;
        for(Integer i:num){
            if(max<count.get(i)){
                max=count.get(i);
                mode=i;
            }
        }
        return mode;
    }
}