readLine.reverse.foldLeft(List[String]()){case(a,b)=>(b+a.headOption.getOrElse(""))::a}.sorted map println