#include <bits/stdc++.h>
const long long mxn = 1e6 + 7;
const long long mod = 1e9 + 7;
const long long inf = 1e18 + 9;
using namespace std;
long long n, nb, ns, nc, cnt;
long long push_back, ps, pc;
long long ab, as, ac;
string s;
long long check(long long x) {
  long long mx_b = max(0ll, (x * ab - nb) * push_back);
  long long mx_s = max(0ll, (x * as - ns) * ps);
  long long mx_c = max(0ll, (x * ac - nc) * pc);
  return mx_b + mx_s + mx_c <= n;
}
long long bin_search() {
  long long l = 0, r = 1e13;
  while (r - l > 1) {
    long long mid = (r + l) / 2;
    if (check(mid)) {
      l = mid;
    } else {
      r = mid;
    }
  }
  return l;
}
int main() {
  ios_base::sync_with_stdio(0), cout.tie(0);
  cin.tie(0);
  cin >> s;
  cin >> nb >> ns >> nc;
  cin >> push_back >> ps >> pc;
  cin >> n;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B')
      ab++;
    else if (s[i] == 'S')
      as++;
    else
      ac++;
  }
  cout << bin_search();
  return 0;
}
