#arc154b. [arc154_b]New Place
[arc154_b]New Place
Problem Statement
You are given strings and of length consisting of lowercase English letters.
You can repeat the following operation any number of times (possibly zero).
- Erase the first character of and insert the same character at any position of .
Determine whether it is possible to make equal , and if it is possible, find the minimum number of operations needed.
Constraints
- and are strings of length consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
Output
If it is impossible to make equal , print -1
. If it is possible, print the minimum number of operations needed.
Sample Input 1
4
abab
abba
Sample Output 1
2
You can make equal in two operations, as follows.
- Erase the first character of , and insert that character
a
at the end of , makingbaba
. - Erase the first character of , and insert that character
b
between the -nd and -rd characters of , makingabba
.
It is impossible to make equal in one or fewer operations, so the answer is .
Sample Input 2
3
arc
cra
Sample Output 2
2