# 1次元dpで解いてみる # dp[枚数]での割引最大値 N = int(input()) A, B, C = map(int, input().split()) dp = [0]*(N+1) for i in range(N+1): if i-3 >= 0: dp[i] = max(dp[i], dp[i-3]+A) if i-5 >= 0: dp[i] = max(dp[i], dp[i-5]+B) if i-10 >= 0: dp[i] = max(dp[i], dp[i-10]+C) #print(dp) ans = dp[N] print(ans)