#include <bits/stdc++.h>
using namespace std;
long long nb, ns, nc, pb, ps, pc;
long long cnt[3] = {0};
long long r;
bool can(long long m) {
  long long cb = pb * (max(m * cnt[0] - nb, 1LL * 0));
  long long cs = ps * (max(m * cnt[1] - ns, 1LL * 0));
  long long cc = pc * (max(m * cnt[2] - nc, 1LL * 0));
  if (r >= cb + cs + cc)
    return true;
  else
    return false;
}
int main() {
  string s;
  cin >> s;
  cin >> nb >> ns >> nc >> pb >> ps >> pc >> r;
  for (int i = 0; i < s.size(); ++i)
    if (s[i] == 'B')
      ++cnt[0];
    else if (s[i] == 'S')
      ++cnt[1];
    else
      ++cnt[2];
  long long ans = 0;
  long long high = 1e12 + 100, low = 0, mid;
  while (high >= low) {
    mid = (high + low) / 2;
    if (can(mid)) {
      ans = max(ans, mid);
      low = mid + 1;
    } else
      high = mid - 1;
  }
  cout << ans;
}
