import re b=[] D='.' l=len for i in re.findall('\d*.',raw_input()): if'{'<i:b[1]+=b[0];b[1]=[j+D*(max(map(l,b[1]))-l(j))for j in b[1]] elif i<D:M=max(map(l,b[:2]));b[:2]=[L+[l(L[0])*D]*(M-l(L))for L in b[:2]];b[1]=map(str.__add__,b[1],b[0]) else:A,B,C=i;b=[0,[C*int(A)]*int(B)]+b b=b[1:] print'\n'.join(b[0])
Note that non-ascii characters in the above source code will be escaped (such as \x9f).