#include <bits/stdc++.h>
using namespace std;
vector<int> phi;
vector<int> spf;
void banao(int n) {
  phi.resize(n + 1);
  for (int i = 0; i < n + 1; i++) phi[i] = i;
  for (int k = 2; k < n + 1; k++) {
    if (phi[k] == k) {
      phi[k] = k - 1;
      for (int i = 2 * k; i <= n; i += k) {
        phi[i] = (phi[i] / k) * (k - 1);
      }
    }
  }
}
bool isprime(int n) {
  if (phi[n] == n - 1)
    return true;
  else
    return false;
}
void pfactor(int n) {
  spf.resize(n + 1, 1);
  for (int i = 2; i < n + 1; i++) spf[i] = i;
  for (int i = 4; i <= n; i += 2) spf[i] = 2;
  for (int i = 3; i * i <= n; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j <= n; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
vector<int> tpf(int x) {
  vector<int> ret;
  while (x != 1) {
    ret.push_back(spf[x]);
    x = x / spf[x];
  }
  return ret;
}
int main() {
  int Test = 1;
  while (Test--) {
    string s;
    cin >> s;
    long long ab, as, ac;
    cin >> ab >> as >> ac;
    long long push_back, ps, pc;
    cin >> push_back >> ps >> pc;
    long long r;
    cin >> r;
    long long nb = 0, ns = 0, nc = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == 'B') {
        nb++;
      } else if (s[i] == 'S') {
        ns++;
      } else {
        nc++;
      }
    }
    if (nb == 0) {
      ab = 0;
    }
    if (ns == 0) {
      as = 0;
    }
    if (nc == 0) {
      ac = 0;
    }
    long long tp = (nb * push_back) + (ns * ps) + (nc * pc);
    long long ans = 0;
    while (ab || as || ac) {
      if (ab >= nb) {
        ab -= nb;
      } else {
        r -= ((nb - ab) * push_back);
        ab = 0;
      }
      if (as >= ns) {
        as -= ns;
      } else {
        r -= ((ns - as) * ps);
        as = 0;
      }
      if (ac >= nc) {
        ac -= nc;
      } else {
        r -= ((nc - ac) * pc);
        ac = 0;
      }
      if (r >= 0) {
        ans++;
      }
      if (r <= 0) {
        break;
      }
    }
    if (r <= 0) {
      cout << ans;
    } else {
      ans += (r / tp);
      cout << ans;
    }
  }
}
