main=interact$concat.foldr(\a b->b++[a:c|c<-b,a/=last b!!0])["\n"]