#include #include using ll = long long; using ull = unsigned long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define REP(i, m, n) for(int i = (int)(m); i < (int)(n); i++) using namespace std; using namespace atcoder; using mint = modint998244353; const int inf = 1000000007; const ll longinf = 1ll << 60; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; ll b, c, x; cin >> b >> c >> x; ll d = b + c; vector a(n - 1); rep(i, n - 1) cin >> a[i]; vector> dp(n); dp[0][0] = x; ll ans = longinf; rep(i, n - 1) { for(auto [ct, cx] : dp[i]) { int k = i; ll nt = ct; while(k < n - 1) { nt += a[k++]; if(nt % d > b) { break; } } if(k == n - 1) { ll ret = max(nt - cx, 0ll); if(ret % d > b) { ret = (ret + d - 1) / d * d; } ans = min(ans, ret); } else { ll s = (nt + d - 1) / d * d; dp[k][s] = max(dp[k][s], cx); ll e = nt / d * d + b; ll need = nt - e; if(cx >= need) { dp[k][e] = max(dp[k][e], cx - need); } } } } cout << ans << endl; return 0; }