Language: C++

#include <bits/stdc++.h>

#define rep(i,n) REP(i,0,n)
#define REP(i, a, n) for(int i = a; i < (int)n ; i++)

using namespace std;

string s;
string list[4];

signed main(){
  cin >> s;
  list[0] = "dream";
  list[1] = "dreamer";
  list[2] = "erase";
  list[3] = "eraser";
  
  int pos;
  bool flag = false;
  while(s.size()!=0){
    flag = false;
    rep(i, 4){
      if((pos = s.find(list[i], s.size()-list[i].size())) != string::npos){
	s.erase(pos, list[i].size());
	flag = true;
      }
    }
    if(!flag){
      cout << "NO" << '\n';
      exit(0);
    }
  }
  
  cout << "YES" << '\n';
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:3: error: reference to 'list' is ambiguous
   13 |   list[0] = "dream";
      |   ^~~~
In file included from /usr/include/c++/14/list:65,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:150,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_list.h:633:11: note: candidates are: 'template<class _Tp, class _Alloc> class std::__cxx11::list'
  633 |     class list : protected _List_base<_Tp, _Alloc>
      |           ^~~~
a.cc:9:8: note:                 'std::string list [4]'
    9 | string list[4];
      |        ^~~~
a.cc:14:3: error: reference to 'list' is ambiguous
   14 |   list[1] = "dreamer";
      |   ^~~~
/usr/include/c++/14/bits/stl_list.h:633:11: note: candidates are: 'template<class _Tp, class _Alloc> class std::__cxx11::list'
  633 |     class list : protected _List_base<_Tp, _Alloc>
      |           ^~~~
a.cc:9:8: note:                 'std::string list [4]'
    9 | string list[4];
      |        ^~~~
a.cc:15:3: error: reference to 'list' is ambiguous
   15 |   list[2] = "erase";
      |   ^~~~
/usr/include/c++/14/bits/stl_list.h:633:11: note: candidates are: 'template<class _Tp, class _Alloc> class std::__cxx11::list'
  633 |     class list : protected _List_base<_Tp, _Alloc>
      |           ^~~~
a.cc:9:8: note:                 'std::string list [4]'
    9 | string list[4];
      |        ^~~~
a.cc:16:3: error: reference to 'list' is ambiguous
   16 |   list[3] = "eraser";
      |   ^~~~
/usr/include/c++/14/bits/stl_list.h:633:11: note: candidates are: 'template<class _Tp, class _Alloc> class std::__cxx11::list'
  633 |     class list : protected _List_base<_Tp, _Alloc>
      |           ^~~~
a.cc:9:8: note:                 'std::string list [4]'
    9 | string list[4];
      |        ^~~~
a.cc:23:24: error: reference to 'list' is ambiguous
   23 |       if((pos = s.find(list[i], s.size()-list[i].size())) != string::npos){
      |                        ^~~~
/usr/include/c++/14/bits/stl_list.h:633:11: note: candidates are: 'template<class _Tp, class _Alloc> class std::__cxx11::list'
  633 |     class list : protected _List_base<_Tp, _Alloc>
      |           ^~~~
a.cc:9:8: note:                 'std::string list [4]'
    9 | string list[4];
      |        ^~~~
a.cc:23:42: error: reference to 'list' is ambiguous
   23 |       if((pos = s.find(list[i], s.size()-list[i].size())) != string::npos){
      |                                          ^~~~
/usr/include/c++/14/bits/stl_list.h:633:11: note: candidates are: 'template<class _Tp, class _Alloc> class std::__cxx11::list'
  633 |     class list : protected _List_base<_Tp, _Alloc>
      |           ^~~~
a.cc:9:8: note:                 'std::string list [4]'
    9 | string list[4];
      |        ^~~~
a.cc:24:22: error: reference to 'list' is ambiguous
   24 |         s.erase(pos, list[i].size());
      |                      ^~~~
/usr/include/c++/14/bits/stl_list.h:633:11: note: candidates are: 'template<class _Tp, class _Alloc> class std::__cxx11::list'
  633 |     class list : protected _List_base<_Tp, _Alloc>
      |           ^~~~
a.cc:9:8: note:                 'std::string list [4]'
    9 | string list[4];
      |        ^~~~