# 全探索で間に合うか # c and b N = int(input()) A, B, C = map(int, input().split()) ans = 0 for c in range(N//10+1): b_max = (N-c*10)//5 for b in range(b_max+1): a = (N-c*10-b*5)//3 calc = a*A+b*B+c*C ans = max(ans, calc) #print('a', a, 'b', b, 'c', c, 'calc', calc, 'ans', ans) print(ans)