open Batteries
let () =
  let s = Scanf.scanf "%s " (fun a -> a) in
  let rev_s = String.rev s in

  let dict = ["dream";"dreamer";"erase";"eraser"] in
  let rev_dict = List.map (fun x -> String.rev x) dict in

  let rec aux s = match s with
      "" -> "YES"
    | s -> 
      let res = List.map (fun dict_s -> dict_s =  String.slice ~last:(String.length dict_s) s) rev_dict |>
                List.filter (fun x -> x = true) |> List.length in
      if res = 0 then "NO" else aux (String.slice ~first:(String.length s) s)
  in


  Printf.printf "%s\n" @@
  aux rev_s
