#include <bits/stdc++.h>
using namespace std;
bool valid(long long n, long long bneed, long long sneed, long long cneed,
           long long bhav, long long shav, long long chav, long long bcost,
           long long scost, long long ccost, long long mon) {
  long long sum = 0;
  if ((n * bneed) - bhav > 0) {
    sum = (((n * bneed) - bhav) * bcost);
  }
  if (((n * sneed) - shav) > 0) {
    sum += (((n * sneed) - shav) * scost);
  }
  if (((n * cneed) - chav) > 0) {
    sum += (((n * cneed) - chav) * ccost);
  }
  if (sum <= mon) {
    return true;
  } else {
    return false;
  }
}
int main() {
  long long i, j, bneed = 0, sneed = 0, cneed = 0, bhav = 0, shav = 0, chav = 0,
                  bcost = 0, scost = 0, ccost = 0, mon = 0, lft = 0, rit = 0,
                  mid = 0, ans = 0;
  string a;
  cin >> a;
  for (i = 0; i < a.length(); i++) {
    if (a[i] == 'B') {
      bneed++;
    } else if (a[i] == 'S') {
      sneed++;
    } else {
      cneed++;
    }
  }
  scanf("%lld %lld %lld", &bhav, &shav, &chav);
  scanf("%lld %lld %lld", &bcost, &scost, &ccost);
  scanf("%lld", &mon);
  lft = 0;
  rit = mon + max(bhav, max(chav, shav)) + 100;
  while (lft <= rit) {
    mid = lft + ((rit - lft) / 2);
    if (valid(mid, bneed, sneed, cneed, bhav, shav, chav, bcost, scost, ccost,
              mon)) {
      ans = mid;
      lft = mid + 1;
    } else {
      rit = mid - 1;
    }
  }
  printf("%lld", ans);
  return 0;
}
