#include <bits/stdc++.h>
using namespace std;
const long long INF = 2 * 1e12;
int b, s, c, nb, ns, nc, pb, ps, pc;
long long mon;
bool judge(long long m) {
  long long cb = (m * b - nb) * pb, cs = (m * s - ns) * ps,
            cc = (m * c - nc) * pc;
  if (cb < 0) {
    cb = 0;
  }
  if (cs < 0) {
    cs = 0;
  }
  if (cc < 0) {
    cc = 0;
  }
  if (cb + cs + cc <= mon) {
    return true;
  } else {
    return false;
  }
}
int main() {
  char a[105];
  while (~scanf("%s", a)) {
    int m = strlen(a);
    b = 0;
    s = 0;
    c = 0;
    for (int i = 0; i < m; i++) {
      if (a[i] == 'B') {
        b++;
      } else if (a[i] == 'S') {
        s++;
      } else if (a[i] == 'C') {
        c++;
      }
    }
    scanf("%d%d%d%d%d%d", &nb, &ns, &nc, &pb, &ps, &pc);
    cin >> mon;
    long long l = 0, r = INF;
    while (r - l) {
      long long mid = (r + l) >> 1;
      if (judge(mid)) {
        l = mid + 1;
      } else {
        r = mid;
      }
    }
    cout << r - 1 << endl;
  }
  return 0;
}
