#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const double EPS = 1e-9;
int mods(int a, int b) { return (b + (a % b)) % b; }
int nb, ns, nc, pb, ps, pc, ib = 0, is = 0, ic = 0;
long long r, rb, rs, rc, ans, lo, mid, hi;
string s;
bool simulate(long long x) {
  long long tmp = 0;
  rb = ib * x;
  rs = is * x;
  rc = ic * x;
  if (rb > nb) tmp += (rb - nb) * pb;
  if (rs > ns) tmp += (rs - ns) * ps;
  if (rc > nc) tmp += (rc - nc) * pc;
  if (tmp > r) return 0;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B')
      ib++;
    else if (s[i] == 'S')
      is++;
    else
      ic++;
  }
  cin >> nb >> ns >> nc >> pb >> ps >> pc >> r;
  lo = hi = 1e18;
  if (ib) lo = min(lo, (long long)nb / ib);
  if (is) lo = min(lo, (long long)ns / is);
  if (ic) lo = min(lo, (long long)nc / ic);
  if (ib) hi = min(hi, r * ib);
  if (is) hi = min(hi, r * is);
  if (ic) hi = min(hi, r * ic);
  hi += lo;
  while (lo <= hi) {
    mid = (lo + hi) >> 1;
    if (simulate(mid)) {
      ans = mid;
      lo = mid + 1;
    } else
      hi = mid - 1;
  }
  cout << ans << '\n';
  return 0;
}
