#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const double eps = 1e-7;
const int maxn = 2e5 + 9;
const double pi = acos(-1.0);
const double inf = 1e17;
const int mod = 1e9 + 7;
char op[109];
long long pq[3], io[3], yu[3], tmp;
bool test(long long p) {
  long long kl = tmp;
  for (int i = 0; i < 3; ++i) {
    long long jk = max(0ll, io[i] * p - pq[i]);
    if (kl >= jk * yu[i]) {
      kl -= jk * yu[i];
    } else
      return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> op;
  for (int i = 0; op[i]; ++i) {
    if (op[i] == 'B')
      ++io[0];
    else if (op[i] == 'S')
      ++io[1];
    else
      ++io[2];
  }
  for (int i = 0; i < 3; ++i) cin >> pq[i];
  for (int i = 0; i < 3; ++i) cin >> yu[i];
  cin >> tmp;
  long long l = 0, r = 1e13;
  while (l < r - 1) {
    long long mid = (l + r) / 2;
    if (test(mid))
      l = mid;
    else
      r = mid;
  }
  cout << l;
  return 0;
}
