/* -*- coding: utf-8 -*- * * 2386.cc: No.2386 Udon Coupon (Easy) - yukicoder */ #include #include using namespace std; /* constant */ const int M = 30; /* typedef */ /* global variables */ int dp[M + 1]; /* subroutines */ inline void setmax(int &a, int b) { if (a < b) a = b; } /* main */ int main() { int n, a, b, c; scanf("%d%d%d%d", &n, &a, &b, &c); int q = n / M, r = n % M; fill(dp, dp + M + 1, -1); dp[0] = 0; for (int i = 0; i + 3 <= r; i++) if (dp[i] >= 0) setmax(dp[i + 3], dp[i] + a); for (int i = 0; i + 5 <= r; i++) if (dp[i] >= 0) setmax(dp[i + 5], dp[i] + b); for (int i = 0; i + 10 <= r; i++) if (dp[i] >= 0) setmax(dp[i + 10], dp[i] + c); int x = max(max(10 * a, 6 * b), 3 * c) * q + *max_element(dp, dp + r + 1); printf("%d\n", x); return 0; }