Counting Optimal Alignments