main=interact$unlines.f.lines f(x:y)=x:filter(x==)y++f(filter(x/=)y) f x=x