#include <bits/stdc++.h>
using namespace std;
string s;
long long na, nb, nc, pa, pb, pc, r, ka, kb, kc, ans = 0;
vector<pair<long long, long long> > a;
int main() {
  cin >> s >> na >> nb >> nc >> pa >> pb >> pc >> r;
  ka = kb = kc = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == 'B')
      ka++;
    else if (s[i] == 'S')
      kb++;
    else
      kc++;
  long long h = 1000;
  if (ka)
    h = min(h, na / ka);
  else
    na = 0;
  if (kb)
    h = min(h, nb / kb);
  else
    nb = 0;
  if (kc)
    h = min(h, nc / kc);
  else
    nc = 0;
  ans = h;
  na -= ans * ka;
  nb -= ans * kb;
  nc -= ans * kc;
  while (na > 0 || nb > 0 || nc > 0) {
    long long ga, gb, gc;
    ga = 0;
    gb = 0;
    gc = 0;
    if (na < ka) ga = (ka - na) * pa;
    if (nb < kb) gb = (kb - nb) * pb;
    if (nc < kc) gc = (kc - nc) * pc;
    if (ga + gb + gc <= r) {
      ans++;
      r -= ga + gb + gc;
      na -= ka;
      nb -= kb;
      nc -= kc;
      if (na < 0) na = 0;
      if (nb < 0) nb = 0;
      if (nc < 0) nc = 0;
    } else
      break;
  }
  long long s = ka * pa + kb * pb + kc * pc;
  ans += r / s;
  cout << ans;
}
