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