#include <bits/stdc++.h>
using namespace std;
long long nb, ns, nc, pb, ps, pc, ab, as, ac, money;
bool solve(long long k) {
  long long cb = k * ab, cs = k * as, cc = k * ac;
  long long cost = 0;
  cost += max(cb - nb, 0LL) * pb;
  cost += max(cs - ns, 0LL) * ps;
  cost += max(cc - nc, 0LL) * pc;
  return cost <= money;
}
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); ++i)
    if (s[i] == 'B')
      ab++;
    else if (s[i] == 'S')
      as++;
    else
      ac++;
  cin >> nb >> ns >> nc >> pb >> ps >> pc;
  cin >> money;
  long long lo = 0, hi = 1e14, mid;
  while (lo < hi) {
    mid = (lo + hi + 1) / 2;
    if (solve(mid))
      lo = mid;
    else
      hi = mid - 1;
  }
  cout << lo << '\n';
}
