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: Wrong Answer)


#include<bits/stdc++.h>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 100010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

 

//SOLVE
void solve(void)
{
  int N;cin>>N;
  vector<map<int,int> > mp (2);
  for (int i = 0; i < N; i++)
  {
    int X;cin>>X;
    mp[i%2][X]++;
  }
  vector<map<int,int,greater<int>>> mp2(2);
  for (auto &&i : mp[0])
  {
    mp2[0][i.second] = i.first;
  }
  for (auto &&i : mp[1])
  {
    mp2[1][i.second] = i.first;
  }
  if(mp[0].begin()->second != mp[1].begin()->second)
  {
    cout<<N - mp[0].begin()->second - mp[1].begin()->second;
  }
  else
  {
    int E1 = mp[0].begin()->second ;
    int E2;
    int O1 =  mp[1].begin()->second;
    int O2;
    if(mp[0].size() == 1)
    {
      E2 = 0;
    }
    else
    {
      auto itr = mp[0].begin();
      itr++;
      E2  = itr->second;
    }

    if(mp[1].size() == 1)
    {
      O2 = 0;
    }
    else
    {
      auto itr = mp[1].begin();
      itr++;
      O2  = itr->second;
    }
      
     cout<<N - max(O1 +E2 ,O2 +E1)<<endl;
  
  }

  
  

  return;
}

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

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}