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)

//AtCoder公式の放送を参考にさせていただきました
#include<stdio.h>
#include<stdlib.h>

int comp(const void* a, const void* b){
    return *(int*)a - *(int*)b;
}

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

    int idx = 0;
    int idxDarr = 0;
    int cnt = 0;
    int maxCnt = -1;
    //奇数番目で一番多く出た数字を見つける
    //oddTrgが奇数番目で一番多く出た数字
    int oddArr[n/2][2];
    int tmp = v[0];
    while(idx < n){
        if(tmp != v[idx]){
            idxDarr++;
            cnt = 1;
            oddArr[idxDarr][0] = v[idx];
            oddArr[idxDarr][1] = cnt;
            tmp = v[idx];
        }else{
            oddArr[idxDarr][0] = v[idx];
            cnt++;
            oddArr[idxDarr][1] = cnt;   
        }
        idx += 2;
    }
    
    //for(int i = 0; i < idxDarr+1; i++){for(int j = 0; j < 2; j++){printf("%d ", oddArr[i][j]);}printf("\n");}
    for(int i = 0; i < idxDarr+1; i++){
        if(maxCnt < oddArr[i][1]){maxCnt = oddArr[i][1]; oddTrg = oddArr[i][0];}
    }
    //printf("%d\n", oddTrg);
    //printf("ans:%d\n", ans);
    //return 0;
    
    int ans = ((n/2) - maxCnt);
    //oddTrg以外で、偶数番目で一番多く出た数字を見つける
    idx = 1;
    idxDarr = 0;
    int evenArr[n/2][2];
    cnt = 0;
    maxCnt = -1;
    tmp = v[1];
    while(idx < n){
        if(tmp != v[idx]){
            idxDarr++;
            cnt = 1;
            evenArr[idxDarr][0] = v[idx];
            evenArr[idxDarr][1] = cnt;
            tmp = v[idx];
        }else{
            evenArr[idxDarr][0] = v[idx];
            //cはこれできないっぽい ... = cnt++;
            cnt++;
            evenArr[idxDarr][1] = cnt;   
        }
        idx += 2;
    }
    //for(int i = 0; i < idxDarr+1; i++){for(int j = 0; j < 2; j++){printf("%d ", evenArr[i][j]);}printf("\n");}
    //return 0;
    int passed = 0;
    for(int i = 0; i < idxDarr+1; i++){
        if((maxCnt < evenArr[i][1]) && (evenArr[i][0] != oddTrg)){
            passed = 1;
            maxCnt = evenArr[i][1];
        }
    }
    if(passed == 0){
        ans += n/2;
    }else{
        ans += ((n/2)-maxCnt);
    }

    printf("%d\n", ans);
    return 0;
}