import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd n = int(input()) a,b,c = map(int,input().split()) dp = [0]*(n+1) for i in range(3,n+1): if i >= 3: dp[i] = max(dp[i-3] + a, dp[i]) if i >= 5: dp[i] = max(dp[i-5] + b, dp[i]) if i >= 10: dp[i] = max(dp[i-10] + c, dp[i]) print(dp[-1])