n = int(input()) a,b,c = map(int,input().split()) dp = [0] * (n + 10) for i in range(n): dp[i + 1] = max(dp[i + 1], dp[i]) 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])