#include <bits/stdc++.h>
using namespace std;
string vow = "aeiou";
const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const long double pie = 3.14159265358979;
const long long mod = 1e9 + 7;
void solve(int test_case) {
  string s;
  cin >> s;
  long long q[3], p[3];
  for (int i = 0; i < 3; i++) cin >> q[i];
  for (int i = 0; i < 3; i++) cin >> p[i];
  long long r;
  cin >> r;
  long long h[3] = {};
  for (auto i : s) {
    if (i == 'B')
      h[0]++;
    else if (i == 'S')
      h[1]++;
    else
      h[2]++;
  }
  long long ans = 0;
  for (long long lo = 0, hi = 1e13; lo <= hi;) {
    long long mid = lo + hi >> 1;
    long long money_needed = 0;
    for (int i = 0; i < 3; ++i)
      money_needed += max(0LL, mid * h[i] - q[i]) * p[i];
    if (money_needed <= r) {
      ans = mid;
      lo = mid + 1;
    } else
      hi = mid - 1;
  }
  cout << ans;
  cout << "\n";
}
int main() {
  int t = 1;
  for (int i = 0; i < t; i++) solve(i);
  return 0;
}
