#include <bits/stdc++.h>
using namespace std;
long long int bnry(long long int it, long long int f);
long long int nb, ns, nc, pb, ps, pc, r, lm, lmb, lms, lmc, MX = 1;
int RB = 0, RS = 0, RC = 0;
int main() {
  int i, l;
  for (i = 1; i <= 16; i++) MX *= 10;
  char s[200];
  scanf("%s", s);
  cin >> nb >> ns >> nc >> pb >> ps >> pc >> r;
  l = strlen(s);
  for (i = 0; i < l; i++) {
    RB += (s[i] == 'B');
    RS += (s[i] == 'S');
    RC += (s[i] == 'C');
  }
  if (RB)
    lmb = (nb / RB);
  else
    lmb = MX;
  if (RS)
    lms = (ns / RS);
  else
    lms = MX;
  if (RC)
    lmc = (nc / RC);
  else
    lmc = MX;
  lm = min(lmb, lms);
  lm = min(lm, lmc);
  nb -= lm * RB;
  ns -= lm * RS;
  nc -= lm * RC;
  long long int L = bnry(0, r + 10);
  cout << lm + L << endl;
  return 0;
}
long long int bnry(long long int it, long long int f) {
  if (it == f) return f;
  long long int m = (it + f) / 2 + 1;
  long long int Tnb, Tnc, Tns;
  Tnb = (m * RB - nb) * pb;
  Tnb = (Tnb > 0) ? Tnb : 0;
  Tns = (m * RS - ns) * ps;
  Tns = (Tns > 0) ? Tns : 0;
  Tnc = (m * RC - nc) * pc;
  Tnc = (Tnc > 0) ? Tnc : 0;
  if (Tnb + Tnc + Tns <= r) return (bnry(m, f));
  return bnry(it, m - 1);
}
