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 <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
 const int mod=1000000007;

 int main(){
	 int n;
	 cin>>n;
	 priority_queue<pii> pq;
	 priority_queue<pii> pq2;
	 map<int,int> mp;
	 map<int,int> mp2;
	 int a[101010]={};
	 FOR(i,0,n){
		 cin>>a[i];
		 if(i%2==0){
			 mp[a[i]]++;
		 }else{
			 mp2[a[i]]++;
		 }
	 }
	 mp[mod]=0;
	 mp2[mod+1]=0;
	 for(auto x:mp){
		 pq.push(MP(x.ND,x.ST));
	 }
	 for(auto x:mp2){
		 pq2.push(MP(x.ND,x.ST));
	 }
	 //cerr<<pq.size()<<" "<<pq2.size()<<endl;
	 int ans=n;
	 pii f=pq.top();
	 pq.pop();
	 pii s=pq.top();
	 pq.pop();
	 pii f2=pq2.top();
	 pq2.pop();
	 pii s2=pq2.top();
	 pq2.pop();
	 if(f.ND!=f2.ND){
		 ans=min(ans,n-f.ST-f2.ST);
	 }
	 if(s.ND!=f2.ND){
		 ans=min(ans,n-s.ST-f2.ST);
	 }
	 if(f.ND!=s2.ND){
		 ans=min(ans,n-f.ST-s2.ST);
	 }
	 if(s.ND!=s2.ND){
		 ans=min(ans,n-s.ST-s2.ST);
	 }
	 cout<<ans<<endl;

   return 0;
 }