#include <bits/stdc++.h>
using namespace std;
long long nb, ns, nc, push_back, ps, pc, r, cb = 0, cs = 0, cc = 0;
int main() {
  string s;
  cin >> s;
  long long i, l;
  cin >> nb >> ns >> nc >> push_back >> ps >> pc >> r;
  l = int((s).size());
  for (i = 0; i < l; i++) {
    if (s[i] == 'B') ++cb;
    if (s[i] == 'S') ++cs;
    if (s[i] == 'C') ++cc;
  }
  long long lo = 0, hi = (long long)2000000000000, mid;
  while (hi - lo > 1) {
    mid = (lo + hi) / 2;
    long long sum = max((long long)0, cb * mid - nb) * push_back +
                    max((long long)0, cs * mid - ns) * ps +
                    max((long long)0, cc * mid - nc) * pc;
    if (sum <= r)
      lo = mid;
    else
      hi = mid;
  }
  cout << lo << endl;
  return 0;
}
