LearnPy Hub
← Arena
AdvancedRating 1500

Cheapest Travel Passes

You travel on the given days of the year. A 1-day pass costs c₁, a 7-day pass c₇ and a 30-day pass c₃₀ (a pass bought on day d covers days d … d + length − 1). Print the least total cost to cover all travel days.

Input

n; the n increasing days (1–365); then c₁ c₇ c₃₀.

Output

One integer.

Sample 1

Input
6
1 4 6 7 8 20
2 7 15
Output
11

Sample 2

Input
12
1 2 3 4 5 6 7 8 9 10 30 31
2 7 15
Output
17
solution.py
Output appears here
Cheapest Travel Passes · Python Arena problem · LearnPy Hub