#include <bits/stdc++.h>
using namespace std;
string str;
long long b, s, c, nb, ns, nc, pb, ps, pc;
long long R;
long long l = 0, r = 1e14, mid;
void input();
bool check(long long x);
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  input();
  while (l <= r) {
    mid = (l + r) / 2;
    if (check(mid))
      l = mid + 1;
    else
      r = mid - 1;
  }
  cout << l - 1 << endl;
  return 0;
}
void input() {
  cin >> str;
  for (int i = 0; i < str.size(); i++) {
    if (str[i] == 'B')
      b++;
    else if (str[i] == 'S')
      s++;
    else
      c++;
  }
  cin >> nb >> ns >> nc;
  cin >> pb >> ps >> pc;
  cin >> R;
}
bool check(long long x) {
  long long bnd = b * x;
  long long snd = s * x;
  long long cnd = c * x;
  long long m = R;
  if (bnd > nb) m -= (bnd - nb) * pb;
  if (snd > ns) m -= (snd - ns) * ps;
  if (cnd > nc) m -= (cnd - nc) * pc;
  return m >= 0LL;
}
