Under construction

Still being built. Things may change

String Product

Time limit4sMemory limit256 MB

Summary
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 f(c)f(c) be the 00-based alphabetic number of a small English letter cc, so f(‘a‘)=0f(`a`) = 0, f(‘b‘)=1f(`b`) = 1, …\ldots, f(‘z‘)=25f(`z`) = 25. The product s×ts \times t of two strings s=s0…sn−1s = s_0 \ldots s_{n - 1} and t=t0…tm−1t = t_0 \ldots t_{m - 1} is the string u=u0…unm−1u = u_0 \ldots u_{nm - 1} where f(uj⋅n+i)=(f(si)+f(tj)) mod 26f(u_{j \cdot n + i}) = (f(s_i) + f(t_j)) \bmod 26 for all i=0,…,n−1i = 0, \ldots, n - 1 and j=0,…,m−1j = 0, \ldots, m - 1. For example, ‘abc‘בde‘=‘defefg‘`abc` \times `de` = `defefg`, ‘de‘בabc‘=‘deeffg‘`de` \times `abc` = `deeffg`, ‘xy‘בyz‘=‘vwwx‘`xy` \times `yz` = `vwwx`.

You are given a string ss. Find two strings aa and bb such that a×b=sa \times b = s. If several pairs (a,b)(a, b) work, find the one for which the string a+ba + b (++ means concatenation) is lexicographically smallest. If several such pairs remain, find the one with the smallest length of aa.

Input

The only line of the input contains the string ss of small English letters (1≤∣s∣≤1061 \le |s| \le 10^6).

Output

If no two strings a,ba, b satisfy a×b=sa \times b = s, print −1-1. Otherwise, print aa and bb separated by a space. Among all suitable pairs (a,b)(a, b), a+ba+b must be lexicographically smallest. If several pairs tie, ∣a∣|a| must be smallest possible.

Examples2

  1. Example 1

    Input
    ddbb
    
    Expected output
    aa db
    
  2. Example 2

    Input
    eefbbcccdddeaabaab
    
    Expected output
    aab ebcdaa