Problem N
Palindromic DNA
A DNA sequence is composed of a series of four possible
nucleobases, namely Adenine, Guanine, Thymine and Cytosine; we
will refer to each of these bases by their initial. For our
purposes, nucleobases have an associated cyclic “order”:
A is followed by G, which in turn is followed by T, which is followed by C, which is followed by A again. State-of-the-art research in genomics
has revealed the startling fact that many diseases are caused
by certain subsequences of bases not forming a palindromic
sequence! Your mission as a leading researcher at ICPC
laboratories is to take a DNA string
-
Leave it unaltered.
-
Increase it by 1 in the cyclic order of nucleobases (e.g. turn C into A).
-
Decrease it by 1 (e.g. turn T into G).
Moreover, owing to limitations of current technology, it is impossible to modify two bases in consecutive positions of the sequence. Is our goal achievable?
By way of example, consider DNA sequence AGTAT. Number positions starting from
One case where no solution is possible is when the string is
CATGC, and we require the
subsequences determined by positions
Input
The input consists of at most
A blank line separates different test cases. The input file is terminated by a line containing 0 0.
Output
In a single line per test case, print YES if the task is solvable and NO otherwise.
Sample Input 1 | Sample Output 1 |
---|---|
5 3 AGTAT 2: 1 4 2: 0 1 3: 0 2 4 5 3 CATGC 0: 2: 0 3 2: 3 4 0 0 |
YES NO |