String Stretching
Time limit1sMemory limit256 MB
Given a lowercase string up to length 200, find the shortest base string that builds it by repeated insertions anywhere, breaking ties alphabetically.
- Level
Medium7 of 10
- Topics
- Dynamic programming, String, Brute force
- Solved
- No attempts yet
Problem
Build a new string from a string like this. Begin with the empty string and insert . Then pick any position in the current string, including the very beginning and the very end, and insert there again. Repeat this as many times as you like.
Suppose is hello. Starting from the empty string, the string can grow like this, with the copy inserted at each step in bold.
- (the empty string)
- hello
- hhelloello
- hhelloelhellolo
- hhehellolloelhellolo
Four copies of hello went in, so the final string is hhehellolloelhellolo.
You are given the final string . Find the shortest string that could have produced it. If several strings of that length could have produced , find the one that comes first in alphabetical order.
Input
The first line contains the string . It consists of lowercase letters only, and its length is between 1 and 200.
Output
Print on the first line the shortest string that could have produced . If more than one string of that length works, print the one that comes first in alphabetical order.