#include <bits/stdc++.h>
using namespace std;
string s;
long long nb, ns, nc, push_back, ps, pc, amt, reqb, reqs, reqc, ans, mid;
long long check(long long no) {
  long long b = max(0ll, no * reqb - nb);
  long long s = max(0ll, no * reqs - ns);
  long long c = max(0ll, no * reqc - nc);
  long long pr = b * push_back + s * ps + c * pc;
  return pr <= amt;
}
long long fun(long long lo, long long hi) {
  while (lo <= hi) {
    mid = (lo + hi) >> 1;
    if (check(mid)) {
      ans = mid;
      lo = mid + 1;
    } else
      hi = mid - 1;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  cin >> nb >> ns >> nc >> push_back >> ps >> pc >> amt;
  for (auto it : s) {
    if (it == 'B')
      reqb++;
    else if (it == 'S')
      reqs++;
    else
      reqc++;
  }
  long long num = fun(0, 1e15);
  cout << num << "\n";
}
