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 {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        int[] array1 = new int[n/2];
        int[] array2 = new int[n/2];
        int index1 = 0;
        int index2 = 0;
        for(int i = 0; i < n; i++) {
            int num = sc.nextInt();
            array[i] = num;
            if(i % 2 == 0) {
                array1[index1] = num;
                index1++;
            } else {
                array2[index2] = num;
                index2++;
            }
        }
        boolean isSameNums = true;
        int prev = array[0];
        for(int i = 0; i < n; i++) {
            if(prev != array[i]) {
                isSameNums = false;
                break;
            }
            prev = array[i];
        }
        if(isSameNums) {
            System.out.println(n/2);
            return;
        }
        Arrays.sort(array1);
        Arrays.sort(array2);
        int maxCount1 = 0;
        int maxCount2 = 0;
        int count1 = 1;
        int count2 = 1;
        int prevNum1 = array1[0];
        int prevNum2 = array2[0];
        int maxNum1 = 0;
        int maxNum2 = 0;
        for(int i = 1; i < n/2; i++) {
            if(prevNum1 == array1[i]) {
                count1++;
            } else {
                count1 = 1;
                prevNum1 = array1[i];
            }
            if(prevNum2 == array2[i]) {
                count2++;
            } else {
                count2 = 1;
                prevNum2 = array2[i];
            }
            if(maxCount1 <= count1) {
                maxNum1 = array1[i];
                maxCount1 = count1;
            }
            if(maxCount2 <= count2) {
                maxNum2 = array2[i];
                maxCount2 = count2;
            }
        }
        
        if(maxNum1 == maxNum2) {
            if(maxCount1 <= maxCount2) {
                count1 = 1;
                maxCount1 = 0;
                prevNum1 = -1;
                for(int i = 0; i < n/2; i++) {
                    if(array1[i] == maxNum1) {
                        continue;
                    } else {
                        if (prevNum1 == array1[i]) {
                            count1++;
                        } else {
                            count1 = 1;
                            prevNum1 = array1[i];
                        }
                    }
                    maxCount1 = Math.max(maxCount1, count1);
                }
            } else {
                count2 = 1;
                maxCount2 = 0;
                prevNum2 = -1;
                for(int i = 0; i < n/2; i++) {
                    if(array2[i] == maxNum2) {
                        continue;
                    } else {
                        if (prevNum2 == array2[i]) {
                            count2++;
                        } else {
                            count2 = 1;
                            prevNum2 = array2[i];
                        }
                    }
                    maxCount2 = Math.max(maxCount2, count2);
                }
            }

            if(maxCount1 <= maxCount2) {
                System.out.println((n/2 - maxCount1) + (n/2 - maxCount2));
            } else {
                System.out.println((n/2 - maxCount1) + (n/2 - maxCount2));
            }
        } else {
            System.out.println((n/2 - maxCount1) + (n/2 - maxCount2));
        }
    }
}