#include <bits/stdc++.h>
using namespace std;
long long rules;
int arr[3], chekin[3], shop[3];
bool valid(long long n) {
  long long r = rules;
  for (int i = 0; i < 3; i++)
    if (1ll * chekin[i] - arr[i] * n < 0) {
      r -= abs(1ll * chekin[i] - arr[i] * n) * shop[i];
      if (r < 0) return 0;
    }
  return 1;
}
long long bs() {
  long long st = 0, en = 10000000000000, mid;
  while (st < en) {
    mid = st + (en - st + 1) / 2;
    if (valid(mid))
      st = mid;
    else
      en = mid - 1;
  }
  return st;
}
int main() {
  string str;
  cin >> str;
  for (int i = 0; i < str.size(); i++) {
    if (str[i] == 'B') arr[0]++;
    if (str[i] == 'S') arr[1]++;
    if (str[i] == 'C') arr[2]++;
  }
  for (int i = 0; i < 3; i++) cin >> chekin[i];
  for (int i = 0; i < 3; i++) cin >> shop[i];
  cin >> rules;
  cout << bs() << endl;
}
