#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; __int64 ma[4], st[4], p[4], mon; char s[1000]; bool judge(__int64 x) { __int64 res = mon; for (__int64 i = 0; i < 3; i++) { if (st[i] < x*ma[i]) { if (res < (x*ma[i] - st[i])*p[i]) return false; else res -= (x*ma[i] - st[i])*p[i]; } } return true; } int main() { while (scanf("%s", s) != EOF) { cin>>st[0]>>st[1]>>st[2]; cin>>p[0]>>p[1]>>p[2]; cin>>mon; ma[0] = 0, ma[1] = 0, ma[2] = 0; __int64 len = strlen(s); for (__int64 i = 0; i < len; i++) { if (s[i] == 'B') ma[0]++; else if (s[i] == 'S') ma[1]++; else ma[2]++; } __int64 lb = 0, ub = 2e13, ans; while (ub >= lb) { __int64 mid = (ub + lb)>>1; if (judge(mid)) { ans = mid; lb = mid + 1; } else ub = mid - 1; } cout<<ans<<endl; } return 0; }