Under construction

Still being built. Things may change

Quilindrome (Hard)

Time limit1sMemory limit512 MB

Summary
Given nickname S, print the shortest palindrome that contains S as a substring, where letter case may change and characters pair by the mirror table, or -1.
Level

Medium7 of 10

Topics
String matching, String
Solved
No attempts yet

Problem

Apart from the input limits, the difficulty level makes no difference to this problem.

After a long think, Sangmin came up with a great nickname, "qilip". Oh, a palindrome!.. he thought, but...

For this nickname to be a palindrome, it would have to read "qilip" when read backward too. Read backward, it becomes "piliq", so the nickname is not a palindrome. A string that looks like a perfect mirror image around its center is called a "quilindrome". For example, "dad" is a palindrome but not a quilindrome, and "mom" is both. Everyone wants a quilindrome nickname.

Daeyoung: Sangmin, make my nickname a quilindrome too!

Sangmin: What's your nickname?

Daeyoung: dy2000

Sangmin: dY2000SYb

Daeyoung: !

Sangmin has been swamped with requests for great quilindrome nicknames, and it is making his daily life hard. A great quilindrome nickname is a palindrome that contains the original nickname as a substring. In other words, if you trim both ends of a great quilindrome nickname, you get the original nickname. Everyone is obsessed with quilindromes, so as long as a quilindrome can be made, changing letter case is fine. For example, "yoy" is not a quilindrome, but "YoY" with the capitals changed is, so people are happy with it.

Write a program that builds the shortest great quilindrome nickname for Sangmin. Special rule: a character that is its own mirror image may be placed at the center of an odd-length quilindrome.

The mirror table Sangmin made, which is not exact but "good enough", is below.

OriginalMirrorOriginalMirrorOriginalMirrorOriginalMirrorOriginalMirror
AANann00
BOObdoo11
CPcpq2S
DQdbqp3E
E3Rer74
FS2fs5Z
GTTgt6
HHUUhuu7r
IIVViivv88
JWWjww9
KXXkxx
LYYlly
MMZ5mmz

Input

The first line contains the original nickname SS.

Output

Print the shortest great quilindrome nickname. If no great quilindrome nickname can be made, print "-1".

Constraints

∣S∣≤1,000,000|S| \le 1,000,000

Examples3

  1. Example 1

    Input
    qilip
    
    Expected output
    qilip
    
  2. Example 2

    Input
    dy2000
    
    Expected output
    dY2000SYb
    
  3. Example 3

    Input
    7owo
    
    Expected output
    7owor