Count anagrams having first character as a consonant and no pair of consonants or vowels placed adjacently | ''Python 3 program for the above approach include <bits/stdc++.h> ; ''Function to compute factorials till N ; '' Iterate in the range [1, N] ; '' Update ans to ans*i ; ''Store the value of ans  in fac[i] ; ''Function to check whether the current character is a vowel or not ; ''Function to count the number of anagrams of S satisfying the given condition ; '' Store the factorials upto N ; '' Function Call to generate  all factorials upto n ; '' Create a hashmap to store  frequencies of all characters ; '' Store the count of  vowels and consonants ; '' Iterate through all  characters in the string ; ''Update the frequency  of current character ; ''Check if the character  is vowel or consonant ; '' Check if C==V+1 or C==V ; ''Store the denominator ; '' Calculate the denominator of the expression ; '' Multiply denominator by factorial of counts of all letters ; '' Store the numerator ; '' Store the answer by dividing  numerator by denominator ; '' Print the answer ; ''Otherwise, print 0 ; ''Driver Code
mod = 1000000007 NEW_LINE N = 1000001 NEW_LINE fac = { } NEW_LINE def Precomputefact ( ) : NEW_LINE INDENT global fac NEW_LINE DEDENT ans = 1 NEW_LINE for i in range ( 1 , N + 1 , 1 ) : NEW_LINE INDENT ans = ( ans * i ) % mod NEW_LINE DEDENT fac [ i ] = ans NEW_LINE INDENT return NEW_LINE DEDENT def isVowel ( a ) : NEW_LINE INDENT if ( a == ' A ' or a == ' E ' or a == ' I ' or a == ' O ' or a == ' U ' ) : NEW_LINE DEDENT return True NEW_LINE INDENT else : NEW_LINE DEDENT return False NEW_LINE def countAnagrams ( s , n ) : NEW_LINE global fac NEW_LINE INDENT Precomputefact ( ) NEW_LINE count = { } NEW_LINE DEDENT vo = 0 NEW_LINE co = 0 NEW_LINE for i in range ( n ) : NEW_LINE if s [ i ] in count : NEW_LINE INDENT count [ s [ i ] ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT count [ s [ i ] ] = 1 NEW_LINE DEDENT if ( isVowel ( s [ i ] ) ) : NEW_LINE INDENT vo += 1 NEW_LINE else : NEW_LINE DEDENT co += 1 NEW_LINE INDENT if ( ( co == vo + 1 ) or ( co == vo ) ) : NEW_LINE deno = 1 NEW_LINE DEDENT for key , value in count . items ( ) : NEW_LINE deno = ( deno * fac [ value ] ) % mod NEW_LINE INDENT nume = fac [ co ] % mod NEW_LINE DEDENT nume = ( nume * fac [ vo ] ) % mod NEW_LINE ans = nume // deno NEW_LINE INDENT print ( ans ) NEW_LINE else : NEW_LINE print ( 0 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT S = " GADO " NEW_LINE l = len ( S ) NEW_LINE countAnagrams ( S , l ) NEW_LINE DEDENT