String Product
Time limit4sMemory limit256 MB
Given a string s, find strings a and b with a times b equal to s (letters add mod 26), minimizing a+b lexicographically, then minimizing |a|.
- Level
Hard8 of 10
- Topics
- String, Math, Number theory, Brute force
- Solved
- No attempts yet
Problem
Let be the -based alphabetic number of a small English letter , so , , , . The product of two strings and is the string where for all and . For example, , , .
You are given a string . Find two strings and such that . If several pairs work, find the one for which the string ( means concatenation) is lexicographically smallest. If several such pairs remain, find the one with the smallest length of .
Input
The only line of the input contains the string of small English letters ().
Output
If no two strings satisfy , print . Otherwise, print and separated by a space. Among all suitable pairs , must be lexicographically smallest. If several pairs tie, must be smallest possible.