n = int(input()) a, b, c = map(int, input().split()) dp = [0] * (n + 1) for i in range(n): if i + 3 <= n: dp[i+3] = max(dp[i+3], dp[i]+a) if i + 5 <= n: dp[i+5] = max(dp[i+5], dp[i]+b) if i + 10 <= n: dp[i+10] = max(dp[i+10], dp[i]+c) print(dp[n])