2000 ACM South Central Regional Programming Contest

Louisiana State University

Problem #2: Shadows

Introduction

A LSU physics researcher who we will call "Sparky" was very successful in procuring funding for the physics department because of his breakthrough research into new 3-dimensional crystalline storage technology. Though a brilliant physicist, Sparky's organizational habits were lacking. His office was strewn with stacks of crystal pictures, and most were not labeled in any way other than to note the orientation of the crystal.

Unfortunately for the physics department, Sparky asphyxiated from laughter after a night grading midterms for his Physics For Non-Majors class. You are the lucky new non-tenured professor that has been hired by the Physics departement to decipher Sparky's research and keep that grant money flowing.

In Sparky's now vacant office, there is a mess of picutures all about. You know that he was taking three pictures of each crystal he grew (one picture down each primary axis: X,Y,Z). You also know that the crystals grew in a liquid suspension and therefore don't necessarily consist of a single continuous mass.

As a first step in organizing the mess you decide to take the pictures three at a time (one down each axis) and see whether or not they could be pictures of the same crystal. Of course, you know Sparky always took pictures of cubical areas, so you pick out pictures of the same dimensions before examining them.

Here are some other useful things that you know about the pictures:

Input

Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets.

A single data set has five components:

  1. Start line - A single line, "START <cube_size>" where <cube_size> is a positive integer in the range 1-10, inclusive, that gives the height/width/depth for the cube (fortunately, height/width/depth are all the same for cubes, so you only need one number). For example:
    START 5
  2. Shadow 1 - A shadow down the Z axis. Shadows consist of X's and O's (letter not number), where an X represents a one unit square area of shadow and an O represents a similarly sized illuminated area. There is no white-space leading or following any of the lines. For example:












  3. Shadow 2 - A shadow down the Y axis












  4. Shadow 3 - A shadow down the X axis











  5. End line - A single line, "END"

Output

For each data set, there will be exactly one line of output. This line will simply be the word "YES" or the word "NO" (all caps with no whitespace leading or following).

A "YES" line will appear only if there exists some solid 3-dimensional object that could project the given silhouettes. (In other words, these could all be pictures of the same crystal).

A "NO" line will be output for all data sets that fail to meet the criteria for a "YES" line.

Sample Input

START 1
O
O
O
END
START 3
XXX
XOX
XOX
XXX
XXX
XXX
XXX
XXX
XXX
END
START 7
XXXXXXX
XXXXXXX
XXXXXXX
XXXXXXX
XXXXXXX
XXXXXXX
XXXXXXX
OOOOOOO
OOOOOOO
OOOOOOO
OOOOOOO
OOOOOOO
OOOOOOO
OOOOOOO
XOOOOOO
OXOOOOO
OOXOOOO
OOOXOOO
OOOOXOO
OOOOOXO
OOOOOOX
END

Sample Output

NO
YES
NO