#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  long long int nb, ns, nc, pb, ps, pc, r, cnt[3];
  memset(cnt, 0, sizeof(cnt));
  cin >> s >> nb >> ns >> nc >> pb >> ps >> pc >> r;
  for (char c : s) {
    if (c == 'B') cnt[0]++;
    if (c == 'S') cnt[1]++;
    if (c == 'C') cnt[2]++;
  }
  long long int total;
  if (cnt[0] == 0 || cnt[1] == 0 || cnt[2] == 0)
    total = 0;
  else
    total = min({nb / cnt[0], ns / cnt[1], nc / cnt[2]});
  nb -= total * cnt[0];
  ns -= total * cnt[1];
  nc -= total * cnt[2];
  int itr = 200;
  while ((nb != 0 || ns != 0 || nc != 0) && itr--) {
    long long int tb = max(0ll, cnt[0] - nb), ts = max(0ll, cnt[1] - ns),
                  tc = max(0ll, cnt[2] - nc);
    long long int req = tb * pb + ts * ps + tc * pc;
    if (req <= r)
      total++, r -= req;
    else
      break;
    nb = max(0ll, nb - cnt[0]);
    ns = max(0ll, ns - cnt[1]);
    nc = max(0ll, nc - cnt[2]);
  }
  long long int one = cnt[0] * pb + cnt[1] * ps + cnt[2] * pc;
  total += r / one;
  cout << total;
}
