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<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++) //0から
#define REP(i,n) for(int j=i;j<n;j++) //iから
#define in(a) cin>>a
#define out(a) cout<<a<<endl

long long int kaijo(long long int n){
    if(n == 0) return 1;
    return n * kaijo(n-1);
}


vector<bool> is_prime;
void Eratosthenes(long long int n){
    is_prime.resize(n+1,true);
    is_prime[0]=false;
    is_prime[1]=false;
    for(long long int i = 2; i <= n; i++){
        if(is_prime[i]){
            for(long long int j = i*i; j <= n; j++){
                is_prime[j] = false;
            }
        }
    }
}

//素数列挙
vector<long long int> Prime;
void Prime_Enumeration(long long int n){
    Eratosthenes(n);
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            Prime.push_back(i);
        }
    }
}

long long int gcd(long long int a, long long int b){
    if(a<b){
        swap(a,b);
    }
    long long int r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return r;
}

long long int lcm(long long int a, long long int b){
    long long int g = gcd(a,b);
    long long int l = (a * b) / g;

    return l;
}

//aが負の時でも余りを非負にしたいとき
long long  mod(long long a, long long m){
    return (a % m + m) % m;
}

//拡張ユークリッド ap + bq = gcd(a,b)
long long extGCD(long long a, long long b, long long &p, long long &q){
    if(b == 0){ p = 1; q = 0; return a;}
    long long d = extGCD(b, a % b, q, p);
    q -= a /b * p;
    
    return d;
}

//中国剰余定理
pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2){
    long long p, q;
    long long d = extGCD(m1, m2, p, q);

    if((b2-b1) % d != 0) return make_pair(0, -1); //解なし

    long long m = m1 * (m2 / d);
    long long tmp = (b2 - b1) / d * p % (m2 / d);
    long long r =mod(b1 + m1 * tmp, m);

    return make_pair(r, m);
}

//mod.mでのa^{-1}
long long modinv(long long a, long long m){
    long long b = m, u = 1, v = 0;
    while(b){
        long long t = a /b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if(u < 0)u += m;
    return u;

}
const long long MOD = 1000000007;

//key以上のうち最小の要素のindex
int binary_search(long long int *a, long long int n, long long int key){
    long long int right = n, left = -1;
    long long int md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}


int main(){
    long long int n,k;
    cin>>n;
    vector<long long int> a(n);
    rep(i,n) in(a[i]);

    vector<int> odd, even;
    rep(i,n){
        if(i%2==0){
            even.push_back(a[i]);
        }else{
            odd.push_back(a[i]);
        }
    }

    sort(even.begin(),even.end());
    sort(odd.begin(),odd.end());

    vector<pair<int,int>> odd_cnt,even_cnt;
    odd_cnt.push_back(make_pair(1,a[1]));
    even_cnt.push_back(make_pair(1,a[0]));

    int oddmax = 1,evenmax = 1;

    k = 0;
    for(int i=1;i<even.size();i++){
        if(even[i-1]==even[i]) {
            even_cnt[k].first++;
            evenmax = max(evenmax, even_cnt[k].first);
        }
        else {
            even_cnt.push_back(make_pair(1,even[i]));
            k++;
        }
    }

     k = 0;
    for(int i=1;i<odd.size();i++){
        if(odd[i-1]==odd[i]) {
            odd_cnt[k].first++;
            oddmax = max(oddmax, odd_cnt[k].first);
        }
        else {
            odd_cnt.push_back(make_pair(1,odd[i]));
            k++;
        }
    }

    sort(even_cnt.begin(),even_cnt.end(),greater<pair<int,int>>());
    sort(odd_cnt.begin(),odd_cnt.end(),greater<pair<int,int>>());

    int ans = n;

    /*
    rep(i,odd.size()) cout<<odd[i]<<' ';
    cout<<endl;
    rep(i,even.size()) cout<<even[i]<<' ';
    cout<<endl;
    */

    //cout<<oddmax<<' '<<evenmax<<endl;

    even_cnt.push_back(make_pair(0,0));
    odd_cnt.push_back(make_pair(0,0));

    int od=0,ev=0;
    if(even_cnt[ev].second == odd_cnt[ev].second){
        if(even_cnt[ev].first == odd_cnt[od].first){
            if(even_cnt[ev+1].first>odd_cnt[od].first){
                ev++;
            }
            else{
                od++;
            }
            ans = n - even_cnt[ev].first - odd_cnt[od].first;
        }
        else {
            ans -= max(even_cnt[ev].first+odd_cnt[od+1].first,even_cnt[ev+1].first+odd_cnt[od].first);
        }
    }else{
        ans = n - even_cnt[ev].first - odd_cnt[od].first;
    }

    cout<<ans<<endl;

    return 0;
}