#include <bits/stdc++.h>
using namespace std;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
inline int addmod(int x, int y) {
  return (x % 1000000007 + y % 1000000007) % 1000000007;
}
inline int submod(int x, int y) {
  return (x % 1000000007 - y % 1000000007 + 1000000007) % 1000000007;
}
inline int mulmod(int x, int y) {
  return (x % 1000000007 * 1LL * y % 1000000007) % 1000000007;
}
inline int nextSubMask(int i, int mask) { return (i - 1) & mask; }
void we_r_done() {
  cout << "NO";
  exit(0);
}
void debug(bool ok, string mssg) {
  if (ok) return;
  cout << mssg;
  exit(0);
}
int main() {
  string S;
  int cb, cs, cc;
  int push_back, ps, pc;
  long long int r;
  cin >> S;
  cin >> cb >> cs >> cc;
  cin >> push_back >> ps >> pc;
  cin >> r;
  int b = 0, s = 0, c = 0;
  for (int i = 0; i < S.size(); i++) {
    b += (S[i] == 'B');
    s += (S[i] == 'S');
    c += (S[i] == 'C');
  }
  long long int ans = 0;
  long long int lo = 0, hi = 1LL << 50, mid;
  while (lo <= hi) {
    mid = (lo + hi) / 2;
    long long int cost = max((mid * b - cb) * push_back, 0LL) +
                         max((mid * s - cs) * ps, 0LL) +
                         max((mid * c - cc) * pc, 0LL);
    if (cost > r)
      hi = mid - 1;
    else {
      ans = max(ans, mid);
      lo = mid + 1;
    }
    if (lo == hi && mid == lo) break;
  }
  cout << ans;
  return 0;
}
