#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int n, a, b, c; cin >> n >> a >> b >> c; vector memo(n + 1, -1); auto dfs = [&](auto &&self, int x) -> int { if (x == 0) return 0; if (memo[x] != -1) return memo[x]; int res = 0; if (x >= 3) res = max(res, self(self, x - 3) + a); if (x >= 5) res = max(res, self(self, x - 5) + b); if (x >= 10) res = max(res, self(self, x - 10) + c); return memo[x] = res; }; cout << dfs(dfs, n) << endl; return 0; }