stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

char s[100002];

int dp[100002];

int main(){

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

    int n = strlen(s+1);

    dp[0] = 1;

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

        if(i >= 5){

            if(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(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){

            if(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];

            }   

        }

        if(i >= 7){

            if(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(dp[n]) printf("YES\n");

    else printf("NO\n");

}

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

#include<string.h>

using namespace std;

char s[1000000];

int len;

bool b=true;

int main(){

	scanf("%s",&s);

	len=strlen(s);

	for (int i=0;i<len;i++){

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

			i+=6;

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

				i+=4;

			}else if ((s[i-1]=='e')&&(s[i]=='r')&&(s[i+1]=='a')&&(s[i+2]=='s')&&(s[i+3]=='e')){

				i+=3;

			}

		}else if ((s[i]=='d')&&(s[i+1]=='r')&&(s[i+2]=='e')&&(s[i+3]=='a')&&(s[i+4]=='m')){

			i+=4;

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

			i+=5;

		}else if ((s[i]=='e')&&(s[i+1]=='r')&&(s[i+2]=='a')&&(s[i+3]=='s')&&(s[i+4]=='e')){

			i+=4;

		}else {

			b=false;

		}

		if (b==false){

			break;

		}

	}

if (b==true){

	printf("YES");

}else{

	printf("NO");

}

return 0;}
// Slower C++ solution:
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

  

using namespace std;

using namespace __gnu_pbds;

 

#define ll long long

#define uint unsigned int

#define ull  unsigned long long

#define pb push_back

#define mk make_pair

#define ins insert

#define all(x) (x).begin(), (x).end()

#define rall(x) (x).rbegin(),(x).rend()

#define X first

#define Y second

#define umap unordered_map

#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n

#define mset multiset

#define pqueue priority_queue

   

template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

        

const int  N = 2e5 + 314;

const int INF = 1e9;

const double PI = acos(-1);

const int MOD = 1e9 + 7;

const double eps = 1e-9;

const long long LINF = 1e18 + 3141;



void solve(){

    string s, t;

    cin >> s;

    string cur = "";

    int n = (int)s.size();

    

    for(int i = n - 1; i >= 0; --i) {

        cur = s[i] + cur;

        if(cur.size() == 8) {

            cout << "NO";

            return;

        }else {

            if(cur == "dream"){

                cur = "";

            }else if(cur == "dreamer") {

                cur = "";

            }else if(cur == "erase") {

                cur = "";

            }else if(cur == "eraser") {

                cur = "";

            }

        }

    }

    if(cur != "") {

        cout << "NO";

    }else{

        cout << "YES";

    }

}

 

int main(){

    speed();

    int t = 1;

    // cin >> t;

    while(t--)solve();

}

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

#include<string.h>

using namespace std;

char s[1000000];

int len;

bool b=true;

int main(){

	scanf("%s",&s);

	len=strlen(s);

	for (int i=0;i<len;i++){

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

			i+=6;

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

				i+=4;

			}else if ((s[i-1]=='e')&&(s[i]=='r')&&(s[i+1]=='a')&&(s[i+2]=='s')&&(s[i+3]=='e')){

				i+=3;

			}

		}else if ((s[i]=='d')&&(s[i+1]=='r')&&(s[i+2]=='e')&&(s[i+3]=='a')&&(s[i+4]=='m')){

			i+=4;

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

			i+=5;

		}else if ((s[i]=='e')&&(s[i+1]=='r')&&(s[i+2]=='a')&&(s[i+3]=='s')&&(s[i+4]=='e')){

			i+=4;

		}else {

			b=false;

		}

		if (b==false){

			break;

		}

	}

if (b==true){

	printf("YES");

}else{

	printf("NO");

}

return 0;}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



char s[1 << 20];

int dp[1 << 20];



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

	cin >> (s + 1);

	int n = strlen(s + 1); 

	dp[0] = 1;

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

		if (dp[i]) {

			if (strncmp(s + i + 1, "dream", 5) == 0) dp[i + 5] = 1;

			if (strncmp(s + i + 1, "dreamer", 7) == 0) dp[i + 7] = 1;

			if (strncmp(s + i + 1, "erase", 5) == 0) dp[i + 5] = 1;

			if (strncmp(s + i + 1, "eraser", 6) == 0) dp[i + 6] = 1;

		}

	}

	if (dp[n]) cout << "YES" << endl;

	else cout << "NO" << endl;

	return 0;

}




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

#include<string.h>

using namespace std;

char s[1000000];

int len;

bool b=true;

int main(){

	scanf("%s",&s);

	len=strlen(s);

	for (int i=0;i<len;i++){

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

			i+=6;

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

				i+=4;

			}else if ((s[i-1]=='e')&&(s[i]=='r')&&(s[i+1]=='a')&&(s[i+2]=='s')&&(s[i+3]=='e')){

				i+=3;

			}

		}else if ((s[i]=='d')&&(s[i+1]=='r')&&(s[i+2]=='e')&&(s[i+3]=='a')&&(s[i+4]=='m')){

			i+=4;

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

			i+=5;

		}else if ((s[i]=='e')&&(s[i+1]=='r')&&(s[i+2]=='a')&&(s[i+3]=='s')&&(s[i+4]=='e')){

			i+=4;

		}else {

			b=false;

		}

		if (b==false){

			break;

		}

	}

if (b==true){

	printf("YES");

}else{

	printf("NO");

}

return 0;}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

	string s; cin >> s;

	vector<string> pat;

	pat.push_back("dream");

	pat.push_back("dreamer");

	pat.push_back("erase");

	pat.push_back("eraser");

	vector<bool> f(s.length() + 1, false);

	f[0] = true;

	for (int i = 1; i <= s.length(); i++) {

		for (auto p : pat) {

			if (i >= p.length() && s.substr(i - p.length(), p.length()) == p && f[i - p.length()]) {

				f[i] = true;

			}

		}

	}

	cout << (f[s.length()] ? "YES\n" : "NO\n");

	return 0;

}


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

#include<string.h>

using namespace std;

char s[1000000];

int len;

bool b=true;

int main(){

	scanf("%s",&s);

	len=strlen(s);

	for (int i=0;i<len;i++){

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

			i+=6;

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

				i+=4;

			}else if ((s[i-1]=='e')&&(s[i]=='r')&&(s[i+1]=='a')&&(s[i+2]=='s')&&(s[i+3]=='e')){

				i+=3;

			}

		}else if ((s[i]=='d')&&(s[i+1]=='r')&&(s[i+2]=='e')&&(s[i+3]=='a')&&(s[i+4]=='m')){

			i+=4;

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

			i+=5;

		}else if ((s[i]=='e')&&(s[i+1]=='r')&&(s[i+2]=='a')&&(s[i+3]=='s')&&(s[i+4]=='e')){

			i+=4;

		}else {

			b=false;

		}

		if (b==false){

			break;

		}

	}

if (b==true){

	printf("YES");

}else{

	printf("NO");

}

return 0;}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

string s,a="dream",b="dreamer",c="erase",d="eraser";

int check(int x)

{

	bool flag=1;

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

	{

		if(s[x+i]!=a[i])flag=0;

	}

	if(flag)return x+a.length();

	

	flag=1;

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

	{

		if(s[x+i]!=b[i])flag=0;

	}

	if(flag)return x+b.length();

	

	flag=1;

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

	{

		if(s[x+i]!=c[i])flag=0;

	}

	if(flag)return x+c.length();

	

	flag=1;

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

	{

		if(s[x+i]!=d[i])flag=0;

	}

	if(flag)return x+d.length();

	return -1;

}

int main()

{

	cin>>s;

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

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

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

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

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

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

	{

		int nx=check(i);

		if(nx==-1){return puts("NO"),0;}

		else i=nx;

		if(i==s.length()-1)break;

	}

	puts("YES");

}

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



char str[100005];



int main(){

    bool flag = true;

    int r = 0;

    scanf("%s",str);

    for(int i=0;str[i];i++){

        if(str[i]=='d'){

            if(r)r=0;

            if(str[i+1]=='r'&&str[i+2]=='e'&&str[i+3]=='a'&&str[i+4]=='m'){

                r = 1;

                if(str[i+5]=='e'){

                    if(str[i+6]=='r'){

                        i+=4;

                    }else {

                        flag = false;break;

                    }

                }else {

                    i+=4;

                }

            }else {

                flag = false;

                break;

            }

        }else if(str[i]=='e'){

            if(str[i+1]=='r'){

                if(str[i+2]=='a'&&str[i+3]=='s'&&str[i+4]=='e'){

                    if(str[i+5]=='r'){

                        i += 5;

                    }else {

                        i += 4;

                    }

                }else if(r){

                    i += 1;

                }else {

                    flag = false;

                    break;

                }

            }else {

                flag = false;

                break;

            }

            r = 0;

        }else {

            flag = false;

            break;

        }

    }

    if(flag)

        puts("YES");

    else

        puts("NO");

    return 0;

}
// Slower C++ solution:
#include <iostream>

using namespace std;

#include <algorithm>

#include <string>

#include <vector>

#define ll long long

struct s

{

    int timu;

    int time;

};

int main()

{



    string s1,s2,s3,s4,s5;

    cin>>s1;

    s2="dream";

    s3="dreamer";

    s4="erase";

    s5="eraser";

    int flag=1;

    int p1,p2,p3,p4;

    int f1,f2,f3,f4;

    ll l;

    while(1)

    {

        flag=0;

        f1=0;f2=0;f3=0;f4=0;

        l=s1.length();

        p1=l-5;

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

        {

            if(s1[p1+i]!=s2[i])

            {

                f1=1;

            }

        }

        if(f1==0)

        {

            s1.erase(p1,5);flag=1;

        }



        l=s1.length();

        p2=l-7;

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

        {

            if(s1[p2+i]!=s3[i])

            {

                f2=1;

            }

        }

        if(f2==0)

        {

            s1.erase(p2,7);flag=1;

        }



        l=s1.length();

        p3=l-5;

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

        {

            if(s1[p3+i]!=s4[i])

            {

                f3=1;

            }

        }

        if(f3==0)

        {

            s1.erase(p3,5);

            flag=1;

        }



        l=s1.length();

        p4=l-6;

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

        {

            if(s1[p4+i]!=s5[i])

            {

                f4=1;

            }

        }

        if(f4==0)

        {

            s1.erase(p4,6);flag=1;

        }



        if(flag==0&&s1.size()!=0)

        {

            cout<<"NO"<<endl;

            return 0;

        }

        if(s1.size()==0)

        {

            cout<<"YES"<<endl;

            return 0;

        }



    }



}


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

#include <cstring>



using namespace std;



int main()

{

  char s[100015];

  int len;

  char c;

  int i;

  bool begin;



  fgets(s, 100015, stdin);

  len = strlen(s) - 1;



#if 0

  printf("string is %s\n", s);

  printf("len %d\n", len);

#endif



  begin = true;

  

  for (i = 0; i<len; i++) {

    if (begin) {

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

        if ((s[i+1] != 'r') ||

            (s[i+2] != 'e') ||

            (s[i+3] != 'a') ||

            (s[i+4] != 'm')) {

           printf("NO\n");

           return 0;

        }

        

        if ((s[i+5] == 'e') &&

            (s[i+6] == 'r') &&

            (s[i+7] != 'a')) {

          i+=6;

        } else {

          i+=4;

        }

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

        if ((s[i+1] != 'r') ||

            (s[i+2] != 'a') ||

            (s[i+3] != 's') ||

            (s[i+4] != 'e')) {

           printf("NO\n");

           return 0;

        }

        if (s[i+5] == 'r') {

          i+=5;

        } else {

          i+=4;

        }



      } else {

        printf("NO\n");

        return 0;

      }

    }

  }



  printf("YES\n");



  return 0;

}
// Slower C++ solution:
#include<iostream>

#include<stdio.h>

#include<string.h>

int main()

{

	using namespace std;

    char d[10]="dream";

    char e[10]="erase";

    char str[100000];

    int test=1,len=0;

    scanf("%s",&str);

    len=strlen(str);

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

    {

        if(str[i]=='d')

        {



            int j;

            for(j=i;j<i+5;j++)

            {

                //cout<<j<<endl;

                if(j>=len||str[j]!=d[j-i])

                {

                    test=0;

                    break;

                }



            }

            if(j==i+5)

                {

                    //cout<<"!"<<endl;

                    i=j-1;

                    if(str[i+1]=='e'&&str[i+2]=='r'&&str[i+3]!='a')

                    {

                        i=j+1;

                    }

                }

        }

        else if(str[i]=='e')

        {

            int j;

            for(j=i;j<i+5;j++)

            {

                //cout<<j<<endl;

                if(j>=len||str[j]!=e[j-i])

                {

                    test=0;

                    break;

                }



            }

            if(j==i+5)

                {

                    i=j-1;

                    if(str[j]=='r')

                    {

                        i=j;

                    }

                    else

                    {

                        i=j-1;

                    }

                }

        }

        else

        {

            test=0;

        }

        //cout<<i<<endl;

    }

    if(test==0)

        {

            cout<<"NO"<<endl;

        }

        else

        {

            cout<<"YES"<<endl;

        }



    return 0;

}


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

#include <cstring>



using namespace std;



int main()

{

  char s[100015];

  int len;

  char c;

  int i;

  bool begin;



  fgets(s, 100015, stdin);

  len = strlen(s) - 1;



#if 0

  printf("string is %s\n", s);

  printf("len %d\n", len);

#endif



  begin = true;

  

  for (i = 0; i<len; i++) {

    if (begin) {

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

        if ((s[i+1] != 'r') ||

            (s[i+2] != 'e') ||

            (s[i+3] != 'a') ||

            (s[i+4] != 'm')) {

           printf("NO\n");

           return 0;

        }

        

        if ((s[i+5] == 'e') &&

            (s[i+6] == 'r') &&

            (s[i+7] != 'a')) {

          i+=6;

        } else {

          i+=4;

        }

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

        if ((s[i+1] != 'r') ||

            (s[i+2] != 'a') ||

            (s[i+3] != 's') ||

            (s[i+4] != 'e')) {

           printf("NO\n");

           return 0;

        }

        if (s[i+5] == 'r') {

          i+=5;

        } else {

          i+=4;

        }



      } else {

        printf("NO\n");

        return 0;

      }

    }

  }



  printf("YES\n");



  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

	string s, t = "";

	cin >> s;

	int n = s.size();

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

		t += s[i];

		if (t == "erase") {

			if (i + 1 < n && s[i + 1] == 'r') {

				i += 1;

			}

			t = "";

		}

		else if (t == "dream") {

			if (i + 2 < n && s[i + 1] == 'e' && s[i + 2] == 'r') {

				if (i + 3 < n && s[i + 3] == 'a') {

					t = "era";

					i += 3;

				}

				else {

					t = "";

					i += 2;

				}

			}

			else {

				t = "";

			}

		}

	}

	if (t == "") {

		cout << "YES";

	}

	else {

		cout << "NO";

	}

	return 0;

}

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

#include <cstring>



using namespace std;



int main()

{

  char s[100015];

  int len;

  char c;

  int i;

  bool begin;



  fgets(s, 100015, stdin);

  len = strlen(s) - 1;



#if 0

  printf("string is %s\n", s);

  printf("len %d\n", len);

#endif



  begin = true;

  

  for (i = 0; i<len; i++) {

    if (begin) {

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

        if ((s[i+1] != 'r') ||

            (s[i+2] != 'e') ||

            (s[i+3] != 'a') ||

            (s[i+4] != 'm')) {

           printf("NO\n");

           return 0;

        }

        

        if ((s[i+5] == 'e') &&

            (s[i+6] == 'r') &&

            (s[i+7] != 'a')) {

          i+=6;

        } else {

          i+=4;

        }

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

        if ((s[i+1] != 'r') ||

            (s[i+2] != 'a') ||

            (s[i+3] != 's') ||

            (s[i+4] != 'e')) {

           printf("NO\n");

           return 0;

        }

        if (s[i+5] == 'r') {

          i+=5;

        } else {

          i+=4;

        }



      } else {

        printf("NO\n");

        return 0;

      }

    }

  }



  printf("YES\n");



  return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstdlib>

using namespace std;

int siz;

string s;

string dream, dreamer, erase, eraser;



void dfs(int st){

	//cout<<st<<endl;

	if(st == siz){

		puts("YES");

		exit(0);

	}

	

	bool flag = 1; // dream

	if(st + 4 <= siz){ 

		//cout<<st<<" "<<"dream"<<endl;

		for(int i=0;i<=4;++i){

			if(s[st+i] != dream[i]){

				flag = 0;

				break;

			}

		}

		if(flag == 1) dfs(st+5);

	} 

	

	if(st + 6 <= siz){

		//cout<<st<<" "<<"dreamer"<<endl;

		flag = 1; // dreamer

		for(int i=0;i<=6;++i){

			if(s[st+i] != dreamer[i]){

				flag = 0;

				break;

			}

		}

		if(flag == 1) dfs(st+7);

	}

	

	if(st + 4 <= siz){

		//cout<<st<<" "<<"erase"<<endl;

		flag = 1; // erase

		for(int i=0;i<=4;++i){

			if(s[st+i] != erase[i]){

				flag = 0;

				break;

			}

		}

		//cout<<flag<<endl;

		if(flag == 1) dfs(st+5);

	}

	

	if(st + 5 <= siz){

		//cout<<st<<" "<<"eraser"<<endl;

		flag = 1; // eraser

		for(int i=0;i<=5;++i){

			if(s[st+i] != eraser[i]){

				flag = 0;

				break;

			}

		}

		if(flag == 1) dfs(st+6);

	}

}



int main(){

	cin>>s; siz = s.size();

	dream = "dream";

	dreamer = "dreamer";

	erase = "erase";

	eraser = "eraser";

	dfs(0);

	puts("NO");

} 

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

#include <cstring>



using namespace std;



int main()

{

  char s[100015];

  int len;

  char c;

  int i;

  bool begin;



  fgets(s, 100015, stdin);

  len = strlen(s) - 1;



#if 0

  printf("string is %s\n", s);

  printf("len %d\n", len);

#endif



  begin = true;

  

  for (i = 0; i<len; i++) {

    if (begin) {

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

        if ((s[i+1] != 'r') ||

            (s[i+2] != 'e') ||

            (s[i+3] != 'a') ||

            (s[i+4] != 'm')) {

           printf("NO\n");

           return 0;

        }

        

        if ((s[i+5] == 'e') &&

            (s[i+6] == 'r') &&

            (s[i+7] != 'a')) {

          i+=6;

        } else {

          i+=4;

        }

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

        if ((s[i+1] != 'r') ||

            (s[i+2] != 'a') ||

            (s[i+3] != 's') ||

            (s[i+4] != 'e')) {

           printf("NO\n");

           return 0;

        }

        if (s[i+5] == 'r') {

          i+=5;

        } else {

          i+=4;

        }



      } else {

        printf("NO\n");

        return 0;

      }

    }

  }



  printf("YES\n");



  return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define YY "YES\n"

#define NN "NO\n"

#define f first

#define s second

#define LL long long

using namespace std;



string s,s1,s2,s3,s4,tmp;

int a,b,c,d,n,aa,bb,cc,dd;

int main(){

	cin>>s;

	n=s.length();

	s1="dream";

	s2="dreamer";

	s3="erase";

	s4="eraser";

	bool ok=true;

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

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

			int j;

			for (j=i;j<=i+4;j++){

				if (j>=n || s[j]!=s1[j-i]){

					ok=false;

					break;

				}

			}

			if(j==i+5) {

	            if(s[j]=='e' && s[j+1]=='r' && s[j+2]!='a') i=j+1;

	            else i=j-1;

	        }

		}

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

			int j;

			for (j=i;j<=i+4;j++){

				if (j>=n || s[j]!=s3[j-i]){

					ok=false;

					break;

				}

			}

			if(j==i+5) {

	            if(s[j]=='r')i=j;

	            else i=j-1;

	        }

		}

		else ok=false;

	}	

	cout<<(ok==true? YY:NN);

}


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

#include <cstring>



using namespace std;



int main()

{

  char s[100015];

  int len;

  char c;

  int i;

  bool begin;



  fgets(s, 100015, stdin);

  len = strlen(s) - 1;



#if 0

  printf("string is %s\n", s);

  printf("len %d\n", len);

#endif



  begin = true;

  

  for (i = 0; i<len; i++) {

    if (begin) {

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

        if ((s[i+1] != 'r') ||

            (s[i+2] != 'e') ||

            (s[i+3] != 'a') ||

            (s[i+4] != 'm')) {

           printf("NO\n");

           return 0;

        }

        

        if ((s[i+5] == 'e') &&

            (s[i+6] == 'r') &&

            (s[i+7] != 'a')) {

          i+=6;

        } else {

          i+=4;

        }

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

        if ((s[i+1] != 'r') ||

            (s[i+2] != 'a') ||

            (s[i+3] != 's') ||

            (s[i+4] != 'e')) {

           printf("NO\n");

           return 0;

        }

        if (s[i+5] == 'r') {

          i+=5;

        } else {

          i+=4;

        }



      } else {

        printf("NO\n");

        return 0;

      }

    }

  }



  printf("YES\n");



  return 0;

}