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 <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
#define range(a) a.begin(), a.end()
#define FASTCIN ios::sync_with_stdio(false); cin.tie(0);
const int mod = 1e9 + 7;
template<typename T> void printVector(const T& a, int type = 0, int left = -1, int right = -1) { if (left != -1 && right != -1) { for (int i = left; i < right; i++) { cout << a[i] << " "; if (type == 1) { cout << endl; } } if (type == 0) { cout << endl; } return; } for (auto it : a) { cout << it << " "; if (type == 1) { cout << endl; } } if (type == 0) { cout << endl; } }
inline int charToInt(char c, char base = 'a') { if (base == '-') { return (int)c; } return (int)(c - base); }
inline char intToChar(int i, char base = 'a') { return (char)(i + charToInt(base, '-')); }
inline void addMod(ll& a, ll b) { a += b; a %= mod; }
inline void subMod(ll& a, ll b) { a -= b; if (a < 0) { a += mod; } }
inline void mulMod(ll& a, ll b) { a *= b; a %= mod; }
inline ll powerMod(ll a, ll n) { ll ans = 1; while (n > 0) { if (n & 1) { mulMod(ans, a); } mulMod(a, a); n >>= 1; } return ans; }
inline ll powerNoMod(ll a, ll n) { ll ans = 1; while (n > 0) { if (n & 1) { ans *= a; } a *= a; n >>= 1; } return ans; }
inline ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); }
inline ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
inline bool isEqualDouble(double a, double b, double epsilon = 0.0000001) { return fabs(a - b) < epsilon; }
// call fact(f) in main first
inline void fact(vector<ll>& f) { f[0] = 1LL; for (int i = 1; i <= 1e6; i++) { mulMod(f[i], (ll)i); } }
inline ll nCk(ll k, ll n) { ll ans = 1; k = max(k, n - k); for (int i = 0; i < k; i++) { ans *= (n - i); ans /= (i + 1); } return ans; }
inline ll nCk(const vector<ll>& f, int k, int n) { if (k < 0 || k > n) { return 0; } ll d = (f[k] * f[n - k]) % mod; d = powerMod(d, (ll)mod - 2LL); return (f[n] * d) % mod; }
/* Author: Alvex Nguyen */
int main()
{
    FASTCIN
    int n;
    cin >> n;
    int i, t;
    vector<int> a;
    for (i = 0; i < n; i++)
    {
        cin >> t;
        a.pb(t);
    }
    int maxLengthEven = 0, maxLengthOdd = 0;
    int number = 0;
    int tempLength = 1;
    for (i = 0; i < n - 2; i += 2)
    {
        if (a[i] == a[i + 2])
        {
            tempLength++;
        }
        else
        {
            if (tempLength > maxLengthEven)
            {
                maxLengthEven = tempLength;
                i -= 2;
            }
            tempLength = 1;
        }
    }
    if (tempLength > maxLengthEven)
    {
        maxLengthEven = tempLength;
    }
    tempLength = 1;
    for (i = 1; i < n - 1; i += 2)
    {
        if (a[i] == a[i + 2])
        {
            tempLength++;
        }
        else
        {
            if (tempLength > maxLengthOdd)
            {
                maxLengthOdd = tempLength;
                i -= 2;
            }
            tempLength = 1;
        }
    }
    if (tempLength > maxLengthOdd)
    {
        maxLengthOdd = tempLength;
    }
    int ans = n - maxLengthEven - maxLengthOdd;
    if (ans == 0)
    {
        ans = n / 2;
    }
    cout << ans;
    return 0;
}