#include <bits/stdc++.h>
using namespace std;
long long nb, nc, ns, s, b, c, pb, i, pc, ps, r, needb, needc, needs, mid, l,
    ru;
string recipe;
bool f(long long x) {
  needb = b * x;
  needc = c * x;
  needs = s * x;
  needb -= nb;
  needc -= nc;
  needs -= ns;
  if (needb < 0) needb = 0;
  if (needc < 0) needc = 0;
  if (needs < 0) needs = 0;
  if (needb * pb + needc * pc + needs * ps <= ru)
    return 1;
  else
    return 0;
};
int main() {
  cin >> recipe;
  cin >> nb >> ns >> nc;
  cin >> pb >> ps >> pc;
  cin >> ru;
  for (i = 0; i < recipe.size(); i++) {
    if (recipe[i] == 'B') b++;
    if (recipe[i] == 'S') s++;
    if (recipe[i] == 'C') c++;
  };
  l = 0;
  r = 10000000000000LL;
  while (l < r) {
    if (l == r - 1) {
      if (f(r)) l = r;
      break;
    };
    mid = (l + r) / 2;
    if (f(mid) == 1)
      l = mid;
    else
      r = mid - 1;
  };
  cout << l;
  return 0;
}
