Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again.

Polycarpus has *n*<sub class="lower-index">*b*</sub> pieces of bread, *n*<sub class="lower-index">*s*</sub> pieces of sausage and *n*<sub class="lower-index">*c*</sub> pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are *p*<sub class="lower-index">*b*</sub> rubles for a piece of bread, *p*<sub class="lower-index">*s*</sub> for a piece of sausage and *p*<sub class="lower-index">*c*</sub> for a piece of cheese.

Polycarpus has *r* rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient.
The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).

The second line contains three integers *n*<sub class="lower-index">*b*</sub>, *n*<sub class="lower-index">*s*</sub>, *n*<sub class="lower-index">*c*</sub> (1 ≤ *n*<sub class="lower-index">*b*</sub>, *n*<sub class="lower-index">*s*</sub>, *n*<sub class="lower-index">*c*</sub> ≤ 100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers *p*<sub class="lower-index">*b*</sub>, *p*<sub class="lower-index">*s*</sub>, *p*<sub class="lower-index">*c*</sub> (1 ≤ *p*<sub class="lower-index">*b*</sub>, *p*<sub class="lower-index">*s*</sub>, *p*<sub class="lower-index">*c*</sub> ≤ 100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer *r* (1 ≤ *r* ≤ 10<sup class="upper-index">12</sup>) — the number of rubles Polycarpus has.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
# Read the input from the user
ingredients = input()
In_kitchen = input()
prices = input()
money = int(input())


def str2int(x):
    for i in range(len(x)):
        x[i] = int(x[i])
    return x


# preprocessing the input to meet our data formats
In_kitchen = In_kitchen.split()
In_kitchen = str2int(In_kitchen)

prices = prices.split()
prices = str2int(prices)

recipe_in_list = [ingredients.count('B'), ingredients.count('S'),
                  ingredients.count('C')]  # number of each ingredient in recipe

recipe_total_cost = recipe_in_list[0] * prices[0] + recipe_in_list[1] * prices[1] + recipe_in_list[2] * prices[
    2]  # Total cost of the recipe

# Calculating if the money can provide a number of recipes(burgers).
number_of_burgers = 0

number_of_burgers = money // recipe_total_cost
if number_of_burgers > 0: money = money - recipe_total_cost * number_of_burgers

# Deleting all zero ingredients on the recipe and the coressponding values to them.
indices_of_zeros = [i for i, e in enumerate(recipe_in_list) if e == 0]
indices_of_zeros = indices_of_zeros[::-1]
for i in indices_of_zeros:
    del In_kitchen[i]
    del recipe_in_list[i]
    del prices[i]

# Checking if the ingredients in the kitchen can make a number of recipes(burgers).
inKitchen_over_recipe = [b // m for b, m in zip(In_kitchen, recipe_in_list)]

if (sum([1 for i in inKitchen_over_recipe if i >= 1])) == len(inKitchen_over_recipe):
    number_of_burgers = number_of_burgers + min(inKitchen_over_recipe)
    temp = [min(inKitchen_over_recipe) * i for i in recipe_in_list]
    In_kitchen = [a - b for a, b in zip(In_kitchen, temp)]


# Functions to loop over the rest of ingradients in the kitchen and the money to see if we can provide another recipie(burger).
def makeBurger():  # This one is to make another recipie in the kitchen after providing the missing ingradients from the shop.
    global number_of_burgers, In_kitchen, recipe_in_list
    number_of_burgers += 1
    In_kitchen = [a - b for a, b in zip(In_kitchen, recipe_in_list)]
    shop()


def shop():  # This one is to check if any ingredient is missing in the kitchen and is affordable to buy it.
    # Check the ingredients one by one.
    global money, In_kitchen, recipe_in_list
    for i in range(len(In_kitchen)):
        if (In_kitchen[i] < recipe_in_list[i]):
            difference = recipe_in_list[i] - In_kitchen[i]
            money = money - difference * prices[i]
            if money >= 0:
                In_kitchen[i] = recipe_in_list[i]
            else:
                return
    makeBurger()


# This if statement is to check if we even have any money to go to the shop and start the loop of just print the number of burgers
if money > 0:
    shop()
    print(number_of_burgers)
else:
    print(number_of_burgers)