Nowadays, our senior is typewriting an article for her graduation. But as you know our senior is foolish sometimes, so she needs your help. You can assume senior’s article is a string, and senior’s typewriter provides two operations to typewrite it:
1) Assume you have typewritten a string s, then you can add a character after s, and the cost of adding each character is given to you.
2) Assume you have typewritten a string s, you can select a substring of s and copy it, then you can paste it after s once. The cost to select a character is A,and the cost to copy and paste a string are all equal B.
Now, you should help senior to typewrite the article by using the minimum cost, can you help her?