#include <bits/stdc++.h>
using namespace std;
int64_t b, s, c;
int64_t pr[3];
int64_t m;
int64_t req[] = {0, 0, 0};
bool binary_search(int64_t mid) {
  int64_t to[3];
  for (int64_t i = 0; i < 3; i++) {
    to[i] = req[i] * mid;
  }
  to[0] -= b;
  to[1] -= s;
  to[2] -= c;
  int64_t cost = 0;
  for (int64_t i = 0; i < 3; i++)
    if (to[i] > 0) cost += to[i] * pr[i];
  if (cost <= m) return true;
  return false;
}
signed main() {
  string ss;
  cin >> ss;
  for (char i : ss) {
    if (i == 'B')
      req[0]++;
    else if (i == 'S')
      req[1]++;
    else
      req[2]++;
  }
  cin >> b >> s >> c;
  for (int64_t i = 0; i < 3; i++) cin >> pr[i];
  cin >> m;
  int64_t st = 0;
  int64_t en = 1e14;
  int64_t ans = 0;
  while (st <= en) {
    int64_t mid = st + (en - st) / 2;
    if (binary_search(mid)) {
      ans = mid;
      st = mid + 1;
    } else {
      en = mid - 1;
    }
  }
  cout << ans << "\n";
  return 0;
}
