#include #include using namespace std; using ll = long long; using ld = long double; using st = string; using mint = atcoder::modint998244353; using Mint = atcoder::modint1000000007; #define vl vector #define vvl vector> #define vb vector #define vs vector #define chmax(n,v) n=nv?v:n #define all(n) begin(n),end(n) #define rev(n) reverse(all(n)) #define sor(n) stable_sort(all(n)) #define rep(i,n) for(ll i=0;i<(n);++i) #define rrep(i,a,n) for(ll i=a;i<(n);++i) #define sz(n) n.size() #define bit(n,shift) ((n&(1< void input(T &a) { cin >> a; }; template void input(T1&a, T2 &...b) { cin >> a; input(b...); }; const ll inf = 1e18; //std::setprecision(13); 出力桁を増やす //2^29<10^9 ll di[8]={1,-1,0,0,1,1,-1,-1}; ll dj[8]={0,0,1,-1,1,-1,-1,1}; //ll da[4]={1,1,-1,-1}; //ll db[4]={1,-1,-1,1}; //ll na[4]={1,0,1,0}; //ll nb[4]={0,1,0,1}; template vector read(size_t n) { vector ts(n); for (size_t i = 0; i < n; i++) cin >> ts[i]; return ts; } bool is_prime(ll N) { if (N == 1) return false; for (ll i = 2; i * i <= N; ++i) { if (N % i == 0) return false; } return true; } int calc_digit(ll N){ int res = 0; while(N>0){ res++; N/=10; } return res; } ll factorial(ll n, ll mod = 1e18) { ll ans = 1; for(ll i = n; i >= 2; i--) ans = (ans * i) % mod; return ans; } void printl(vl v){ ll vsz=v.size(); for(ll i=0;i par; vector size; UnionFind(ll n){ par.resize(n+1,-1); size.resize(n+1,1); } ll root(ll x){ if (par[x]==-1) return x; return par[x]=root(par[x]); } void unite(ll u,ll v){ ll RootU=root(u),RootV=root(v); if(RootU==RootV){ return; } if(size[RootU]> prime_factorize(ll N){ vector > res; for (ll a = 2; a * a <= N; ++a) { if (N % a != 0) continue; ll ex = 0; while (N % a == 0) { ex++; N /= a; } res.push_back({a, ex}); } if (N != 1) res.push_back({N, 1}); return res; } int main(){ ll n,a,b,c; cin >> n >> a >> b >> c; vl dp(n+1,0); rep(i,n+1){ if(i>=1)dp[i]=max(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]; }