#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  long long int nb, ns, nc, push_back, ps, pc, money;
  cin >> str >> nb >> ns >> nc >> push_back >> ps >> pc >> money;
  long long int b, s, c;
  b = s = c = 0;
  for (long long int i = 0; i < str.size(); i++) {
    if (str[i] == 'B') b++;
    if (str[i] == 'S') s++;
    if (str[i] == 'C') c++;
  }
  long long int l, r, f, m;
  l = 0;
  r = 1e13;
  while (l < r) {
    m = (l + r + 1) / 2;
    f = max(0ll, b * m - nb) * push_back + max(0ll, s * m - ns) * ps +
        max(0ll, c * m - nc) * pc;
    if (f > money)
      r = m - 1;
    else
      l = m;
  }
  cout << l << "\n";
  return 0;
}
