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 Java7 (OpenJDK 1.7.0) (judge verdict: Runtime Error)



import java.util.Scanner;

public class Main {

	public static int max(int v[], int e) {
		int max = 0;
		for (int i = 1; i <= v.length; ++i) {
			if (i != e) {
				if (v[max] < v[i]) {
					max = i;
				}
			}
		}
		return max;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n, s1, s2, s3, s4, count = 0;
		int v[];
		int count1[], count2[];
		count1 = new int[100001];
		count2 = new int[100001];

		n = sc.nextInt();

		v = new int[n + 1];
		for (int i = 1; i <= n; ++i) {
			v[i] = sc.nextInt();
			if (i % 2 != 0) {
				++count1[v[i]];
			} else {
				++count2[v[i]];
			}
		}

		s1 = max(count1, 0);
		s3 = max(count1, s1);
		s2 = max(count2, 0);
		s4 = max(count2, s2);
		// System.out.println(s1 + " " + s3 + " " + s2 + " " + s4);
		if (s1 == s2) {
			if (count1[s1] > count2[s2]) {
				s2 = s4;
			} else if (count1[s1] < count1[s2]) {
				s1 = s3;
			} else {
				if (s4 > 0) {
					s2 = s4;
				} else {
					count = n / 2;
					s2 = 0;
				}
			}
		}

		// System.out.println(s1 + " " + s3 + " " + s2 + " " + s4);
		for (int i = 1; i <= n; ++i) {
			if (i % 2 != 0) {
				if (v[i] != s1) {
					++count;
				}
			} else {
				if (s2 > 0) {
					if (v[i] != s2) {
						++count;
					}
				}
			}
		}

		System.out.println(count);
		sc.close();
	}

}