#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int sz = 200002;
long long na, nb, nc, pa, push_back, pc, rb, a = 0, b = 0, c = 0;
void bs(long long m, char &ch) {
  long long an = m * a, bn = m * b, cn = c * m;
  long long dr = rb;
  bool can = true;
  if (na < an) {
    if ((an - na) * pa <= dr) {
      dr -= pa * (an - na);
    } else
      can = false;
  }
  if (nb < bn) {
    if ((bn - nb) * push_back <= dr) {
      dr -= push_back * (bn - nb);
    } else
      can = false;
  }
  if (nc < cn) {
    if ((cn - nc) * pc <= dr) {
      dr -= pc * (cn - nc);
    } else
      can = false;
  }
  if (can)
    ch = 'R';
  else
    ch = 'L';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  cin >> na >> nb >> nc;
  cin >> pa >> push_back >> pc;
  cin >> rb;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B')
      a++;
    else if (s[i] == 'S')
      b++;
    else
      c++;
  }
  long long toAdd = 0;
  while (na >= a && nb >= b && nc >= c) {
    toAdd++;
    na -= a;
    nb -= b;
    nc -= c;
  }
  long long l = 0, r = 1000000000000;
  long long mid;
  while (l < r) {
    mid = l + (r - l + 1) / 2;
    char ch = 'x';
    bs(mid, ch);
    if (ch == 'R')
      l = mid;
    else
      r = mid - 1;
  }
  cout << l + toAdd << '\n';
}
