410785: GYM104114 A AppendAppendAppend

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. AppendAppendAppendtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Momo has a string $$$s$$$ which he plays with. After each day, he takes the initial string and appends it to the one that he currently has, that is, if the string is "$$$abc$$$", on the first day the string will remain "$$$abc$$$", on the second day the string will become "$$$abcabc$$$", on the third day the string becomes "$$$abcabcabc$$$", and so on.

Bobo has another string $$$t$$$. Bobo is curious whether his string $$$t$$$ can be found as a subsequence in Momo's string. He is curious what is the first day when this property will hold.

A string $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements.

Input

The first line of the input contains Momo's string $$$s$$$.

The second line of the input contains Bobo's string $$$t$$$.

Both strings have lengths at least $$$1$$$ and at most $$$5\cdot 10^5$$$ and contain only lowercase letters of the English alphabet.

Output

Output a single integer  — the number of the day when Bobo's string will be a subsequence of Momo's string for the first time.

It is guaranteed that for all test cases in this problem such a day exists.

ExampleInput
dwalkcake
cakewalk
Output
2
Note

During the first day, the string is "$$$dwalkcake$$$", and doesn't contain "$$$cakewalk$$$" as a subsequence.

During the second day, the string is "$$$dwalkcakedwalkcake$$$", and it contains "$$$cakewalk$$$" as a subsequence.

加入题单

上一题 下一题 算法标签: