n = int(input()) a, b, c = map(int, input().split()) max_discount = 0 max_c10 = n // 10 for c10 in range(max_c10 + 1): remaining = n - 10 * c10 if remaining < 0: continue current_c = c10 * c y_max = remaining // 5 best_5_3 = 0 # Check y in [y_max-4, y_max] start_y = max(0, y_max - 4) for y in range(start_y, y_max + 1): rem_after_5 = remaining - 5 * y if rem_after_5 < 0: continue x = rem_after_5 // 3 total = b * y + a * x if total > best_5_3: best_5_3 = total total_d = current_c + best_5_3 if total_d > max_discount: max_discount = total_d print(max_discount)