#include <bits/stdc++.h>
using namespace std;
string s;
long long cost[3], a[3], b[3], k;
bool CanI(long long num) {
  long long temp = k, sum = 0;
  for (int i = 0; i < 3; i++) {
    if (num * a[i] > b[i]) sum += cost[i] * (num * a[i] - b[i]);
  }
  if (sum > temp) return 0;
  return 1;
}
long long BS() {
  long long sol = 0, left = 0, right = k + 200, middle;
  while (left <= right) {
    middle = (left + right) >> 1;
    if (CanI(middle)) {
      sol = middle;
      left = middle + 1;
    } else {
      right = middle - 1;
    }
  }
  return sol;
}
int main() {
  cin >> s;
  for (int i = 0; s[i]; ++i) {
    if (s[i] == 'B')
      a[0]++;
    else if (s[i] == 'S')
      a[1]++;
    else
      a[2]++;
  }
  for (int i = 0; i < 3; ++i) cin >> b[i];
  for (int i = 0; i < 3; ++i) cin >> cost[i];
  cin >> k;
  cout << BS();
  return 0;
}
