406005: GYM102215 K Deck Sorting
Description
You have a deck of cards, lying on the table in front of you face up. The cards can be red, green and blue, and you know the order of cards in the deck. You want to sort the cards so that the cards of each color form a continuous segment. The order of colors doesn't matter.
The table doesn't have much free space — only for two piles of cards. In one turn, you take a top card from the deck and put it onto the top of one of the piles, face up. After all cards are distributed to the piles, you take one of these piles and put it onto the top of the other pile, again, face up.
Is it possible to sort the cards with the described procedure?
InputThe input contains a string of characters «R», «G» and «B». Its length is between $$$1$$$ and $$$1000$$$. The characters correspond to the colors of the cards in the deck, starting from the top one.
OutputOutput «YES» or «NO», depending on if it's possible to sort the deck or not.
ExamplesInputRGBRGBOutput
YESInput
RGBRGBRGBOutput
NOInput
RBBRRBOutput
YESNote
In the first sample the deck is «RGBRGB» (starting from the top card). The 1st, the 4th and the 5th cards can be put to the first pile (it will be «GRR»), and the 2nd, the 3rd and the 6th cards can be put to the second pile (it will be «BBG»). After that the second pile can be put to the top of the first one, and the deck becomes sorted: «BBGGRR».