import kotlin.system.exitProcess val br = System.`in`.bufferedReader() fun readLine(): String? = br.readLine() fun readString() = readLine()!! fun readInt() = readString().toInt() fun readLong() = readString().toLong() fun readDouble() = readString().toDouble() fun readStrings() = readLine()?.split(" ")?.filter { it.isNotEmpty() } ?: listOf() fun readInts() = readStrings().map { it.toInt() }.toIntArray() fun readLongs() = readStrings().map { it.toLong() }.toLongArray() fun readDoubles() = readStrings().map { it.toDouble() }.toDoubleArray() fun readLines(n: Int) = Array(n) { readString() } const val MAX_STACK_SIZE: Long = 128 * 1024 * 1024 fun main() { val thread = Thread(null, ::run, "solve", MAX_STACK_SIZE) thread.setUncaughtExceptionHandler { _, e -> e.printStackTrace(); exitProcess(1) } thread.start() } fun run() { val S = readString() output(solve(S)) } fun solve(S: String): Pair { // 01234 // L: (^^*) // R: (*^^) val dpL = IntArray(5) val dpR = IntArray(5) for (c in S) { when (c) { '(' -> { dpL[0]++ dpR[0]++ } '^' -> { dpL[2] += dpL[1].also { dpL[1] = dpL[0] }.also { dpL[0] = 0 } dpR[3] += dpR[2].also { dpR[2] = dpR[1] }.also { dpR[1] = 0 } } '*' -> { dpL[3] += dpL[2].also { dpL[2] = 0 } dpR[1] += dpR[0].also { dpR[0] = 0 } } ')' -> { dpL[4] += dpL[3] dpR[4] += dpR[3] } } } return dpL[4] to dpR[4] } fun output(res: Pair) = println(res.toList().joinToString(" "))