#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
void PLAY() {
  cout << fixed << setprecision(10);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  PLAY();
  string s;
  map<char, int> mp;
  long long ss = 0, r;
  cin >> s;
  for (int i = 0; i < s.size(); i++) mp[s[i]]++;
  vector<int> v(3);
  vector<int> vv(3);
  for (int i = 0; i < 3; i++) cin >> v[i];
  for (int i = 0; i < 3; i++) cin >> vv[i];
  cin >> r;
  long long res = 0;
  long long lo = 0, hi = 1e12 + 100, md, sum = 0;
  while (lo <= hi) {
    md = (lo + hi) / 2;
    sum = max(0LL, md * mp['B'] * vv[0] - v[0] * vv[0]) +
          max(0LL, md * mp['S'] * vv[1] - v[1] * vv[1]) +
          max(0LL, md * mp['C'] * vv[2] - v[2] * vv[2]);
    if (sum > r)
      hi = md - 1;
    else if (sum <= r) {
      lo = md + 1;
      res = md;
    }
  }
  cout << res << endl;
  return 0;
}
