100 atcoder#ABC138E. [ABC138E] Strings of Impurity
[ABC138E] Strings of Impurity
Score : points
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
.
contest
son
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 .
contest
programming
-1
programming
is not a substring of contestcontestcontest...
. Thus, there is no integer satisfying the condition.
contest
sentence
33
Note that the answer may not fit into a -bit integer type, though we cannot put such a case here.