/**
CodeForces 371C Hamburgers 二分
链接:https://codeforces.com/problemset/problem/371/C
题意:给定一个只含'B' 'S' 'C' 字符的字符串;
现在给出部分'B' 'S' 'C' 的数量 及 分别对应字符的价格;
现在拥有sum的钱 这些能够买到相应的字符
问 买入部分字符后 最多能够得到多少个原始的字符串
分析:二分直接枚举答案,看所花钱和拥有的钱的大小即可卡出答案;
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int cntb,cnts,cntc;
int nb,ns,nc;
int pb,ps,pc;
ll sum;
bool judge(ll x){
ll cost=0;
if(x*cntb>nb) cost+=(x*cntb-nb)*pb;
if(x*cnts>ns) cost+=(x*cnts-ns)*ps;
if(x*cntc>nc) cost+=(x*cntc-nc)*pc;
return cost>sum;
}
int main (){
ios_base::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
string str;
cin>>str;
cntb=0,cnts=0,cntc=0;
int len=str.length();
for(int i=0;i<len;i++)
if(str[i]=='B') cntb++;
else if(str[i]=='S') cnts++;
else if(str[i]=='C') cntc++;
cin>>nb>>ns>>nc;
cin>>pb>>ps>>pc;
cin>>sum;
ll l=0,r=1e12+101,mid;//二分上界为最多的字符数量; 或者是 sum + max(na,nb,nc) + 1;
while(r-l>1){
mid=(l+r)/2;
if(judge(mid)) r=mid;
else l=mid;
}
cout<<l<<endl;
return 0;
}