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++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <fstream>
#include <vector>
#include <cassert>
#include <algorithm>

using namespace std;


/**
* @fn
* /\/\/\/
* @brief 奇数個目で一番頻出のやつ(A1)がなにかを調べる
*        偶数個目で同様に行い(B1)、N - (A1+B1)を回答。ただし、A1=B1の場合は、次に多くでてくるやつにする(A2>=B2ならA2)
*        すべてA2がない場合は、B2。B2もなければ、無なので、N-A1+0となる
* @param (引数名) 引数の説明
* @param (引数名) 引数の説明
* @return 戻り値の説明
* @sa 参照すべき関数を書けばリンクが貼れる
* @detail 詳細な説明
*/
int main(){
    int N,tmp;
    vector<int> v_odd(100001,0);
    vector<int> v_even(100001,0);
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());

    cin >> N;


    for(int i = 0; i < N; i++)
    {
        cin >> tmp;
        if(i % 2 == 0)v_even[tmp]++;
        else{v_odd[tmp]++;}
    }

    int max_odd,max_even,second_odd,second_even;
    //配列番号がほしい
    
    std::vector<int>::iterator max_odd_iter = std::max_element(v_odd.begin(), v_odd.end());
    int max_odd_index = std::distance(v_odd.begin(), max_odd_iter);
    max_odd = *max_odd_iter;

    std::vector<int>::iterator max_even_iter = std::max_element(v_even.begin(), v_even.end());
    int max_even_index = std::distance(v_even.begin(), max_even_iter);
    max_even = *max_even_iter;

    //2番目を取得
    //削除した後は要素番号は必要ないのでよしとする
    v_odd.erase(v_odd.begin()+ max_odd_index);
    v_even.erase(v_even.begin()+ max_even_index);

    std::vector<int>::iterator second_odd_iter = std::max_element(v_odd.begin(), v_odd.end());
    //int second_odd_index = std::distance(v_odd.begin(), second_odd_iter);
    second_odd = *second_odd_iter;

    std::vector<int>::iterator second_even_iter = std::max_element(v_even.begin(), v_even.end());
    //int second_even_index = std::distance(v_even.begin(), second_even_iter);
    second_even = *second_even_iter;

    int A,B;
    //maxの値が一致していたら
    if(max_odd_index == max_even_index)
    {
        //A2,B2がなかったら?
        //A2を取得
        //A1を削除してmaxを取得
        //B2
        if(second_odd >= second_even)
        {
            A = second_odd;
            B = max_even;
        }
        else
        {
            A = max_odd;
            B = second_even;
        }
    }
    else
    {
        A = max_odd;
        B = max_even;
    }

    int res;

    res = N -(A+B);
    cout << res << endl;
}