y=0;p=0;m=9;X={} L=io.read() for i=1,L:len()do c=L:byte(i) y=y+(c>p and 1 or(c<p and -1)or 0) m=y<m and y or m X[y]=X[y]or{};X[y][i]=c p=c end for i=#X,m,-1 do C="" for j=1,L:len()do C=C..string.char(X[i][j]or 32) end print((C:gsub(" +$",""))) end
Note that non-ascii characters in the above source code will be escaped (such as \x9f).