stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<string>

using namespace std;

string S;

int i;

int check(string str){

    int t = i;

    for(int j = str.size()-1;j >= 0;--j){

        if(t < 0) return 0;

        if(str[j] != S[t--]) return 0;

    }

    return 1;

}

int main(){

    string S1 = "dream";

    string S2 = "dreamer";

    string S3 = "erase";

    string S4 = "eraser";

    while(cin >> S){

        // 01234 56789 10

        // dream erase r



        // dreaeeraser

        for(i = S.size()-1;i >= 0;){

            if(check(S1)){

                i -= S1.size();

                continue;

            }

            if(check(S2)){

                i -= S2.size();

                continue;

            }

            if(check(S3)){

                i -= S3.size();

                continue;

            }

            if(check(S4)){

                i -= S4.size();

                continue;

            }

            break;

        }

        if(i != -1) cout << "NO" << endl;

        else cout << "YES" << endl;

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstdlib>

#include <algorithm>

#include <cstring>



const int maxn = 1e5 + 20;



char s[maxn];

int n;

bool flag[maxn];

char ch[4][10] = {"dream", "dreamer", "erase", "eraser"};

int len[4] = {5, 7, 5, 6};



bool check(char *s1, char *s2, int l)

{

	for(int i = 0; i < l; i++)

	{

		if(s1[i] != s2[i]) return false;

	}

	

	return true;

}

int main()

{

	scanf("%s", s + 1);

	n = strlen(s + 1);

	

	flag[0] = true;

	for(int i = 1; i <= n; i++)

	{

		for(int j = 0; j < 4; j++)

		{

			if(i - len[j] >= 0 && flag[i - len[j]] && check(s + (i - len[j] + 1), ch[j], len[j]))

			{

				flag[i] = true;

				break;

			}

		}

	}

	

	puts(flag[n] ? "YES" : "NO");

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

 

const int DIM = 1e5 + 5;

 

int dp[DIM];

 

int main( void ) {

    

    string str;

    cin >> str;

    

    dp[0] = 1;

    for( int i = 0; i < str.length(); i ++ ) {

        if( dp[i] == 0 )

            continue;

        

        if( str.length() - i >= 5 && str.substr( i, 5 ) == "dream" )

            dp[i + 5] = 1;

        if( str.length() - i >= 5 && str.substr( i, 5 ) == "erase" )

            dp[i + 5] = 1;

        

        if( str.length() - i >= 7 && str.substr( i, 7 ) == "dreamer" )

            dp[i + 7] = 1;

        if( str.length() - i >= 6 && str.substr( i, 6 ) == "eraser" )

            dp[i + 6] = 1;

    }

    

    if( dp[str.length()] == 1 )

        cout << "YES" << endl;

    else

        cout << "NO" << endl;

    

    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstdlib>

#include <algorithm>

#include <cstring>



const int maxn = 1e5 + 20;



char s[maxn];

int n;

bool flag[maxn];

char ch[4][10] = {"dream", "dreamer", "erase", "eraser"};

int len[4] = {5, 7, 5, 6};



bool check(char *s1, char *s2, int l)

{

	for(int i = 0; i < l; i++)

	{

		if(s1[i] != s2[i]) return false;

	}

	

	return true;

}

int main()

{

	scanf("%s", s + 1);

	n = strlen(s + 1);

	

	flag[0] = true;

	for(int i = 1; i <= n; i++)

	{

		for(int j = 0; j < 4; j++)

		{

			if(i - len[j] >= 0 && flag[i - len[j]] && check(s + (i - len[j] + 1), ch[j], len[j]))

			{

				flag[i] = true;

				break;

			}

		}

	}

	

	puts(flag[n] ? "YES" : "NO");

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <iostream>

using namespace std;



char s1[4][11] = {"dream", "dreamer", "erase", "eraser"};

int l1[4] = {5, 7, 5, 6};



char s[101010];

bool f[101010];



int main()

{

	scanf("%s", s);

	int l = strlen(s);

	f[0] = 1;

	for(int i = 0; i < l; ++i)

	{

		if(f[i])

		{

//			cout<<i<<endl;

			for(int j = 0; j < 4; ++j)

			{

				bool flag = 0;

				for(int k = 0; k < l1[j]; ++k)

					if(s1[j][k] != s[i + k])

					{

						flag = 1;

						break;

					}

				if(!flag)

					f[i + l1[j]] = 1;

			}

		}

	}

	if(f[l])

		puts("YES");

	else

		puts("NO");

	

	return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <algorithm>

int  a,b,c,d,i,j,k,x,y,z,ans;

char f[100005];

int main(){

	scanf("%s",f);

	c=0;

	while (true){

		d=c+4;

		if ((f[c]=='d') and (f[c+1]=='r') and (f[c+2]=='e') and (f[c+3]=='a') and (f[c+4]=='m')){

			if (d==strlen(f)-1){

				printf("YES\n");

				return 0;

			}

			else if (d==strlen(f)-3){

				if ((f[d+1]=='e') and (f[d+2]=='r')){

					printf("YES\n");

					return 0;	

				}

				else {

					printf("NO\n");

					return 0;					

				}

			}

			else if ((f[d+1]=='e') and (f[d+2]=='r')){

				if (f[d+3]=='a') c+=5; else c+=7;

			}

			else {

				c+=5;

			}

		}

		else if ((f[c]=='e') and (f[c+1]=='r') and (f[c+2]=='a') and (f[c+3]=='s') and (f[c+4]=='e')){

			if (d==strlen(f)-1){

				printf("YES\n");

				return 0;

			}

			else if (d==strlen(f)-2){

				if (f[d+1]=='r'){

					printf("YES\n");

					return 0;	

				}

				else {

					printf("NO\n");

					return 0;					

				}

			}

			else if (f[d+1]=='r') c+=6;

			else {

				c+=5;

			}

		}

		else {

			printf("NO\n");

			return 0;					

		}

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <fstream>

#include <sstream>

#include <algorithm>

#include <cstdio>

#include <cassert>

#include <cmath>

#include <cstdlib>

#include <cstring>

#include <string>

#include <deque>

#include <queue>

#include <vector>

#include <list>

#include <map>

#include <set>

#include <bitset>

#include <stack>

#include <iomanip>

#include <utility>

#include <functional>

using namespace std;

//orz jzm

#define ll long long

#define ull unsigned ll

const ll PR=19260817;

int main() {

	string s;

	cin>>s;

	reverse(s.begin(), s.end());

	int i=0, l=s.length();

	while (i<l) {

		if (s[i]=='m') {

			if (s.substr(i, 5)!="maerd") {

				cout<<"NO"<<endl;

				return 0;

			}

			i+=5;

		}

		else if (s[i]=='e') {

			if (s.substr(i, 5)!="esare") {

				cout<<"NO"<<endl;

				return 0;

			}

			i+=5;

		} else if (s[i]=='r') {

			if (i+2>=l||s[i+1]!='e') {

				cout<<"NO"<<endl;

				return 0;

			}i+=2;

			if (s[i]=='m') {

				if (s.substr(i, 5)!="maerd") {

					cout<<"NO"<<endl;

					return 0;

				}i+=5;

			} else if (s[i]=='s') {

				if (s.substr(i, 4)!="sare") {

					cout<<"NO"<<endl;

					return 0;

				}i+=4;

			} else {

				cout<<"NO"<<endl;

				return 0;

			}

		} else {

			cout<<"NO"<<endl;

			return 0;

		}

	}

	cout<<"YES"<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <algorithm>

int  a,b,c,d,i,j,k,x,y,z,ans;

char f[100005];

int main(){

	scanf("%s",f);

	c=0;

	while (true){

		d=c+4;

		if ((f[c]=='d') and (f[c+1]=='r') and (f[c+2]=='e') and (f[c+3]=='a') and (f[c+4]=='m')){

			if (d==strlen(f)-1){

				printf("YES\n");

				return 0;

			}

			else if (d==strlen(f)-3){

				if ((f[d+1]=='e') and (f[d+2]=='r')){

					printf("YES\n");

					return 0;	

				}

				else {

					printf("NO\n");

					return 0;					

				}

			}

			else if ((f[d+1]=='e') and (f[d+2]=='r')){

				if (f[d+3]=='a') c+=5; else c+=7;

			}

			else {

				c+=5;

			}

		}

		else if ((f[c]=='e') and (f[c+1]=='r') and (f[c+2]=='a') and (f[c+3]=='s') and (f[c+4]=='e')){

			if (d==strlen(f)-1){

				printf("YES\n");

				return 0;

			}

			else if (d==strlen(f)-2){

				if (f[d+1]=='r'){

					printf("YES\n");

					return 0;	

				}

				else {

					printf("NO\n");

					return 0;					

				}

			}

			else if (f[d+1]=='r') c+=6;

			else {

				c+=5;

			}

		}

		else {

			printf("NO\n");

			return 0;					

		}

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/*

	专 业 爆 搜

			--InterestingLSY 

*/

#include <iostream>

#include <cstdio>

#include <cmath>

#include <vector>

#include <cstring>

#include <stack>

#include <queue>

#include <algorithm>

#include <set>

#include <map>

#define pb push_back

#define mp make_pair

#define INF 9999999

#define LINF 9999999999999999

#define SINF "%"

#define uint unsigned int

#define msn(a,v) memset(a,v,sizeof(a))

#define ms(a) msn(a,0)

#define NONE -1

#define ll long long

#define ull unsigned ll

#define uchar unsigned char

#define sint short int

#define usint unsigned sint

#define xsize(a) sizeof(a)/1024/1024

#define fr(aaaaa,bbbbb) for(aaaaa = 1;aaaaa <= bbbbb;aaaaa++)

#define frr(aaaaa,bbbbb,ccccc) for(aaaaa = ccccc;aaaaa <= bbbbb;aaaaa++)

using namespace std;

#define MAXN 100100



char s[MAXN];

int n;

string ss[5];

int lens[5];



bool kmp(int pos,int id){

	for(int i = 0;i < lens[id];i++){

		if(s[pos+i] != ss[id][i])

			return 0;

	}

	return 1;

}



bool dp[MAXN];

bool dfs(int pos){

	if(pos == n) return 1;

	bool ans = 0;

	for(int i = 1;i <= 4;i++)

		if(pos + i < n  &&  kmp(pos,i)){

			ans = dfs(pos + lens[i]);

			if(ans)

				return 1;

		}

	return 0;

}



int main(){

	//freopen("C.txt","r",stdin);

	ss[1] = "dream"; ss[2] = "dreamer";

	ss[3] = "erase"; ss[4] = "eraser";

	for(int i = 1;i <= 4;i++)

		lens[i] = ss[i].length();

	

	scanf("%s",&s);

	n = strlen(s);

	

	if(dfs(0)) printf("YES\n");

	else printf("NO\n");

	

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <algorithm>

int  a,b,c,d,i,j,k,x,y,z,ans;

char f[100005];

int main(){

	scanf("%s",f);

	c=0;

	while (true){

		d=c+4;

		if ((f[c]=='d') and (f[c+1]=='r') and (f[c+2]=='e') and (f[c+3]=='a') and (f[c+4]=='m')){

			if (d==strlen(f)-1){

				printf("YES\n");

				return 0;

			}

			else if (d==strlen(f)-3){

				if ((f[d+1]=='e') and (f[d+2]=='r')){

					printf("YES\n");

					return 0;	

				}

				else {

					printf("NO\n");

					return 0;					

				}

			}

			else if ((f[d+1]=='e') and (f[d+2]=='r')){

				if (f[d+3]=='a') c+=5; else c+=7;

			}

			else {

				c+=5;

			}

		}

		else if ((f[c]=='e') and (f[c+1]=='r') and (f[c+2]=='a') and (f[c+3]=='s') and (f[c+4]=='e')){

			if (d==strlen(f)-1){

				printf("YES\n");

				return 0;

			}

			else if (d==strlen(f)-2){

				if (f[d+1]=='r'){

					printf("YES\n");

					return 0;	

				}

				else {

					printf("NO\n");

					return 0;					

				}

			}

			else if (f[d+1]=='r') c+=6;

			else {

				c+=5;

			}

		}

		else {

			printf("NO\n");

			return 0;					

		}

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



int dp[100005];



int main()

{

	dp[0] = 1;

	string s;

	cin >> s;

	for(int i = 0; i < s.size(); i++) {

	 	if(dp[i] != 0 && (s.size() - i >= 7) && s.substr(i, 7) == "dreamer")	dp[i + 7] = 1;

	 	if(dp[i] != 0 && (s.size() - i >= 6) && s.substr(i, 6) == "eraser")	dp[i + 6] = 1;

	 	if(dp[i] != 0 && (s.size() - i >= 5) && (s.substr(i, 5) == "dream" || s.substr(i, 5) == "erase"))	dp[i + 5] = 1;



	}

	if(dp[s.size()] == 1)

		cout << "YES" << endl;

	else

		cout << "NO" << endl;



	return 0;

}	

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <algorithm>

int  a,b,c,d,i,j,k,x,y,z,ans;

char f[100005];

int main(){

	scanf("%s",f);

	c=0;

	while (true){

		d=c+4;

		if ((f[c]=='d') and (f[c+1]=='r') and (f[c+2]=='e') and (f[c+3]=='a') and (f[c+4]=='m')){

			if (d==strlen(f)-1){

				printf("YES\n");

				return 0;

			}

			else if (d==strlen(f)-3){

				if ((f[d+1]=='e') and (f[d+2]=='r')){

					printf("YES\n");

					return 0;	

				}

				else {

					printf("NO\n");

					return 0;					

				}

			}

			else if ((f[d+1]=='e') and (f[d+2]=='r')){

				if (f[d+3]=='a') c+=5; else c+=7;

			}

			else {

				c+=5;

			}

		}

		else if ((f[c]=='e') and (f[c+1]=='r') and (f[c+2]=='a') and (f[c+3]=='s') and (f[c+4]=='e')){

			if (d==strlen(f)-1){

				printf("YES\n");

				return 0;

			}

			else if (d==strlen(f)-2){

				if (f[d+1]=='r'){

					printf("YES\n");

					return 0;	

				}

				else {

					printf("NO\n");

					return 0;					

				}

			}

			else if (f[d+1]=='r') c+=6;

			else {

				c+=5;

			}

		}

		else {

			printf("NO\n");

			return 0;					

		}

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define sz(x) ((int)(x).size())

#define rep(i,a,b) for (int i=(a); i<(b); i++)

#define per(i,a,b) for (int i=(b-1); i>=(a); i--)

#define debug(x) cout << #x << " => " << x << endl

using namespace std;



#define fi first

#define se second

#define mp make_pair

typedef pair<int,int> pii;



#define pb push_back

typedef vector<int> vi;



typedef long long ll;

typedef long double ld;



const int MAX_N = 7 + 100000;

///----------------------------------------------

bool f[MAX_N];

int main() {

	

	///read

	string str; cin>>str;

	

	///work

	static string tab[4] = {"dream","dreamer","erase","eraser"};

	memset(f,false,sizeof(f)); f[0]=true;

	rep(i,0,sz(str)) {

		rep(j,0,4) if (i+1>=sz(tab[j])) {

			if (i-sz(tab[j])==-1 || f[i-sz(tab[j])])

				if (str.substr(i-sz(tab[j])+1,sz(tab[j]))==tab[j]) {

					f[i]=true;

					break;

				}

		}

		//debug(f[i]);

	}

	

	///print

	puts(f[sz(str)-1] ? "YES" : "NO");









}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <algorithm>

int  a,b,c,d,i,j,k,x,y,z,ans;

char f[100005];

int main(){

	scanf("%s",f);

	c=0;

	while (true){

		d=c+4;

		if ((f[c]=='d') and (f[c+1]=='r') and (f[c+2]=='e') and (f[c+3]=='a') and (f[c+4]=='m')){

			if (d==strlen(f)-1){

				printf("YES\n");

				return 0;

			}

			else if (d==strlen(f)-3){

				if ((f[d+1]=='e') and (f[d+2]=='r')){

					printf("YES\n");

					return 0;	

				}

				else {

					printf("NO\n");

					return 0;					

				}

			}

			else if ((f[d+1]=='e') and (f[d+2]=='r')){

				if (f[d+3]=='a') c+=5; else c+=7;

			}

			else {

				c+=5;

			}

		}

		else if ((f[c]=='e') and (f[c+1]=='r') and (f[c+2]=='a') and (f[c+3]=='s') and (f[c+4]=='e')){

			if (d==strlen(f)-1){

				printf("YES\n");

				return 0;

			}

			else if (d==strlen(f)-2){

				if (f[d+1]=='r'){

					printf("YES\n");

					return 0;	

				}

				else {

					printf("NO\n");

					return 0;					

				}

			}

			else if (f[d+1]=='r') c+=6;

			else {

				c+=5;

			}

		}

		else {

			printf("NO\n");

			return 0;					

		}

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define sz(x) ((int)(x).size())

#define rep(i,a,b) for (int i=(a); i<(b); i++)

#define per(i,a,b) for (int i=(b-1); i>=(a); i--)

#define debug(x) cout << #x << " => " << x << endl

using namespace std;



#define fi first

#define se second

#define mp make_pair

typedef pair<int,int> pii;



#define pb push_back

typedef vector<int> vi;



typedef long long ll;

typedef long double ld;



const int MAX_N = 7 + 100000;

///----------------------------------------------

bool f[MAX_N];

int main() {

	

	///read

	string str; cin>>str;

	

	///work

	static string tab[4] = {"dream","dreamer","erase","eraser"};

	memset(f,false,sizeof(f));

	rep(i,0,sz(str)) {

		rep(j,0,4) if (i+1>=sz(tab[j])) {

			if (i-sz(tab[j])==-1 || f[i-sz(tab[j])])

				if (str.substr(i-sz(tab[j])+1,sz(tab[j]))==tab[j]) {

					f[i]=true;

					break;

				}

		}

		//debug(f[i]);

	}

	

	///print

	puts(f[sz(str)-1] ? "YES" : "NO");









}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <algorithm>

int  a,b,c,d,i,j,k,x,y,z,ans;

char f[100005];

int main(){

	scanf("%s",f);

	c=0;

	while (true){

		d=c+4;

		if ((f[c]=='d') and (f[c+1]=='r') and (f[c+2]=='e') and (f[c+3]=='a') and (f[c+4]=='m')){

			if (d==strlen(f)-1){

				printf("YES\n");

				return 0;

			}

			else if (d==strlen(f)-3){

				if ((f[d+1]=='e') and (f[d+2]=='r')){

					printf("YES\n");

					return 0;	

				}

				else {

					printf("NO\n");

					return 0;					

				}

			}

			else if ((f[d+1]=='e') and (f[d+2]=='r')){

				if (f[d+3]=='a') c+=5; else c+=7;

			}

			else {

				c+=5;

			}

		}

		else if ((f[c]=='e') and (f[c+1]=='r') and (f[c+2]=='a') and (f[c+3]=='s') and (f[c+4]=='e')){

			if (d==strlen(f)-1){

				printf("YES\n");

				return 0;

			}

			else if (d==strlen(f)-2){

				if (f[d+1]=='r'){

					printf("YES\n");

					return 0;	

				}

				else {

					printf("NO\n");

					return 0;					

				}

			}

			else if (f[d+1]=='r') c+=6;

			else {

				c+=5;

			}

		}

		else {

			printf("NO\n");

			return 0;					

		}

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>

#include <vector>

using namespace std;



string S;

int dp[100000];



bool daydream(int now){

    if(now == S.size()){

        return true;

    }else if(dp[now] != -1){

        return dp[now];

    }else{

        int ans = false;

        if(now <= S.size() - 5){

            if(S.substr(now, 5) == "dream"){

                ans |= daydream(now + 5);

            }

            if(S.substr(now, 5) == "erase"){

                ans |= daydream(now + 5);

            }

        }

        if(now <= S.size() - 6){

            if(S.substr(now, 6) == "eraser"){

                ans |= daydream(now + 6);

            }

        }

        if(now <= S.size() - 7){

            if(S.substr(now, 7) == "dreamer"){

                ans |= daydream(now + 7);

            }

        }

        return dp[now] = ans;

    }

}



int main(){

    cin >> S;

    fill(dp, dp + 100000, -1);

    if(daydream(0)){

        cout << "YES" << endl;

    }else{

        cout << "NO" << endl;

    }

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <algorithm>

#include <vector>

using namespace std;



int main(){

    string S;

    cin >> S;

    reverse(S.begin(), S.end());

    for(int i = 0; i < S.size(); ){

        if(i >= S.size() - 4){

            cout << "NO" << endl;

            return 0;

        }else if(S.substr(i, 5) == "maerd" || S.substr(i, 5) == "esare"){

            i += 5;

        }else if(i == S.size() - 5){

            cout << "NO" << endl;

            return 0;

        }else if(S.substr(i, 6) == "resare"){

            i += 6;

        }else if(i == S.size() - 6){

            cout << "NO" << endl;

            return 0;

        }else if(S.substr(i, 7) == "remaerd"){

            i += 7;

        }else{

            cout << "NO" << endl;

            return 0;

        }

    }

    cout << "YES" << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

string s;

int dp[100005];

int main()

{

	cin>>s;

    dp[0]=1;

	for(int i=0;i<s.size();i++)

	{

		if(dp[i]==0)continue;

		if(i+5<=s.size()&&s.substr(i,5)=="dream") dp[i+5]=1;

		if(i+5<=s.size()&&s.substr(i,5)=="erase") dp[i+5]=1;

		if(i+6<=s.size()&&s.substr(i,6)=="eraser") dp[i+6]=1;

		if(i+7<=s.size()&&s.substr(i,7)=="dreamer") dp[i+7]=1;

		}	

	if(dp[s.size()]==1) cout<<"YES"<<endl;

	else 

	    cout<<"NO"<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

char s[100050];

int fail;

int maxlen;

const char str[4][10]={"eraser ","erase ","dreamer ","dream "};

const int len[4]={6,5,7,5};

bool dfs(int pos)

{

	if(pos==maxlen) return 1;

	for(int i=3;i>=0;i--)

	{

		bool flag=1;

		for(int j=0;str[i][j]!=' ';j++)

			if(pos+j>=maxlen || str[i][j]!=s[pos+j])

			{flag=0;break;}

		if(flag)

		{

			if(dfs(pos+len[i])) return 1;

		}

	}

	return 0;

}

int main()

{

	scanf("%s",s);

	maxlen=strlen(s);

	bool ans=dfs(0);

	if(ans) puts("YES");

	else puts("NO");

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main(){

    string str[4]={"maerd","remaerd","resare","esare"};

	string s;

	cin>>s;

	reverse(s.begin(),s.end());

	bool a=true;

	for(int i=0;i<s.size();)

	{

		bool b=false;

		for(int j=0;j<4;j++)

		{   

		    string d=str[j];

			if(s.substr(i,d.size())==d){

				b=true;i+=d.size();

			}

		}

		if(!b){

			a=false;break;

		}

	}

	if(a)cout<<"YES"<<endl;

	else cout<<"NO"<<endl;

} 

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

char s[100050];

int fail;

int maxlen;

const char str[4][10]={"eraser ","erase ","dreamer ","dream "};

const int len[4]={6,5,7,5};

bool dfs(int pos)

{

	if(pos==maxlen) return 1;

	for(int i=3;i>=0;i--)

	{

		bool flag=1;

		for(int j=0;str[i][j]!=' ';j++)

			if(pos+j>=maxlen || str[i][j]!=s[pos+j])

			{flag=0;break;}

		if(flag)

		{

			if(dfs(pos+len[i])) return 1;

		}

	}

	return 0;

}

int main()

{

	scanf("%s",s);

	maxlen=strlen(s);

	bool ans=dfs(0);

	if(ans) puts("YES");

	else puts("NO");

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <algorithm>

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

#define ALL(v) (v).begin(), (v).end()

#define REVERSED(v) reverse( ALL(v) )

#define YESNO(x) cout << ( x ? "YES" : "NO" ) << endl

using namespace std;



string divide[4] = {"dream", "dreamer", "erase", "eraser"};



int main() {

    string S;

    cin >> S;



    REVERSED(S);

    REP(i,4) REVERSED(divide[i]);



    bool can = true;

    for (int i = 0; i < S.size(); ) {

        can = false;

        REP(j,4) {

            string d = divide[j];

            if ( S.substr(i, d.size()) == d ) {

                can = true;

                i += d.size();

            }

        }

        if (!can) {

            break;

        }

    }



    YESNO(can);

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>



char s[100005]; int n;

bool dp[100005];



int main() {

  scanf("%s", s + 1); n = strlen(s + 1);



  dp[0] = 1;

  for (int i = 1; i <= n; ++i) {

    if (i>=5 && s[i-4]=='d' && s[i-3]=='r' && s[i-2]=='e' && s[i-1]=='a' && s[i]=='m')

      dp[i] |= dp[i-5];

    if (i>=7 && s[i-6]=='d' && s[i-5]=='r' && s[i-4]=='e' && s[i-3]=='a' && s[i-2]=='m' && s[i-1]=='e' && s[i]=='r')

      dp[i] |= dp[i-7];

    if (i>=5 && s[i-4]=='e' && s[i-3]=='r' && s[i-2]=='a' && s[i-1]=='s' && s[i]=='e')

      dp[i] |= dp[i-5];

    if (i>=6 && s[i-5]=='e' && s[i-4]=='r' && s[i-3]=='a' && s[i-2]=='s' && s[i-1]=='e' && s[i]=='r')

      dp[i] |= dp[i-6];

  }



  puts(dp[n] ? "YES" : "NO");



  return 0;

}

// Fastest known solution for this problem: