import sys tmp = None while True: c = sys.stdin.buffer.read(1) if c==tmp: continue sys.stdout.buffer.write(c) tmp=c if c==b'\n': break