#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1024;
long long pb, ps, pc;
long long nb, ns, nc;
long long r;
long long b = 0;
long long s = 0;
long long c = 0;
bool verify(long long mi) {
  long long br = (mi * b) - nb;
  long long sr = (mi * s) - ns;
  long long cr = (mi * c) - nc;
  long long tt = 0;
  if (br > 0) {
    tt += br * pb;
  }
  if (sr > 0) {
    tt += sr * ps;
  }
  if (cr > 0) {
    tt += cr * pc;
  }
  if (tt <= r)
    return true;
  else
    return false;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string qr;
  cin >> qr;
  for (auto ra : qr) {
    switch (ra) {
      case 'B':
        b++;
        break;
      case 'C':
        c++;
        break;
      case 'S':
        s++;
        break;
    }
  }
  cin >> nb >> ns >> nc;
  cin >> pb >> ps >> pc;
  cin >> r;
  long long lo = 0;
  long long hi = 1e15;
  while (hi - lo > 0) {
    long long mi = lo + (hi - lo + 1) / 2;
    if (verify(mi) == false)
      hi = mi - 1;
    else
      lo = mi;
  }
  cout << lo << endl;
  return 0;
}
