#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
long long bnum, snum, cnum;
long long hb, hs, hc;
long long bp, sp, cp;
long long M;
bool check(long long mid) {
  long long k1 = max(mid * bnum - hb, (long long)0);
  long long k2 = max(mid * snum - hs, (long long)0);
  long long k3 = max(mid * cnum - hc, (long long)0);
  long long res = k1 * bp + k2 * sp + k3 * cp;
  return M >= res;
}
int main(void) {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  string str;
  cin >> str;
  cin >> hb >> hs >> hc;
  cin >> bp >> sp >> cp;
  cin >> M;
  for (long long i = 0; i < str.size(); i++) {
    if (str[i] == 'B') bnum++;
    if (str[i] == 'S') snum++;
    if (str[i] == 'C') cnum++;
  }
  long long l = 0;
  long long r = 1e13;
  while (l < r) {
    long long mid = (l + r + 1) >> 1;
    if (check(mid))
      l = mid;
    else
      r = mid - 1;
  }
  cout << l << endl;
  return 0;
}
