#include <bits/stdc++.h>
using namespace std;
void solve();
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
void solve() {
  string s;
  cin >> s;
  long long nb, ns, nc;
  cin >> nb >> ns >> nc;
  long long pb, ps, pc;
  cin >> pb >> ps >> pc;
  long long t;
  cin >> t;
  long long cb = 0, cs = 0, cc = 0;
  long long n = s.size();
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'B')
      cb++;
    else if (s[i] == 'S')
      cs++;
    else if (s[i] == 'C')
      cc++;
  }
  long long l = 0;
  long long r = 1e14 + 5;
  while (l < r) {
    long long mid = (l + r) / 2;
    long long cost = max(0ll, cb * mid - nb) * pb +
                     max(0ll, cs * mid - ns) * ps +
                     max(0ll, cc * mid - nc) * pc;
    mid++;
    long long cost1 = max(0ll, cb * mid - nb) * pb +
                      max(0ll, cs * mid - ns) * ps +
                      max(0ll, cc * mid - nc) * pc;
    mid--;
    if (cost < t && cost1 > t) {
      l = mid;
      r = mid;
      break;
    }
    if (cost > t)
      r = mid - 1;
    else if (cost < t)
      l = mid + 1;
    else {
      break;
    }
  }
  cout << (l + r) / 2;
  return;
}
