#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, mod = 1e9 + 7;
long long need[500];
char s[200];
long long nb, ns, nc, push_back, ps, pc, ru;
long long check(long long n) {
  long long money;
  money = max(0ll, n * need['B'] - nb) * push_back +
          max(0ll, n * need['C'] - nc) * pc + max(0ll, n * need['S'] - ns) * ps;
  return money;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int i, j, k, m, n;
  cin >> s;
  for (i = 0; s[i]; ++i) {
    need[int(s[i])]++;
  }
  cin >> nb >> ns >> nc >> push_back >> ps >> pc >> ru;
  long long l = 0, r = 1e15 + 10;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (check(mid) <= ru)
      l = mid + 1;
    else
      r = mid;
  }
  if (check(l) > ru) l--;
  cout << l;
  return 0;
}
