#d2962. 汉堡制作
汉堡制作
Burger Making
Problem Description
A burger recipe is a string made of characters B, S, C, indicating the ingredients needed for a burger from bottom to top: B for bread, S for sausage, and C for cheese. A burger must be made exactly according to the recipe's ingredient counts — not one more, not one less.
The kitchen currently has pieces of bread, sausages, and pieces of cheese. If ingredients are insufficient, you can buy them at the supermarket: each piece of bread costs yuan, each sausage costs yuan, and each piece of cheese costs yuan. You have yuan in total.
Find the maximum number of burgers you can make.
Input Format
The first line contains a string , the recipe.
The second line contains three integers , the current ingredient counts in the kitchen.
The third line contains three integers , the unit prices of the three ingredients at the supermarket.
The fourth line contains an integer , the amount of money available.
Output Format
Output one integer, the maximum number of burgers that can be made.
Sample Input
BBBSSC
6 4 1
1 2 3
4
Sample Output
2