Language: C++

#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> P;
lli MOD = 1000000007;
bool flag = true;
string ok(string s)
{
    if (s == "dream" || s == "dreamer" || s == "erase" || s == "eraser") {
        return "";
    }
    if (s.size() <= 7) {
        flag = false;
        return "NO";
    } else {
        string a = "";
        rep(i, 5)
        {
            a += s[s.size() - 5 + i];
        }

        if (a == "dream" || a == "erase") {
            string r = "";
            rep(i, s.size() - 5)
            {
                r += s[i];
            }
            return r;
        }
        a = "";
        rep(i, 6)
        {
            a += s[s.size() - 6 + i];
        }

        if (a == "eraser") {
            string r = "";
            rep(i, s.size() - 6)
            {
                r += s[i];
            }
            return r;
        }
        a = "";
        rep(i, 7)
        {
            a += s[s.size() - 7 + i];
        }

        if (a == "dreamer") {
            string r = "";
            rep(i, s.size() - 7)
            {
                r += s[i];
            }
            return r;
        }
    }
    return s;
};
int main()
{
    string s;
    cin >> s;
    queue<string> que;
    que.push(s);
    s = ok(s);
    //cout << s << endl;
    int cnt = 0;
    while (s != "NO" && s != "") {
        //cout << s << endl;
        s = ok(s);
        cnt++;
        if (cnt >= 100000) {
            s = "NO";
            break;
        }
    }
    cout << ((s == "") ? "YES" : "NO") << endl;
}
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> P;
lli MOD = 1000000007;
bool flag = true;
string ok(string s)
{
    if (s == "dream" || s == "dreamer" || s == "erase" || s == "eraser") {
        return "";
    }
    if (s.size() <= 7) {
        flag = false;
        return "NO";
    } else {
        string a = "";
        rep(i, 5)
        {
            a += s[s.size() - 5 + i];
        }

        if (a == "dream" || a == "erase") {
            string r = "";
            rep(i, s.size() - 5)
            {
                r += s[i];
            }
            return r;
        }
        a = "";
        rep(i, 6)
        {
            a += s[s.size() - 6 + i];
        }

        if (a == "eraser") {
            string r = "";
            rep(i, s.size() - 6)
            {
                r += s[i];
            }
            return r;
        }
        a = "";
        rep(i, 7)
        {
            a += s[s.size() - 7 + i];
        }

        if (a == "dreamer") {
            string r = "";
            rep(i, s.size() - 7)
            {
                r += s[i];
            }
            return r;
        }
    }
    return s;
};
int main()
{
    string s;
    cin >> s;
    queue<string> que;
    que.push(s);
    s = ok(s);
    //cout << s << endl;
    int cnt = 0;
    while (s != "NO" && s != "") {
        //cout << s << endl;
        s = ok(s);
        cnt++;
        if (cnt >= 100000) {
            s = "NO";
            break;
        }
    }
    cout << ((s == "") ? "YES" : "NO") << endl;
}


Compiler output:
a.cc:103:5: error: redefinition of 'lli MOD'
  103 | lli MOD = 1000000007;
      |     ^~~
a.cc:14:5: note: 'lli MOD' previously defined here
   14 | lli MOD = 1000000007;
      |     ^~~
a.cc:104:6: error: redefinition of 'bool flag'
  104 | bool flag = true;
      |      ^~~~
a.cc:15:6: note: 'bool flag' previously defined here
   15 | bool flag = true;
      |      ^~~~
a.cc:105:8: error: redefinition of 'std::string ok(std::string)'
  105 | string ok(string s)
      |        ^~
a.cc:16:8: note: 'std::string ok(std::string)' previously defined here
   16 | string ok(string s)
      |        ^~
a.cc:159:5: error: redefinition of 'int main()'
  159 | int main()
      |     ^~~~
a.cc:70:5: note: 'int main()' previously defined here
   70 | int main()
      |     ^~~~