Codeforces Round 239 (Div. 2)
B
Garland
Codeforces
1200
原题
← AC →
翻译中…

Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought $*n*$ colored sheets of paper, the area of each sheet is 1 square meter.

翻译中…

The garland must consist of exactly $*m*$ pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland.

翻译中…

Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of ​​$*m*$ pieces of paper in the garland. Calculate what the maximum total area of ​​the pieces of paper in the garland Vasya can get.

翻译中…

Input

翻译中…

The first line contains a non-empty sequence of $*n*$ ($1 ≤ *n* ≤ 1000$) small English letters ("a"$...$"z"). Each letter means that Vasya has a sheet of paper of the corresponding color.

翻译中…

The second line contains a non-empty sequence of $*m*$ ($1 ≤ *m* ≤ 1000$) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make.

翻译中…

Output

翻译中…

Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.

翻译中…

Note

翻译中…

In the first test sample Vasya can make an garland of area 6: he can use both sheets of color $*b*$, three (but not four) sheets of color $*a*$ and cut a single sheet of color $*c*$ in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.

翻译中…

In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color $*z*$.

翻译中…

样例

Input #1
aaabbac
aabbccac
Output #1
6
InputCopy OutputCopy
Input #2
a
z
Output #2
-1
InputCopy OutputCopy
题目信息
题号
408B
时间限制
1 s
内存限制
256 MB
标签
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。