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])