program main
   character(len=3) :: s(4) = (/"eam", "mer", "ase", "ser"/)
   character(len=100000) :: b
   integer :: L(4) = (/5, 7, 5, 6/)
   read(*, *) b
   N = len_trim(b)
   a: do while(N > 0)
      if (N < 5) then
         write(*, *)"NO"
      stop
      endif
      do i = 1, 4
         if(s(i) == b(N-2:N))then
            N = N - L(i)
            cycle a
         endif
      enddo
      write(*, *)"NO"
      stop
   enddo a
   write(*, *) "YES"
end
