#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long int
#define ld long double
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define endl '\n'
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
template<class T>
void printC (T Collection)
{
for (auto&i:Collection)
cout << i << " \n";
cout << '\n';
}
/*
* Think twice, code once
* Think of different approaches to tackle a problem: write them down.
* Think of different views of the problem. don't look from only one side.
* don't get stuck in one approach.
* common mistakes: - over_flow
* - out_of_bound index
* - infinite loop
* - corner cases
* - duplication counting.
*/
bool good(int mid,int Bcnt,int Scnt,int Ccnt,int B,int S,int C,int Bshop,int Sshop,int Cshop,int pounds)
{
int Bneed = Bcnt*mid, Sneed = Scnt*mid, Cneed = Ccnt*mid;
if (B < Bneed)
pounds -= Bshop*(Bneed-B);
if (S < Sneed)
pounds -= Sshop*(Sneed-S);
if (C < Cneed)
pounds -= Cshop*(Cneed-C);
return pounds >= 0;
}
void solve()
{
string s; cin >> s;
int Bcnt = 0, Scnt = 0, Ccnt = 0;
int B, S, C;
int Bshop, Sshop, Cshop;
int pounds;
for (int i = 0; i < s.size(); ++i)
{
if (s[i] == 'B')
Bcnt++;
else if (s[i] == 'S')
Scnt++;
else
Ccnt++;
}
cin >> B >> S >> C;
cin >> Bshop >> Sshop >> Cshop;
cin >> pounds;
int l = 0, r = 10e13, ans = 0;
while (l <= r)
{
int mid = (l+r)>>1;
if (good(mid, Bcnt, Scnt, Ccnt, B, S, C, Bshop, Sshop, Cshop, pounds))
{
ans = mid;
l = mid + 1;
}else
r = mid - 1;
}
cout << ans;
}
int32_t main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// freopen("Errors.txt", "w", stderr);
// #endif
fast
int t = 1;
// cin >> t;
while (t--)
{
solve();
if (t) cout << '\n';
}
cout << '\n';
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzd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kKICAgICAgICB7CiAgICAgICAgICAgIGFucyA9IG1pZDsKICAgICAgICAgICAgbCA9IG1pZCArIDE7CiAgICAgICAgfWVsc2UKICAgICAgICAgICAgciA9IG1pZCAtIDE7CiAgICB9CiAgICBjb3V0IDw8IGFuczsKfQoKaW50MzJfdCBtYWluKCkKewovLyAjaWZuZGVmIE9OTElORV9KVURHRQovLyAgICAgZnJlb3BlbigiaW5wdXQudHh0IiwgInIiLCBzdGRpbik7Ci8vICAgICBmcmVvcGVuKCJvdXRwdXQudHh0IiwgInciLCBzdGRvdXQpOwovLyAgICAgZnJlb3BlbigiRXJyb3JzLnR4dCIsICJ3Iiwgc3RkZXJyKTsKLy8gI2VuZGlmCiAgICBmYXN0CiAgICBpbnQgdCA9IDE7CiAgICAvLyBjaW4gPj4gdDsKICAgIHdoaWxlICh0LS0pCiAgICB7CiAgICAgICAgc29sdmUoKTsKICAgICAgICBpZiAodCkgY291dCA8PCAnXG4nOwogICAgfQogICAgY291dCA8PCAnXG4nOwogICAgcmV0dXJuIDA7Cn0=