403749: GYM101257 A The Fault in Our Cubes
Description
Rula is the Human Resources Manager at Mixed Dimensions Inc. She has some very delightful puzzles for the employees to enjoy their free time at the office. One of these puzzles is the Worm Puzzle.
The puzzle consists of 27 cubic pieces of several types. The pieces are connected by a rope that runs through holes in the pieces, and allows the pieces to rotate. In order to solve the puzzle, you need to build a 3x3x3 cube.
Each piece has one of the following three types:
- Type E represents an end cube, it has a hole at one face only. This piece is always connected to only one other piece.
- Type I represents a cube which has two holes on opposite faces, the rope goes straight into one hole and out through the other.
- Type L represents a cube which has two holes in two adjacent faces, the rope enters through one face, makes a 90 degree turn, and exits through the other face.
Well, Hasan has cut the rope of the puzzle by mistake, of course he didn’t want to tell Rula about it, so he bought a new rope and linked the pieces together to make a new Worm Puzzle, but he wasn't sure whether he linked them in their original order or not.
Now Rula has been trying to solve the puzzle for two days, but with no success, although she used to solve it in 30 seconds. She started to suspect that something might be wrong with the puzzle.
She asked one of the engineers at Mixed Dimensions to verify whether the puzzle is solvable or not. Unfortunately, that engineer was Hasan, and of course, the question is difficult for him to answer.
Given the type of each piece, and the order in which Hasan linked the pieces together, can you help him by finding whether the given puzzle is solvable or not?
InputThe input consists of a string of 27 letters, each letter will be either an E, I, or L, which represents the type of that piece.
The first and last letters are always E.
OutputPrint YES if the given puzzle is solvable, otherwise print NO.
ExamplesInputEILILLLLLLILILLLLLLILILLLLEOutput
YESInput
EILLLILLILLLILILLLLILILILIEOutput
YESInput
EILLILLLILLILLLILLLILLLLILEOutput
NO