import List;main=interact$unlines.foldr(\e a->a++map(e:)a)[[]].nub.init