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++ (GCC 9.2.1) (judge verdict: Runtime Error)

#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
int main() {
    /*int n;cin >> n;
    int count = 0;
    vi a(n);
    vi cnt(n+1);
    rep(i, n) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    vb bo(n+1,false);
    for(int i = 0;i<n-2;i+=2) {
        if(a[i]==a[i+2]&&!bo[a[i]]) bo[a[i]]=true;
        else if(a[i]==a[i+2]&&bo[a[i]]) count+=2;
        else if(!bo[a[i]]) {
            bo[a[i]] = true;
            count++;
        }
        else count+=2;
    } */
    /*for(int i = 1;i<n-1;i+=2) {
        if(a[i]==a[i+2]&&!bo[a[i]]) bo[a[i]]=true;
        else if(a[i]==a[i+2]&&bo[a[i]]) count+=2;
        else if(!bo[a[i]]) {
            bo[a[i]] = true;
            count++;
        }
        else count+=2;
    } */
    /*cout << count << endl;*/
    int n;cin >>  n;
    vi a(n);
    // set<int> st;
    bool ok = false;
    rep(i, n) {
        cin >> a[i];
        // st.insert(n);
        if(!ok)if(i>0)if(a[i]!=a[i-1]) ok = true;
    }
    if(!ok) {
        cout << n/2 << endl;
        return 0;
    }
    int p,q;
    int ma = -1;
    vi cnt(n+1,0);
    vi cntt(n+1,0);
    for(int i = 0;i<n;i+=2) {
        cnt[a[i]]++;
        if(chmax(ma,cnt[a[i]])) p = a[i];
    }
    int mx = -1;
    for(int i = 1;i<n;i+=2) {
        cntt[a[i]]++;
        if(chmax(mx,cntt[a[i]])) q = a[i];
    }
    resort(cnt);
    resort(cntt);
    if(p!=q) cout << n/2 - ma + n/2 - mx << "\n";
    else if(p>q) cout << n/2 - ma + n/2 - cntt[1] << "\n";
    else cout << n/2 - cnt[1] - n/2 - mx << "\n";
    return 0;
}