#include <bits/stdc++.h>
using namespace std;
int main() {
  string recipe;
  cin >> recipe;
  int n_b, n_s, n_c, p_b, p_s, p_c;
  long long money;
  cin >> n_b >> n_s >> n_c >> p_b >> p_s >> p_c;
  cin >> money;
  int arr[3];
  int price[3];
  int available[3];
  price[0] = p_b;
  price[1] = p_s;
  price[2] = p_c;
  available[0] = n_b;
  available[1] = n_s;
  available[2] = n_c;
  memset(arr, 0, sizeof(arr));
  for (int i = 0; i < recipe.size(); i++) {
    if (recipe[i] == 'B') {
      arr[0]++;
    } else if (recipe[i] == 'S') {
      arr[1]++;
    } else {
      arr[2]++;
    }
  }
  for (int i = 0; i < 3; i++) {
    if (arr[i] == 0) {
      price[i] == 0;
      available[i] = 0;
    }
  }
  bool flag = false;
  long long num = 0;
  while (!flag & money >= 0) {
    for (int i = 0; i < 3; i++) {
      if (available[i] <= arr[i]) {
        long long val = (arr[i] - available[i]);
        val *= price[i];
        money -= val;
        available[i] = 0;
      } else {
        available[i] -= arr[i];
      }
    }
    if (money >= 0) {
      num++;
    }
    if (available[0] == 0 & available[1] == 0 & available[2] == 0) {
      flag = true;
    }
  }
  long long val;
  val = price[0] * arr[0] + price[1] * arr[1] + price[2] * arr[2];
  if (money < val) {
    cout << num;
  } else {
    long long temp_ans;
    long long start = 0;
    long long end = 1e13;
    long long mid;
    long long temp;
    while (start <= end) {
      mid = start + (end - start) / 2;
      temp = (long long)(money - (long long)mid * val);
      if (temp >= 0) {
        temp_ans = mid;
        start = mid + 1;
      } else {
        end = mid - 1;
      }
    }
    num += temp_ans;
    cout << num;
  }
  return 0;
}
