Under construction

Still being built. Things may change

Small Cube Lover

Time limit1sMemory limit512 MB

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

small cube

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.

color layout

Examples2

  1. Example 1

    Input
    W B O
    B W R
    G O Y
    R W G
    Y O B
    O G W
    B R Y
    G Y R
    
    Expected output
    YES
    
  2. Example 2

    Input
    R O W
    B Y G
    W B O
    W R G
    Y R O
    G Y R
    W G B
    O B Y
    
    Expected output
    NO