import
java.util.*;
import
java.lang.*;
class
GFG
{
static
boolean
isVowel(
char
ch)
{
if
(ch ==
'a'
|| ch ==
'e'
||
ch ==
'i'
|| ch ==
'o'
||
ch ==
'u'
)
return
true
;
else
return
false
;
}
static
long
fact(
long
n)
{
if
(n <
2
)
{
return
1
;
}
return
n * fact(n -
1
);
}
static
long
only_vowels(HashMap<Character, Integer> freq)
{
long
denom =
1
;
long
cnt_vwl =
0
;
for
(Map.Entry<Character, Integer> itr : freq.entrySet())
{
if
(isVowel(itr.getKey()))
{
denom *= fact(itr.getValue());
cnt_vwl += itr.getValue();
}
}
return
fact(cnt_vwl) / denom;
}
static
long
all_vowels_together(HashMap<Character, Integer> freq)
{
long
vow = only_vowels(freq);
long
denom =
1
;
long
cnt_cnst =
0
;
for
(Map.Entry<Character, Integer> itr : freq.entrySet())
{
if
(!isVowel(itr.getKey()))
{
denom *= fact(itr.getValue());
cnt_cnst += itr.getValue();
}
}
long
ans = fact(cnt_cnst +
1
) / denom;
return
(ans * vow);
}
static
long
total_permutations(HashMap<Character, Integer> freq)
{
long
cnt =
0
;
long
denom =
1
;
for
(Map.Entry<Character, Integer> itr : freq.entrySet())
{
denom *= fact(itr.getValue());
cnt += itr.getValue();
}
return
fact(cnt) / denom;
}
static
long
no_vowels_together(String word)
{
HashMap<Character, Integer> freq =
new
HashMap<>();
for
(
int
i =
0
; i < word.length(); i++)
{
char
ch = Character.toLowerCase(word.charAt(i));
if
(freq.containsKey(ch))
{
freq.put(ch, freq.get(ch)+
1
);
}
else
{
freq.put(ch,
1
);
}
}
long
total = total_permutations(freq);
long
vwl_tgthr = all_vowels_together(freq);
long
res = total - vwl_tgthr;
return
res;
}
public
static
void
main(String[] args) {
String word =
"allahabad"
;
long
ans = no_vowels_together(word);
System.out.println(ans);
word =
"geeksforgeeks"
;
ans = no_vowels_together(word);
System.out.println(ans);
word =
"abcd"
;
ans = no_vowels_together(word);
System.out.println(ans);
}
}