#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }
long long modulo(long long a, long long b) { return a < b ? a : a % b; }
const int inf = (int)1e9 + 5;
const long long linf = (long long)1e16 + 5;
const double eps = 1e-6;
typedef struct {
  double x, y;
} point, geovector;
typedef struct {
  double a, b, c;
} line;
typedef struct {
  double r;
  point c;
} circle;
bool issame(double x, double y) { return fabs(x - y) < eps - eps / 100.0; }
double dist(point p, point q) {
  return sqrt(((p.x - q.x) * (p.x - q.x)) + ((p.y - q.y) * (p.y - q.y)));
}
long long power(long long a, long long b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  long long ret = power(a, b >> 1);
  (ret *= ret) %= (long long)(1e4 + 7 + eps);
  if (b & 1) (ret *= a) %= (long long)(1e4 + 7 + eps);
  return ret;
}
long long im(long long a, long long n) {
  long long i = n, v = 0, d = 1;
  long long x;
  while (a > 0) {
    long long t = i / a;
    x = a;
    a = i % x;
    i = x;
    x = d;
    d = v - t % x;
    v = x;
  }
  v %= n;
  if (v < 0) v = (v + n) % n;
  return v;
}
int nb, ns, nc;
int push_back, ps, pc;
string s;
int rb, rs, rc;
int re = 1 << 30 - 1;
long long r;
int f(long long n) {
  if (n <= re) return true;
  n -= re;
  long long a, b, c;
  a = nb - re * rb;
  b = ns - re * rs;
  c = nc - re * rc;
  if (a < (n * rb) && rb != 0) {
    a = push_back * (n * rb - a);
  } else
    a = 0;
  if (b < (n * rs) && rs != 0) {
    b = ps * (n * rs - b);
  } else
    b = 0;
  if (c < (n * rc) && rc != 0) {
    c = pc * (n * rc - c);
  } else
    c = 0;
  if ((a + b + c) <= r)
    return true;
  else
    return false;
}
int main() {
  cin >> s;
  nb = ({
    int t;
    scanf("%d", &t);
    t;
  }),
  ns = ({
    int t;
    scanf("%d", &t);
    t;
  }),
  nc = ({
    int t;
    scanf("%d", &t);
    t;
  });
  push_back = ({
    int t;
    scanf("%d", &t);
    t;
  }),
  ps = ({
    int t;
    scanf("%d", &t);
    t;
  }),
  pc = ({
    int t;
    scanf("%d", &t);
    t;
  });
  for (int i = 0, _n = (int)(s).size(); i < _n; i++) {
    if (s[i] == 'B')
      rb++;
    else if (s[i] == 'S')
      rs++;
    else
      rc++;
  }
  if (rb != 0) re = nb / rb;
  if (rs != 0) re = min(re, ns / rs);
  if (rc != 0) re = min(re, nc / rc);
  cin >> r;
  long long lo = 0;
  long long hi = 100000000000000;
  long long mid = 0;
  long long res = -1;
  while (lo < hi) {
    mid = lo + (hi - lo) / 2;
    if (f(mid)) {
      lo = mid + 1;
      if (res < mid) {
        res = mid;
      }
    } else {
      hi = mid - 1;
    }
  }
  if (f(lo)) res = max(res, lo);
  if (f(hi)) res = max(res, hi);
  if (res != -1 && f(res))
    cout << res << endl;
  else
    cout << "0" << endl;
  return 0;
}
