#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);
const long long MAXN = 1e5 + 5;
const long long MOD = 1e9 + 7;
inline long long in() {
  long long f = 1, p = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    p = p * 10 + c - '0';
    c = getchar();
  }
  return f * p;
}
long long b, s, c;
long long bi, si, ci;
long long push_back = 0, ps = 0, pc = 0;
long long mon;
long long devi(long long a, long long b) {
  if (b == 0) return INF;
  return a / b;
}
bool judge(long long mid) {
  long long needb = mid * push_back;
  long long needs = mid * ps;
  long long needc = mid * pc;
  long long tmpmon = mon;
  if (needb > b) tmpmon -= (needb - b) * bi;
  if (needc > c) tmpmon -= (needc - c) * ci;
  if (needs > s) tmpmon -= (needs - s) * si;
  if (tmpmon >= 0) return true;
  return false;
}
int main() {
  string ss;
  cin >> ss;
  for (long long i = 0; i < ss.length(); i++) {
    if (ss[i] == 'B') push_back++;
    if (ss[i] == 'S') ps++;
    if (ss[i] == 'C') pc++;
  }
  b = in(), s = in(), c = in();
  bi = in(), si = in(), ci = in();
  cin >> mon;
  long long l = 0, r = 1e14;
  long long mid;
  while (r - l > 1) {
    mid = (l + r) / 2;
    if (judge(mid))
      l = mid;
    else
      r = mid;
  }
  cout << l;
  return 0;
}
