Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int n;
  cin >> n;
  vector<int> odd(n/2), even(n/2);
  rep(i,n){
    if(i % 2 == 0) cin >> even[i/2];
    if(i % 2 != 0) cin >> odd[(i-1)/2];
  }
  vector<pair<int,int> > odd_count, even_count;
  sort(all(odd));
  sort(all(even));
  int now = odd[0];
  int count = 0;
  for(n:odd){
    if(now == n) count++;
    else{
      odd_count.push_back(make_pair(count,now));
      now = n;
      count = 1;
    }
  }
  odd_count.push_back(make_pair(count,now));
  now = even[0];
  count = 0;
  for(n:even){
    if(now == n) count++;
    else{
      even_count.push_back(make_pair(count,now));
      now = n;
      count = 1;
    }
  }
  even_count.push_back(make_pair(count,now));
  sort(all(odd_count));
  sort(all(even_count));
  reverse(all(odd_count));
  reversr(all(even_count));
  int ofn = odd_count[0].second;
  int efn = even_count[0].second;
  int least;
  if(odd_count.size() == 1 && even_count.size() == 1){
    if(ofn == efn) least = n/2;
    else least = n;
  }
  else if(odd_count.size() > 1 && even_count.size() == 1){
    if(ofn != efn) least = n/2 + odd_count[0].first;
    else least = n/2 + odd_count[1].first;
  }
  else if(odd_count.size() == 1 && even_count.size() > 1){
    if(ofn != efn) least = n/2 + even_count[0].first;
    else least = n/2 + even_count[1].first;
  }
  else{
    if(ofn != efn) least = odd_count[0].first + even_count[0].first;
    else least = max(odd_count[0].first + even_count[1].first,
                     odd_count[1].first + even_count[0].first);
  }
  cout << n - least << endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:21:8: error: found ':' in nested-name-specifier, expected '::'
   21 |   for(n:odd){
      |        ^
      |        ::
a.cc:21:7: error: 'n' is not a class, namespace, or enumeration
   21 |   for(n:odd){
      |       ^
a.cc:29:22: error: could not convert 'odd_count.std::vector<std::pair<int, int> >::push_back(std::make_pair<int&, int&>(count, now))' from 'void' to 'bool'
   29 |   odd_count.push_back(make_pair(count,now));
      |   ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
      |                      |
      |                      void
a.cc:30:16: error: expected ')' before ';' token
   30 |   now = even[0];
      |                ^
      |                )
a.cc:21:6: note: to match this '('
   21 |   for(n:odd){
      |      ^
a.cc:32:8: error: found ':' in nested-name-specifier, expected '::'
   32 |   for(n:even){
      |        ^
      |        ::
a.cc:32:7: error: 'n' is not a class, namespace, or enumeration
   32 |   for(n:even){
      |       ^
a.cc:40:23: error: could not convert 'even_count.std::vector<std::pair<int, int> >::push_back(std::make_pair<int&, int&>(count, now))' from 'void' to 'bool'
   40 |   even_count.push_back(make_pair(count,now));
      |   ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
      |                       |
      |                       void
a.cc:41:23: error: expected ')' before ';' token
   41 |   sort(all(odd_count));
      |                       ^
      |                       )
a.cc:32:6: note: to match this '('
   32 |   for(n:even){
      |      ^
a.cc:44:3: error: 'reversr' was not declared in this scope
   44 |   reversr(all(even_count));
      |   ^~~~~~~