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<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

void solve() {

	int n;
	cin >> n;

	vi v(n);
	vi s, s2;

	int sra[3];
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		if (i & 1) {
			s2.pb(v[i]);
		}
		else {
			s.pb(v[i]);
		}
	}
	sort(ALL(s));
	sort(ALL(s2));
	int size = s.size();
	int max = 0, max2 = 0, tmp = -1, tmp2 = -1;
	sra[0] = s[0];
	if (n > 2) {
		sra[1] = -1;
	}
	else {
		sra[1] = s2[0];
	}
	REP(i, size - 1) {
		if (s[i] != s[i + 1]) {
			if (max < i - tmp) {
				max = i - tmp;
				sra[0] = s[i];
			}
			tmp = i;
		}
		if (s2[i] != s2[i + 1]) {
			if (max2 <= i - tmp2) {
				max2 = i - tmp2;
				sra[2] = sra[1];
				sra[1] = s2[i];
			}
			tmp2 = i;
		}
	}
	if (max < s.size() - 1 - tmp) {
		max = s.size() - 1 - tmp;
		sra[0] = s.back();
	}
	if (max2 <= s2.size() - tmp2) {
		max2 = s2.size() - tmp2;
		sra[2] = sra[1];
		sra[1] = s2.back();
	}

	if (sra[0] == sra[1]) {
		if (sra[2] != -1) {
			sra[1] = sra[2];
		}
		else {
			sra[1] = sra[0] + 1;
		}
	}

	int cnt = 0;
	REP(i, n) {
		if (v[i] != sra[i & 1]) cnt++;
	}

	out(cnt);

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}