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