N = int(input()) A, B, C = map(int, input().split()) discount = [0 for _ in range(N+1)] for i in range(1,N+1): if i>=3: discount[i] = max(discount[i], discount[i-3] + A) if i>=5: discount[i] = max(discount[i], discount[i-5] + B) if i>=10: discount[i] = max(discount[i], discount[i-10] + C) print(max(discount))