$27$byteで終了時最短であった。HITCON 2016 qualsのregex問の経験が生きた。

print s/(.)(?!\1)//g-1for<>