import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random #sys.setrecursionlimit(10**9) n = int(input()) a,b,c = map(int,input().split()) ans =-1 for i in range(2*10**5+1): if n < i*3: continue temp = a * i ntemp = n - 3 * i if 2*b >= c: temp += (ntemp // 5) * b else: temp += (ntemp // 10) * c ntemp %= 10 temp += (ntemp // 5) * b ans = max(ans,temp) print(ans)