Language: C++

#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=5e5+10;

char c[maxn];
int n,m;
int dp[maxn];
int len[maxn];
int prev[maxn];
int rmq[maxn][21];

void update(int p)
{
	rmq[p][0]=dp[p]-p;
	for(int i=1;i<=20;i++)
	{
		if (p-(1<<(i-1))<0) rmq[p][i]=rmq[p][i-1];
		else rmq[p][i]=max(rmq[p][i-1],rmq[p-(1<<(i-1))][i-1]);
	}
	return;
}

int maxi(int l,int r)
{
	int ans=-100000;
	for(int i=20;i>=0;i--)
	{
		if (r-(1<<i)>=l-1)
		{
			ans=max(ans,rmq[r][i]);
			r-=(1<<i);
		}
	}
	return ans;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<=n;i++)	c[i]=getchar();
	
	for(int i=1;i<=n;i++)
		if (c[i]=='0')
		{
			if (i==1 || c[i-1]=='0') len[i]=0;
			else
			{
				len[i]=1;
				while(i-len[i]-1>0 && c[i-len[i]-1]=='1') len[i]++;
			}
		}
	
	int nxt=-1;
	for(int i=1;i<=n;i++)
	{
		if (c[i]=='0') nxt=i;
		prev[i]=nxt;
	}
	
	dp[0]=0;
	for(int i=1;i<=n;i++)
	{
		dp[i]=dp[i-1];
		if (i>=3 && c[i]=='1' && c[i-1]=='0')
			dp[i]=max(dp[i],maxi((i-1)-len[i-1]-1,i-2)+(i-2));
		if (i>=3 && c[i]=='1' &&  prev[i]>1 && c[prev[i]-1]=='1')
			dp[i]=max(dp[i],dp[prev[i]-2]+i-prev[i]);
		update(i);
	}
	
	printf("%d\n",dp[n]);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:58:17: error: reference to 'prev' is ambiguous
   58 |                 prev[i]=nxt;
      |                 ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:10:5: note:                 'int prev [500010]'
   10 | int prev[maxn];
      |     ^~~~
a.cc:67:43: error: reference to 'prev' is ambiguous
   67 |                 if (i>=3 && c[i]=='1' &&  prev[i]>1 && c[prev[i]-1]=='1')
      |                                           ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:10:5: note:                 'int prev [500010]'
   10 | int prev[maxn];
      |     ^~~~
a.cc:67:58: error: reference to 'prev' is ambiguous
   67 |                 if (i>=3 && c[i]=='1' &&  prev[i]>1 && c[prev[i]-1]=='1')
      |                                                          ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:10:5: note:                 'int prev [500010]'
   10 | int prev[maxn];
      |     ^~~~
a.cc:68:44: error: reference to 'prev' is ambiguous
   68 |                         dp[i]=max(dp[i],dp[prev[i]-2]+i-prev[i]);
      |                                            ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:10:5: note:                 'int prev [500010]'
   10 | int prev[maxn];
      |     ^~~~
a.cc:68:57: error: reference to 'prev' is ambiguous
   68 |                         dp[i]=max(dp[i],dp[prev[i]-2]+i-prev[i]);
      |                                                         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:10:5: note:                 'int prev [500010]'
   10 | int prev[maxn];
      |     ^~~~