n = int(input()) a, b, c = map(int, input().split()) max_total = 0 max_x = n // 10 for x in range(max_x + 1): m = n - 10 * x if m < 0: continue max_y = m // 5 start_y = max(0, max_y - 4) current_max = 0 for y in range(start_y, max_y + 1): remaining = m - 5 * y if remaining < 0: continue k = remaining // 3 current = b * y + a * k if current > current_max: current_max = current total = c * x + current_max if total > max_total: max_total = total print(max_total)