#include <bits/stdc++.h>
using namespace std;
int main() {
  int cb = 0, cc = 0, cs = 0, nb, ns, nc, pb, ps, pc;
  char describe[103];
  cin >> describe;
  for (int i = 0; i < strlen(describe); i++) {
    if (describe[i] == 'B')
      cb = cb + 1;
    else if (describe[i] == 'C')
      cc = cc + 1;
    else
      cs = cs + 1;
  }
  cin >> nb >> ns >> nc;
  cin >> pb >> ps >> pc;
  long long r, cost, ans = 0;
  cin >> r;
  while ((nb && cb) || (cc && nc) || (cs && ns)) {
    if (nb < cb) {
      r -= pb * (cb - nb);
      nb = cb;
    }
    if (nc < cc) {
      r -= pc * (cc - nc);
      nc = cc;
    }
    if (ns < cs) {
      r -= ps * (cs - ns);
      ns = cs;
    }
    if (r <= 0)
      break;
    else {
      ans++;
      ns -= cs;
      nb -= cb;
      nc -= cc;
    }
  }
  if (r >= 0) ans = ans + (r == 0 ? 1 : r / (cb * pb + cs * ps + cc * pc));
  cout << ans;
  return 0;
}
