#include <bits/stdc++.h>
using namespace std;
const int MAX = 200005;
string str;
long long c[3], p[3], n[3];
long long ans, tmp, x, l, r, price;
int main() {
  cin >> str;
  for (int i = 0; i < str.size(); ++i) {
    if (str[i] == 'B') {
      ++c[0];
    } else {
      if (str[i] == 'S') {
        ++c[1];
      } else {
        ++c[2];
      }
    }
  }
  for (int i = 0; i < 3; ++i) {
    cin >> n[i];
  }
  for (int i = 0; i < 3; ++i) {
    cin >> p[i];
  }
  cin >> price;
  l = 1;
  r = 1e12 + 100;
  ans = 0;
  while (l <= r) {
    x = (l + r) >> 1;
    tmp = 0;
    for (int i = 0; i < 3; ++i) {
      tmp += p[i] * max(0LL, c[i] * x - n[i]);
    }
    if (tmp <= price) {
      ans = x;
      l = x + 1;
    } else {
      r = x - 1;
    }
  }
  cout << ans;
}
