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>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)

#define DEBUG_VARIABLE(variable) cout << #variable << ":" << variable << endl

#define WHITE 1//（未訪問）
#define GRAY 2//（訪問）未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3//（訪問完了）未訪問への頂点への辺を持たない
#define N 100
#define INFTY (1 << 21) //10^21
#define INF (1 << 9)
int M[N][N];//隣接行列
int color[N];

//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

void printArray(int *array, int);
void printVector(Vector &v);
void printDimention(DVector &dv);
//nCr方式で組み合わせの数を求める
int combination(int, int);
//nPrで階乗を求める
int factorial(int, int);
//桁数を返す
int find_digits(int);
// 各桁の和を計算する関数
int findSumOfDigits(int);
//次数を得る
int degree(int);
//四捨五入
int shishagonyu(double);
//切り上げ
int roundUp(double);
//切り捨て
int roundDown(double);
//四捨五入
int roundOff(double);
//最大公約数(Greatest Common Divisor)
int gcd (int, int);
//最小公倍数(Least Common Multiple)
int lcm(int, int);
//素因数分解
void prime_factorization(int);
//エラトステネスの篩
int Eratosthenes(int);
//偶奇判定。奇数ならtrue。
bool odd_even(int);

#define lim 100000
//奇数，偶数，実際の数 - 1 = 添字 
int odd[lim], even[lim];

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    int a[n];
    
    //memset(odd, 0, sizeof(odd));
    //memset(even, 0, sizeof(even));
    rep(i, n){
        cin >> a[i];
        if((i + 1) % 2){
            odd[a[i] - 1]++;
        }else{
            even[a[i] - 1]++;
        }
    }
    //個数の大きい数の添え字を格納
    int odd_fir, odd_sec, even_fir, even_sec;
    //個数を格納
    int num_max;
    if(odd[0] <= odd[1]){
        odd_fir = 1;
        odd_sec = 0;
        num_max = odd[1];
    }else{
        odd_fir = 0;
        odd_sec = 1;
        num_max = odd[0];
    }
    FOR(i, 2, lim){
        if(num_max <= odd[i]){
            num_max = odd[i];
            odd_sec = odd_fir;
            odd_fir = i;
        }
    }
    
    if(even[0] <= even[1]){
        even_fir = 1;
        even_sec = 0;
        num_max = even[1];
    }else{
        even_fir = 0;
        even_sec = 1;
        num_max = even[0];
    }
    FOR(i, 2, lim){
        if(num_max <= even[i]){
            num_max = even[i];
            even_sec = even_fir;
            even_fir = i;
        }
    }
    //DEBUG_VARIABLE(odd_fir);
    //DEBUG_VARIABLE(odd_sec);
    //DEBUG_VARIABLE(even_fir);
    //DEBUG_VARIABLE(even_sec);
    int half = n / 2;
    int odd_res, even_res;
    if(odd_fir == even_fir){
        if(odd[odd_fir] < even[even_fir]){
            odd_res = odd[odd_sec];
            even_res = even[even_fir];
        }else if(odd[odd_fir] > even[even_fir]){
            odd_res = odd[odd_fir];
            even_res = even[even_sec];
        }else if(odd[odd_fir] == even[even_fir]){
            if(odd[odd_sec] < even[even_sec]){
                odd_res = odd[odd_fir];
                even_res = even[even_sec];
            }else if(odd[odd_sec] >= even[even_sec]){
                odd_res = odd[odd_sec];
                even_res = even[even_fir];
            }
        }
    }else{
        odd_res = odd[odd_fir];
        even_res = even[even_fir];
    }
    int res = (half - odd_res) + (half - even_res);
    cout << res << endl;
}

//配列の表示
void printArray(int array[], int n){
    rep(i, n){
        if(i)   cout << " ";
        cout << array[i];
    }
    cout << endl;
}

//Vectorの表示
void printVector(Vector &v){
    rep(i, (int)v.size()){
        if(i)   cout << " ";
        cout << v[i];
    }
    cout << endl;
}

//二次元配列の表示
void printDimention(DVector &dv){
    rep(i, (int)dv.size()){
        rep(j, (int)dv[i].size()){
            if(j)   cout << " ";
            cout << dv[i][j];
        }
        cout << endl;
    }
}

//numの中に何個2がかかってるか
int factor2(int num){
    int cnt = 0;
    while(num % 2 == 0){
        num /= 2;
        cnt++;
    }
    return cnt;
}

//nCr方式で組み合わせの数を求める
int combination(int n, int r){
    int up = 1, down = 1;

    rep(i, n)   up *= (i + 1);

    rep(i, n-r) down *= (i + 1);
    rep(i, r)   down *= (i + 1);

    return up/down;
}

//nPr方式で階乗を求める
int factorial(int n, int r){
    if(n < r){
        cout << "error" << endl;
        return 0;
    }else{
        int res = 1;
        while(r){
            r--;
            res *= n;
            n--;
        }
        return res;
    }
}

//桁数を返す
int find_digits(int n){
    int digit = 0;

    while(n){
        n /= 10;
        digit++;
    }
    return digit;
}
// 各桁の和を計算する関数
int findSumOfDigits(int n){
    int sum = 0;
    while (n > 0) { // n が 0 になるまで
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
//次数を得る
int degree(int n){
    int count = 0;
    while(1){
        if(count <= 0)  break;
        count /= 2;
        count++;
    }
    return count;
}

//四捨五入
int shishagonyu( double x )
{
    return (int)( x < 0.0 ? x-0.5 : x+0.5 );
}

//切り上げ
int roundUp(double n){
    if(n >= 0){ 
        return (int)n + 1;
    }else{
        return (int)n - 1;
    }
}

//切り捨て
int roundDown(double n){
    return (int)n;
}

//四捨五入
int roundOff(double n){
    double decimal = 0;

    decimal = n - (int)n;

    if(decimal >= 0.5 || decimal <= -0.5){
        return roundUp(n);
    }else{
        return roundDown(n);
    }
}

//最大公約数(Greatest Common Divisor)
int gcd (int m, int n){
    //引数に0がある場合は0を返す
    if(m == 0 || n == 0)    return 0;
    
    //ユークリッドの互除法
    while(m != n){
        if(m > n)   m = m - n;
        else    n = n - m;
    }
    return m;
}

//最小公倍数(Least Common Multiple)
int lcm(int m, int n){
    //引数に0がある場合は0を返す
    if(m == 0 || n == 0)    return 0;
    
    //lcm = m * n / gcd(m, n)
    return ((m / gcd(m, n)) * n);
}

//素因数分解
void prime_factorization(int n){
    int a = 2, res;
    
    while(n >= a * a){
        if(n % a == 0){
            res = a;
            //resをグローバルな配列に代入すれば記録できる。
            n /= a;
        }else{
            a++;
        }
    }
    //ラス1の素因数
    res = n;
}

//エラトステネスの篩
int Eratosthenes(int n){
    bool prime[n];
    //prime[0]が1、prime[n - 1]がn。
    rep(i, n)   prime[i] = true;
    
    for(int i = 2; i < sqrt(n); i++){
        if(prime[i]){
            for(int j = 0; i * (j + 2) < n; j++){
                prime[i *(j + 2)] = false;
            }
        }
    }

    int cnt = 0;
    for(int i = 2; i < n; i++){
        if(prime[i]){
            cnt++;
        }
    }
    return cnt;
}
//偶奇判定。奇数ならtrue。
bool odd_even(int num){
    bool judge;
    if(num % 2){
        judge = true;
    }else{
        judge = false;
    }
    return judge;
}