Problem H. H2O and other slogans

Author:A. Klenin   Time limit:2 sec
Input file:input.txt   Memory limit:64 Mb
Output file:output.txt  

Statement

When young programmer Vasya was even younger, he found a book on organic chemistry. He did not understand a thing, but liked the pictures of structural chemical formulae in the book and started to draw many similar ones.

Years later, while clearing his room, Vasya found his old drawings and wondered which of them were correct. Since there were many of them, he decided to write a program for that task.

The structural formula of a chemical compound is a graphical representation of the molecular structure showing how the atoms are arranged. Atoms are denoted by letters, and chemical bonds between them — by line segments.

Formula is represented in input file as a two-dimensional array of characters. Each character may be: '.' (ASCII 46) — empty space, 'C' — carbon atom, 'H' — hydrogen atom, 'O' — oxygen atom, '|' (ASCII 124), '/' (ASCII 47), '\' (ASCII 92), '-' (ASCII 45) — chemical bonds. Bonds in correct formula are drawn as straight vertical, horizontal or diagonal lines without intersections. Atoms represented by adjacent letters are not considered bonded.

Correct formula must contain at least one atom and must be connected (there must be a path from each atom to each other passing through bonds).

Additionally, Vasya wants to check that the number of bonds for each atom is equal to the valency number of the corresponding chemical element. For simplicity, he decided that number would be always equal to 4 for carbon, 2 for oxygen and 1 for hydrogen.

Input file format

First line of input file contains integers N M. Following N lines contain M characters each — formula representation.

Output file format

Output file must contain a single string: GOOD, if the drawing represents correct formula, VALENCY if the formula is correct in everything except valencies, and BAD otherwise.

Constraints

1 ≤ N, M ≤ 50

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
2 3
-C|
..|
BAD
2
3 6
..HH..
./..\.
O----O
GOOD
3
3 6
H--C..
....\.
.....H
VALENCY

0.195s 0.019s 15