n = int(input()) a, b, c = map(int, input().split()) max_total = 0 max_z = n // 10 for z in range(max_z + 1): m = n - 10 * z if m < 0: continue y_max = m // 5 y_opt = (m * 2) % 3 # This gives the y that makes (m - 5y) divisible by 3 (0 mod 3) candidates = {y_max, y_max - 1, y_max - 2, y_opt, y_opt + 1, y_opt - 1} valid = [] for y in candidates: if 0 <= y <= y_max: valid.append(y) current_max = 0 for y in valid: remaining = m - 5 * y if remaining < 0: continue x = remaining // 3 total = b * y + a * x if total > current_max: current_max = total total_z = c * z + current_max if total_z > max_total: max_total = total_z print(max_total)