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");
        free(input);
        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]++;
    }
    //要素数 = table[EVEN][最後に取得した文字]+table[ODD][最後に取得した文字]なら全ての数値が同じ
    if(n==table[EVEN][num]+table[ODD][num]){
        printf("%d",table[EVEN][num]);
        free(input);
        return 0;
    }
    //一番回数の大きいやつを除いた総出現数が解
    int max_times[EVEN_AND_ODD] = {0,0};//偶数、奇数番目それぞれについての最大回数
    int second_max_times[EVEN_AND_ODD] = {0,0};//偶数、奇数番目それぞれについて、二番目に大きい回数
    int mode[EVEN_AND_ODD] = {99,99};//偶数、奇数番目それぞれについての最頻値
    int solution[EVEN_AND_ODD] = {0,0};
    for(int c=0;c<100000;c++){
        for(int even_odd=0;even_odd<EVEN_AND_ODD;even_odd++){
            solution[even_odd] += table[even_odd][c];
            if(max_times[even_odd]<table[even_odd][c]){
                max_times[even_odd] = table[even_odd][c];
                mode[even_odd] = c;
            }
            else if(second_max_times[even_odd]<table[even_odd][c]) second_max_times[even_odd] = table[even_odd][c];
        }
    }
    /*printf("max_times        even:%d,odd:%d\n",max_times[EVEN],max_times[ODD]);
    printf("second_max_times even:%d,odd:%d\n",second_max_times[EVEN],second_max_times[ODD]);
    printf("mode             even:%d,odd:%d\n",mode[EVEN],mode[ODD]);*/
    //
    if(mode[EVEN]==mode[ODD]){
        int entire = solution[EVEN]+solution[ODD];
        if(entire-second_max_times[EVEN]-max_times[ODD]<entire-max_times[EVEN]-second_max_times[ODD]){
            solution[EVEN]-=second_max_times[EVEN];
            solution[ODD]-=max_times[ODD];
        }else{
            solution[EVEN]-=max_times[EVEN];
            solution[ODD]-=second_max_times[ODD];
        }
    }else{
        solution[EVEN]-=max_times[EVEN];
        solution[ODD]-=max_times[ODD];
    }

    printf("%d",solution[EVEN]+solution[ODD]);
    free(input);
    return 0;
}