Tiny code style nitpick: ```flag += 1``` (space after =). It's the same for the lines below.