#include <bits/stdc++.h>
using namespace std;
long long b = 0, s = 0, c = 0;
long long nb, ns, nc;
long long pb, ps, pc;
long long r;
bool isPoss(long long m) {
  long long rnb = b * m - nb < 0 ? 0 : b * m - nb;
  long long rns = s * m - ns < 0 ? 0 : s * m - ns;
  long long rnc = c * m - nc < 0 ? 0 : c * m - nc;
  long long rs = rnb * pb + rns * ps + rnc * pc;
  if (rs <= r && rs >= 0) {
    return true;
  }
  return false;
}
int main() {
  string st;
  cin >> st;
  long long n = st.size();
  for (long long i = 0; i < n; i++) {
    if (st[i] == 'B') {
      b++;
    }
    if (st[i] == 'S') {
      s++;
    }
    if (st[i] == 'C') {
      c++;
    }
  }
  cin >> nb >> ns >> nc;
  cin >> pb >> ps >> pc;
  cin >> r;
  long long l = 0;
  long long h = 1e16;
  long long m = (h + l) / 2;
  int flag = 0;
  while (l <= h) {
    m = (h + l) / 2;
    if (isPoss(m)) {
      if (!isPoss(m + 1)) {
        flag = 1;
        cout << m << endl;
        break;
      } else {
        l = m + 1;
      }
    } else {
      h = m - 1;
    }
  }
  if (flag == 0) cout << 0 << endl;
  return 0;
}
