cswork / OAOpen practice workspace

WaymoOA #1

Decode Repeated Groups

Estimated MediumJudge-ready

Topics (AI-labelled)Stacks & HeapsStrings

Decode lowercase letters and (substring){k} repeat groups, with nesting and k=0 allowed.

See "Input" for the standard input/output conventions and constraints added by this site.

Input

q lines of encoded strings; this site adds that each string and its decoded length are ≤200000, with depth ≤1000.

Output

Output each decoded string on its own line.

Example 1

Input:

3
abs(cs){3}g
a(b(c){2}){2}
x(yz){0}q

Output:

abscscscsg
abccbcc
xq

Example 2

Input:

1
a(b){0}c

Output:

ac

Example 3

Input:

1
(ab){2}

Output:

abab

Editorial

Loading solution…