This page is still under construction.

Parts of this page are still being built. What you see may change.

String Stretching

Time limit1sMemory limit256 MB

Summary
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 ss from a string pp like this. Begin with the empty string and insert pp. Then pick any position in the current string, including the very beginning and the very end, and insert pp there again. Repeat this as many times as you like.

Suppose pp is hello. Starting from the empty string, the string can grow like this, with the copy inserted at each step in bold.

  1. (the empty string)
  2. hello
  3. hhelloello
  4. hhelloelhellolo
  5. hhehellolloelhellolo

Four copies of hello went in, so the final string is hhehellolloelhellolo.

You are given the final string ss. Find the shortest string pp that could have produced it. If several strings of that length could have produced ss, find the one that comes first in alphabetical order.

Input

The first line contains the string ss. It consists of lowercase letters only, and its length is between 1 and 200.

Output

Print on the first line the shortest string pp that could have produced ss. If more than one string of that length works, print the one that comes first in alphabetical order.

Examples3

  1. Example 1

    Input
    hhehellolloelhellolo
    
    Expected output
    hello
    
  2. Example 2

    Input
    a
    
    Expected output
    a
    
  3. Example 3

    Input
    aabaabaa
    
    Expected output
    aaba