from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N = int(input()) X = list(map(int,input().split())) dp = [0]*(N+2) for i in range(N): dp[min(i+3,N+1)] = max(dp[min(i+3,N+1)],dp[i]+X[0]) dp[min(i+5,N+1)] = max(dp[min(i+5,N+1)],dp[i]+X[1]) dp[min(i+10,N+1)] = max(dp[min(i+10,N+1)],dp[i]+X[2]) print(max(dp[:N+1]))