stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.372322007369473x):
#include<stdio.h>

#include<string.h>

char a[100005];

int main(){

    while(~scanf("%s",a)){

        int n=strlen(a);

        int p=1;

        int i=n;

        while(i>0){

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

                i=i-7;

            }

            else{

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

                    i=i-6;

                }

                else{

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

                        i=i-5;

                    }

                    else{

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

                            i=i-5;

                        }

                        else{

                            p=0;

                            break;

                        }

                    }

                }

            }

        }

        if(p){

            printf("YES\n");

        }

        else{

            printf("NO\n");

        }

    }

    return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.381022839267338x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.3806863312436235x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.379046630110962x):
#include <cstdio>

#include <cstring>

#include <algorithm>



typedef long long ll;



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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.378710245671603x):
#include <cstdio>

#include <cstring>

#include <algorithm>



typedef long long ll;



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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.368546197862382x):
#include<cstdio>

#include<cstring>

using namespace std;

char s[100005];

int dp[100005],len;

int f(int n){

	if (dp[n]) return 1;

	if (n<5) return 0;

	char tmp[10];

	for (int i=0; i<5; i++) tmp[i]=s[i+n-5];

	tmp[5]='\0';

	if (strcmp(tmp,"dream")==0&&f(n-5)) return 1;

	else if (strcmp(tmp,"erase")==0&&f(n-5)) return 1;

	if (n<6) return 0;

	for (int i=0; i<6; i++) tmp[i]=s[i+n-6];

	tmp[6]='\0';

	if (strcmp(tmp,"eraser")==0&&f(n-6)) return 1;	

	if (n<7) return 0;

	for (int i=0; i<7; i++) tmp[i]=s[i+n-7];

	tmp[7]='\0';

	if (strcmp(tmp,"dreamer")==0&&f(n-7)) return 1;

	return 0;	

}

int main(){

	scanf("%s",s);

	len=strlen(s);

	dp[0]=1;

	for (int i=1; i<=len; i++) dp[i]=0;

	if (f(len)) printf("YES\n");

	else printf("NO\n");

	return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.368210470078795x):
#include<cstdio>

#include<cstring>

using namespace std;

char s[100005];

int dp[100005],len;

int f(int n){

	if (dp[n]) return 1;

	if (n<5) return 0;

	char tmp[10];

	for (int i=0; i<5; i++) tmp[i]=s[i+n-5];

	tmp[5]='\0';

	if (strcmp(tmp,"dream")==0&&f(n-5)) return 1;

	else if (strcmp(tmp,"erase")==0&&f(n-5)) return 1;

	if (n<6) return 0;

	for (int i=0; i<6; i++) tmp[i]=s[i+n-6];

	tmp[6]='\0';

	if (strcmp(tmp,"eraser")==0&&f(n-6)) return 1;	

	if (n<7) return 0;

	for (int i=0; i<7; i++) tmp[i]=s[i+n-7];

	tmp[7]='\0';

	if (strcmp(tmp,"dreamer")==0&&f(n-7)) return 1;

	return 0;	

}

int main(){

	scanf("%s",s);

	len=strlen(s);

	dp[0]=1;

	for (int i=1; i<=len; i++) dp[i]=0;

	if (f(len)) printf("YES\n");

	else printf("NO\n");

	return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.257848935080175x):
#include<cstdio>

#include<cstring>

using namespace std;

char s[100005];

int dp[100005],len;

int f(int n){

	if (dp[n]) return 1;

	if (n<5) return 0;

	char tmp[10];

	for (int i=0; i<5; i++) tmp[i]=s[i+n-5];

	tmp[5]='\0';

	if (strcmp(tmp,"dream")==0&&f(n-5)) return 1;

	else if (strcmp(tmp,"erase")==0&&f(n-5)) return 1;

	if (n<6) return 0;

	for (int i=0; i<6; i++) tmp[i]=s[i+n-6];

	tmp[6]='\0';

	if (strcmp(tmp,"eraser")==0&&f(n-6)) return 1;	

	if (n<7) return 0;

	for (int i=0; i<7; i++) tmp[i]=s[i+n-7];

	tmp[7]='\0';

	if (strcmp(tmp,"dreamer")==0&&f(n-7)) return 1;

	return 0;	

}

int main(){

	scanf("%s",s);

	len=strlen(s);

	dp[0]=1;

	for (int i=1; i<=len; i++) dp[i]=0;

	if (f(len)) printf("YES\n");

	else printf("NO\n");

	return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.364258612348431x):
#include<cstdio>

#include<cstring>

using namespace std;

char s[100005];

int dp[100005],len;

int f(int n){

	if (dp[n]) return 1;

	if (n<5) return 0;

	char tmp[10];

	for (int i=0; i<5; i++) tmp[i]=s[i+n-5];

	tmp[5]='\0';

	if (strcmp(tmp,"dream")==0&&f(n-5)) return 1;

	else if (strcmp(tmp,"erase")==0&&f(n-5)) return 1;

	if (n<6) return 0;

	for (int i=0; i<6; i++) tmp[i]=s[i+n-6];

	tmp[6]='\0';

	if (strcmp(tmp,"eraser")==0&&f(n-6)) return 1;	

	if (n<7) return 0;

	for (int i=0; i<7; i++) tmp[i]=s[i+n-7];

	tmp[7]='\0';

	if (strcmp(tmp,"dreamer")==0&&f(n-7)) return 1;

	return 0;	

}

int main(){

	scanf("%s",s);

	len=strlen(s);

	dp[0]=1;

	for (int i=1; i<=len; i++) dp[i]=0;

	if (f(len)) printf("YES\n");

	else printf("NO\n");

	return 0;

}
// Slower C++ solution:
/*

	专 业 爆 搜

			--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;

}

// Faster C++ solution for the same problem (measured speedup: 5.300088971525449x):
#include<cstdio>

#include<cstring>

using namespace std;

char s[100005];

int dp[100005],len;

int f(int n){

	if (dp[n]) return 1;

	if (n<5) return 0;

	char tmp[10];

	for (int i=0; i<5; i++) tmp[i]=s[i+n-5];

	tmp[5]='\0';

	if (strcmp(tmp,"dream")==0&&f(n-5)) return 1;

	else if (strcmp(tmp,"erase")==0&&f(n-5)) return 1;

	if (n<6) return 0;

	for (int i=0; i<6; i++) tmp[i]=s[i+n-6];

	tmp[6]='\0';

	if (strcmp(tmp,"eraser")==0&&f(n-6)) return 1;	

	if (n<7) return 0;

	for (int i=0; i<7; i++) tmp[i]=s[i+n-7];

	tmp[7]='\0';

	if (strcmp(tmp,"dreamer")==0&&f(n-7)) return 1;

	return 0;	

}

int main(){

	scanf("%s",s);

	len=strlen(s);

	dp[0]=1;

	for (int i=1; i<=len; i++) dp[i]=0;

	if (f(len)) printf("YES\n");

	else printf("NO\n");

	return 0;

}
// Slower C++ solution:
#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;

}	

// Faster C++ solution for the same problem (measured speedup: 5.378313315278754x):
#include<cstdio>

#include<cstring>

using namespace std;

char s[100005];

int dp[100005],len;

int f(int n){

	if (dp[n]) return 1;

	if (n<5) return 0;

	char tmp[10];

	for (int i=0; i<5; i++) tmp[i]=s[i+n-5];

	tmp[5]='\0';

	if (strcmp(tmp,"dream")==0&&f(n-5)) return 1;

	else if (strcmp(tmp,"erase")==0&&f(n-5)) return 1;

	if (n<6) return 0;

	for (int i=0; i<6; i++) tmp[i]=s[i+n-6];

	tmp[6]='\0';

	if (strcmp(tmp,"eraser")==0&&f(n-6)) return 1;	

	if (n<7) return 0;

	for (int i=0; i<7; i++) tmp[i]=s[i+n-7];

	tmp[7]='\0';

	if (strcmp(tmp,"dreamer")==0&&f(n-7)) return 1;

	return 0;	

}

int main(){

	scanf("%s",s);

	len=strlen(s);

	dp[0]=1;

	for (int i=1; i<=len; i++) dp[i]=0;

	if (f(len)) printf("YES\n");

	else printf("NO\n");

	return 0;

}
// Slower C++ solution:
#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");









}


// Faster C++ solution for the same problem (measured speedup: 5.879147952101457x):
#include<cstdio>

#include<cstring>

using namespace std;

char s[100005];

int dp[100005],len;

int f(int n){

	if (dp[n]) return 1;

	if (n<5) return 0;

	char tmp[10];

	for (int i=0; i<5; i++) tmp[i]=s[i+n-5];

	tmp[5]='\0';

	if (strcmp(tmp,"dream")==0&&f(n-5)) return 1;

	else if (strcmp(tmp,"erase")==0&&f(n-5)) return 1;

	if (n<6) return 0;

	for (int i=0; i<6; i++) tmp[i]=s[i+n-6];

	tmp[6]='\0';

	if (strcmp(tmp,"eraser")==0&&f(n-6)) return 1;	

	if (n<7) return 0;

	for (int i=0; i<7; i++) tmp[i]=s[i+n-7];

	tmp[7]='\0';

	if (strcmp(tmp,"dreamer")==0&&f(n-7)) return 1;

	return 0;	

}

int main(){

	scanf("%s",s);

	len=strlen(s);

	dp[0]=1;

	for (int i=1; i<=len; i++) dp[i]=0;

	if (f(len)) printf("YES\n");

	else printf("NO\n");

	return 0;

}