P2799 The King's Magic Mirror
Description
The king has a magic mirror that doubles anything touching its surface—only, because it is a mirror, the added part is reversed. For example, consider a necklace represented by AB, where different letters denote different colors of pearls. If the end B touches the mirror, the mirror turns the necklace into ABBA. If an end touches it again, it becomes ABBAABBA (assume the king always touches the mirror with one end of the necklace). Given the final necklace, write a program to output the minimal possible length of the original necklace before the mirror was used.
Input Format
A single string consisting of uppercase English letters (length $ \le 100000 $), representing the final necklace.
Output Format
A single integer, representing the minimal possible length of the original necklace before the king used the mirror.
Explanation/Hint
Translated by ChatGPT 5