Language: C++

#include <iostream>
#include <utility>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  map<int,int> c[2];
  for(int i = 0; n > i; i++){
  	int a;
    cin >> a;
    c[i%2][a]++;
  }
  int ans = 0;
  
  auto check = [&](int a, int b){
    if(a == b) return 100000000;
    int ret = 0;
    for(auto itr : c[0]){
      if(itr.first != a) ret += itr.second;
    }
    for(auto itr : c[1]){
      if(itr.first != b) ret += itr.second;
    }
    return ret;
  };
  
  vector<pair<int,int>> cand[2];
  for(int i = 0; 2 > i; i++){ 
    for(auto itr : c[i])
      cand[i].push_back({itr.second, itr.first});
    cand[i].push_back({0,-1});
  }
  sort(cand.begin(), cand.end(), greater<pair<int,int>>());
  
  cout << min({check(cand[0][0],cand[1][0]),check(cand[0][0],cand[1][1]),check(cand[0][1],cand[1][0])}) << endl;
  
  return 0;  
}


Compiler output:
a.cc: In function 'int main()':
a.cc:37:13: error: request for member 'begin' in 'cand', which is of non-class type 'std::vector<std::pair<int, int> > [2]'
   37 |   sort(cand.begin(), cand.end(), greater<pair<int,int>>());
      |             ^~~~~
a.cc:37:27: error: request for member 'end' in 'cand', which is of non-class type 'std::vector<std::pair<int, int> > [2]'
   37 |   sort(cand.begin(), cand.end(), greater<pair<int,int>>());
      |                           ^~~
a.cc:39:21: error: no match for call to '(main()::<lambda(int, int)>) (__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type&, __gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type&)'
   39 |   cout << min({check(cand[0][0],cand[1][0]),check(cand[0][0],cand[1][1]),check(cand[0][1],cand[1][0])}) << endl;
      |                ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
a.cc:19:16: note: candidate: 'main()::<lambda(int, int)>'
   19 |   auto check = [&](int a, int b){
      |                ^
a.cc:19:16: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'int'
a.cc:39:50: error: no match for call to '(main()::<lambda(int, int)>) (__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type&, __gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type&)'
   39 |   cout << min({check(cand[0][0],cand[1][0]),check(cand[0][0],cand[1][1]),check(cand[0][1],cand[1][0])}) << endl;
      |                                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
a.cc:19:16: note: candidate: 'main()::<lambda(int, int)>'
   19 |   auto check = [&](int a, int b){
      |                ^
a.cc:19:16: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'int'
a.cc:39:79: error: no match for call to '(main()::<lambda(int, int)>) (__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type&, __gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type&)'
   39 |   cout << min({check(cand[0][0],cand[1][0]),check(cand[0][0],cand[1][1]),check(cand[0][1],cand[1][0])}) << endl;
      |                                                                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
a.cc:19:16: note: candidate: 'main()::<lambda(int, int)>'
   19 |   auto check = [&](int a, int b){
      |                ^
a.cc:19:16: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'int'
a.cc:39:14: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   39 |   cout << min({check(cand[0][0],cand[1][0]),check(cand[0][0],cand[1][1]),check(cand[0][1],cand[1][0])}) << endl;
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   candidate expects 2 arguments, 1 provided