import sys input = sys.stdin.readline N = int(input()) A, B, C = map(int, input().split()) a = max(10*A, 6*B, 3*C) base = N//30*a N %= 30 D = 0 for x in range(N+1): for y in range(N+1): for z in range(N+1): if 3*x+5*y+10*z <= N: D = max(D, A*x+B*y+C*z) D += base print(D)