#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
#ifdef __GNUC__
#include <ext/hash_map>
#define unordered_map __gnu_cxx::hash_map
#else
#include <unordered_map>
#endif
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
template<typename T>
struct DP2x
{
const int N1, N2;
vector<T> data;
DP2x(int, int N2, const T& t = T())
: N1(2), N2(N2), data(N1*N2, t) { assert(data.size()*sizeof(T)<(1<<26)); }
T& operator()(int i1, int i2)
{ i1&=1; return data[ (i1*N2)+i2 ]; }
void swap(DP2x& rhs)
{ data.swap(rhs.data); }
};
class ColorfulCookie { public:
int getMaximum(vector <int> cookies, int P1, int P2)
{
int L = 0;
int R = accumulate(cookies.begin(), cookies.end(), 0) / (P1+P2) + 1;
while( R-L > 1 ) { // [L, R)
int C = (L+R) / 2;
(possible(cookies, P1, P2, C) ? L : R) = C;
}
return L * (P1+P2);
}
bool possible(const vector<int>& C, int P1, int P2, int Times)
{
DP2x<int> maxP2forP1(C.size()+1, Times+1, -1);
maxP2forP1(0,0) = 0;
for(int i=0; i<C.size(); ++i)
for(int n=0; n<=Times; ++n) {
maxP2forP1(i+1,n) = maxP2forP1(i,n);
for(int a=0; a<=n; ++a) {
if( n-a>=0 && maxP2forP1(i,n-a)>=0 && C[i]-a*P1>=0 )
maxP2forP1(i+1,n) = max(maxP2forP1(i+1,n),
maxP2forP1(i,n-a) + min(Times-a,(C[i]-a*P1)/P2)
);
}
}
return maxP2forP1(C.size(), Times) >= Times;
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, ColorfulCookie().getMaximum(cookies, P1, P2));}
int main(){
CASE(0)
int cookies_[] = {100, 100};
vector <int> cookies(cookies_, cookies_+sizeof(cookies_)/sizeof(*cookies_));
int P1 = 50;
int P2 = 50;
int _ = 200;
END
CASE(1)
int cookies_[] = {50, 250, 50};
vector <int> cookies(cookies_, cookies_+sizeof(cookies_)/sizeof(*cookies_));
int P1 = 50;
int P2 = 100;
int _ = 300;
END
CASE(2)
int cookies_[] = {2000};
vector <int> cookies(cookies_, cookies_+sizeof(cookies_)/sizeof(*cookies_));
int P1 = 100;
int P2 = 200;
int _ = 0;
END
CASE(3)
int cookies_[] = {123, 456, 789, 555};
vector <int> cookies(cookies_, cookies_+sizeof(cookies_)/sizeof(*cookies_));
int P1 = 58;
int P2 = 158;
int _ = 1728;
END
/*
CASE(4)
int cookies_[] = ;
vector <int> cookies(cookies_, cookies_+sizeof(cookies_)/sizeof(*cookies_));
int P1 = ;
int P2 = ;
int _ = ;
END
CASE(5)
int cookies_[] = ;
vector <int> cookies(cookies_, cookies_+sizeof(cookies_)/sizeof(*cookies_));
int P1 = ;
int P2 = ;
int _ = ;
END
*/
}
// END CUT HERE