#include <bits/stdc++.h>
using namespace std;
string str;
int nb, ns, nc;
int pb, ps, pc;
long long r;
int b = 0, s = 0, c = 0;
bool judge(long long x) {
  long long k = 0;
  long long now_money = (max(k, x * b - nb) * pb) + (max(k, x * s - ns) * ps) +
                        (max(k, x * c - nc) * pc);
  return (r >= now_money);
}
int main() {
  cin >> str;
  for (int i = 0; i < (int)str.size(); i++) {
    if (str[i] == 'B')
      b++;
    else if (str[i] == 'S')
      s++;
    else
      c++;
  }
  cin >> nb >> ns >> nc;
  cin >> pb >> ps >> pc;
  cin >> r;
  long long l = 0, r = 1e14;
  while (l + 1 < r) {
    long long mid = (l + r) / 2;
    if (judge(mid))
      l = mid;
    else
      r = mid - 1;
  }
  if (judge(r))
    cout << r << endl;
  else
    cout << l << endl;
  return 0;
}
