#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 5, INF = (int)1e9;
const long double EPS = 1e-9;
int a[N], n, m;
long long n1, n2, n3, p1, p2, p3, first, second, z, ss;
string s;
bool check(long long m, long long r, long long n1, long long n2, long long n3) {
  long long a = first * m, b = second * m, c = z * m;
  r = r - max(0LL, a - n1) * p1 - max(0LL, b - n2) * p2 - max(0LL, c - n3) * p3;
  if (r < 0) return false;
  return true;
}
int main() {
  long long l = 0, r = (long long)1e13, m, rr;
  cin >> s;
  cin >> n1 >> n2 >> n3 >> p1 >> p2 >> p3 >> rr;
  n = (int)s.size();
  for (int i = 0; i < n; i++) {
    if (s[i] == 'B') first++;
    if (s[i] == 'S') second++;
    if (s[i] == 'C') z++;
  }
  ss = p1 * first + p2 * second + p3 * z;
  while (r - l > 1) {
    m = (l + r) / 2;
    if (check(m, rr, n1, n2, n3))
      l = m;
    else
      r = m;
  }
  cout << l << endl;
  return 0;
}
