해설
If a character or remains in the string, the condition is not satisfied. Therefore, every occurrence of and in the original string must be erased.
Conversely, if we erase exactly all occurrences of and , the remaining string contains neither nor . Hence the answer is the number of occurrences of the characters and in .
We can compute it by scanning the string once. The time complexity is and the memory complexity is .