

Time Limit: 2 sec / Memory Limit: 256 MB
Score : points
Problem Statement
Shik's job is very boring. At day , his boss gives him a string of length which consists of only lowercase English letters. In the -th day after day , Shik's job is to copy the string to a string . We denote the -th letter of as .
Shik is inexperienced in this job. In each day, when he is copying letters one by one from the first letter to the last letter, he would make mistakes. That is, he sometimes accidentally writes down the same letter that he wrote previously instead of the correct one. More specifically, is equal to either or . (Note that always equals to .)
You are given the string and another string .
Please determine the smallest integer such that could be equal to . If no such exists, please print -1
.
Constraints
- The lengths of and are both .
- Both and consist of lowercase English letters.
Input
The input is given from Standard Input in the following format:
Output
Print the smallest integer such that could be equal to . If no such exists, print -1
instead.
Sample Input 1Copy
5 abcde aaacc
Sample Output 1Copy
2
= abcde
, = aaccc
and = aaacc
is a possible sequence such that .
Sample Input 2Copy
5 abcde abcde
Sample Output 2Copy
0
Sample Input 3Copy
4 acaa aaca
Sample Output 3Copy
2
Sample Input 4Copy
5 abcde bbbbb
Sample Output 4Copy
-1
配点 : 点
問題文
シックの仕事はコピー取りです。ある日、シックは上司から英小文字からなる長さ の文字列 を受け取りました(この日を 日目とします)。これ以降、 日目の仕事は、文字列 を にコピーすることです。以下、 の 番目の文字を と表します。
シックはまだこの仕事に慣れていません。毎日、文字列を先頭の文字から順に書き写していくのですが、正しい文字の代わりに誤って直前に書いた文字と同じ文字を書いてしまうことがあります。すなわち、 は または のどちらかと等しくなります。(ただし、文字列の先頭の文字を書き間違えることはありません。すなわち、 は必ず と等しくなります。)
二つの文字列 と が与えられます。 が と等しくなる可能性があるような最小の整数 を求めてください。もしそのような が存在しなければ、代わりに -1
と答えてください。
制約
- と の長さはともに である。
- と はともに英小文字のみからなる。
入力
入力は以下の形式で標準入力から与えられる。
出力
が と等しくなる可能性のあるような が存在するならば、そのような のうち最小のものを出力せよ。そのような が存在しなければ、代わりに -1
と出力せよ。
入力例 1Copy
5 abcde aaacc
出力例 1Copy
2
= abcde
, = aaccc
, = aaacc
のように、 となる可能性が存在します。
入力例 2Copy
5 abcde abcde
出力例 2Copy
0
入力例 3Copy
4 acaa aaca
出力例 3Copy
2
入力例 4Copy
5 abcde bbbbb
出力例 4Copy
-1