#include <bits/stdc++.h>
using namespace std;
long long maxHB(string str, long long nb, long long ns, long long nc,
                long long pb, long long ps, long long pc, long long amt) {
  long long s = 0, e = 1000000100000;
  long long ans = 0;
  int cb = 0, cs = 0, cc = 0;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == 'B')
      cb++;
    else if (str[i] == 'S')
      cs++;
    else
      cc++;
  }
  while (s <= e) {
    long long mid = (s + e) / 2;
    long long reqBA = (mid * cb - nb) * pb < 0 ? 0 : ((mid * cb - nb)) * pb;
    long long reqSA = (mid * cs - ns) * ps < 0 ? 0 : ((mid * cs - ns)) * ps;
    long long reqCA = (mid * cc - nc) * pc < 0 ? 0 : ((mid * cc - nc)) * pc;
    long long reqAmt = reqBA + reqSA + reqCA;
    if (reqAmt == amt) {
      return mid;
    } else if (reqAmt < amt) {
      ans = mid;
      s = mid + 1;
    } else
      e = mid - 1;
  }
  return ans;
}
int main() {
  string rec;
  cin >> rec;
  long long nb, ns, nc, pb, ps, pc;
  long long amt;
  cin >> nb >> ns >> nc >> pb >> ps >> pc;
  cin >> amt;
  cout << maxHB(rec, nb, ns, nc, pb, ps, pc, amt) << endl;
  return 0;
}
