#include using namespace std; int main(){ int n,a,b,c; cin >> n >> a >> b >> c; int ans = 0; for(int j = 0;j * 10 <= n;j++){ for(int i = 0;j * 10 + i * 5 <= n;i++){ ans = max(ans,j * c + i * b + (n - j * 10 - i * 5) / 3 * a); } } cout << ans << endl; return 0; }