#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  int nb, ns, nc, pb, ps, pc, b = 0, s = 0, c = 0;
  long long r, ans = 0;
  string word;
  cin >> word;
  int i = 0;
  while (i < word.length()) {
    if (word[i] == 'B')
      b++;
    else if (word[i] == 'S')
      s++;
    else
      c++;
    i++;
  }
  cin >> nb >> ns >> nc;
  cin >> pb >> ps >> pc;
  cin >> r;
  while (nb >= b && ns >= s && nc >= c) {
    ans++;
    nb -= b;
    ns -= s;
    nc -= c;
  }
  while (r > 0 &&
         ((nb != 0 && b > 0) || (nc != 0 && c > 0) || (ns != 0 && s > 0))) {
    while (nb < b) {
      r -= (pb);
      nb += 1;
    }
    while (ns < s) {
      r -= (ps);
      ns += 1;
    }
    while (nc < c) {
      r -= (pc);
      nc += 1;
    }
    if (nb >= b && ns >= s && nc >= c && r >= 0) {
      ans++;
      nb -= b;
      ns -= s;
      nc -= c;
    }
  }
  int totalcost = (pc * c) + (pb * b) + (ps * s);
  ans += (r / totalcost);
  cout << ans << endl;
  return 0;
}
