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 C (GCC 5.4.1) (judge verdict: Accepted)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <malloc.h>

#define char_max 200000
#define Nmax 100000

int Pow(int n, int m);
int Max(int N[], int n);
int Min(int N[], int n);
int Sum(int N[], int n);





int main()
{
	int n = 0;
	int ans = 0;
	int* v = (int*)calloc(Nmax, sizeof(int));

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &v[i]);
	}

	int* v1 = (int*)calloc(Nmax, sizeof(int));
	int* v2 = (int*)calloc(Nmax, sizeof(int));

	for (int i = 0; i < n / 2; i++) {
		v1[v[2 * i]]++;
	}

	for (int i = 0; i < n / 2; i++) {
		v2[v[2 * i + 1]]++;
	}
	
	//printf("v1: ");
	//for (int i = 0; i < 10; i++) {
	//	printf("%d, ", v1[i]);
	//}
	//printf("\n");

	//printf("v2: ");
	//for (int i = 0; i < 10; i++) {
	//	printf("%d, ", v2[i]);
	//}
	//printf("\n");

	int maxv1 = Max(v1, Nmax);
	int maxv2 = Max(v2, Nmax);

	int nmaxv1 = 0;
	int nmaxv2 = 0;

	for (int i = 0; i < Nmax; i++) {
		if (v1[i] == maxv1) {
			nmaxv1 = i;
			break;
		}
	}

	for (int i = 0; i < Nmax; i++) {
		if (v2[i] == maxv1) {
			nmaxv2 = i;
			break;
		}
	}

	
	
	if (nmaxv1 == nmaxv2) {
		v1[nmaxv1] = 0;
		v2[nmaxv2] = 0;
		int amaxv1 = Max(v1, Nmax);
		int amaxv2 = Max(v2, Nmax);
		if (maxv1 + amaxv2 < amaxv1 + maxv2) {
			ans = n - amaxv1 - maxv2;
		}else {
			ans = n - maxv1 - amaxv2;
		}

	}else {
		ans = n - maxv1 - maxv2;
	}
	

	printf("%d", ans);


	return 0;
}

int Pow(int n, int m) {
	int ret = 1;

	for (int i = 0; i < m; i++) {
		ret *= n;
	}

	return ret;
}

int Max(int N[], int n) {
	int max = N[0];

	for (int i = 0; i < n; i++) {
		max = max < N[i] ? N[i]: max;
	}

	return max;
}

int Min(int N[], int n) {
	int min = N[0];

	for (int i = 0; i < n; i++) {
		min = min > N[i] ? N[i] : min;
	}

	return min;
}

int Sum(int N[], int n) {
	int sum = 0;

	for (int i = 0; i < n; i++) {
		sum += N[i];
	}

	return sum;
}