import scala.io.StdIn object Problem265 { def d(freq: Int, di: Int): Int = { if (freq < di) return 0 di match { case 0 => 1 case _ => freq * d(freq - 1, di - 1) } } def proc(N: Int, dmax: Int, S: String): String = { val cnt = Array.fill(dmax + 1)(0L) var di = 0 var cof = 0L var freq = 0 def commit: Unit = { if (freq >= di) { cnt(freq - di) += d(freq, di) * cof } cof = 0L freq = 0 } for (i <- 0 until N) { S(i) match { case 'd' => di += 1 case '}' => commit; di -= 1 case '+' => commit case 'x' => freq += 1; if (cof == 0L) cof = 1L case c if c.isDigit => cof = c - '0' case _ => } } commit cnt.mkString(" ") } def main(args: Array[String]) { val N = StdIn.readInt() val d = StdIn.readInt() val S = StdIn.readLine() val result = proc(N, d, S) println(result) } }