#include <bits/stdc++.h>
using namespace std;
string s;
int c[3] = {0};
int nb, ns, nc;
int push_back, ps, pc;
long long ruble;
bool can(long long x) {
  long long ans = 0;
  ans += max(0LL, c[0] * x - nb) * push_back;
  ans += max(0LL, c[1] * x - ns) * ps;
  ans += max(0LL, c[2] * x - nc) * pc;
  return ans <= ruble;
}
int main() {
  cin >> s;
  scanf("%d%d%d", &nb, &ns, &nc);
  scanf("%d%d%d", &push_back, &ps, &pc);
  scanf("%lld", &ruble);
  for (int i = 0; i < (int)s.length(); ++i) {
    if (s[i] == 'B')
      c[0]++;
    else if (s[i] == 'S')
      c[1]++;
    else
      c[2]++;
  }
  long long l = 0;
  long long r = ruble + nb + ns + nc;
  long long mid;
  while (l < r) {
    mid = l + (r - l + 1) / 2;
    if (can(mid))
      l = mid;
    else
      r = mid - 1;
  }
  cout << (l) << '\n';
  return 0;
}
