Language: C++

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;

int n;
int v[2][100010];
int last[2][100010],next[2][100010];

int main(){
	scanf("%d",&n);
	for(int i=0;i<=1;i++)
		for(int j=1;j<=100000;j++) v[i][j]=n/2;
	last[0][0]=last[1][0]=next[0][100001]=next[1][100001]=1e9;
	int x;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		v[i%2][x]--;
	}
	for(int i=1;i<=100000;i++) last[0][i]=min(last[0][i-1],v[0][i]),last[1][i]=min(last[1][i-1],v[1][i]);
	for(int i=100000;i>=1;i--) next[0][i]=min(next[0][i+1],v[0][i]),next[1][i]=min(next[1][i+1],v[1][i]);
	int mmin=1e9;
	for(int i=1;i<=100000;i++){
		mmin=min(mmin,v[0][i]+min(last[1][i-1],next[1][i+1]));
		mmin=min(mmin,v[1][i]+min(last[0][i-1],next[0][i+1]));
	}
	printf("%d\n",mmin);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:31: error: reference to 'next' is ambiguous
   15 |         last[0][0]=last[1][0]=next[0][100001]=next[1][100001]=1e9;
      |                               ^~~~
In file included from /usr/include/c++/14/string:47,
                 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:4:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:21: note:                 'int next [2][100010]'
    9 | int last[2][100010],next[2][100010];
      |                     ^~~~
a.cc:15:47: error: reference to 'next' is ambiguous
   15 |         last[0][0]=last[1][0]=next[0][100001]=next[1][100001]=1e9;
      |                                               ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:21: note:                 'int next [2][100010]'
    9 | int last[2][100010],next[2][100010];
      |                     ^~~~
a.cc:22:36: error: reference to 'next' is ambiguous
   22 |         for(int i=100000;i>=1;i--) next[0][i]=min(next[0][i+1],v[0][i]),next[1][i]=min(next[1][i+1],v[1][i]);
      |                                    ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:21: note:                 'int next [2][100010]'
    9 | int last[2][100010],next[2][100010];
      |                     ^~~~
a.cc:22:51: error: reference to 'next' is ambiguous
   22 |         for(int i=100000;i>=1;i--) next[0][i]=min(next[0][i+1],v[0][i]),next[1][i]=min(next[1][i+1],v[1][i]);
      |                                                   ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:21: note:                 'int next [2][100010]'
    9 | int last[2][100010],next[2][100010];
      |                     ^~~~
a.cc:22:73: error: reference to 'next' is ambiguous
   22 |         for(int i=100000;i>=1;i--) next[0][i]=min(next[0][i+1],v[0][i]),next[1][i]=min(next[1][i+1],v[1][i]);
      |                                                                         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:21: note:                 'int next [2][100010]'
    9 | int last[2][100010],next[2][100010];
      |                     ^~~~
a.cc:22:88: error: reference to 'next' is ambiguous
   22 |         for(int i=100000;i>=1;i--) next[0][i]=min(next[0][i+1],v[0][i]),next[1][i]=min(next[1][i+1],v[1][i]);
      |                                                                                        ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:21: note:                 'int next [2][100010]'
    9 | int last[2][100010],next[2][100010];
      |                     ^~~~
a.cc:25:56: error: reference to 'next' is ambiguous
   25 |                 mmin=min(mmin,v[0][i]+min(last[1][i-1],next[1][i+1]));
      |                                                        ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:21: note:                 'int next [2][100010]'
    9 | int last[2][100010],next[2][100010];
      |                     ^~~~
a.cc:26:56: error: reference to 'next' is ambiguous
   26 |                 mmin=min(mmin,v[1][i]+min(last[0][i-1],next[0][i+1]));
      |                                                        ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:21: note:                 'int next [2][100010]'
    9 | int last[2][100010],next[2][100010];
      |                     ^~~~