3841: Typewriter

内存限制:256 MB 时间限制:2.000 S
评测方式:文本比较 命题人:
提交:3 解决:1

题目描述

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.

输入

This problem contains multiple test cases. Process until the end of file.
For each test case, the first line contains string S (|S|≤2×10^5,∑|S|≤5×10^6), consisting of only lowercase Latin letters. And the second line contains 2 integers p and q (1≤p,q<2^31).

输出

For each test case, output one line containing the minimum number of coins Jerry needs to pay.

样例输入 复制

abc
1 2
aabaab
2 1

样例输出 复制

3
6

来源/分类