#include <bits/stdc++.h>
using namespace std;

struct StCond                  // 材料質量・限界量
{
  int m_nWaterA;
  int m_nWaterB;
  int m_nSugerC;
  int m_nSugerD;
  double m_nConcE;
  int m_nLimitF;
};

struct StAmt                   // 使用量
{
  StAmt() : m_nAmtA(0), m_nAmtB(0), m_nAmtC(0), m_nAmtD(0) { }

  int m_nAmtA, m_nAmtB, m_nAmtC, m_nAmtD;
};

struct StRslt                  // 出力結果
{
  StRslt() : m_nAllMass(0), m_nSugerMass(0) { }

  int m_nAllMass, m_nSugerMass;
};

void fnInput(StCond& roCond)
{
  cin >> roCond.m_nWaterA >> roCond.m_nWaterB >> roCond.m_nSugerC >> roCond.m_nSugerD;
  cin >> roCond.m_nConcE  >> roCond.m_nLimitF;
}

double fnConcCalc(StAmt& roAmt, const StCond& cnroCond)
{
  int fnAmtProc(string, const StCond&, StAmt&);

  double nLimtConc = cnroCond.m_nConcE / (100.0 + cnroCond.m_nConcE);
  double nNowConc =  (double)fnAmtProc("sumSUG", cnroCond, roAmt)
                   / (double)fnAmtProc("sumALL", cnroCond, roAmt);

  if (nLimtConc < nNowConc)  return 0.0;
  else                       return nNowConc;
}

int fnAmtProc(string sProc, const StCond& cnroCond, StAmt& roAmt)
{ 
  if (sProc[0] == 'c')
  {
    if      (sProc[3] == 'A')
      { roAmt.m_nAmtA = 0; roAmt.m_nAmtB = 0; roAmt.m_nAmtC = 0; roAmt.m_nAmtD = 0; }
    else if (sProc[3] == 'B')
      { roAmt.m_nAmtB = 0; roAmt.m_nAmtC = 0; roAmt.m_nAmtD = 0; }
    else if (sProc[3] == 'C')
      { roAmt.m_nAmtC = 0; roAmt.m_nAmtD = 0; }
    else if (sProc[3] == 'D')
      { roAmt.m_nAmtD = 0; }
    return 0;
  }
  else                         // sProc[0] == 's'
    if      (sProc[3] == 'A')
      return  (cnroCond.m_nWaterA * roAmt.m_nAmtA + cnroCond.m_nWaterB * roAmt.m_nAmtB) * 100
            + (cnroCond.m_nSugerC * roAmt.m_nAmtC + cnroCond.m_nSugerD * roAmt.m_nAmtD);
    else                       // sProc[3] == 'S'         
      return  (cnroCond.m_nSugerC * roAmt.m_nAmtC + cnroCond.m_nSugerD * roAmt.m_nAmtD);
}

void fnConcCheck(const StCond& cnroCond, StRslt& roRslt)
{
  StAmt oAmt;
  double nMaxConc = -1.0;

  fnAmtProc("clrA", cnroCond, oAmt);
  while (true)
  {
    fnAmtProc("clrB", cnroCond, oAmt);
    if (fnAmtProc("sumALL", cnroCond, oAmt) > cnroCond.m_nLimitF)  break;

    if (!oAmt.m_nAmtA)  oAmt.m_nAmtB = 1;
    while (true)
    {
      fnAmtProc("clrC", cnroCond, oAmt);
      if (fnAmtProc("sumALL", cnroCond, oAmt) > cnroCond.m_nLimitF)  break;

      while (true)
      {
        fnAmtProc("clrD", cnroCond, oAmt);
        if (fnAmtProc("sumALL", cnroCond, oAmt) > cnroCond.m_nLimitF)  break;

        while (true)
        {
          if (fnAmtProc("sumALL", cnroCond, oAmt) > cnroCond.m_nLimitF)  break;

          double nNowConc = fnConcCalc(oAmt, cnroCond);
          if (nMaxConc < nNowConc)
          {
            nMaxConc = nNowConc;
            roRslt.m_nAllMass = fnAmtProc("sumALL", cnroCond, oAmt);
            roRslt.m_nSugerMass = fnAmtProc("sumSUG", cnroCond, oAmt);
          }
          oAmt.m_nAmtD++;
        }
        oAmt.m_nAmtC++;
      }
      oAmt.m_nAmtB++;
    }
    oAmt.m_nAmtA++;
  }
}

int main()
{
  StCond oCond;
  StRslt oRslt;

  fnInput(oCond);
  fnConcCheck(oCond, oRslt);
  cout << oRslt.m_nAllMass << " " << oRslt.m_nSugerMass << endl;

  return 0;
}

Measured memory_bytes: 256