#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s1;
  cin >> s1;
  long long cb = 0, cs = 0, cc = 0;
  long long nb, ns, nc, pb, ps, pc, r;
  cin >> nb >> ns >> nc >> pb >> ps >> pc >> r;
  for (auto i : s1) {
    if (i == 'B')
      cb++;
    else if (i == 'S')
      cs++;
    else
      cc++;
  }
  long long ans = 0;
  long long low = 1, high = 1e14;
  while (low <= high) {
    long long x = (low + high) / 2;
    long long cost = max(0LL, x * cb - nb) * pb + max(0LL, x * cs - ns) * ps +
                     max(0LL, x * cc - nc) * pc;
    if (cost <= r) {
      ans = x;
      low = x + 1;
    } else
      high = x - 1;
  }
  cout << ans;
  return 0;
}
