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