Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,a,b,x=0,y=0;cin>>N;N/=2;
  int A[N],B[N];
  for(int i=0;i<N;i++)cin>>A[i]>>B[i];
  sort(A,A+N);sort(B,B+N);
  for(int i=0;i<N;i=upper_bound(A,A+N,A[i])-A){
    if(x<upper_bound(A,A+N,A[i])-lower_bound(A,A+N,A[i]))a=A[i],x=upper_bound(A,A+N,A[i])-lower_bound(A,A+N-A[i]));
    if(y<upper_bound(B,B+N,B[i])-lower_bound(B,B+N,B[i]))b=B[i],y=upper_bound(B,B+N,B[i])-lower_bound(B,B+N-A[i]));
  }
  if(a==b){
    int MA=0,MB=0;
    for(int i=0;i<N;i=upper_bound(A,A+N,A[i])-A){
      if(a!=A[i]&&MA<upper_bound(A,A+N,A[i])-lower_bound(A,A+N,A[i]))MA=upper_bound(A,A+N,A[i])-lower_bound(A,A+N-A[i]));
      if(b!=B[i]&&MB<upper_bound(B,B+N,B[i])-lower_bound(B,B+N,B[i]))MB=upper_bound(B,B+N,B[i])-lower_bound(B,B+N-A[i]));
    }
    cout<<2*N-min(x+MA,y+MB)<<endl;
  }
  else cout<<2*N-x-y<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:102: error: no matching function for call to 'lower_bound(int [N], int*)'
    9 |     if(x<upper_bound(A,A+N,A[i])-lower_bound(A,A+N,A[i]))a=A[i],x=upper_bound(A,A+N,A[i])-lower_bound(A,A+N-A[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:1530:5: note: candidate: 'template<class _ForwardIterator, class _Tp> _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&)'
 1530 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1530: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:1963:5: note: candidate: 'template<class _FIter, class _Tp, class _Compare> _FIter std::lower_bound(_FIter, _FIter, const _Tp&, _Compare)'
 1963 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1963:5: note:   candidate expects 4 arguments, 2 provided
a.cc:10:102: error: no matching function for call to 'lower_bound(int [N], int*)'
   10 |     if(y<upper_bound(B,B+N,B[i])-lower_bound(B,B+N,B[i]))b=B[i],y=upper_bound(B,B+N,B[i])-lower_bound(B,B+N-A[i]));
      |                                                                                           ~~~~~~~~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1530:5: note: candidate: 'template<class _ForwardIterator, class _Tp> _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&)'
 1530 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1530:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:1963:5: note: candidate: 'template<class _FIter, class _Tp, class _Compare> _FIter std::lower_bound(_FIter, _FIter, const _Tp&, _Compare)'
 1963 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1963:5: note:   candidate expects 4 arguments, 2 provided
a.cc:15:108: error: no matching function for call to 'lower_bound(int [N], int*)'
   15 |       if(a!=A[i]&&MA<upper_bound(A,A+N,A[i])-lower_bound(A,A+N,A[i]))MA=upper_bound(A,A+N,A[i])-lower_bound(A,A+N-A[i]));
      |                                                                                                 ~~~~~~~~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1530:5: note: candidate: 'template<class _ForwardIterator, class _Tp> _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&)'
 1530 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1530:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:1963:5: note: candidate: 'template<class _FIter, class _Tp, class _Compare> _FIter std::lower_bound(_FIter, _FIter, const _Tp&, _Compare)'
 1963 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1963:5: note:   candidate expects 4 arguments, 2 provided
a.cc:16:108: error: no matching function for call to 'lower_bound(int [N], int*)'
   16 |       if(b!=B[i]&&MB<upper_bound(B,B+N,B[i])-lower_bound(B,B+N,B[i]))MB=upper_bound(B,B+N,B[i])-lower_bound(B,B+N-A[i]));
      |                                                                                                 ~~~~~~~~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1530:5: note: candidate: 'template<class _ForwardIterator, class _Tp> _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&)'
 1530 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1530:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:1963:5: note: candidate: 'template<class _FIter, class _Tp, class _Compare> _FIter std::lower_bound(_FIter, _FIter, const _Tp&, _Compare)'
 1963 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1963:5: note:   candidate expects 4 arguments, 2 provided