n = int(input()) a, b, c = map(int, input().split()) m = max(a*10, b*6, c*3) ans = n // 30 * m n %= 30 tmp = 0 for i in range(n//3+1): for j in range((n-i*3)//5+1): k = (n - i * 3 - j * 5) // 10 tmp = max(tmp, i*a+j*b+k*c) ans += tmp print(ans)