Multigram


Submit solution


Points: 100 (partial)
Time limit: 1.0s
Python 2 4.0s
Memory limit: 64M
Python 2 128M

Authors:
Problem type
Allowed languages
Ada, BrainF***, C#, C++, Dart, Go, Java, JS, Kotlin, Lua, Pascal, Prolog, Python, Swift, VB

Pedro is a passionate lover of riddles. The newest type of riddles he has come across requires the solver to check whether the given word is a multigram.

A multigram is a word that consists of concatenating two or more words that are all mutually anagrams. The first of these words is called the root of the multigram. For instance, the word bbabab is a multigram with the root bba because it consists of anagrams bba and bab.

Help Pero solve the riddle by determining whether his word is a multigram and determining its root in case it is. If there are multiple possible roots of the multigram, output the shortest. Please note: Two words are mutually anagrams if one of them can be obtained from the other by changing the letter order.

INPUT

The first and only line of input contains a word of length at most 100 000 lowercase English characters.

OUTPUT

If the given word is not a multigram, output -1. Otherwise, output the shortest root of the given word in one line.

Sample

Input 1

aaaa

Output 1

a

Input 2

ab

Output 2

-1

Input 3

bbabab

Output 3

bba

Clarification of the first example: Notice that the word “aa” could also be the root, but “a” is shorter.

Clarification of the second example: The word is not a multigram because “a” and “b” are not mutually anagrams.


Comments


  • -7
    Osnielfc_07  commented on Sept. 16, 2020, 2:33 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -13
    Primervirgen  commented on Aug. 4, 2019, 6:04 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.