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 "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 1e9;
const LL LLINF = 1e18;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int histEven[100001];
int histOdd[100001];

void solve()
{
    int N; cin >> N;

    vector<int> V(N+1);
    int v_max = 0;
    int v_min = INTINF;
    REP1(i, N)
    {
        int v; cin >> v;
        V[i] = v;
        if (i % 2 == 0) histEven[v]++;
        else if (i % 2 == 1) histOdd[v]++;
        v_max = max(v_max, v);
        v_min = min(v_min, v);
    }

    int h_e_max = 0;
    int h_o_max = 0;
    
    int h_e_argmax = 0;
    int h_e_argmax_2 = 0;
    int h_o_argmax = 0;
    int h_o_argmax_2 = 0;

    FOR(i, v_min, v_max+1)
    {
        if (h_e_max < histEven[i])
        {
            h_e_argmax_2 = h_e_argmax;
            h_e_max = histEven[i];
            h_e_argmax = i;
        }
        if (h_o_max < histOdd[i])
        {
            h_o_argmax_2 = h_o_argmax;
            h_o_max = histOdd[i];
            h_o_argmax = i;
        }
    }

    int ans0 = 0;
    int ans1 = 0;
    int ans2 = 0;
    
    REP1(i, N/2)
    {
        ans0 += (V[2*i  ] != h_e_argmax);
        ans0 += (V[2*i-1] != h_o_argmax);

        ans1 += (V[2*i  ] != h_e_argmax_2);
        ans1 += (V[2*i-1] != h_o_argmax );
        
        ans2 += (V[2*i  ] != h_e_argmax );
        ans2 += (V[2*i-1] != h_o_argmax_2);
    }
    cout << ((h_o_argmax != h_e_argmax) ? ans0 : min(ans1, ans2)) << endl;  
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    solve();
    return 0;
}