group elements by hallvabo (no import)

while 1:
 s=' '
 for e in raw_input()[::2]:s+=('] [',' ')[e==s[-1]]+e
 print s[3:]+']'

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return top