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 <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <stack>
#include <functional>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

#define ASIZE(arr) (sizeof(arr)/sizeof(arr[0])

//int dp[1000][1000];
//int n, W, w[1000], v[1000];
//void solve() {
//	for (int i = n - 1; i >= 0; i--)
//	{
//		for (int j = 0; j <= W; j++)
//		{
//			if (j < w[i]) {
//				dp[i][j] = dp[i + 1][j];
//			}
//			else {
//				dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
//			}
//		}
//	}
//}

vector<ll> p = { 1 }, b = { 1 };

ll solve(ll n, ll x) {
	if (n == 0)return x <= 0 ? 0 : 1;
	else if (x <= 1 + b[n - 1]) return solve(n - 1, x - 1);
	else return p[n - 1] + 1 + solve(n - 1, x - 2 - b[n - 1]);
}

int main() {
	ll n;
	cin >> n;
	vector<ll> a(100001, 0), b(100001, 0);

	for (ll i = 0; i < n / 2; i++)
	{
		ll temp;
		cin >> temp;
		a[temp - 1]++;
		cin >> temp;
		b[temp - 1]++;
	}

	auto max_a = max_element(a.begin(), a.end()), max_b = max_element(b.begin(), b.end());
	ll ans = 1000000;
	if (max_a - a.begin() == max_b - b.begin()) {
		if (*max_a == *max_b)
		{
			if (*max_a == n / 2) {
				cout << *max_a << endl;
			}
			else {
				vector<ll> _a, _b;
				_a.push_back(*max_a), _b.push_back(*max_b);
				a.erase(max_a), b.erase(max_b);
				max_a = max_element(a.begin(), a.end()), max_b = max_element(b.begin(), b.end());
				_a.push_back(*max_a), _b.push_back(*max_b);
				for (ll i = 0; i < 2; i++)
				{
					for (ll k = 0; k < 2; k++)
					{
						ans = min(ans, n - _a[i] - _b[k]);
					}
				}
				cout << ans << endl;
			}
		}
	}
	else {
		cout << n - *max_a - *max_b << endl;
	}

}