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 eps 1e-7
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fr freopen
#define pi acos(-1.0)
#define Vector Point
typedef pair<int,int> pii;
const long long linf=1LL<<62;
const int iinf=1000000009;
const double dinf=1e17;
const int Mod=1e9+9;
typedef long long ll;
typedef long double ld;
const int maxn=1000005;
int n,ans;
int a[maxn];
int b[maxn];
int r1[maxn],r2[maxn];
int vs1[100005],vs2[100005];
int rt1,rt2;
bool cmp1(int a,int b){
	return vs1[a]>vs1[b];
}
bool cmp2(int a,int b){
	return vs2[a]>vs2[b];
}
int chk(){
	int cnt=0;
	For(i,3,n) b[i]=b[i-2];
	For(i,1,n) if(a[i]!=b[i]) cnt++;
	return cnt;
}
void solve(){
	iossy;
	cin>>n;ans=iinf;met(vs1,0);met(vs2,0);rt1=0;rt2=0;
	For(i,1,n) {
		cin>>a[i];
		if(i%2){
			vs1[a[i]]++;
			if(vs1[a[i]]==1)		r1[rt1++]=a[i];
		}else {
			vs2[a[i]]++;
			if(vs2[a[i]]==1)		r2[rt2++]=a[i];
		}
	}
	sort(r1,r1+rt1,cmp1);
	sort(r2,r2+rt2,cmp2);
	For(i,0,min(50,rt1-1)){
		For(j,0,min(50,rt2-1)){
			b[1]=r1[i];b[2]=r2[i];
			if(b[1]==b[2]) b[2]++;
			ans=min(ans,chk());
		}
	}
	cout<<ans<<endl;
}
int main(){
	int t=1;
	while(t--) solve();
	return 0;
}