luogu#P3102. [USACO14FEB] Secret Code S

[USACO14FEB] Secret Code S

Problem Description

Farmer John has secret message that he wants to hide from his cows; the message is a string of length at least 22 containing only the characters A..Z\texttt A..\texttt Z.

To encrypt his message, FJ applies a sequence of "operations" to it, where an operation applied to a string SS first shortens SS by removing either some (but not all) of the initial characters or some (but not all) of the final characters from SS, after which the original string SS is attached either at the beginning or end. For example, a single operation to the string ABC\texttt{ABC} could result in eight possible strings:

$$\texttt{AABC}, \texttt{ABABC}, \texttt{BCABC}, \texttt{CABC}, \texttt{ABCA}, \texttt{ABCAB}, \texttt{ABCBC}, \texttt{ABCC}$$

Given the final encrypted string, please count the number of possible ways FJ could have produced this string using one or more repeated operations applied to some source string. Operations are treated as being distinct even if they give the same encryption of FJ's message. For example, there are four distinct separate ways to obtain AAA\texttt{AAA} from AA\texttt{AA}.

Print your answer out modulo 20142014.

Input Format

  • Line 11: A single encrypted string of length at most 100100.

Output Format

  • Line 11: The number of ways FJ could have produced this string with one or more successive operations applied to some initial string of length at least 22, written out modulo 20142014. If there are no such ways, output zero.
ABABA 

8 

Hint

Here are the different ways FJ could have produced ABABA\texttt{ABABA}:

  1. Start with ABAAB+ABA\texttt{ABA} \to \texttt{AB}+\texttt{ABA}

  2. Start with ABAABA+BA\texttt{ABA} \to \texttt{ABA}+\texttt{BA}

  3. Start with $\texttt{AB} \to \texttt{AB}+\texttt{A} \to \texttt{AB}+\texttt{ABA}$

  4. Start with $\texttt{AB} \to \texttt{AB}+\texttt{A} \to \texttt{ABA}+\texttt{BA}$

  5. Start with $\texttt{BA} \to \texttt{A}+\texttt{BA} \to \texttt{AB}+\texttt{ABA}$

  6. Start with $\texttt{BA} \to \texttt{A}+\texttt{BA} \to \texttt{ABA}+\texttt{BA}$

  7. Start with ABABABAB+A\texttt{ABAB} \to \texttt{ABAB}+\texttt{A}

  8. Start with BABAA+BABA\texttt{BABA} \to \texttt{A}+\texttt{BABA}