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 <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

bool func(pair<ll,ll> a , pair<ll,ll> b){
	if(a.first > b.first) return true;
	else return false;
}

int main()
{
	ll N;
	cin >> N;
	N/=2;

	vector<ll> lst[2];
	map<ll,ll> cnt[2];

	rep(i,N){
		ll a, b;
		cin >> a >> b ;
		lst[0].pb(a);
		lst[1].pb(b);
		cnt[0][a]++;
		cnt[1][b]++;
	}

	rmsame(lst[0]);
	rmsame(lst[1]);

	vector<pair<ll,ll> > res[2];
	rep(i,lst[0].size()){
		if(i >= 2){
			if(cnt[0][lst[0][i]] == cnt[0][lst[0][i-2]])continue;
		}
		else res[0].pb(mp(lst[0][i], cnt[0][lst[0][i]]));
	}
	rep(i,lst[1].size()){
		if(i>=2){
			if(cnt[1][lst[1][i]] == cnt[1][lst[1][i-2]]) continue;
		}
		else res[1].pb(mp(lst[1][i], cnt[1][lst[1][i]]));
	}

	sort(all(res[0]));
	sort(all(res[1]));

	ll ans = N*2-2;

	rep(i, res[0].size()) rep(j, res[1].size()){
		if(res[0][i].first == res[1][j].first){
			ans = min(ans,  N*2- max(res[0][i].second, res[1][j].second));
		}
		else{
			ans = min(ans, N*2 - res[0][i].second - res[1][j].second);
		}
	}
	cout << ans << endl;


	return 0;
}

/*
/^[\w!\x22\#$%&@\'() * +,-.\/;:]+$/
*/