public void solve() throws IOException {
    String burger = nextLine();
    int bread = nextInt();
    int sausage = nextInt();
    int cheese = nextInt();
    int bprice = nextInt();
    int sprice = nextInt();
    int cprice = nextInt();
    BigInteger money = new BigInteger(nextLine());

    int bcount = burger.length() - burger.replaceAll("B", "").length();
    int scount = burger.length() - burger.replaceAll("S", "").length();
    int ccount = burger.length() - burger.replaceAll("C", "").length();

    int burgerprice = bcount * bprice + scount * sprice + ccount * cprice;
    int count = 0;
    while (bread > 0 || sausage > 0 || cheese > 0) {
      if (bread >= bcount)
        bread -= bcount;
      else {
        money = money.subtract(new BigInteger(String.valueOf(bprice * (bcount - bread))));
        bread = 0;
      }

      if (sausage >= scount)
        sausage -= scount;
      else {
        money = money.subtract(new BigInteger(String.valueOf(sprice * (scount - sausage))));
        sausage = 0;
      }

      if (cheese >= ccount)
        cheese -= ccount;
      else {
        money = money.subtract(new BigInteger(String.valueOf(cprice * (ccount - cheese))));
        cheese = 0;
      }

      // System.out.println(money.toString());

      if (money.compareTo(new BigInteger("0")) < 0) {
        System.out.println(count);
        return;
      }
      count++;

      // System.out.println(bread + " " + sausage + " " + cheese);
    }
    BigInteger additional = money.divide(new BigInteger(String.valueOf(burgerprice)));
    System.out.println(additional.add(new BigInteger(String.valueOf(count))).toString());
  }