#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
map<char, long long> mp;
string s;
long long nb, nc, ns, pb, ps, pc, ans = 0, r, low = 0, high = 10000000000000,
                                  mid;
long long ok(long long mid) {
  long long cost = 0;
  if (mp['B'] * mid > nb) {
    cost += ((mp['B'] * mid) - (nb)) * pb;
  }
  if (mp['S'] * mid > ns) {
    cost += ((mp['S'] * mid) - (ns)) * ps;
  }
  if (mp['C'] * mid > nc) {
    cost += ((mp['C'] * mid) - (nc)) * pc;
  }
  return cost <= r;
}
int main() {
  cin >> s >> nb >> ns >> nc >> pb >> ps >> pc >> r;
  for (long long i = 0; i < s.size(); i++) mp[s[i]]++;
  while (low <= high) {
    mid = (low + high) / 2;
    if (ok(mid)) {
      ans = mid;
      low = mid + 1;
    } else
      high = mid - 1;
  }
  cout << ans;
  return 0;
}
