Language: C++

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main() {
    int n;
    cin >> n;
    vector<int> v(n), odd, even;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        if(i & 1) odd.push_back(v[i]);
        else even.push_back(v[i]);
    }
    for(int i = 0; i < n; i++) {
        if (i & 1) odd[v[i]]++;
        else even[v[i]]++;
    }
    vector<pair<int, int>> odd_top(2), even_top(2);
    auto comp = [](auto &x, auto &y) {return x.second > y.second; };
    partial_sort_copy(odd.begin(), odd.end(), odd_top.begin(), odd_top.end(), comp);
    partial_sort_copy(even.begin(), even.end(), even_top.begin(), even_top.end(), comp);
    int result = 0;
    if (odd_top[0].first == even_top[0].first)
        result = n - max(odd_top[0].second + even_top[1].second, odd_top[1].second + even_top[0].second);
    else
        result = n - (odd_top[0].second + even_top[0].second);
    cout << result << "\n";
}

Compiler output:
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h: In instantiation of '_RandomAccessIterator std::__partial_sort_copy(_InputIterator, _InputIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _InputIterator = __gnu_cxx::__normal_iterator<long long int*, vector<long long int> >; _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<long long int, long long int>*, vector<pair<long long int, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(auto:28&, auto:29&)> >]':
/usr/include/c++/14/bits/stl_algo.h:1739:38:   required from '_RAIter std::partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter, _Compare) [with _IIter = __gnu_cxx::__normal_iterator<long long int*, vector<long long int> >; _RAIter = __gnu_cxx::__normal_iterator<pair<long long int, long long int>*, vector<pair<long long int, long long int> > >; _Compare = main()::<lambda(auto:28&, auto:29&)>]'
 1739 |       return std::__partial_sort_copy(__first, __last,
      |              ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
 1740 |                                       __result_first, __result_last,
      |                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1741 |                                 __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:22:22:   required from here
   22 |     partial_sort_copy(odd.begin(), odd.end(), odd_top.begin(), odd_top.end(), comp);
      |     ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1620:31: error: no match for 'operator=' (operand types are 'std::pair<long long int, long long int>' and 'long long int')
 1620 |           *__result_real_last = *__first;
      |           ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60:
/usr/include/c++/14/bits/stl_pair.h:946:9: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U2 = _U1; _T1 = long long int; _T2 = long long int]'
  946 |         operator=(const pair<_U1, _U2>& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:946:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algo.h:1620:31: note:   mismatched types 'const std::pair<_T1, _T2>' and 'long long int'
 1620 |           *__result_real_last = *__first;
      |           ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:957:9: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U2 = _U1; _T1 = long long int; _T2 = long long int]'
  957 |         operator=(pair<_U1, _U2>&& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:957:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algo.h:1620:31: note:   mismatched types 'std::pair<_T1, _T2>' and 'long long int'
 1620 |           *__result_real_last = *__first;
      |           ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:921:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<((bool)std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value), const std::pair<_T1, _T2>&, const std::__nonesuch&>) [with _T1 = long long int; _T2 = long long int; std::__conditional_t<((bool)std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value), const std::pair<_T1, _T2>&, const std::__nonesuch&> = const std::pair<long long int, long long int>&]'
  921 |       operator=(__conditional_t<__and_<is_copy_assignable<_T1>,
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:923:65: note:   no known conversion for argument 1 from 'long long int' to 'std::__conditional_t<true, const std::pair<long long int, long long int>&, const std::__nonesuch&>' {aka 'const std::pair<long long int, long long int>&'}
  921 |       operator=(__conditional_t<__and_<is_copy_assignable<_T1>,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  922 |                                        is_copy_assignable<_T2>>::value,
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  923 |                                 const pair&, const __nonesuch&> __p)
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_pair.h:931:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<((bool)std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value), std::pair<_T1, _T2>&&, std::__nonesuch&&>) [with _T1 = long long int; _T2 = long long int; std::__conditional_t<((bool)std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value), std::pair<_T1, _T2>&&, std::__nonesuch&&> = std::pair<long long int, long long int>&&]'
  931 |       operator=(__conditional_t<__and_<is_move_assignable<_T1>,
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:933:55: note:   no known conversion for argument 1 from 'long long int' to 'std::__conditional_t<true, std::pair<long long int, long long int>&&, std::__nonesuch&&>' {aka 'std::pair<long long int, long long int>&&'}
  931 |       operator=(__conditional_t<__and_<is_move_assignable<_T1>,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  932 |                                        is_move_assignable<_T2>>::value,
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  933 |                                 pair&&, __nonesuch&&> __p)
      |                                 ~~~~~~~~~~~~~~~~~~~~~~^~~