100 atcoder#ABC138E. [ABC138E] Strings of Impurity

[ABC138E] Strings of Impurity

Score : 500500 points

Problem Statement

Given are two strings ss and tt consisting of lowercase English letters. Determine if there exists an integer ii satisfying the following condition, and find the minimum such ii if it exists.

  • Let ss' be the concatenation of 1010010^{100} copies of ss. tt is a subsequence of the string s1s2si{s'}_1{s'}_2\ldots{s'}_i (the first ii characters in ss').

Notes

  • A subsequence of a string aa is a string obtained by deleting zero or more characters from aa and concatenating the remaining characters without changing the relative order. For example, the subsequences of contest include net, c, and contest.

Constraints

  • 1s1051 \leq |s| \leq 10^5
  • 1t1051 \leq |t| \leq 10^5
  • ss and tt consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

ss

tt

Output

If there exists an integer ii satisfying the following condition, print the minimum such ii; otherwise, print -1.

contest
son
10

t=t = son is a subsequence of the string contestcon (the first 1010 characters in s=s' = contestcontestcontest...), so i=10i = 10 satisfies the condition.

On the other hand, tt is not a subsequence of the string contestco (the first 99 characters in ss'), so i=9i = 9 does not satisfy the condition.

Similarly, any integer less than 99 does not satisfy the condition, either. Thus, the minimum integer ii satisfying the condition is 1010.

contest
programming
-1

t=t = programming is not a substring of s=s' = contestcontestcontest.... Thus, there is no integer ii satisfying the condition.

contest
sentence
33

Note that the answer may not fit into a 3232-bit integer type, though we cannot put such a case here.