#include <bits/stdc++.h>
using namespace std;
vector<long long int> n(3), p(3), cnt(3);
long long int r, ans = 1000000000, price = 0;
bool flag = 1;
void next() {
  if (!(n[0] | n[1] | n[2])) {
    ans += r / price;
    r %= price;
    flag = false;
    return;
  }
  for (long long int i = 0; i < 3; i++) {
    if (cnt[i] > 0) {
      if (n[i] / cnt[i] == 0) {
        if ((cnt[i] - n[i]) * p[i] <= r) {
          r -= (cnt[i] - n[i]) * p[i];
          n[i] = 0;
        } else
          flag = false;
      } else
        n[i] -= cnt[i];
    }
  }
  if (flag) ans++;
  return;
}
void solve() {
  string recipe;
  cin >> recipe;
  for (long long int i = 0; i < 3; i++) cin >> n[i];
  for (long long int i = 0; i < 3; i++) cin >> p[i];
  cin >> r;
  for (char c : recipe) {
    if (c == 'B') {
      cnt[0]++;
      price += p[0];
    } else if (c == 'C') {
      cnt[2]++;
      price += p[2];
    } else {
      cnt[1]++;
      price += p[1];
    };
  }
  for (long long int i = 0; i < 3; i++) {
    if (cnt[i] > 0)
      ans = min(ans, n[i] / cnt[i]);
    else
      n[i] = 0;
  }
  for (long long int i = 0; i < 3; i++) {
    n[i] -= cnt[i] * ans;
  }
  while (flag) {
    next();
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int test;
  test = 1;
  while (test--) {
    solve();
    cout << '\n';
  }
  return 0;
}
