#include <bits/stdc++.h>
using namespace std;
string s;
int n[3], p[3], r[3] = {0};
long long m, a = 0;
bool alcanza(long long x, long long m) {
  for (int i = 0; i < 3; i++)
    m -= max((long long)0, (p[i] * (r[i] * x - n[i])));
  if (m < 0) return false;
  return true;
}
int main() {
  cin >> s;
  for (int i = 0; i < 3; i++) cin >> n[i];
  for (int i = 0; i < 3; i++) cin >> p[i];
  cin >> m;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B')
      r[0]++;
    else if (s[i] == 'S')
      r[1]++;
    else
      r[2]++;
  }
  bool puedo = 1;
  while (puedo) {
    puedo = 1;
    for (int i = 0; i < 3; i++)
      if (r[i] > n[i]) puedo = 0;
    if (puedo) {
      a++;
      for (int i = 0; i < 3; i++) n[i] -= r[i];
    }
  }
  long long mi = 0, ma = 10e12 + 10, s;
  while (true) {
    s = (mi + ma) / 2;
    if (alcanza(s, m) && !alcanza(s + 1, m)) break;
    if (!alcanza(s, m))
      ma = s;
    else
      mi = s;
  }
  a += s;
  cout << a << endl;
  return 0;
}
