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 <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int a[n/2]={0};
  int b[n/2]={0};
  int j=0,k=0;
  for(int i=0;i<n;i++){
    if(i%2==0){
      cin >> a[j];
      j++;
    }else{
      cin >> b[k];
      k++;
    }
  }
  sort(a,a+(n/2));
  sort(b,b+(n/2));
  /*for(int i=0;i<n/2;i++){
    cout << a[i] << endl;
  }*/
  int na,nb;
  int s=0;
  int cnt=0;
  int a1=0,b1=0,a2=0,b2=0;
  bool flag;

  for(int i=0;i<n/2;i++){
    if(s!=a[i]){
      s=a[i];
      cnt=1;
      flag=true;
    }else{
      cnt++;
    }
    if(cnt>a1){
      if(flag){
        a2=a1;
        flag=false;
      }
      a1=cnt;
      na=s;
    }else if(cnt>=a2){
      a2=cnt;
    }else{
      continue;
    }
  }

  cnt=0;
  s=0;

  for(int i=0;i<n/2;i++){
    if(s!=b[i]){
      s=b[i];
      cnt=1;
      flag=true;
    }else{
      cnt++;
    }
    if(cnt>b1){
      if(flag){
        b2=b1;
        flag=false;
      }
      b1=cnt;
      nb=s;
    }else if(cnt>=b2){
      b2=cnt;
    }else{
      continue;
    }
  }

  ll cost=0;
  if(na!=nb){
    cost=n-a1-b1;
    cout << cost << endl;
    return 0;
  }else{
    if(a1>b1){
      cost=n-a1-b2;
    }else{
      cost=n-b1-a2;
    }
  }
  cout << cost << endl;
  /*cout << a1 << b1 << a2 << b2 <<endl;*/
  return 0;
}