Carlo’s Library

Time limit: 0.2s Memory limit: 64MB Input: Output:

Carlo loves organizing his library and has arranged all books in lexicographical order. To enhance their appearance, he wants to insert a new book between two existing titles. The two titles, AA and BB, are given as strings containing only lowercase letters of the English alphabet.

Task

Your task is to help Carlo find a title CC, also consisting of only lowercase letters of the English alphabet for the new book such that:

  • CC is lexicographically strictly between AA and BB.
  • The length of CC is minimized.

Help Carlo find a title CC satisfying these requirements, or determine that it doesn't exist.

Input data

The input file consists of:

  • a line containing string AA.
  • a line containing string BB.

Output data

The output file must contain a single line consisting of string CC or -1 if it doesn't exist. If there is more than one correct answer, you can print any.

Constraints and clarifications

  • 1len(A),len(B)1 000 0001 \le \text{len}(A), \text{len}(B) \le 1 \ 000 \ 000
  • A<BA < B lexicographically.
  • AA and BB contain only lowercase letters of the English alphabet.
# Points Constraints
1 0 Examples
2 15 len(A)=len(B)\text{len}(A) = \text{len}(B)
3 15 AA and BB contain only vowels.
4 30 len(A),len(B)1 000\text{len}(A), \text{len}(B) \le 1 \ 000
5 40 No additional constraints.

Example 1

stdin

abc
abca

stdout

-1

Explanation

There is no title CC that satisfies the constraints.

Example 2

stdin

abc
def

stdout

c

Explanation

We have that abc << c << def, and there is no shorter title CC that satisfies the constraints.

Note that C=C = b or C=C = d are strings of length 11 which satisfy the constraints and are, therefore, accepted by the checker.

Example 3

stdin

pcn
pk

stdout

pf

Example 4

stdin

mppxtzmo
mppxu

stdout

mppxtzz

Example 5

stdin

abc
abcaa

stdout

abca

Log in or sign up to be able to send submissions!