#include <bits/stdc++.h>
using namespace std;
int main() {
  char str[111];
  scanf("%s", str);
  long long len = strlen(str);
  long long n1, n2, n3;
  long long p1, p2, p3;
  long long money;
  scanf("%I64d%I64d%I64d%I64d%I64d%I64d%I64d", &n1, &n2, &n3, &p1, &p2, &p3,
        &money);
  long long B = 0, S = 0, C = 0;
  for (int i = 0; i < len; i++) {
    if (str[i] == 'B')
      B++;
    else if (str[i] == 'S')
      S++;
    else if (str[i] == 'C')
      C++;
  }
  long long ans = 0;
  long long l = 1, r = 1000000000000 + 1111;
  while (l < r) {
    long long m = (l + r) >> 1;
    if (max(0LL, m * B - n1) * p1 + max(0LL, m * S - n2) * p2 +
            max(0LL, m * C - n3) * p3 <=
        money)
      l = m + 1;
    else
      r = m;
  }
  printf("%I64d\n", l - 1);
  return 0;
}
