#include <bits/stdc++.h>
using namespace std;
bool isFile = 0;
const long long INF = 1e18 + 1234;
const int N = 1e6 + 1234;
const long long MOD = 998244353;
const long long mod = 1e9 + 7;
double EPS = 3e-18;
const double PI = acos(-1);
void faster() {
  if (isFile) {
    freopen(
        ""
        ".in",
        "r", stdin);
    freopen(
        ""
        ".out",
        "w", stdout);
  }
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
long long used[N];
void solve() {
  string second;
  cin >> second;
  long long b[3], s[3], c[3], p, l = 0, r = 1e13;
  b[0] = 0;
  s[0] = 0;
  c[0] = 0;
  int n = (int)second.size();
  for (int i = 0; i < n; i++) {
    if (second[i] == 'B') b[0]++;
    if (second[i] == 'S') s[0]++;
    if (second[i] == 'C') c[0]++;
  }
  cin >> b[1] >> s[1] >> c[1];
  cin >> b[2] >> s[2] >> c[2];
  cin >> p;
  while (l + 1 < r) {
    long long m = (l + r) / 2;
    long long q = 0;
    if (m * b[0] - b[1] > 0) q += (m * b[0] - b[1]) * b[2];
    if (m * s[0] - s[1] > 0) q += (m * s[0] - s[1]) * s[2];
    if (m * c[0] - c[1] > 0) q += (m * c[0] - c[1]) * c[2];
    if (q > p)
      r = m;
    else
      l = m;
  }
  cout << l;
}
int main() {
  faster();
  int t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
