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 = { cnt(freq - di) += d(freq, di) * cof clear } def clear: Unit = { cof = 0 freq = 0 } for (i <- 0 until N) { S(i) match { case 'd' => di += 1 case '}' => if (freq - di >= 0) commit else clear; di -= 1 case '+' => if (freq - di >= 0) commit else clear case 'x' => freq += 1; if (cof == 0) cof = 1 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) } }