Counting with weights

g = A B C D