#abc138e. [abc138_e]Strings of Impurity
[abc138_e]Strings of Impurity
Problem Statement
Given are two strings and consisting of lowercase English letters. Determine if there exists an integer satisfying the following condition, and find the minimum such if it exists.
- Let be the concatenation of copies of . is a subsequence of the string (the first characters in ).
Notes
- A subsequence of a string is a string obtained by deleting zero or more characters from and concatenating the remaining characters without changing the relative order. For example, the subsequences of
contest
includenet
,c
, andcontest
.
Constraints
- and consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
Output
If there exists an integer satisfying the following condition, print the minimum such ; otherwise, print -1
.
Sample Input 1
contest
son
Sample Output 1
10
son
is a subsequence of the string contestcon
(the first characters in contestcontestcontest...
), so satisfies the condition.
On the other hand, is not a subsequence of the string contestco
(the first characters in ), so does not satisfy the condition.
Similarly, any integer less than does not satisfy the condition, either. Thus, the minimum integer satisfying the condition is .
Sample Input 2
contest
programming
Sample Output 2
-1
programming
is not a substring of contestcontestcontest...
. Thus, there is no integer satisfying the condition.
Sample Input 3
contest
sentence
Sample Output 3
33
Note that the answer may not fit into a -bit integer type, though we cannot put such a case here.