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 <limits.h>

typedef struct {
    int index1;
    int index2;
    int max1;
    int max2;
} max_info;

int max(int a, int b) {
    if(a > b) {
        return a;
    }
    else {
        return b;
    }
}

int main() {
    int N;
    scanf("%d", &N);
    int i;
    int *v = (int*)malloc(N * sizeof(int));
    int *list_odd = (int*)malloc((100000+1) * sizeof(int));
    int *list_even= (int*)malloc((100000+1) * sizeof(int));
    for(i=0; i<100000+1; i++) {
        list_odd[i] = 0;
        list_even[i] = 0;
    }


    for(i=0; i<N; i++) {
        scanf("%d", &v[i]);
        if(i % 2 == 0) {
            list_odd[v[i]]++;
        }
        else {
            list_even[v[i]]++;
        }
    }

    max_info odd;
    odd.index1 = 0;
    odd.index2 = 0;
    odd.max1 = 0;
    odd.max2 = 0;
    max_info even;
    even.index1 = 0;
    even.index2 = 0;
    even.max1 = 0;
    even.max2 = 0;
    for(i=0; i<100000+1; i++) {
        if(odd.max1 < list_odd[i]) {
            odd.max2 = odd.max1;
            odd.index2 = odd.index1;
            odd.max1 = list_odd[i];
            odd.index1 = i;
        }
        else if(odd.max2 < list_odd[i]) {
            odd.max2 = list_odd[i];
            odd.index2 = i;
        }
        if(even.max1 < list_even[i]) {
            even.max2 = even.max1;
            even.index2 = even.index1;
            even.max1 = list_even[i];
            even.index1 = i;
        }
        else if(even.max2 < list_even[i]) {
            even.max2 = list_even[i];
            even.index2 = i;
        }
    }
    // printf("%d, %d, %d, %d\n", odd.index1, odd.max1, odd.index2, odd.max2);
    // printf("%d, %d, %d, %d\n", even.index1, even.max1, even.index2, even.max2);
    int odd_max, even_max;
    if(odd.index1 == even.index1) {
        printf("%d\n", N - max(odd.max1+even.max2, odd.max2+even.max1));
        return 0;
    }
    else {
        odd_max = odd.max1;
        even_max = even.max1;
    }


    printf("%d\n", N - odd_max - even_max);
    free(v);
    free(list_odd);
    free(list_even);
    return 0;
}