#include <bits/stdc++.h>
using namespace std;
int main() {
  string recipee;
  cin >> recipee;
  int nb, ns, nc, pb, ps, pc;
  long long r;
  cin >> nb;
  cin >> ns;
  cin >> nc;
  cin >> pb;
  cin >> ps;
  cin >> pc;
  cin >> r;
  int cb = 0;
  int cs = 0;
  int cc = 0;
  long long nbur = 0;
  bool done = false;
  for (int i = 0; i < recipee.size(); i++) {
    if (recipee.at(i) == 'B')
      cb++;
    else if (recipee.at(i) == 'S')
      cs++;
    else if (recipee.at(i) == 'C')
      cc++;
  }
  while (
      !((nb == 0 || cb == 0) && (ns == 0 || cs == 0) && (nc == 0 || cc == 0))) {
    if (nb >= cb && ns >= cs && nc >= cc) {
      nb = nb - cb;
      ns = ns - cs;
      nc = nc - cc;
      nbur++;
    } else {
      if (nb < cb) {
        int falta = cb - nb;
        int costo = pb * falta;
        if (costo > r) {
          done = true;
          break;
        } else {
          r = r - costo;
          nb = nb + falta;
        }
      }
      if (ns < cs) {
        int falta = cs - ns;
        int costo = ps * falta;
        if (costo > r) {
          done = true;
          break;
        } else {
          r = r - costo;
          ns = ns + falta;
        }
      }
      if (nc < cc) {
        int falta = cc - nc;
        int costo = pc * falta;
        if (costo > r) {
          done = true;
          break;
        } else {
          r = r - costo;
          nc = nc + falta;
        }
      }
    }
  }
  if (done) {
    cout << nbur;
    return 0;
  }
  nbur = nbur + r / (pb * cb + ps * cs + pc * cc);
  cout << nbur;
  return 0;
}
