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: Accepted)

#include<iostream>
#include<map>

using namespace std;

pair<long long, long long> calc(map<int, int> odd) {
    pair<long long, long long> o1, o2;
    o1 = o2 = make_pair(int(), 0); // 0を-1にすると事故る 2種類以上なかったら0が答え
    for (auto e : odd) {
        if (e.second > o1.second) {
            if (o1.second > o2.second) o2 = o1;
            o1 = e;
        } else if (e.second > o2.second) {
            o2 = e;
        }
    }
    // cout << o1.first << " " << o1.second << endl;
    // cout << o2.first << " " << o2.second << endl;
    o1.first += o2.first * 1e6;
    o1.second += o2.second * 1e6;
    return o1;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int x[n];
    map<int, int> odd, even;
    for (int i = 0; i < n; ++i) { cin >> x[i]; if (i % 2 == 0) even[x[i]]++; else odd[x[i]]++; }
    if (n == 2) { // 第2候補までとれる条件
        if (x[0] == x[1]) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    } else if (n == 3) {
        if (x[0] == x[2] && x[0] != x[1]) cout << 0 << endl;
        else if (x[0] == x[2] && x[0] == x[1]) cout << 1 << endl;
        else if (x[0] != x[2] && x[0] != x[1]) cout << 1 << endl;
        else cout << 1 << endl;
        return 0;
    }
    pair<long long, long long> tmp = calc(odd);
    // cout << tmp.first << " " << tmp.second << endl;
    pair<int, int> o1, o2;
    o1 = make_pair(tmp.first % 1000000, tmp.second % 1000000);
    o2 = make_pair(tmp.first / 1000000, tmp.second / 1000000);
    tmp = calc(even);
    pair<int, int> e1, e2;
    e1 = make_pair(tmp.first % 1000000, tmp.second % 1000000);
    e2 = make_pair(tmp.first / 1000000, tmp.second / 1000000);
    if (o1.first != e1.first) {
        cout << n - o1.second - e1.second << endl;
    } else {
        cout << n - max(o1.second + e2.second, o2.second + e1.second) << endl;
    }
}