{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\n 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.\n \u003cbr\u003eJerry 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.\u003cbr\u003e\n你要打印一段字符串,往尾部添加一个字符需要花费p元,复制一段字符到尾部需要花费q元,求打印完全部字符的最小花费。\n\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"This problem contains multiple test cases. Process until the end of file.\n\u003cbr\u003eFor each test case, the first line contains string $S$ ($|S| \\le 2 \\times 10 ^ 5, \\sum |S| \\leq 5\\times 10 ^ 6$), consisting of only lowercase Latin letters. And the second line contains $2$ integers $p$ and $q$ ($1 \\leq p,q \u0026lt; 2^{31}$)."}},{"title":"Output","value":{"format":"HTML","content":"For each test case, output one line containing the minimum number of coins Jerry needs to pay."}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003eabc\n1 2\naabaab\n2 1\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e3\n6\u003c/pre\u003e"}}]}