#include using namespace std; typedef long long ll; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; std::vector b(3); std::vector f(n + 1); for(int i = 0;i < 3;i ++)cin >> b[i]; std::vector a = {3,5,10}; for(int i = 0;i < 3;i ++){ for(int j = a[i];j <= n;j ++){ f[j] = max(f[j - a[i]] + b[i],f[j]); } } cout << f[n] << "\n"; return 0; }