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 javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.BiConsumer;

public class Main {

    //グローバル変数を定義

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        int[] oddArray = new int[n/2];
        int[] evenArray = new int[n/2];

        for(int i=0; i<n; i++){
            array[i] = sc.nextInt();
        }

        int evenCount = 0;
        int oddCount = 0;

        for(int i=0; i<n; i++){
            if((i+1) % 2 == 0){
                evenArray[evenCount] = array[i];
                evenCount++;
            } else {
                oddArray[oddCount] = array[i];
                oddCount++;
            }
        }

        int first = array[0];
        if(isAllSame(array, first)) {
            System.out.println(array.length/2);
        } else {
            HashMap<Integer, Integer> oddMap = getMap(oddArray);
            HashMap<Integer, Integer> evenMap = getMap(evenArray);

            int oddNum = maxCountNum(oddMap);
            int evenNum = maxCountNum(evenMap);

            int finalOdd = oddArray.length-oddNum;
            int finalEven = evenArray.length-evenNum;

            if(oddNum == evenNum){
                int nextOddNum = nextMaxCountNum(oddMap, oddNum);
                int nextEvenNum = nextMaxCountNum(evenMap, evenNum);

                int nextFinalOdd = oddArray.length-nextOddNum;
                int nextFinalEven = oddArray.length-nextEvenNum;

                System.out.println(Math.min(finalOdd+nextFinalEven, nextFinalOdd+finalEven));
            } else {
                System.out.println(finalOdd + finalEven);
            }
        }
    }

    boolean isAllSame(int[] array, int first) {
        int count = 0;
        for(int i=0; i<array.length; i++){
            if(array[i] == first) count++;
        }
        if(count == array.length){
            return true;
        }
        return false;
    }

    HashMap<Integer, Integer> getMap(int[] array){
        HashMap<Integer, Integer> map = new HashMap<>();
        for(int i=0; i<array.length; i++){
            if(map.containsKey(array[i])) map.put(array[i], map.get(array[i])+1);
            else map.put(array[i], 1);
        }
        return map;
    }

    int maxCountNum(HashMap<Integer, Integer> map){
        int maxKey = -1;
        for(Integer key: map.keySet()){
            int value = map.get(key);
            if(value > maxKey){
                maxKey = value;
            }
        }
        return maxKey;
    }

    int nextMaxCountNum(HashMap<Integer, Integer> map, int maxKey){
        int nextMaxKey = -1;
        for(Integer key: map.keySet()){
            if(key == maxKey) continue;
            int value = map.get(key);
            if(value > nextMaxKey){
                nextMaxKey = value;
            }
        }
        return nextMaxKey;
    }
}