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 <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

#define huge 1000000007
typedef long long ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll M = 0;
	//ll M = 0;
	ll a[200] = {};
	ll b[200] = {};
	ll v[3] = {};
	//ll *a, *b, *x;
	string S,T,U[52];
	ll count = 0;
	ll count2 = 0;
	ll sum = 0;
	//ll min = 100000;
	ll max = 0;
	ll smax = 0;
	ll max2 = 0;
	ll smax2 = 0;
	int tmax = 0;
	int tmax2 = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;
	
	
	//char p;


	

	

	//cin >> S;
	
	//a = (ll *)malloc(M * sizeof(ll));
	//b = (ll *)malloc(M * sizeof(ll));
	//vector<pair<int,int>> ch(50);

	//vector<bool> flag(N);
	
	cin >> N;
	vector<ll> c(N);
	vector<ll> c1(N/2);
	vector<ll> c2(N/2);

	

	rep(i, 0, N) {
		cin >> c[i];
	}

	rep(i, 0, N) {
		if (i % 2 == 0)
			c1[i / 2] = c[i];
		else
			c2[i / 2] = c[i];
	}

	sort(c1.begin(), c1.end());
	sort(c2.begin(), c2.end());

	

	count++;
		rep(i, 1, N/2) {
			if (c1[i] == c1[i - 1])
				count++;
			else {
				if (max < count) {
					max = count;
					A = c1[i - 1];
				}
				else if (smax < count) {
					smax = count;
					C = c1[i - 1];
				}
				else if (tmax < count) {
					tmax = count;
				}
				count = 1;

			}

			
		}

		if (max < count) {
			A = c1[N/2 - 1];
			max = count;
		}
		else if (smax < count) {
			smax = count;
			C = c1[N/2 - 1];
		}
		else if (tmax < count) {
			tmax = count;
		}
	//cout << max << endl;



	count2++;


	rep(i, 1, N / 2) {
		if (c2[i] == c2[i - 1])
			count2++;
		else {
			if (max2 < count2) {
				max2 = count2;
				B = c2[i - 1];
			}
			else if (smax2 < count2) {
				smax2 = count2;
				D = c2[i - 1];
			}
			else if (tmax2 < count2) {
				tmax2 = count2;
			}
			count2 = 1;

		}
	}


	if (max2 < count2) {
		B = c2[N/2 - 1];
		max2 = count2;
	}
	else if (smax2 < count2) {
		smax2 = count2;
		D = c2[N/2 - 1];
	}
	else if (tmax2 < count2) {
		tmax2 = count2;
	}
	//cout << max2 << endl;
	//cout << A << B << endl;

	if (A != B) {
		cout << N - max - max2 << endl;
	}
	else {
		tmax = N - (smax)-(max2);
		tmax2 = N - (max)-(smax2);

		cout << min(tmax, tmax2) << endl;
	}
	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;



	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	


	return 0;

}

ll gcd(ll a, ll b) {
	ll c;
	c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}

	return b;
}