#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1e9;
const long long LINF = INF * (long long)INF;
const double EPS = 1e-7;
const int MAX = 20 * 1000 + 47;
const int MAS = 2 * 1e5 + 10;
const int MOD = 998244353;
long long haves, haveb, havec;
long long priceb, prices, pricec;
long long money;
long long cntS, cntB, cntC;
bool check(long long cnt) {
  long long a1 = max(0LL, (cntS * cnt - haves) * prices);
  long long a2 = max(0LL, (cntB * cnt - haveb) * priceb);
  long long a3 = max(0LL, (cntC * cnt - havec) * pricec);
  return a1 + a2 + a3 <= money;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  cntC = cntB = cntC = 0;
  for (int i = (0); i < ((int)s.size()); i++) {
    if (s[i] == 'S') cntS++;
    if (s[i] == 'B') {
      cntB++;
    }
    if (s[i] == 'C') cntC++;
  }
  cin >> haveb >> haves >> havec;
  cin >> priceb >> prices >> pricec;
  cin >> money;
  long long l = 0;
  long long r = 1e14 + 10;
  for (int i = (0); i < (200); i++) {
    long long m = (l + r) / 2;
    if (check(m)) {
      l = m;
    } else {
      r = m;
    }
  }
  cout << l << endl;
}
