Under construction

Still being built. Things may change

Battle Simulation

Interview

Time limit2sMemory limit512 MB

Summary
Read a monster attack string and output the mech's counters, merging each earliest triple of R, B, L into one C.
Level

Medium4 of 10

Topics
Stack, String, Greedy
Solved
No attempts yet

Problem

A 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.

  • Rake, written R.
  • Bite, written B.
  • Laser breath, written L.

To defeat the monster, the mech answers every monster move with a counter move.

  • Slice, written S, counters a rake.
  • Kick, written K, counters a bite.
  • Shield, written 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.

Input

The first line holds a string consisting only of the letters R, B and L. Its length is between 1 and 1,000,000.

Output

Print one line with the string of moves the mech performs, in order.

Examples3

  1. Example 1

    Input
    RRBBBLLR
    
    Expected output
    SSKKKHHS
    
  2. Example 2

    Input
    RBLLLBRR
    
    Expected output
    CHCS
    
  3. Example 3

    Input
    RBLBR
    
    Expected output
    CKS