#include <bits/stdc++.h>
using namespace std;
bool is(long long x, long long req[], long long cost[], long long arr[],
        long long val) {
  long long ans = 0;
  for (int i = 0; i < 3; i++) {
    long long cnt = 0;
    if (req[i] * x - arr[i] > 0) {
      cnt += cost[i] * (req[i] * x - arr[i]);
    }
    ans += cnt;
  }
  if (ans > val) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string str;
  cin >> str;
  long long n = str.size();
  long long arr[3];
  for (int i = 0; i < 3; i++) cin >> arr[i];
  long long cost[3];
  for (int j = 0; j < 3; j++) cin >> cost[j];
  long long val;
  cin >> val;
  long long l = 0, r = val + 101;
  long long req[3] = {};
  for (int i = 0; i < n; i++) {
    if (str[i] == 'B')
      req[0]++;
    else if (str[i] == 'S')
      req[1]++;
    else
      req[2]++;
  }
  long long ans = -1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (is(mid, req, cost, arr, val)) {
      if (mid > ans) ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << ans;
  return 0;
}
