import sys input = sys.stdin.readline N = int(input()) A, B, C = map(int, input().split()) a = max(10*A, 6*B, 3*C) D = 0 for x in range(11): for y in range(7): for z in range(4): n = 3*x+5*y+10*z if n > N: continue rem = (N-n)//30*a D = max(D, A*x+B*y+C*z+rem) print(D)