eolymp
bolt
Try our new interface for solving problems
Məsələlər

Генетика

Генетика

A colony of alien bacteria has recently been discovered close to a crater in New Mexico. Dr. Poucher is in charge of the scientific team at the ICPC BioLab committed to the study of the alien DNA structure. We briefly sketch their discoveries here. Alien DNA molecules have the structure of a circular sequence. Each sequence is composed of nucleotides. There are \textbf{26} different types of nucleotides, and each of them can occur in two faces. It is very important to remark that in any given alien DNA molecule, every nucleotide either does not appear at all or appears exactly twice (hence, the length of a DNA molecule is an even integer between \textbf{2} and \textbf{52}). In case a nucleotide occurs twice, each occurrence can be of either type independently. Alien bacteria have two types of extremities, which in the technical biological jargon are referred to as arms and legs. A major discovery of Dr. Poucher’s team is a method to determine the exact number of arms and legs of a bacterium by examining its DNA structure. Here we represent each nucleotide as a letter of the alphabet. We refer to the different nucleotides as \textbf{a}, \textbf{A}, . . . \textbf{z}, \textbf{Z}, where the lowercase and uppercase forms of a letter represent the two possible faces a nucleotide may appear with; we shall also use \textbf{a}/\textbf{A}, \textbf{b}/\textbf{B}, . . . \textbf{z}/\textbf{Z} to refer to a nucleotide in either face. To determine the number of extremities, Dr. Poucher starts by initializing two counters of arms and legs to zero, and then proceeds to perform a number of surgeries, transforming a DNA sequence into another one. After each transformation, you may need to increase some of the counters, depending on the type of surgery applied. When the empty sequence of nucleotides (which will be denoted by \textbf{∅}) has been reached, the number of extremities of the original molecule has been found. The possible surgeries are: \textbf{1.} Eliminate consecutive instances of a given nucleotide appearing with opposite faces. The number of arms and legs is preserved. For example: \textbf{aBbCaC} → \textbf{aCaC} by eliminating \textbf{Bb}. Another example: \textbf{DeHhEd} → \textbf{eHhE} by eliminating \textbf{dD}. Remember that DNA structure is circular, so in our representation as a string the last and first letters are connected. \textbf{2.} Eliminate consecutive nucleotides appearing with the same face. Add one to the number of arms. For example: \textbf{BBcgCg }→ \textbf{cgCg} by eliminating \textbf{BB}. Another example: \textbf{xabyyaBX} → \textbf{xabaBX} by eliminating \textbf{yy}. \textbf{3.} Eliminate a sequence of four nucleotides formed by two different nucleotides that appear alternately where different occurrences of the same nucleotide have opposite faces. Add one to the number of legs. For example: \textbf{dcDCefFe} → \textbf{efFe}, by eliminating \textbf{dcDC}. Another example: \textbf{cmNMnC} → \textbf{cC} by eliminating \textbf{mNMn}. \textbf{4.} Cut and paste, the most sophisticated procedure. First, a nucleotide is selected, for instance \textbf{a}/\textbf{A}, and the DNA sequence is chopped into two linear chains such that the nucleotide appears once in each of them. Second, if both occurrences of \textbf{a}/\textbf{A} are of the same face, one of the chains is “inverted” by reversing the sequence and changing the face of every nucleotide in the chain. Then, the chains are combined by concatenating the subsequence occurring before a with the sub-sequence occurring after \textbf{A}, and the subsequence occurring after a with the sub-sequence occurring before \textbf{A}. Finally, two new \textbf{a}/\textbf{A} nucleotides are added to close the chain into a circular shape. The face of the new nucleotides are the same if the original pair of nucleotides selected had the same face, and is different otherwise. Formally, suppose you select the nucleotide \textbf{a}/\textbf{A}, and further assume for the moment that it appears both times with the face \textbf{a} (\textbf{A}). The cut and paste surgery turns sequences of the form \textbf{S_1aS_2S_3aS_4} (respectively \textbf{S_1AS_2S_3AS_4}) into \textbf{S_2aS_1S_3aS_4} (respectively \textbf{S_2AS_1S_3AS_4}). On the other hand, if nucleo-tide \textbf{a}/\textbf{A} appears with its two different faces, the surgery turns sequences of the form \textbf{S_1aS_2S_3AS_4} into \textbf{S_2aS_1S_4AS_3}. \textbf{S_1}, \textbf{S_2}, \textbf{S_3} and \textbf{S_4} are arbitrary sub-chains (possibly empty). In both cases the original circular chain was chopped into \textbf{S_1}(\textbf{a}/\textbf{A})\textbf{S_2} and \textbf{S_3}(\textbf{a}/\textbf{A})\textbf{S_4}. For example (see the figure below): starting with the sequence \textbf{BacDcAbD}, we can get chains \textbf{BacDc }and \textbf{AbD}. Then, merging at nucleotide \textbf{a}/\textbf{A} we get the sequence \textbf{cDca’BbDA’} where \textbf{a’} and \textbf{A’} represent the new \textbf{a}/\textbf{A} nucleotides. Here, \textbf{S_1} = \textbf{B}, \textbf{S_2} = \textbf{cDc}, \textbf{S_3}= \textbf{∅} and \textbf{S_4}= \textbf{bD}. Another example: take the same DNA sequence \textbf{BacDcAbD}, and cut to get the chains \textbf{DBac} and \textbf{DcAb}; paste nucleotide \textbf{c}/\textbf{C} (in this case you need to reverse one chain, for example \textbf{BaCd}) to get the sequence \textbf{cDBadcBa}. Here, \textbf{S_1} = \textbf{DBa}, \textbf{S_2} = \textbf{∅}, \textbf{S_3} = \textbf{D} and \textbf{S_4} = \textbf{Ab}. \includegraphics{https://static.e-olymp.com/content/4a/4a291c98b6e8c7c735559ac4f7823556d1f46046.jpg} This surgery does not modify the number of arms or legs, but can be used cleverly in combination with the previous surgeries to reduce the size of the DNA molecule and finish the calculation. However, alien bacteria do not present both arms and legs at the same time. This is due to the fact that, in their early development, a leg, in the presence of one or more arms, becomes two arms. Because of the above, the end result is either a number of arms or a number of legs, but not both at the same time. In order to avoid expensive surgical procedures, Dr. Poucher has hired you to write a program that computes the number of arms and legs a bacterium will develop, given its DNA sequence. It is guaranteed that the result is determined uniquely by the original string, regardless of the particular sequence of surgeries applied. \InputFile Each test case consists of a string of even length between \textbf{2} and \textbf{52}, inclusive, representing the DNA structure of an alien bacterium. All characters are letters. There will be one case per line in the input. The last line contains the word “\textbf{END}” and must not be processed. \OutputFile The output for each test case should have exactly one line, containing the number of arms or legs the bacterium will have, followed by the word “arms” or “legs” respectively (if the number is \textbf{1}, the words should be in singular). In case there will be neither arms nor legs, the program should print the word “none”.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
rkrk
abcdeABCDE
shcoOCfFHS
END
Çıxış verilənləri #1
1 arm
2 legs
none