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.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

class Pair implements Comparable<Pair>{
	int i, num;
	public Pair(int _i, int n) {
		i = _i; num = n;
	}
	public int compareTo(Pair p) {
		return p.num - num;
	}
}

class Main{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int n = sc.nextInt();
		int[] left = new int[n / 2];
		int[] right = new int[n / 2];
		for(int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if(i % 2 == 0) left[i / 2] = a;
			else right[i / 2] = a;
		}
		Arrays.sort(left);
		Arrays.sort(right);
		TreeSet<Pair> left_set = new TreeSet<Pair>();
		TreeSet<Pair> right_set = new TreeSet<Pair>();

		for(int i = 0; i < left.length; i++) {
			int tmp = i;
			while(i + 1 < left.length && left[i] == left[i + 1]) i++;
			left_set.add(new Pair(left[i], i - tmp + 1));
		}
		for(int i = 0; i < right.length; i++) {
			int tmp = i;
			while(i + 1 < right.length && right[i] == right[i + 1]) i++;
			right_set.add(new Pair(right[i],  i - tmp + 1));
		}
		Pair left_first = left_set.pollFirst(), left_second = left_set.pollFirst();
		Pair right_first = right_set.pollFirst(), right_second = right_set.pollFirst();

		if(left_first.i != right_first.i) {
			System.out.println(n - left_first.num - right_first.num);
		}else {
			if(right_second == null && left_second == null) {
				// 全部同じ要素
				System.out.println(n / 2);
			}else if(left_second == null) {
				// leftが同じ要素で出来てる
				System.out.println(n / 2 - right_second.num);
			}else if(right_second == null) {
				System.out.println(n / 2 - left_second.num);
			}else {
				System.out.println(Math.min(n - right_first.num - left_second.num, n - right_second.num - left_first.num));
			}
		}
	}
}