Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll MAX=200030;
const ll MOD=1000000007;
int N;
char S[MAX];
int dp[MAX],dpn[MAX],next[26],start;
main(){
    scanf(" %s",S);
    N=strlen(S);
    for(int i=0;i<26;i++) next[i]=N+i;
    for(int i=N-1;i>=0;i--) {
        dp[i]=MAX;
        for(int j=0;j<26;j++) if(dp[i]>dp[next[j]]) dpn[i]=next[j], dp[i]=dp[next[j]];
        dp[i]++;
        next[S[i]-'a']=i;
    }
    int t=MAX;
    for(int i=0;i<26;i++){
        if(t>dp[next[i]]) start=next[i],t=dp[next[i]];
    }
    while(start<N){
        printf("%c",S[start]);
        start=dpn[start];
    }
    printf("%c\n",start-N+'a');

    return 0;
}


Compiler output:
a.cc:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:13:27: error: reference to 'next' is ambiguous
   13 |     for(int i=0;i<26;i++) next[i]=N+i;
      |                           ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 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:9:22: note:                 'int next [26]'
    9 | int dp[MAX],dpn[MAX],next[26],start;
      |                      ^~~~
a.cc:16:43: error: reference to 'next' is ambiguous
   16 |         for(int j=0;j<26;j++) if(dp[i]>dp[next[j]]) dpn[i]=next[j], dp[i]=dp[next[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:9:22: note:                 'int next [26]'
    9 | int dp[MAX],dpn[MAX],next[26],start;
      |                      ^~~~
a.cc:16:60: error: reference to 'next' is ambiguous
   16 |         for(int j=0;j<26;j++) if(dp[i]>dp[next[j]]) dpn[i]=next[j], dp[i]=dp[next[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:9:22: note:                 'int next [26]'
    9 | int dp[MAX],dpn[MAX],next[26],start;
      |                      ^~~~
a.cc:16:78: error: reference to 'next' is ambiguous
   16 |         for(int j=0;j<26;j++) if(dp[i]>dp[next[j]]) dpn[i]=next[j], dp[i]=dp[next[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:9:22: note:                 'int next [26]'
    9 | int dp[MAX],dpn[MAX],next[26],start;
      |                      ^~~~
a.cc:18:9: error: reference to 'next' is ambiguous
   18 |         next[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:9:22: note:                 'int next [26]'
    9 | int dp[MAX],dpn[MAX],next[26],start;
      |                      ^~~~
a.cc:22:17: error: reference to 'next' is ambiguous
   22 |         if(t>dp[next[i]]) start=next[i],t=dp[next[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:22: note:                 'int next [26]'
    9 | int dp[MAX],dpn[MAX],next[26],start;
      |                      ^~~~
a.cc:22:33: error: reference to 'next' is ambiguous
   22 |         if(t>dp[next[i]]) start=next[i],t=dp[next[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:22: note:                 'int next [26]'
    9 | int dp[MAX],dpn[MAX],next[26],start;
      |                      ^~~~
a.cc:22:46: error: reference to 'next' is ambiguous
   22 |         if(t>dp[next[i]]) start=next[i],t=dp[next[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:22: note:                 'int next [26]'
    9 | int dp[MAX],dpn[MAX],next[26],start;
      |                      ^~~~