#include #define int long long int n, a, b, c, ans, tmp; signed main(){ scanf("%lld", &n); scanf("%lld%lld%lld", &a, &b, &c); ans = n / 30 * std::max(10 * a, std::max(6 * b, 3 * c)); n = n % 30; for(int i = 0;3 * i <= n;i++){ for(int j = 0;3 * i + 5 * j <= n;j++){ for(int k = 0;3 * i + 5 * j + 10 * k <= n;k++){ tmp = std::max(tmp, i * a + j * b + k * c); } } } printf("%lld", ans + tmp); return 0; }