new character pair algorithm