Flatten the Expression

No attempts yetTime limit1sMemory limit128 MB

Problem

Consider the language defined below. An expression in this language is one of the following two forms.

  • Letter: a single lower-case letter $c$.
  • Group: $(e_1\ e_2\ \cdots\ e_t\ n)$ — zero or more expressions $e_1, e_2, \ldots, e_t$ followed by a natural number $n$, where $t \ge 0$.

The flattening of an expression is defined as follows.

  • A single letter is flattened to itself.
  • An expression of the form $(e_1\ e_2\ \cdots\ e_t\ n)$ is flattened by concatenating the flattenings of $e_1, \ldots, e_t$ in order and repeating that concatenation $n$ times.

In other words, if $f(e)$ is the flattening of $e$ and $+$ denotes concatenation, then $f\big((e_1\ e_2\ \cdots\ e_t\ n)\big)$ is:

$$ \underbrace{f(e_1)+f(e_2)+\cdots+f(e_t)}{1} + \underbrace{f(e_1)+f(e_2)+\cdots+f(e_t)}{2} + \cdots + \underbrace{f(e_1)+f(e_2)+\cdots+f(e_t)}_{n} $$

The table below shows some sample expressions and the result of flattening each.

expressionflattening
ww
(c 4)cccc
(a (b c 2) 3)abcbcabcbcabcbc

Write a program that flattens a given expression.

Input

The input consists of one or more test cases. Each test case is a single, grammatically correct expression, and a $ character marks the end of that expression. The last line of the input is not a test case: it consists of a single $ character (possibly with leading and/or trailing whitespace).

Every expression in the input is grammatically correct according to the grammar above. An expression may contain leading, trailing, and/or embedded spaces, and all such spaces must be ignored. Letters and numbers are separated from one another by at least one space character.

Output

For each test case expression, print its flattening on its own line. The output must contain no spaces other than newlines.