4376: 马哈茂德最长不公共子序列

内存限制:256 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:7 通过:6

题目描述

当马哈茂德和埃哈布为IOI做测试时,他们发现一个名叫最长公共子序列的问题。他们解决了这个问题,然后埃哈布用另一个问题挑战马哈茂德。

给定两个字符串ab,找出它们最长的不公共子序列的长度,这是其中一个字符串的子序列而不是另一个的子序列的最长字符串。

某些字符串的子序列是以相同顺序出现在字符串中的字符序列,其出现不必连续,例如,字符串“ac”,“bc”,“abc”和“a”是字符串“abc”的子序列,而字符串“abbc”“acb”则不是。空字符串是任何字符串的子序列。任何字符串都是其自身的子序列。

While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.

Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
Input
The first line contains string a, and the second line− string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
Output
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.
Examples
Input
abcd
defgh
Output
5
Input
a
a
Output
-1
Note
在第一个例子中:你可以从字符串 b 中选择“defgh”,因为它是字符串 b 的最长子序列,不会显示为字符串 a 的子序列。
In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.


输入格式

第一行包含字符串a,第二行包含字符串b。这两个字符串都是非空的,由英文字母的小写字母组成。每个字符串的长度不超过105次方个字符。

输出格式

如果没有不常见的子序列,请打印“-1”。否则,打印ab的最长不常见子序列的长度。

输入样例 复制

abcd
defgh

输出样例 复制

5