#P2799. Magic Mirror Necklace
Magic Mirror Necklace
Magic Mirror Necklace
The king possesses a magic mirror that has the peculiar property of doubling anything that touches its surface. More precisely, when one end of a necklace is placed against the mirror, the mirror produces a new necklace by appending the reverse of the original sequence. Formally, if the original necklace is represented as a string \(S\), then after a mirror operation the necklace becomes \(f(S) = S + \text{reverse}(S)\). For example, if \(S = \texttt{AB}\), then \(f(S) = \texttt{ABBA}\). If the mirror is used again on one end of the new necklace, the process continues (e.g., \(f(\texttt{ABBA}) = \texttt{ABBAABBA}\)).
Given the final necklace string, your task is to determine the minimum possible length of the original necklace \(S\) such that by applying zero or more mirror operations, the final necklace is obtained. Note that if the mirror was never used, the final necklace is identical to the original.
Hint: Repeatedly check if the given necklace can be expressed in the form \(T = A + \text{reverse}(A)\) (where \(|A| = |T|/2\)). If so, then it is possible that \(T\) was produced by a mirror operation. Continue this process until it is no longer possible.
inputFormat
The input consists of a single line containing a non-empty string which represents the final necklace. The string consists of uppercase English letters and its length does not exceed 105.
outputFormat
Output a single integer corresponding to the minimum possible length of the original necklace before any mirror operations were applied.
sample
ABBA
2