#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
string s;
long long nb, nc, ns, push_back, pc, ps, money, cntb, cntc, cnts, l, r, mid, mb,
    ms, mc;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> s >> nb >> ns >> nc >> push_back >> ps >> pc >> money;
  for (size_t i = 0; i < s.length(); i++) {
    if (s[i] == 'B')
      cntb++;
    else if (s[i] == 'S')
      cnts++;
    else
      cntc++;
  }
  l = 0;
  r = 1e14;
  while (l <= r) {
    mid = (l + r) / 2;
    mb = max(0ll, (cntb * mid - nb) * push_back);
    ms = max(0ll, (cnts * mid - ns) * ps);
    mc = max(0ll, (cntc * mid - nc) * pc);
    if (mc + mb + ms <= money)
      l = mid + 1;
    else
      r = mid - 1;
  }
  cout << r;
  return 0;
}
