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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            int n = sc.nextInt();
            int[] odd = new int[150000];
            int[] even = new int[150000];
            Arrays.fill(odd, 0);
            Arrays.fill(even, 0);

            int oddMax = 0;
            int oddMaxIndex=0;
            int oddSec = 0;
            int oddSecIndex=0;
            int evenMax = 0;
            int evenMaxIndex=0;
            int evenSec = 0;
            int evenSecIndex=0;

            for (int i = 0; i < n; i++) {
                int tmp = sc.nextInt();
                if (i%2 == 1) {
                    odd[tmp]++;
                    if (oddMax < odd[tmp]) {
                        oddSec = oddMax;
                        oddSecIndex = oddMaxIndex;
                        oddMax = odd[tmp];
                        oddMaxIndex = tmp;
                    } else if (oddSec < odd[tmp]) {
                        oddSec = odd[tmp];
                        oddSecIndex = tmp;
                    }
                } else {
                    even[tmp] ++;
                    if (evenMax < even[tmp]) {
                        evenSec = evenMax;
                        evenSecIndex = evenMaxIndex;
                        evenMax = even[tmp];
                        evenMaxIndex = tmp;
                    } else if (evenSec < even[tmp]) {
                        evenSec = even[tmp];
                        evenSecIndex = tmp;
                    }
                }
            }
            if (evenMaxIndex == oddMaxIndex) {
                if (evenSecIndex== oddSecIndex && evenSecIndex == evenMaxIndex) {
                    System.out.println(n- Math.max(even[evenMaxIndex], odd[oddMaxIndex]) );
                } else if (evenMaxIndex == evenSecIndex) {
                    System.out.println(n - even[evenMaxIndex] - odd[oddSecIndex]);
                } else if (oddMaxIndex == oddSecIndex) {
                    System.out.println(n - odd[oddMaxIndex]- even[evenSecIndex]);
                } else {
                    System.out.println(n - Math.max(even[evenMaxIndex] + odd[oddSecIndex], even[evenSecIndex] + odd[oddMaxIndex]));
                }
            } else {
                System.out.println(n - even[evenMaxIndex] - odd[oddMaxIndex]);
            }




        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}