#include <bits/stdc++.h>
using namespace std;
long long int costing(long long int b, long long int r, long long int c,
                      long long int cb, long long int cr, long long int cc) {
  if (b < 0) b = 0;
  if (r < 0) r = 0;
  if (c < 0) c = 0;
  long long int ans = b * cb + r * cr + c * cc;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  int breqd = 0, sreqd = 0, creqd = 0;
  for (int i = 0; i < s.size(); i++) {
    breqd += (s[i] == 'B');
    sreqd += (s[i] == 'S');
    creqd += (s[i] == 'C');
  }
  int b_hai = 0, s_hai = 0, c_hai = 0;
  cin >> b_hai >> s_hai >> c_hai;
  int b_cost, s_cost, c_cost;
  cin >> b_cost >> s_cost >> c_cost;
  long long int money;
  cin >> money;
  long long int lo = 0, hi = 100000000000000;
  while (lo < hi) {
    long long int mid = (lo + hi + 1) / 2;
    if (costing(mid * breqd - b_hai, mid * sreqd - s_hai, mid * creqd - c_hai,
                b_cost, s_cost, c_cost) <= money)
      lo = mid;
    else
      hi = mid - 1;
  }
  cout << lo << "\n";
  return 0;
}
