#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  long long cnb = 0, cns = 0, cnc = 0;
  for (long long i = 0; i < (long long)str.size(); ++i) {
    if (str[i] == 'B')
      cnb++;
    else if (str[i] == 'S')
      cns++;
    else
      cnc++;
  }
  long long nb, ns, nc;
  cin >> nb >> ns >> nc;
  long long pb, ps, pc;
  cin >> pb >> ps >> pc;
  long long ruby;
  cin >> ruby;
  long long l = 0;
  long long r = 1e15;
  long long lw = 0;
  while (l <= r) {
    long long mid = (l + r) / 2;
    long long need = max(mid * cnb * pb - nb * pb, 0LL) +
                     max(mid * cns * ps - ns * ps, 0LL) +
                     max(mid * cnc * pc - nc * pc, 0LL);
    if (need <= ruby) {
      lw = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  cout << lw << "\n";
  return 0;
}
