Unique String

Limits: 1s, 64 MB

There are 3 types of letters available. They are A, B and C. You are given the frequencies of them. You have to make a word with all of them but have to maintain one condition that letter A and B will not be adjacent to each other. How many different words you can make maintaining the condition.

This is a companion discussion topic for the original entry at https://toph.co/p/unique-string