Duel Languages
https://codeforces.com/group/cRJbcAFEwS/contest/487230/problem/D
Question
Somehow, Abby managed to convince Cody that while it is admirable to be proud of his country's culture, his crusade against hiram na titik was starting to border on irrational. She tweeted out that she had finally calmed Cody down and placed three hashtags to reflect her mood. But then Abby ran into her own problems—in his short tyrannical frenzy, Cody had already made many followers and many enemies.
When her hashtags contained Abakoda letters (ABKD and their lowercase), people complained, "Sorry sis, parang like I find it medyo hard to speak Tagalog!"
When her hashtags contained hiram na titik (CFJQVXZ and their lowercase), people complained, "Eugh, nosebleed! I cannot understand the dire-diretso i-spokening of English!"
Personally, Abby found herself very annoyed with both parties, so she found a way to hopefully shut them both up.
Abby has a pool of n possible words that she's okay with using as hashtags. She must select a first hashtag, a second hashtag, and then a third hashtag, such that the following are all satisfied.
The first hashtag contains an Abakoda letter.
The second hashtag contains a hiram na titik.
The third hashtag contains an Abakoda letter and a hiram na titik.
She cannot use the same word in more than one hashtag. In other words, the three chosen hashtags are distinct.
Note that it is okay for the first hashtag to contain a hiram na titik, so long as it has an Abakoda letter, and vice versa for the second hashtag containing an Abakoda letter.
Given Abby's pool of words, help her count all the possible ways to choose the three hashtags. Note that the order of the three hashtags matters. See the explanation of the third sample input for an example.
Input Format
The first line of input contains a single positive integer n.
Then, n lines of input follow, each containing a word that Abby could put in a hashtag.
Constraints
Each word consists of at least and at most upper or lowercase English letters.
No two words in the input are the same. Note that this is case-sensitive (so He and he could both appear in the input as different words).
Output Format
Output a single line containing the number of possible ways that Abby can choose her three hashtags.
Sample Inputs:
Last updated