#P15187. [SWERC 2019] Gnalcats

[SWERC 2019] Gnalcats

题目描述

Researchers have discovered a new form of life they have named Gnalcats. Gnalcats have a very strange form of DNA and proteins but the researchers have understood how they work. They are now trying to classify species of Gnalcats by comparing their DNA.

A gene of their DNA is a sequence of bases. These genes operate on proteins, which are extremely long chains of amino-acids (abca - b - c - \ldots). Amino-acids are either simple or complex (composed of two other amino-acids). Proteins always contain several billions of amino-acids.

Genes operate on proteins in the following way: the seven different bases (C, D, L, P, R, S, U) correspond to different transformations on the protein. The result of the operation of a gene on a protein is obtained as the combination of the individual transformations by each base of the gene: the first base of the gene transforms the input protein, the resulting protein is then transformed according to the second base of the gene, and so on. Life is not perfect and thus one of these transformations may fail, in which case the overall transformation fails. If, at any point in the transformation, the protein is reduced to a chain of three or fewer amino-acids (simple or complex) then the transformation fails.

The effect of each base is described in the following table where XX denotes the tail of the protein, while aa, bb, and cc are amino-acids (either simple or complex):

base input protein output protein
C aXa - X aaXa - a - X
D XX
L $\begin{cases} b - X & \text{if } a \text{ is the complex amino-acid } (b,c) \\ \text{fail} & \text{if } a \text{ is a simple amino-acid} \end{cases}$
P abXa - b - X cXc - X where cc is the complex amino-acid (a,b)(a,b)
R aXa - X $\begin{cases} c - X & \text{if } a \text{ is the complex amino-acid } (b,c) \\ \text{fail} & \text{if } a \text{ is a simple amino-acid} \end{cases}$
S abXa - b - X baXb - a - X
U aXa - X $\begin{cases} b - c - X & \text{if } a \text{ is the complex amino-acid } (b,c) \\ \text{fail} & \text{if } a \text{ is a simple amino-acid} \end{cases}$

For example, the gene PSDPCRPSDUL transforms a protein like this:

  • the input protein is abcdefa - b - c - d - e - f - \ldots
  • then applying the rule for the first P produces: (a,b)cdef(a,b) - c - d - e - f - \ldots
  • then applying the rule for S produces: c(a,b)defc - (a,b) - d - e - f - \ldots
  • then D gives: (a,b)def(a,b) - d - e - f - \ldots
  • then S gives: d(a,b)efd - (a,b) - e - f - \ldots
  • then P gives: (d,(a,b))ef(d, (a,b)) - e - f - \ldots
  • then C gives: (d,(a,b))(d,(a,b))ef(d, (a,b)) - (d, (a,b)) - e - f - \ldots
  • then R gives: (a,b)(d,(a,b))ef(a,b) - (d, (a,b)) - e - f - \ldots
  • then P gives: ((a,b),(d,(a,b)))ef((a,b), (d, (a,b))) - e - f - \ldots
  • then S gives: e((a,b),(d,(a,b)))fe - ((a,b), (d, (a,b))) - f - \ldots
  • then D gives: ((a,b),(d,(a,b)))f((a,b), (d, (a,b))) - f - \ldots
  • then U gives: (a,b)(d,(a,b))f(a,b) - (d, (a,b)) - f - \ldots
  • and finally L gives: a(d,(a,b))fa - (d, (a,b)) - f - \ldots

You are given two genes, and you must decide whether they are equivalent. Two genes are equivalent if for every input protein composed of at least one billion of simple amino-acids, either the application of both genes produces the same output protein, or both applications fail.

输入格式

The input consists of two lines, each representing a Gnalcats gene.

输出格式

The output consists of a single word: "True" if the genes are equivalent, "False" otherwise.

PU
SS
True
L
R
True
PSPCRSL
PS
True
U
C
False
PL
PR
False

提示

Sample Explanation 1

These genes do nothing: they always transforms a protein into the exact same protein.

Sample Explanation 2

These genes always fail because both L and R bases fail on simple amino acids.

Limits

Each gene contains at least one base. The sum of the length of input genes is not greater than 10410^4.