Small Cube Lover
Time limit1sMemory limit512 MB
Given eight corner pieces with three colored stickers each, decide whether they can be oriented and placed to form a 2x2x2 cube with each face a single color.
- Level
Medium6 of 10
- Topics
- Brute force, Implementation, Math
- Solved
- No attempts yet
Problem
Small Cube Lover had eight small 1×1×1 cube pieces. Each piece has three stickers on faces that share one corner. Small Cube Lover assembled the pieces into a 2×2×2 cube where the four stickers on each face have the same color, and stickers on different faces have different colors. Small Cube Lover loved the small cube very much.

One day, a Cube Ruber flew in, shuffled the stickers on the small cube, and took the cube apart into eight pieces. Shuffling means repeatedly picking any two stickers, removing them, and swapping their positions, many times.
Small Cube Lover was very sad, but bravely ***beep-***ed the Cube Ruber and recovered the eight pieces. Small Cube Lover wants to assemble these pieces into a small cube again. Please help!
Input
Eight lines describe the pieces. Each line gives the colors on the stickers of one piece, read in the order top face, left face, right face, with the three faces all visible. Each color is one of B (blue), G (green), O (orange), R (red), W (white), or Y (yellow). For example, the center piece in the image above is given as Y B R.
The input guarantees that each letter appears the same number of times.
Output
If the pieces can be assembled into a 2×2×2 cube that meets the conditions, print YES. Otherwise, print NO.
Hint
The pieces in the first sample can form a cube with the color layout below.
