############################################################# import sys sys.setrecursionlimit(10**7) from heapq import heappop,heappush from collections import deque,defaultdict,Counter from bisect import bisect_left, bisect_right from itertools import product,combinations,permutations ipt = sys.stdin.readline def iin(): return int(ipt()) def lmin(): return list(map(int,ipt().split())) MOD = 998244353 ############################################################# N = iin() A,B,C = lmin() inf = 1<<60 dp = [-inf]*(N+1) dp[0] = 0 for i in range(1,N+1): if i >= 3: dp[i] = max(dp[i],dp[i-3]+A) if i >= 5: dp[i] = max(dp[i],dp[i-5]+B) if i >= 10: dp[i] = max(dp[i],dp[i-10]+C) print(max(dp))