Split each of two short strings into two non-overlapping contiguous pieces so that A+C equals B+D, and output the lexicographically smallest longest result.
Hard8StringBrute forceDynamic programmingNo attempts yetTime limit2sMemory limit512 MBKangho and Junkyu closed the stores they used to run on their own and opened a new store together.
Today they want to decide the name of the new store. Each of them still keeps the signboard of the old store, and they want to build the new name by cutting those signboards. The procedure is the following. Uppercase and lowercase letters count as different letters.
Given the string X written on Kangho's signboard and the string Y written on Junkyu's signboard, write a program that finds the longest possible name of the new store. If several names share the longest length, choose the one that comes first in lexicographic order. Lexicographic order follows ASCII codes, so every uppercase letter comes before every lowercase letter.
The first line contains the string X of Kangho and the string Y of Junkyu, separated by one space. The length of each string is between 1 and 47, and both consist only of uppercase and lowercase letters.
Print the longest possible name of the new store. If several names share the longest length, print the one that comes first in lexicographic order.
If no name is possible, print -1.