Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/stack-ichma-ich-siqilgan-satr

Decoding a nested compressed string

Medium 1000 ms 128 MB 56%
Share

A string is given in compressed form: k[t] means the string $t$ written $k$ times in a row, and $t$ itself may also be compressed (for example, 3[a2[c]]b is accaccaccb). Restore the original string.

Nested brackets: the part inside each bracket is repeated as many times as the number before it says

Input

One line with the compressed string.

Output

The original string.

Note

the length of the compressed string is at most $10^{4}$, the length of the original string is at most $10^{5}$
the string contains lowercase Latin letters, digits and square brackets; every [ is preceded by a number from $1$ to $99$ (without a leading zero), and the brackets are never empty

Examples

Input #1
3[a2[c]]b
Output #1
accaccaccb
Input #2
2[ab]3[c]
Output #2
ababccc

Sign in to submit a solution

Signing up is free and takes a minute.