#include <bits/stdc++.h>
using namespace std;
string s;
long long Nb, Ns, Nc, Pb, Ps, Pc, money;
long long demB, demS, demC;
long long max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
bool check(long long x) {
  long long sum = 0;
  long long t = max(x * demB - Nb, 0);
  sum += t * Pb;
  t = max(x * demS - Ns, 0);
  sum += t * Ps;
  t = max(x * demC - Nc, 0);
  sum += t * Pc;
  return sum <= money;
}
int main() {
  cin >> s;
  cin >> Nb >> Ns >> Nc;
  cin >> Pb >> Ps >> Pc;
  cin >> money;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'B') demB++;
    if (s[i] == 'S') demS++;
    if (s[i] == 'C') demC++;
  }
  long long dau = 0;
  long long cuoi = (long long)1e15;
  while (dau + 1 < cuoi) {
    long long giua = (dau + cuoi) / 2;
    if (check(giua))
      dau = giua;
    else
      cuoi = giua;
  }
  cout << dau;
}
