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.
# hamburger_constituent 汉堡成分
hc = input()
# BSC_count 一份汉堡中所需不同材料数量
bc = [hc.count('B'), hc.count('S'), hc.count('C')]
# BSC_number 蟹老板给的材料数量
bn = list(map(int, input().split()))
# BSC_price 每种材料的单价
bp = list(map(int, input().split()))
# money 蟹老板给的钱
money = int(input())
# hamburger_number 做出来的汉堡数量
hn = 0

# 如果汉堡不需要某个成分，就不要蟹老板给的这种材料
for i in range(len(bc)):
    bn[i] = bn[i] if bc[i] else 0

# 判断现有材料能做多少份汉堡
while(bn[0]+bn[1]+bn[2]):
    # 依次查看三种材料能否凑出一份汉堡
    for i in range(len(bc)):
        # 如果材料够，就直接扣除一份的量；如果不够，就花钱补足一份；
        if (bn[i] >= bc[i]):
            bn[i] -= bc[i]
        else:
            money -= ((bc[i] - bn[i]) * bp[i])
            bn[i] = 0
    # 这份做完了如果没欠钱，说明这个汉堡可以吃；如果欠钱了，就不可以吃它，并且不用再做了。
    if money >= 0:
        hn += 1
    else:
        break

# 现有材料用完后还剩了钱，就用每份汉堡的价格除余额，算还能做多少份；如果没钱了，就不做了。
if money > 0:
    hn += (money // (bc[0]*bp[0] + bc[1]*bp[1] + bc[2]*bp[2]))

# 输出已做汉堡数量
print(hn)

	   	  	    	      			 	  	 	 	