N = int(input()) A,B,C = map(int,input().split()) ans = 0 for i in range(101): for j in range(201): if i * 10 + j * 5 > N:continue tmp = i * C + j * B + (N - i * 10 - j * 5) // 3 * A if tmp > ans:ans = tmp print(ans)