#K3636. Good String Transformation
Good String Transformation
Good String Transformation
You are given a string S
consisting only of the characters 'A' and 'B'. You are allowed to perform an operation that removes one character from any pair of consecutive identical characters. A string is called good if it does not contain two consecutive 'A's or two consecutive 'B's, i.e. it is strictly alternating.
It can be proven that S
can be transformed into a good string by a sequence of such operations if and only if S
does not contain the substring AAA
or BBB
. Your task is to determine whether it is possible to transform the given string into a good string.
Note: The allowed operation is to remove one character from any adjacent identical pair.
inputFormat
The input consists of a single line containing the string S
which only contains the characters 'A' and 'B'.
outputFormat
Output a single line containing YES
if it is possible to transform S
into a good string using the described operations, or NO
otherwise.
AABBAA
YES