#ARC136A. [ARC136A] A ↔ BB
[ARC136A] A ↔ BB
Score : points
Problem Statement
You are given a string of length consisting of A, B, C.
You can do the following two kinds of operations on any number of times in any order.
- Choose
Ain , delete it, and insertBBat that position. - Choose two adjacent characters that are
BBin , delete them, and insertAat that position.
Find the lexicographically smallest possible string that can become after your operations.
What is the lexicographical order?
Simply speaking, the lexicographical order is the order in which words are listed in a dictionary. As a more formal definition, here is the algorithm to determine the lexicographical order between different strings and .
Below, let denote the -th character of . Also, if is lexicographically smaller than , we will denote that fact as ; if is lexicographically larger than , we will denote that fact as .
- Let be the smaller of the lengths of and . For each , we check whether and are the same.
- If there is an such that , let be the smallest such . Then, we compare and . If comes earlier than in alphabetical order, we determine that and quit; if comes later than , we determine that and quit.
- If there is no such that , we compare the lengths of and . If is shorter than , we determine that and quit; if is longer than , we determine that and quit.
Constraints
- is a string of length consisting of
A,B,C.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
4
CBAA
CAAB
We should do the following.
- Initially, we have
CBAA. - Delete the -rd character
Aand insertBB, makingCBBBA. - Delete the -nd and -rd characters
BBand insertA, makingCABA. - Delete the -th character
Aand insertBB, makingCABBB. - Delete the -rd and -th characters
BBand insertA, makingCAAB.
We cannot make lexicographically smaller than CAAB. Thus, the answer is CAAB.
1
A
A
We do no operation.
6
BBBCBB
ABCA