Typewriter
题号:NC237664
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

One day, Jerry found a strange typewriter. This typewriter has 2 input modes: pay p coins to append an arbitrary single letter to the back, or q coins to copy a substring that has already been outputted and paste it in the back.
Jerry now wants to write a letter to Tom. The letter is a string S which contains only lowercase Latin letters. But as Jerry is not very wealthy, he wants to know the minimum number of coins he needs to write this letter.

输入描述:

The first line contains string  which contains only lowercase Latin letters.
The second line contains 2 integers p and

输出描述:

Output one line containing the minimum number of coins Jerry needs to pay.
示例1

输入

复制
abc
1 2

输出

复制
3
示例2

输入

复制
aabaab
2 1

输出

复制
6

备注:

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=6583