#include <bits/stdc++.h>
using namespace std;
string s;
int nb, ns, nc, pb, ps, pc;
long long r;
long long rbread = 0, rsausage = 0, rcheese = 0;
bool check(long long k) {
  long long b, sg, c;
  b = rbread * k;
  sg = rsausage * k;
  c = rcheese * k;
  long long cost = 0;
  if (nb < b) {
    cost += pb * (b - nb);
  }
  if (ns < sg) {
    cost += ps * (sg - ns);
  }
  if (nc < c) {
    cost += pc * (c - nc);
  }
  if (cost > r)
    return false;
  else
    return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> s;
  cin >> nb >> ns >> nc >> pb >> ps >> pc;
  cin >> r;
  for (int i = 0; i < s.length(); i++) {
    switch (s[i]) {
      case 'B':
        rbread++;
        break;
      case 'S':
        rsausage++;
        break;
      case 'C':
        rcheese++;
        break;
    }
  }
  long long ans = 0;
  long long lt = 0, rt = r + max(max(nb, ns), nc);
  while (lt <= rt) {
    long long mid = (lt + rt) / 2;
    bool b = check(mid);
    if (b) {
      ans = mid;
      lt = mid + 1;
    } else
      rt = mid - 1;
  }
  cout << ans;
  return 0;
}
