#include <bits/stdc++.h>
using namespace std;
long long m, b = 0, s = 0, c = 0, nb, ns, nc, pb, ps, pc;
bool check(long long mid) {
  long long nnb = mid * b, nns = mid * s, nnc = mid * c;
  long long cb = nnb - nb, cs = nns - ns, cc = nnc - nc;
  if (cb < 0) cb = 0;
  if (cs < 0) cs = 0;
  if (cc < 0) cc = 0;
  long long money = cb * pb + cs * ps + cc * pc;
  if (money <= m)
    return 1;
  else
    return 0;
}
int main() {
  long long mmin = 1e14;
  string re;
  getline(cin, re);
  scanf("%lld%lld%lld", &nb, &ns, &nc);
  scanf("%lld%lld%lld", &pb, &ps, &pc);
  scanf("%lld", &m);
  for (long long i = 0; i < re.size(); i++) {
    if (re[i] == 'B') b++;
    if (re[i] == 'S') s++;
    if (re[i] == 'C') c++;
  }
  if (b != 0) {
    if ((m / pb + nb) / b < mmin) mmin = (m / pb + nb) / b;
  }
  if (s != 0) {
    if ((m / ps + ns) / s < mmin) mmin = (m / ps + ns) / s;
  }
  if (c != 0) {
    if ((m / pc + nc) / c < mmin) mmin = (m / pc + nc) / c;
  }
  long long l = 0, r = mmin;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (check(mid) == 1)
      l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%lld", (l + r) / 2);
  return 0;
}
