#include using namespace std; #ifdef tabr #include "library/debug.cpp" #else #define debug(...) #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long n; cin >> n; vector> c(3); c[0].first = 3; c[1].first = 5; c[2].first = 10; for (int i = 0; i < 3; i++) { cin >> c[i].second; } sort(c.begin(), c.end(), [&](auto x, auto y) { return x.second * y.first < y.second * x.first; }); vector a(3), b(3); for (int i = 0; i < 3; i++) { a[i] = c[i].first; b[i] = c[i].second; } long long ans = 0; for (int i = 0; i < 2023; i++) { for (int j = 0; j < 2023; j++) { if (a[0] * i + a[1] * j > n) { break; } ans = max(ans, b[0] * i + b[1] * j + b[2] * ((n - a[0] * i - a[1] * j) / a[2])); } } cout << ans << '\n'; return 0; }