#!/usr/bin/env rdmd
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;

void main()
{
    for(string S; (S=readln().chomp()).length; )
    {
        long[3] h;
        foreach(c;S)
            if(c=='B') ++h[0];
            else if(c=='S') ++h[1];
            else ++h[2];
        auto n = array(readln().split().map!(to!long)());
        auto p = array(readln().split().map!(to!long)());
        auto r = readln().chomp().to!long();
        long lo=0, hi=1000000000000000;
        while(lo+1<hi)
        {
            auto m = (lo+hi)/2;
            long c = 0;
            foreach(i;0..3)
                c += p[i]*max(0,m*h[i]-n[i]);
            if(c<=r) lo=m;
            else hi=m;
        }
        writeln(lo);
    }
}
