Input: Fix isRepeated off-by-one error and do small optim.