#K57492. Valid Sequence Checker
Valid Sequence Checker
Valid Sequence Checker
In this problem, you are given a sequence consisting only of characters A
and B
. Your task is to determine whether the sequence is valid.
A sequence is considered valid if it does not contain any adjacent B
characters. In other words, for every index \(i\) (with \(1 \le i < n\)), if \(s_i = \text{B}\) then \(s_{i+1} \neq \text{B}\). This condition can be expressed in \(\LaTeX\) as:
$$\forall\, i \in [1, n-1], \quad \text{if } s_i = \text{B} \text{ then } s_{i+1} \neq \text{B}.$$
Output VALID
if the sequence satisfies the condition, otherwise output INVALID
.
inputFormat
The input is read from stdin
and consists of a single line containing a non-empty string. The string contains only the characters A
and B
.
outputFormat
Output VALID
if the sequence is valid (i.e. it does not contain two consecutive B's), otherwise output INVALID
.
The output should be written to stdout
.
AABAB
VALID
</p>