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<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd 
/****************************/
int n;
struct g
{
	int a;
	int b;
};
g a[100010];
g b[100010];
/*bool a2[50010];
bool b2[50010];
vi a1;
vi b1;*/
bool cmp(g a,g b)
{
	return a.a>b.a; 
}
int main()
{
	cin>>n;
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	rep(i,n)
	{
		int j;
		cin>>j;
		if(i%2==0)
		{
			a[j].a++;
			a[j].b=j;
			//a2[j]=true;
		}
		else
		{
			b[j].a++;
			b[j].b=j;
			//b2[j]=true;
		}
	}
	sort(a,a+100010,cmp);
	sort(b,b+100010,cmp);
	/*for(int i=0;i<4;i++)
	{
		cout<<b[i]<<" ";
	}
	cout<<endl;*/
	int ans=0;
	/*cout<<a[0].a<<" "<<a[0].b<<endl;
	cout<<b[0].a<<" "<<b[0].b<<endl;*/
	bool isa=true;
	int l=0;
	//cout<<a[0].b<<" "<<b[0].b<<endl;
	for(int i=0;i<n/2+1;i++)
	{
		if(a[i].b!=b[i].b)
		{
			break;
		}
		if(a[i].a>b[i].a)
		{
			isa=true;
			break;
		}
		if(a[i].a<b[i].a)
		{
			isa=false;
			break;
		}
		l++;
	}
	if(isa)
	{	
		ans+=n/2-a[0].a;
		ans+=n/2-b[l].a;
	}
	else
	{
		ans+=n/2-a[l].a;
		ans+=n/2-b[0].a;
	}
	cout<<ans;
	return 0;
}