#include using namespace std; using ll = long long; template using min_priority_queue = priority_queue, greater>; using pii = pair; using pll = pair; using Graph = vector>; const ll INF = 1LL << 60; template void chmax(T& a, T b) { if (b > a) a = b; } template void chmin(T& a, T b) { if (b < a) a = b; } template std::ostream& operator<<(std::ostream& os, const pair& x) noexcept { return os << "(" << x.first << ", " << x.second << ")"; } template void print_vector(vector a) { cout << '['; for (int i = 0; i < a.size(); i++) { cout << a[i]; if (i != a.size() - 1) { cout << ", "; } } cout << ']' << endl; } void solve() { ll N, A, B, C; cin >> N; ll nA = 3; ll nB = 5; ll nC = 10; cin >> A >> B >> C; ll ret = 0; for (int ic = 0; ic <= N / nC; ic++) { ll vc = C * ic; for (int ib = 0; ib <= N / nB; ib++) { ll n_fuda_BC = nC * ic + nB * ib; if (n_fuda_BC > N) break; ll vb = B * ib; ll ia = (N - n_fuda_BC) / nA; ll va = A * ia; chmax(ret, va + vb + vc); } } std::cout << ret << "\n"; // if (C * nA > A * nC && C * nB > B * nC) { // ll m = N / nC; // ret += m * C; // N -= nC * m; // } // if (B * nA > A * nB) { // ll m = N / nB; // ret += m * B; // N -= nB * m; // } // ll m = N / nA; // ret += m * A; // N -= nA * m; // std::cout << ret << "\n"; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int T = 1; while (T--) { solve(); } return 0; }