n = int(input()) a, b, c = map(int, input().split()) max_total = 0 max_x = n // 10 for x in range(max_x + 1): rem = n - 10 * x if rem < 0: continue y_max = rem // 5 start_y = max(0, y_max - 4) for y in range(start_y, y_max + 1): if 5 * y > rem: continue rem_after = rem - 5 * y z = rem_after // 3 total = c * x + b * y + a * z if total > max_total: max_total = total print(max_total)