#include using namespace std; auto main() -> int { int n; cin >> n; vector b{3, 5, 10}; vector a(3); for (int i = 0; i < 3; i++) { cin >> a[i]; } vector dp(n + 1); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { int k = i + b[j]; if (k > n) { continue; } dp[k] = max(dp[k], dp[i] + a[j]); } } cout << dp[n] << '\n'; }