hamburgers = input()
b, s, c = map(int, input().split())
q, w, e = map(int, input().split())
p = int(input())
F = str.count
B = F(hamburgers, 'B')
S = F(hamburgers, 'S')
C = F(hamburgers, 'C')
l = -1
r = 10 ** 20
while l < r-1:
m = (l + r) // 2
if q * max(0, B * m - b) + w * max(0, S * m - s) + e * max(0, C * m - c) <= p:
l = m
else:
r = m
print(l)
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define fo(i, a, n) for (int i = a; i <= n; i++)
#define repll(i, a, n) for (lli i = a; i <= n; i++)
#define mkp make_pair
#define pb emplace_back
#define ff first
#define ss second
#define ll long long
#define lli long long int
#define ii int, int
#define pii pair<int, int>
#define pll pair<long, long>
#define plli pair<long long int, long long int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vlli vector<long long int>
#define vpii vector<pair<int, int>>
#define vplli vector<pair<long long int, long long int>>
#define vvlli vector<vector<long long int>>
#define MAXLL 1e18
#define endl '\n'
#define sp ' '
#define dsort(v) sort(v.begin(), v.end(), greater<int>())
#define asort(v) sort(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define all(v) v.begin(), v.end()
#define umap unordered_map
#define uset unordered_set
#define sz(x) ((int)(x).size())
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define pr(x) cout << x
#define prsp(x) cout << x << sp
#define prln(x) cout << x << endl
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
#include<bits/stdc++.h>
using namespace std;
ll gcd(ll a, ll b)
{
if(b == 0) {
return a;
}
else {
return gcd(b, a % b);
}
}
long long lcm(long long a,long long b){
if(a>b)
return (a/gcd(a,b))*b;
else
return (b/gcd(a,b))*a;
}
const int mod = 1000000007;
void solve()
{
string s;
cin>> s;
ll b1,b2,b3,p1,p2,p3;
cin >> b1 >> b2 >> b3 >> p1 >> p2 >> p3;
ll r;
cin >> r;
ll a=0,b=0,c=0;
for(auto ch:s){
if(ch=='B') a++;
else if(ch=='S') b++;
else c++;
}
ll low=0,high=r+101;
while(low<=high){
ll mid=low+(high-low)/2;
ll z=0;
ll r1=max(a*mid-b1,z);
ll r2=max(b*mid-b2,z);
ll r3=max(c*mid-b3,z);
ll price=r1*p1+r2*p2+r3*p3;
if(price<=r) low=mid+1;
else high=mid-1;
}
cout<<high;
}
int main()
{
fastio;
solve();
}
1230B - Ania and Minimizing | 1201A - Important Exam |
676A - Nicholas and Permutation | 431A - Black Square |
474B - Worms | 987B - High School Become Human |
1223A - CME | 1658B - Marin and Anti-coprime Permutation |
14B - Young Photographer | 143A - Help Vasilisa the Wise 2 |
320A - Magic Numbers | 1658A - Marin and Photoshoot |
514A - Chewbaсca and Number | 382A - Ksenia and Pan Scales |
734B - Anton and Digits | 1080A - Petya and Origami |
1642D - Repetitions Decoding | 1440A - Buy the String |
1658F - Juju and Binary String | 478A - Initial Bet |
981A - Antipalindrome | 365A - Good Number |
1204B - Mislove Has Lost an Array | 1409D - Decrease the Sum of Digits |
1476E - Pattern Matching | 1107A - Digits Sequence Dividing |
1348A - Phoenix and Balance | 1343B - Balanced Array |
1186A - Vus the Cossack and a Contest | 1494A - ABC String |