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