#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 bb pieces of bread, ss sausages, and cc pieces of cheese. If ingredients are insufficient, you can buy them at the supermarket: each piece of bread costs BB yuan, each sausage costs SS yuan, and each piece of cheese costs CC yuan. You have moneymoney yuan in total.

Find the maximum number of burgers you can make.

Input Format

The first line contains a string ss, the recipe.

The second line contains three integers b,s,cb, s, c, the current ingredient counts in the kitchen.

The third line contains three integers B,S,CB, S, C, the unit prices of the three ingredients at the supermarket.

The fourth line contains an integer moneymoney, 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

Constraints

  • ∣s∣≤100|s|\le 100
  • 0≤b,s,c≤1000\le b,s,c\le 100
  • 0≤B,S,C≤1000\le B,S,C\le 100
  • 0≤money≤10120\le money\le 10^{12}