import List m@main=readLn>>=print.concat.sort.foldr(%)[]>>m x%(y:z)|[x]<=y=(x+0:y):z;x%y=[x]:y