// Template for reading lines from stdin and printing the line count to stdout.
// Copy this code to your IDE to get started.

fun main() {
    fun String.press(t: String) = when {
        t[0] == '*' -> (toInt() * t.drop(1).toInt()).toString()
        t[0] == '/' -> (toInt() / t.drop(1).toInt()).toString()
        "->" in t -> replace(t[0], t.last())
        t == "oct" -> toInt().toString(8)
        t == "bksp" -> (if (length == 1) "0" else dropLast(1))
        this == "0" -> t
        else -> this + t
    }.takeUnless { it.length > 4 } ?: this

    val tokens = readln().split(" ").map { it.drop(1).dropLast(1) }

    var v = setOf("0")

    while (true) {
        v  = v.flatMap { tokens.map(it::press) }.toSet().apply {
            if (size == v.size) break
        }
    }

    println(v.sumOf(String::toInt))
}
