#include using namespace std; #define ll long long #define all(x) x.begin(),x.end() #define rep(i,a,b) for(int i=a;i<=b;i++) #define each(a,x) for (auto& x: a) const char nl = '\n'; int dp[200005]; void solve(){ int n; cin >> n; int a,b,c; cin >> a >> b >> c; rep(i,3,n) { dp[i] = dp[i-1]; if (i >= 3) dp[i] = max(dp[i], dp[i-3] + a); if (i >= 5) dp[i] = max(dp[i], dp[i-5] + b); if (i >= 10) dp[i] = max(dp[i], dp[i-10] + c); } cout << dp[n] << nl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1;// cin >> t; while (t--){ solve(); } }