#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
char s[105];
int main() {
  long long i, n, q, t, x, a, b, c, r, n1, n2, n3, num = 0;
  scanf("%s", &s);
  scanf("%lld%lld%lld", &n1, &n2, &n3);
  scanf("%lld%lld%lld", &a, &b, &c);
  scanf("%lld", &r);
  long long len = strlen(s);
  long long c1 = 0, c2 = 0, c3 = 0;
  for (i = 0; i < len; i++) {
    if (s[i] == 'B')
      c1++;
    else if (s[i] == 'S')
      c2++;
    else
      c3++;
  }
  while (n1 >= c1 && n2 >= c2 && n3 >= c3) {
    num++;
    n1 -= c1;
    n2 -= c2;
    n3 -= c3;
  }
  while (1) {
    if ((n1 == 0 || c1 == 0) && (n2 == 0 || c2 == 0) && (n3 == 0 || c3 == 0))
      break;
    if (n1 < c1) r -= (c1 - n1) * a;
    if (n1 > c1)
      n1 -= c1;
    else
      n1 = 0;
    if (r < 0) break;
    if (n2 < c2) r -= (c2 - n2) * b;
    if (n2 > c2)
      n2 -= c2;
    else
      n2 = 0;
    if (r < 0) break;
    if (n3 < c3) r -= (c3 - n3) * c;
    if (n3 > c3)
      n3 -= c3;
    else
      n3 = 0;
    if (r < 0) break;
    num++;
  }
  if (r > 0) {
    num += r / (a * c1 + b * c2 + c * c3);
  }
  printf("%lld\n", num);
  return 0;
}
