# 6. wonderland

6 6-1

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

const lines = [];
rl.on('line', (line) => {
    lines.push(line);
});
rl.on('close', () => {
    const costs = lines[0].split(' ').map(Number);
    const days = line[1].split(' ').map(Number);
    const maxday = Math.max(...days);
    let traversedays = new Array(maxday+1).fill(false);
    days.forEach((item) => traversedays[item] = true);
    let dp = new Array(maxday+1).fill(0);

    for(let i=1; i<=maxday; i++) {
        if(!traversedays[i]) {
            dp[i] = dp[i-1];
        } else {
            cost1 = dp[Math.min(i-1, 0)] + cost[0];
            cost3 = dp[Math.min(i-3, 0)] + cost[1];
            cost7 = dp[Math.min(i-7, 0)] + cost[2];
            cost30 = dp[Math.min(i-30, 0)] + cost[3];
            dp[i] = Math.min(cost1, cost3, cost7, cost30);
        }
    }

    console.log(dp[maxday]);
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32