#include <bits/stdc++.h>
using namespace std;
const long long INF_LL = 0x3F3F3F3F3F3F3F3FLL;
int need[3];
int have[3];
int price[3];
int main() {
  string s;
  long long money;
  cin >> s;
  for (char ch : s) {
    if (ch == 'B') {
      ++need[0];
    } else if (ch == 'S') {
      ++need[1];
    } else {
      ++need[2];
    }
  }
  for (int i = 0; i < 3; ++i) cin >> have[i];
  for (int i = 0; i < 3; ++i) cin >> price[i];
  cin >> money;
  long long l = -1, r = 1e15 + 10;
  while (l + 1 < r) {
    long long mid = (l + r) >> 1;
    long long cost = 0;
    for (int i = 0; i < 3; ++i) {
      if (need[i] * mid > have[i]) {
        cost += (need[i] * mid - have[i]) * price[i];
      }
    }
    if (cost > money) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << l << endl;
  return 0;
}
