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 <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 2000005
#define MOD 1000000007
#define MOD2 998244353
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vp vector<pii>
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

ll mexp(ll a, ll b){
    ll ans=1;
    a%=MOD;
    while(b){
        if(b&1) ans=ans*a%MOD;
        b>>=1;
        a=a*a%MOD;
    }
    return ans;
}

int f[100005],g[100005];

int main(){

    int n;
    cin>>n;
    set<int>s,t;
    FOR(i,1,n+1){
        int x;
        cin>>x;
        if(i%2){
            f[x]++;
            s.insert(x);
        }
        else{
            g[x]++;
            t.insert(x);
        }
    }
    vector<pair<int,int> >v,w;
    for(int x:s){
        v.pb(mp(f[x],x));
    }
    for(int x:t){
        w.pb(mp(g[x],x));
    }
    sort(all(v));
    sort(all(w));
    if(sz(v)==1 && sz(w)==1){
        if(v[0].S==w[0].S){
            cout<<n/2;
            return 0;
        }
        else{
            cout<<0;
            return 0;
        }
    }
    else{
        if(sz(v)==1 && sz(w)>1){
            if(v[0].S==w[sz(w)-1].S){
                cout<<n/2-w[sz(w)-2].F;
            }
            else{
                cout<<n/2-w[sz(w)-1].F;
            }
        }
        else if(sz(v)>1 && sz(w)==1){
            if(w[0].S==v[sz(v)-1].S){
                cout<<n/2-v[sz(v)-2].F;
            }
            else{
                cout<<n/2-v[sz(v)-1].F;
            }
        }
        else{
            if(v[sz(v)-1].S==w[sz(w)-1].S){
                cout<<min(n-v[sz(v)-1].F-w[sz(w)-2].F,n-v[sz(v)-2].F-w[sz(w)-1].F);
            }
            else{
                cout<<n-v[sz(v)-1].F-w[sz(w)-1].F;
            }
        }
    }

    cerr<<"Time: "<<1.0/CLOCKS_PER_SEC<<" ms"<<endl;
    return 0;
}