#include <bits/stdc++.h>
long long n_b, n_s, n_c, p_b, p_s, p_c;
int r_b, r_s, r_c;
long long money;
long long ans;
long long cmp(long long x, long long y) {
  if (x > y) {
    return x;
  } else {
    return y;
  }
}
bool check(long long mid) {
  long long pan;
  pan = money;
  if (n_b < r_b * mid) {
    pan -= (r_b * mid - n_b) * p_b;
  }
  if (n_s < r_s * mid) {
    pan -= (r_s * mid - n_s) * p_s;
  }
  if (n_c < r_c * mid) {
    pan -= (r_c * mid - n_c) * p_c;
  }
  if (pan < 0) {
    return 0;
  } else {
    return 1;
  }
}
long long binary() {
  long long left, right, mid;
  ans = 0;
  left = 0;
  right = cmp(n_b + money / p_b, cmp(n_s + money / p_s, n_c + money / p_c));
  while (left <= right) {
    mid = left + (right - left) / 2;
    if (check(mid)) {
      if (mid > ans) {
        ans = mid;
      }
      left = mid + 1;
    } else {
      right = mid - 1;
    }
  }
  return ans;
}
using namespace std;
int main() {
  int T;
  int i;
  int n;
  char let[107];
  cin >> let;
  cin >> n_b >> n_s >> n_c;
  cin >> p_b >> p_s >> p_c;
  cin >> money;
  n = strlen(let);
  r_b = r_s = r_c = 0;
  for (i = 0; i < n; i++) {
    if (let[i] == 'B') {
      r_b++;
    } else if (let[i] == 'S') {
      r_s++;
    } else if (let[i] == 'C') {
      r_c++;
    }
  }
  ans = binary();
  printf("%lld\n", ans);
  return 0;
}
