#P3820. XML

XML

Description

In this problem, you are asked to determine if a given document satisfies the syntax of an XML-like language.

A simple XML-like document can be parsed as a sequence of the following:
  1. Plain text---ASCII codes between 32 and 127 (inclusive), with none of the following symbols: <

    ,

    >

    ,

    &

</p>2. The sequences: &lt;

&gt;

&amp;

These encode a <

,

>

, or

&

respectively.

3. &xHEX;

HEX must be any even (positive) number of upper or lower case hexadecimal digits, and this represents the bytes given.

4. <tag>

Tag can be any lowercase alphanumeric string. This tag is pushed onto the context stack.

5. <tag/>

This tag is not pushed onto the context stack (there is no closing context).

6. </tag>

This tag removes the

<tag>

context from the stack, which must be topmost on the stack.

By the time the entire document is parsed, the context stack is empty for a valid document. We should also note that the empty string is considered valid.

Input

You will be given a number of documents to process. Each document is given as one line of text which may be empty. The input is terminated by the end of file.

Output

For each document given, print

valid

on a single line if it is a valid XML-like document, or

invalid

otherwise.

the quick brown fox.
the &lt;i&gt;&lt;b&gt;quick&lt;/b&gt; brown&lt;/i&gt; fox.
&lt;doc&gt;fox &amp;amp; socks.&lt;/doc&gt;
3x+5&amp;gt;7
Null: &amp;x00;
&lt;doc&gt;the quick brown fox.
the &lt;i&gt;quick &lt;b&gt;brown&lt;/i&gt;&lt;/b&gt; fox
fox &amp; socks.
3x+5&gt;7
Null: &amp;x0;
valid
valid
valid
valid
valid
invalid
invalid
invalid
invalid
invalid

Source

2009 Rocky Mountain