#include <bits/stdc++.h>
using namespace std;
long long int avail[3], price[3], br = 0, sa = 0, ch = 0;
long long int r;
long long int ans = 0, final = 0;
void binary(long long int x, long long int y) {
  if (x > y) return;
  long long int mid = x + (y - x) / 2;
  long long int number =
      max((long long int)0, ((br * mid - avail[0]) * price[0]));
  number += max((long long int)0, ((sa * mid - avail[1]) * price[1]));
  number += max((long long int)0, ((ch * mid - avail[2]) * price[2]));
  if (number >= ans && number <= r) {
    ans = number;
    final = mid;
  }
  if (number > r)
    binary(x, mid - 1);
  else if (number < r)
    binary(mid + 1, y);
  return;
}
int main() {
  string s;
  cin >> s;
  for (int i = 0; i < 3; i++) cin >> avail[i];
  for (int i = 0; i < 3; i++) cin >> price[i];
  cin >> r;
  for (int k = 0; k < s.size(); k++) {
    if (s[k] == 'B') br++;
    if (s[k] == 'S') sa++;
    if (s[k] == 'C') ch++;
  }
  binary(0, 1000000000101);
  cout << final;
}
