structure A  = Array
structure C  = Char
structure CV = CharVector
structure I  = Int
structure L  = List
structure LI = LargeInt
structure S  = String
structure SC = StringCvt
structure T  = TextIO

fun scan rdr strm = SOME (SC.splitl (not o C.isSpace) rdr (SC.skipWS rdr strm))

fun next () = valOf (T.scanStream scan T.stdIn)

fun nextInt () = valOf (T.scanStream (I.scan SC.DEC) T.stdIn)

val () =
    let
        fun f ([], x)      = [x]
          | f ([c], x)     = [x]
          | f (c1::c2::cs, x) = if c1 = c2 then f (c2::cs, x + 1)
                                else x :: f (c2::cs, 1)
        fun g [] = 0
          | g [x] = if x <= 1 then x
                    else if x <= 4 then x - 1
                    else x - 2
          | g (x1::x2::xs) = if x1 <= 1 then x1 + g (x2::xs)
                             else if x1 = 2 andalso x2 >= 2 then 2 + g ((x2-1)::xs)
                             else if x1 <= 4 then x1 - 1 + g (x2::xs)
                             else x1 - 2 + g (x2::xs)
        val cs = explode (next ())
        val l = f (cs, 1)
    in
        print (I.toString (g l) ^ "\n")
    end
