Modified run-length encoding of a list