#include <bits/stdc++.h>
using namespace std;
string s;
int nb, ns, nc;
int pb, ps, pc;
long long r;
int B, S, C;
long long ans;
bool ok(long long mid) {
  long long ans = 0;
  ans += max((mid * B - nb) * pb, 0LL);
  ans += max((mid * S - ns) * ps, 0LL);
  ans += max((mid * C - nc) * pc, 0LL);
  return ans <= r;
}
int main() {
  cin >> s;
  cin >> nb >> ns >> nc;
  cin >> pb >> ps >> pc;
  cin >> r;
  B = S = C = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    if (s[i] == 'B')
      B++;
    else if (s[i] == 'S')
      S++;
    else
      C++;
  }
  long long st = 0;
  long long en = 1e13;
  long long mid;
  while (st < en) {
    mid = (st + en) / 2;
    if (ok(mid)) {
      st = mid + 1;
    } else {
      en = mid;
    }
  }
  cout << st - 1 << endl;
  return 0;
}
