Language: C++

#include <iostream>
#include <cstring>
using namespace std;
char s[200005];
int next[2000005][30],n,dp[200005];
int main()
{
    cin.getline(s+1,200005);
    n=strlen(s+1);
    for(int i=0;i<26;++i) next[n+1][i]=n+1;
    dp[n+1]=1;
    for(int i=n;i>=1;--i)
    {
        for(int j=0;j<26;++j) next[i][j]=next[i+1][j];
        next[i][s[i]-'a']=i;
        dp[i]=n+1;
        for(int j=0;j<26;++j) dp[i]=min(dp[i],dp[next[i][j]+1]);
        ++dp[i];
    }
    int poz=1;
    while(poz<=n)
    {
        for(int i=0;i<26;++i)
        {
            if(next[poz][i]>n||dp[next[poz][i]+1]<dp[poz])
            {
                cout<<(char)('a'+i);
                poz=next[poz][i]+1;
                break;
            }
        }
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:27: error: reference to 'next' is ambiguous
   10 |     for(int i=0;i<26;++i) next[n+1][i]=n+1;
      |                           ^~~~
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: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:5:5: note:                 'int next [2000005][30]'
    5 | int next[2000005][30],n,dp[200005];
      |     ^~~~
a.cc:14:31: error: reference to 'next' is ambiguous
   14 |         for(int j=0;j<26;++j) next[i][j]=next[i+1][j];
      |                               ^~~~
/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:5:5: note:                 'int next [2000005][30]'
    5 | int next[2000005][30],n,dp[200005];
      |     ^~~~
a.cc:14:42: error: reference to 'next' is ambiguous
   14 |         for(int j=0;j<26;++j) next[i][j]=next[i+1][j];
      |                                          ^~~~
/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:5:5: note:                 'int next [2000005][30]'
    5 | int next[2000005][30],n,dp[200005];
      |     ^~~~
a.cc:15:9: error: reference to 'next' is ambiguous
   15 |         next[i][s[i]-'a']=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:5:5: note:                 'int next [2000005][30]'
    5 | int next[2000005][30],n,dp[200005];
      |     ^~~~
a.cc:17:50: error: reference to 'next' is ambiguous
   17 |         for(int j=0;j<26;++j) dp[i]=min(dp[i],dp[next[i][j]+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:5:5: note:                 'int next [2000005][30]'
    5 | int next[2000005][30],n,dp[200005];
      |     ^~~~
a.cc:25:16: error: reference to 'next' is ambiguous
   25 |             if(next[poz][i]>n||dp[next[poz][i]+1]<dp[poz])
      |                ^~~~
/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:5:5: note:                 'int next [2000005][30]'
    5 | int next[2000005][30],n,dp[200005];
      |     ^~~~
a.cc:25:35: error: reference to 'next' is ambiguous
   25 |             if(next[poz][i]>n||dp[next[poz][i]+1]<dp[poz])
      |                                   ^~~~
/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:5:5: note:                 'int next [2000005][30]'
    5 | int next[2000005][30],n,dp[200005];
      |     ^~~~
a.cc:28:21: error: reference to 'next' is ambiguous
   28 |                 poz=next[poz][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:5:5: note:                 'int next [2000005][30]'
    5 | int next[2000005][30],n,dp[200005];
      |     ^~~~