Presort array by

r=reduce
f=lambda a,b:(a+[[b]])if a[-1][-1]>b else(a[:-1]+[a[-1]+[b]])
while True:print repr(r(lambda a,b:a+b,sorted(r(f,eval(raw_input()),[[999]])[1:]),[])).replace(' ','')

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return top