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: Wrong Answer)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define EVEN 0
#define ODD 1
#define EVEN_AND_ODD 2
int main(void){
    // Your code here!
    int n;
    scanf("%d\n",&n);
    char *input;
    input = (char*)malloc(7*n);
    fgets(input,7*n,stdin);
    //要素数2なら結果は自明
    if(n==2){
        printf("0");
        return 0;
    }
    //スペース区切りで数字取得
    int table[EVEN_AND_ODD][100000];//mが偶数、奇数それぞれの時において、table[v_m]=v_mが何回登場したか
    for(int j=0;j<100000;j++){
        table[EVEN][j] = 0;
        table[ODD][j] = 0;
    }
    //v_mが何回出現したかを偶数、奇数番目それぞれについてカウント
    int num = atoi(strtok(input," "));
    table[EVEN][num]++;
    for(int i=1;i<n;i++){
        num = atoi(strtok(NULL," "));
        //printf("num[%d]:%d\n",i,num);
        table[i%2][num]++;
    }
    //一番回数の大きいやつを除いた総出現数が解
    int max_times[EVEN_AND_ODD] = {0,0};//偶数、奇数番目それぞれについての最大回数
    int solution[EVEN_AND_ODD] = {0,0};
    for(int c=0;c<100000;c++){
        solution[EVEN] += table[EVEN][c];
        if(max_times[EVEN]<table[EVEN][c]){
            max_times[EVEN] = table[EVEN][c];
        }
        
        solution[ODD] += table[ODD][c];
        if(max_times[ODD]<table[ODD][c]){
            max_times[ODD] = table[ODD][c];
        }
    }
    solution[EVEN]-=max_times[EVEN];
    solution[ODD]-=max_times[ODD];
    printf("%d",solution[EVEN]+solution[ODD]);
    free(input);
    return 0;
}