406005: GYM102215 K Deck Sorting

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

K. Deck Sortingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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?

Input

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

Output

Output «YES» or «NO», depending on if it's possible to sort the deck or not.

ExamplesInput
RGBRGB
Output
YES
Input
RGBRGBRGB
Output
NO
Input
RBBRRB
Output
YES
Note

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

加入题单

算法标签: