/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
			System.out.print("3[a]2[bc]");
	//	System.out.print(decodeString("3[a]2[bc]"));
	}
	 public String decodeString(String s) {
	 		System.out.print(decodeString("3[a]2[bc]"));
        Stack<Character> ss = new Stack<>();
        Stack<String> bb = new Stack<>();
        boolean temp = false;
        int n = 0;
        String resl = "";
        for (Character c : s.toCharArray()) {
            if (c == '[') {
                n = ss.pop();//循环次数
                temp = true;
            } else if (c == ']') {
                temp = false;
                
                StringBuilder sb = new StringBuilder();
                StringBuilder res = new StringBuilder();
                for (String cc : bb) {
                    sb.append(cc);
                }
                bb.clear();
                //sb.reverse();
                for (int i = 0; i < n; i++) {
                    res.append(sb);
                }
                resl += res.toString();
                n=0;
            } else {
                if (temp)
                    bb.push("" + c);
                else
                    ss.push(  c);
            }
        }
         return resl;

    }
}