#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  long long n, m, i, j, s = 0, B, S, C, Pb, Ps, Pc, Cb = 0, Cs = 0, Cc = 0, s1,
                        c = 1000000000, s2, r, cc, l;
  cin >> str;
  cin >> B >> S >> C >> Pb >> Ps >> Pc >> n;
  for (i = 0; i < str.size(); i++)
    if (str[i] == 'B')
      Cb++;
    else if (str[i] == 'S')
      Cs++;
    else if (str[i] == 'C')
      Cc++;
  l = 0;
  r = 1000000000110;
  while (r - l > 1) {
    cc = (r + l) / 2;
    s2 = 0;
    s1 = Cc * cc - C;
    if (s1 < 0) s1 = 0;
    s2 += s1 * Pc;
    s1 = Cb * cc - B;
    if (s1 < 0) s1 = 0;
    s2 += s1 * Pb;
    s1 = Cs * cc - S;
    if (s1 < 0) s1 = 0;
    s2 += s1 * Ps;
    if (s2 == n) {
      cout << cc;
      return 0;
    }
    if (s2 < n) l = cc;
    if (s2 > n) r = cc;
  }
  cout << l;
  return 0;
}
