Language: C++

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = long long ;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n;
    cin >> n;
    vi v(n);
    rep(i,n) cin >> v.at(i);
    // 全部同じはダメ
    vi a(100100,0);
    vi b(100100,0);
    rep(i,n){
        if(i%2){
            // 偶数番目
            a.at(v.at(i))++;
        }else{
            // 奇数番目
            b.at(v.at(i))++;
        }
    }
    ll a1 = 0;
    ll b1 = 0;
    ll a1i, b1i;
    rep(i,a.size()) {
        if(a.at(i)>=a1){
            a1 = a.at(i);
            a1i = i;
        }
    }
    rep(i,a.size()) {
        if(b.at(i)>=b1){
            b1 = b.at(i);
            b1i = i;
        }
    }
    ll a2 = 0;
    ll b2 = 0;
    rep(i,a.size()) {
        if(a.at(i)!=a1) {
            a2 = max(a2, a.at(i));
        }
    }
    rep(i,a.size()) {
        if(b.at(i)!=b1) {
            b2 = max(b2, b.at(i));
        }
    }
    cerr << "a1i:" << a1i << " b1i:" << b1i << endl;
    cerr << "a1:" << a1 << " b1:" << b1 << endl;
    cerr << "a2:" << a2 << " b2:" << b2 << endl;
    ll res = 0;
    if(a1i!=b1i){
        res += (n/2) - a1;
        res += (n/2) - b1;
    }else{
        if(a2 >= b2){
            res += (n/2) - a2;
            res += (n/2) - b1;
        }else{
            res += (n/2) - a1;
            res += (n/2) - b2;
        }
    }
    cout << res << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:53:21: error: no matching function for call to 'max(ll&, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type&)'
   53 |             a2 = max(a2, a.at(i));
      |                  ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:53:21: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
   53 |             a2 = max(a2, a.at(i));
      |                  ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:53:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   53 |             a2 = max(a2, a.at(i));
      |                  ~~~^~~~~~~~~~~~~
a.cc:58:21: error: no matching function for call to 'max(ll&, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type&)'
   58 |             b2 = max(b2, b.at(i));
      |                  ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:58:21: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
   58 |             b2 = max(b2, b.at(i));
      |                  ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:58:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   58 |             b2 = max(b2, b.at(i));
      |                  ~~~^~~~~~~~~~~~~