correct the distance calculation based on bad character shifting rule