printРабочее место участника

printЗадачи

1487. H2O and other slogans

Ограничения: время – 1s/2s, память – 64MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод copy
Послать решение Blockly Посылки Темы Где Обсудить (0)

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.
11939.png
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 Input 1

2 3
-C|
..|

Sample Output 1

BAD

Sample Input 2

3 6
..HH..
./..\.
O----O

Sample Output 2

GOOD

Sample Input 3

3 6
H--C..
....\.
.....H

Sample Output 3

VALENCY
Source: NEERC ICPC, Far Eastern subregion, 2008
loading