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 (Clang 3.8.0) (judge verdict: Accepted)

#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;

typedef tuple<int, int, int> tri;

vector<int> get_unique(vector<int> v) {
    // sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}

tri counter(const vector<int> &org, const vector<int> &uv) {
    int max_ct1 = 0;
    int max_ct2 = 0;
    int max_v = -1;
    // int id = lower_bound(vals[p].begin(), vals[p].end(), Y[i]) - vals[p].begin();
    int last_lb = 0;
    int ct = 0;
    for(int i=1; i<uv.size(); i++) {
        int lb = lower_bound(org.begin(), org.end(), uv[i]) - org.begin();
        ct = lb - last_lb;
        // print("i=", i, "ct=", ct);
        last_lb = lb;
        if (ct > max_ct1) {
            max_ct2 = max_ct1;
            max_ct1 = ct;
            max_v = uv[i-1];
        } else if(ct > max_ct2) {
            max_ct2 = ct;
        }
    }
    ct = org.size() - last_lb;
    if (ct > max_ct1) {
        max_ct2 = max_ct1;
        max_ct1 = ct;
        max_v = uv[uv.size()-1];
    } else if(ct > max_ct2) {
        max_ct2 = ct;
    }
    // cout << "uv= ";
    // REP(i, uv.size()) { cout << uv[i] << " ";}
    // cout << endl;

    // print(max_v, max_ct1, max_ct2);
    return make_tuple(max_v, max_ct1, max_ct2);
}

int main() { 
    int n; cin >> n;
    vector<int> v1(n/2);
    vector<int> v2(n/2);
    REP(i, n) {
        if(i%2==0) cin >> v1[i/2];
        else cin >> v2[i/2];
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    auto uv1 = get_unique(v1);
    auto uv2 = get_unique(v2);
    int res = 0;
    auto tri1= counter(v1, uv1);
    int maxv1 = get<0>(tri1);
    int ct11 = get<1>(tri1);
    int ct12 = get<2>(tri1);

    auto tri2= counter(v2, uv2);
    int maxv2 = get<0>(tri2);
    int ct21 = get<1>(tri2);
    int ct22 = get<2>(tri2);

    if (maxv1 == maxv2) {
        if(ct12>ct22) {
            res += (n/2) - ct12;
            res += (n/2) - ct21;
        } else {
            res += (n/2) - ct11;
            res += (n/2) - ct22;
        }
    } else {
        res += (n/2) - ct11;
        res += (n/2) - ct21;
    }

    // if(get<0>(tri1) == get<0>(tri2)) { // same value check
    //     print("---");
    //     print(get<1>(tri1) , get<1>(tri2));
    //     if(get<1>(tri1) > get<1>(tri2)) {
    //         res += (n/2) - get<1>(tri1);
    //         res += (n/2) - get<2>(tri2);
    //     } else {
    //         res += (n/2) - get<2>(tri1);
    //         res += (n/2) - get<1>(tri2);
    //     }
    // } else {
    //     print("!---");
    //     res += (n/2) - get<1>(tri1);
    //     res += (n/2) - get<1>(tri2);
    // }
    print(res);
    
    return 0;
}