Language: C++

#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long n;
	cin>>n;
	vector<long long> a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	const long long mx=200020;
	vector<long long> c(mx),d(mx);
	for(long long i=0;i<n;i++)
	{
		if(i&1)
			c[a[i]]++;
		else
			d[a[i]]++;
	}
	long long x=max_element(c.begin(),c.end()-c.begin());
	long long y=max_element(d.begin(),d.end()-d.begin());
	if(x!=y)
	{
		cout<<n-(c[x]+d[y])<<endl;
		return 0;
	}
	long long ans=n;
	{
		long long z=0;
		for(long long i=0;i<mx;i++)
		{
			if(i==x)
				continue;
			if(c[z]<c[i])
				z=i;
		}
		chmin(ans,n-(c[z]+d[y]));
	}
	{
		long long z;
		for(long long i=0;i<mx;i++)
		{
			if(i==y)
				continue;
			if(d[z]<d[i])
				z=i;
		}
		chmin(ans,n-(c[x]+d[z]));
	}
	cout<<ans<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:32: error: no matching function for call to 'max_element(std::vector<long long int>::iterator, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
   20 |         long long x=max_element(c.begin(),c.end()-c.begin());
      |                     ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:5641:5: note: candidate: 'template<class _FIter> constexpr _FIter std::max_element(_FIter, _FIter)'
 5641 |     max_element(_ForwardIterator __first, _ForwardIterator __last)
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5641:5: note:   template argument deduction/substitution failed:
a.cc:20:32: note:   deduced conflicting types for parameter '_FIter' ('__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' and 'long int')
   20 |         long long x=max_element(c.begin(),c.end()-c.begin());
      |                     ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5666:5: note: candidate: 'template<class _FIter, class _Compare> constexpr _FIter std::max_element(_FIter, _FIter, _Compare)'
 5666 |     max_element(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5666:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:524:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::max_element(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Compare)'
  524 | max_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp);
      | ^~~~~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:524:1: note:   candidate expects 4 arguments, 2 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:528:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::max_element(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator)'
  528 | max_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
      | ^~~~~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:528:1: note:   candidate expects 3 arguments, 2 provided
a.cc:21:32: error: no matching function for call to 'max_element(std::vector<long long int>::iterator, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
   21 |         long long y=max_element(d.begin(),d.end()-d.begin());
      |                     ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5641:5: note: candidate: 'template<class _FIter> constexpr _FIter std::max_element(_FIter, _FIter)'
 5641 |     max_element(_ForwardIterator __first, _ForwardIterator __last)
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5641:5: note:   template argument deduction/substitution failed:
a.cc:21:32: note:   deduced conflicting types for parameter '_FIter' ('__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' and 'long int')
   21 |         long long y=max_element(d.begin(),d.end()-d.begin());
      |                     ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5666:5: note: candidate: 'template<class _FIter, class _Compare> constexpr _FIter std::max_element(_FIter, _FIter, _Compare)'
 5666 |     max_element(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5666:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:524:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::max_element(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Compare)'
  524 | max_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp);
      | ^~~~~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:524:1: note:   candidate expects 4 arguments, 2 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:528:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::max_element(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator)'
  528 | max_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
      | ^~~~~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:528:1: note:   candidate expects 3 arguments, 2 provided
a.cc:37:17: error: 'chmin' was not declared in this scope
   37 |                 chmin(ans,n-(c[z]+d[y]));
      |                 ^~~~~
a.cc:48:17: error: 'chmin' was not declared in this scope
   48 |                 chmin(ans,n-(c[x]+d[z]));
      |                 ^~~~~