跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F0622. Newspaper Headline

    ID: 628 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 4 上传者: 标签>贪心字符串算法思想进阶难度共享题库Codeforces英文题面题目来源题面语言

Newspaper Headline

题目描述

A. Newspaper Headline
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A newspaper is published in Walrusland. Its heading is s1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. After that walrus erase several letters from this string in order to get a new word s2. It is considered that when Fangy erases some letter, there's no whitespace formed instead of the letter. That is, the string remains unbroken and it still only consists of lowercase Latin letters.

For example, the heading is "abc". If we take two such headings and glue them one to the other one, we get "abcabc". If we erase the letters on positions 1 and 5, we get a word "bcac".

Which least number of newspaper headings s1 will Fangy need to glue them, erase several letters and get word s2?

Input

The input data contain two lines. The first line contain the heading s1, the second line contains the word s2. The lines only consist of lowercase Latin letters (1≤|s1|≤104,1≤|s2|≤106).

Output

If it is impossible to get the word s2 in the above-described manner, print "-1" (without the quotes). Otherwise, print the least number of newspaper headings s1, which Fangy will need to receive the word s2.

Examples
Input
abc
xyz
Output
-1
Input
abcd
dabc
Output
2

题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 29 题。保留原作者与原赛事署名。