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 MOD 1000000007
//#define INF 10000000000000009
#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

signed main(){
    int N;
    int Ans=0;
    int v[114514];
    int p[114514],q[114514];
    cin >> N;
    REP(i,N){
        cin >> v[i];
        if(i%2==0){
            p[i/2]=v[i];
        }else{
            q[i/2]=v[i];
        }
    }
    //pの要素数は(N+1)/2、qの要素数はN/2
    int x=(N+1)/2,y=N/2;
    
    //メジアン候補数
    int c,d;
    
    sort(p,p+x);
    sort(q,q+y);
    //中央値はp[x/2],q[y/2]
    
    REP(i,x){
        Ans+=abs(p[i]-p[x/2]);
    }
    REP(i,y){
        Ans+=abs(q[i]-q[y/2]);
    }
    
    if(x%2==1){
        c=1;
    }else{
        c=p[(x+1)/2]-p[x/2]+1;
    }
    if(y%2==1){
        d=1;
    }else{
        d=q[(y+1)/2]-q[y/2]+1;
    }
    
    if(c==1&&d==1&&p[x/2]==q[y/2]){
        Ans+=y;
    }
    
    cout << Ans << endl;
    return 0;
}