CF408B.Garland

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn colored sheets of paper, the area of each sheet is 1 square meter.

The garland must consist of exactly mm 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 ​​ mm pieces of paper in the garland. Calculate what the maximum total area of ​​the pieces of paper in the garland Vasya can get.

输入格式

The first line contains a non-empty sequence of nn ( 1<=n<=10001<=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 mm ( 1<=m<=10001<=m<=1000 ) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make.

输出格式

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.

输入输出样例

  • 输入#1

    aaabbac
    aabbccac
    

    输出#1

    6
    
  • 输入#2

    a
    z
    

    输出#2

    -1

说明/提示

In the first test sample Vasya can make an garland of area 6: he can use both sheets of color bb , three (but not four) sheets of color aa and cut a single sheet of color cc 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 zz .

首页