#include using namespace std; typedef long long int ll; typedef unsigned long long ull; typedef long double ld; int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, 1, 0, -1, 1, -1, 1, -1 }; const long long mod = 998244353; const ll inf = 1LL << 60; const int INF = 1e9 + 1; int main() { int n; cin >> n; int a, b, c; cin >> a >> b >> c; int x = max({ 10 * a, 6 * b, 3 * c }); if (n <= 30) { int ans = 0; ans += n / 30 * x; n %= 30; int plus = 0; for (int i = 0; i < 20; i++) { for (int j = 0; j < 12; j++) { for (int k = 0; k < 6; k++) { int sum = 0; if (3 * i + 5 * j + 10 * k > n) continue; sum = i * a + j * b + k * c; plus = max(plus, sum); } } } cout << ans + plus << endl; return 0; } int ans = 0; ans += (n - 30) / 30 * x; n %= 30; n += 30; int plus = 0; for (int i = 0; i < 20; i++) { for (int j = 0; j < 12; j++) { for (int k = 0; k < 6; k++) { int sum = 0; if (3 * i + 5 * j + 10 * k > n) continue; sum = i * a + j * b + k * c; plus = max(plus, sum); } } } cout << ans + plus << endl; }