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