Read a monster attack string and output the mech's counters, merging each earliest triple of R, B, L into one C.
Medium4StackStringGreedyInterviewNo attempts yetTime limit2sMemory limit512 MBA giant monster is rampaging through Neo Tokyo 5. The Earth Defense Force sent one mech to stop it. Only a single mech survived the earlier rampages, so the Earth Defense Force simulates the coming battle before it attacks.
The analysts found that the monster's attack pattern is a series of moves performed one after another. Writing each move as a single letter turns the pattern into one string, read from left to right. The monster has three moves.
R.B.L.To defeat the monster, the mech answers every monster move with a counter move.
S, counters a rake.K, counters a bite.H, counters a laser breath.There is one condition. When the monster performs a rake, a bite and a laser breath in three consecutive moves, in any order, the result is a very powerful attack, and the mech answers it with a single move called combo breaker, written C. One combo breaker absorbs the whole combination of three moves. The moves that follow are countered one by one or as part of a new combination. A monster move never belongs to more than one combination.
The mech always breaks the earliest combination it can. Read the attack pattern from the left: if the first three moves that are still uncountered hold a rake, a bite and a laser breath in some order, the mech answers all three with one combo breaker, otherwise it answers the first uncountered move with the matching counter move.
You are given the string of moves that the monster will use against the mech. Print the moves the mech performs, in order, to defeat it.
The first line holds a string consisting only of the letters R, B and L. Its length is between 1 and 1,000,000.
Print one line with the string of moves the mech performs, in order.