#include <bits/stdc++.h>
using namespace std;
int main() {
  string z;
  int bp, sp, cp, bread = 0, sausage = 0, cheese = 0, b, s, c;
  long long int money, ans = 0;
  cin >> z;
  for (int i = 0; i < z.size(); i++) {
    if (z[i] == 'B') bread++;
    if (z[i] == 'S') sausage++;
    if (z[i] == 'C') cheese++;
  }
  cin >> b >> s >> c >> bp >> sp >> cp >> money;
  if (sausage == 0) s = 0;
  if (bread == 0) b = 0;
  if (cheese == 0) c = 0;
  while (123456789) {
    if (b == 0 && s == 0 && c == 0) break;
    if (money < 0) {
      ans--;
      break;
    }
    if (b >= bread) {
      b = b - bread;
    } else {
      money = money - ((bread - b) * bp);
      if (money < 0) continue;
      b = b + (bread - b);
      b = b - bread;
    }
    if (s >= sausage) {
      s = s - sausage;
    } else {
      money = money - ((sausage - s) * sp);
      if (money < 0) continue;
      s = s + (sausage - s);
      s = s - sausage;
    }
    if (c >= cheese) {
      c = c - cheese;
    } else {
      money = money - ((cheese - c) * cp);
      if (money < 0) continue;
      c = c + (cheese - c);
      c = c - cheese;
    }
    ans++;
  }
  if (money < 0) ans++;
  ans = ans + (money / ((bp * bread) + (cp * cheese) + (sp * sausage)));
  cout << ans;
  return 0;
}
