#C7276. Valid Permutations without Adjacent 'A' and 'B'
Valid Permutations without Adjacent 'A' and 'B'
Valid Permutations without Adjacent 'A' and 'B'
Given a string ( s ) consisting of unique characters, count the number of valid permutations of ( s ) such that the characters 'A' and 'B' do not appear consecutively (i.e. neither "AB" nor "BA" occurs).
For example, if ( s = \texttt{ABC} ), the valid permutations are those arrangements where 'A' and 'B' are never side by side. Your task is to compute and output the total number of such valid arrangements.
Note: Since ( s ) contains unique characters, the total number of permutations is ( n! ) and you need to subtract those that violate the condition. All formulas are rendered in ( \LaTeX ) format.
inputFormat
The input is provided via standard input as a single line containing the string ( s ).
outputFormat
Output the number of valid permutations (an integer) to standard output.## sample
ABC
2