n = int(input()) a, b, c = map(int, input().split()) max_m = n dp = [0] * (max_m + 1) for m in range(1, max_m + 1): option1 = dp[m - 5] + b if m >= 5 else 0 option2 = dp[m - 3] + a if m >= 3 else 0 dp[m] = max(option1, option2) max_discount = 0 max_z = n // 10 for z in range(max_z + 1): remaining = n - 10 * z if remaining < 0: continue current_total = z * c + dp[remaining] if current_total > max_discount: max_discount = current_total print(max_discount)