#include <bits/stdc++.h>
using namespace std;
long long const MAXN = 1010;
char s[MAXN];
long long xa, xb, xc, na, nb, nc, pa, pb, pc, m;
long long ans;
bool pd(long long n) {
  long long money = max((n * xa - na), 0ll) * pa +
                    max((n * xb - nb), 0ll) * pb + max((n * xc - nc), 0ll) * pc;
  if (money > m) return 0;
  return 1;
}
signed main() {
  long long l = 0;
  long long r = 1e13;
  scanf("%s", s + 1);
  for (long long i = 1, len = strlen(s + 1); i <= len; i++) {
    if (s[i] == 'B')
      xa++;
    else if (s[i] == 'S')
      xb++;
    else if (s[i] == 'C')
      xc++;
  }
  scanf("%lld%lld%lld", &na, &nb, &nc);
  scanf("%lld%lld%lld", &pa, &pb, &pc);
  scanf("%lld", &m);
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (pd(mid)) {
      ans = mid, l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
