#include <bits/stdc++.h>
using namespace std;
const int M = (int)1e5;
const long long int mod = (long long int)1e9 + 7;
const long long int inf = 0x3f3f3f3f3f;
struct node {
  long long int need;
  long long int num;
  long long int price;
} s[3];
long long int money;
bool check(long long int mid) {
  long long int cost = 0;
  for (int i = 0; i < 3; ++i) {
    if (mid * s[i].need - s[i].num > 0)
      cost += (mid * s[i].need - s[i].num) * s[i].price;
  }
  return cost <= money;
}
int main() {
  string str;
  cin >> str;
  int len = str.size();
  for (int i = 0; i < len; ++i) {
    if (str[i] == 'B')
      s[0].need++;
    else if (str[i] == 'S')
      s[1].need++;
    else if (str[i] == 'C')
      s[2].need++;
  }
  scanf("%lld %lld %lld", &s[0].num, &s[1].num, &s[2].num);
  scanf("%lld %lld %lld", &s[0].price, &s[1].price, &s[2].price);
  scanf("%lld", &money);
  long long int l = 0;
  long long int r = max(max(s[0].num, s[1].num), s[2].num) + money;
  while (l < r) {
    long long int mid = (l + r + 1) >> 1;
    if (check(mid))
      l = mid;
    else
      r = mid - 1;
  }
  printf("%lld\n", l);
  return 0;
}
