Language: C++

#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int dp[500010],front[500010],next[500010];
int main()
{
	int n,i;
	scanf("%d",&n);
	char c[500010];
	scanf("%s",c);
	string s=c;
	for(i=0;i<n;i++)
	{
		if(s[i]=='0')
			front[i]=i;
		else
		{
			if(i==0)
				front[i]=-1;
			else
				front[i]=front[i-1];
		}
	}
	for(i=n-1;i>=0;i--)
	{
		if(s[i]=='0')
			next[i]=i;
		else
			next[i]=next[i+1];
	}
	for(i=0;i<=n;i++)
	{
		if(i>=3 && s[i-1]=='1' && s[i-2]=='0' && s[i-3]=='1')
		{
			int temp=front[i-3];
			dp[i]=max(dp[i],dp[temp+1]+(i-temp-3));
			if(i!=temp+4)
			{
				dp[i]=max(dp[i],dp[temp+2]+(i-temp-4));
			}
		}
		if(i==n)	break;
		if(i+3<=n && s[i]=='1' && s[i+1]=='0' && s[i+2]=='1')
		{
			int temp=next[i+2];
			dp[temp]=max(dp[temp],dp[i]+(temp-i-2));
			if(temp!=i+3)
			{
				dp[temp-1]=max(dp[temp-1],dp[i]+(temp-i-3));
			}
		}
		dp[i+1]=max(dp[i],dp[i+1]);
	}
	printf("%d",dp[n]);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:25: error: reference to 'next' is ambiguous
   29 |                         next[i]=i;
      |                         ^~~~
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:2:
/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:6:30: note:                 'int next [500010]'
    6 | int dp[500010],front[500010],next[500010];
      |                              ^~~~
a.cc:31:25: error: reference to 'next' is ambiguous
   31 |                         next[i]=next[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:6:30: note:                 'int next [500010]'
    6 | int dp[500010],front[500010],next[500010];
      |                              ^~~~
a.cc:31:33: error: reference to 'next' is ambiguous
   31 |                         next[i]=next[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:6:30: note:                 'int next [500010]'
    6 | int dp[500010],front[500010],next[500010];
      |                              ^~~~
a.cc:47:34: error: reference to 'next' is ambiguous
   47 |                         int temp=next[i+2];
      |                                  ^~~~
/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:6:30: note:                 'int next [500010]'
    6 | int dp[500010],front[500010],next[500010];
      |                              ^~~~