#pragma GCC target("avx,avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #include using namespace std; using ll = long long int; //// 任意長整数型 //namespace mp = boost::multiprecision; //using Bint = mp::cpp_int; int main() { //input int N; cin >> N; int A, B, C; cin >> A >> B >> C; vector dp(N + 1); for (int i = 0; i < N + 1; ++i) { dp[i] = 0; } for (int index = N; 0 <= index; --index) { if (3 <= index) { dp[index - 3] = max(dp[index - 3], dp[index] + A); } if (5 <= index) { dp[index - 5] = max(dp[index - 5], dp[index] + B); } if (10 <= index) { dp[index - 10] = max(dp[index - 10], dp[index] + C); } } int ans = 0; for (int i = 0; i < 10; ++i) { ans = max(ans, dp[i]); } //ans cout << ans << endl; return 0; }