class State private constructor(val direction: Int, val state: Int, val score: Int) {
    constructor():this(0, 0, 0)
    fun move(command: Char): State {
        val diff = when(command){
            'R' -> 1
            'L' -> -1
            else -> TODO()
        }
        val newDirection = (direction + diff + 4) % 4
        return when {
            diff == 1 && newDirection == 0 && state == (1 shl 4) - 1 -> State(0, 0, score + 1)
            diff == 1 && newDirection == 1 -> State(1, 3, score)
            newDirection == 0 -> State(0, 0, score)
            else -> State(newDirection, state or (1 shl newDirection), score)
        }
    }

    override fun toString(): String {
        return "State(direction = $direction, state = $state, score = $score)"
    }
}
fun main(args: Array<String>?): Unit {
    println(
            readLine()!!.trim().fold(State()){s, c ->
                s.move(c)
            }.score
    )
}
