Painter buying paint

A painter paints one room a day; room i needs liters[i] litres of paint. Paint costs a per litre, or b for a big bucket of S litres. You may buy more than you need, but leftover paint cannot be used on another day. Find the minimum total cost for all the rooms.

Reported in: Infosys (SP / DSE · 22 Nov 2026) (memory-based)

Input

First line: N. Second line: N litre amounts. Third line: S a b.

Output

The minimum total cost.

Constraints

1 ≤ N ≤ 10^5; 1 ≤ litres, S, a, b ≤ 10^9.

Example 1

Input:
1
7
4 1 5

Output:
7

Example 2

Input:
1
10
6 2 1

Output:
2

Example 3

Input:
3
5 9 12
4 3 10

Output:
66

Hint: Each room is its own problem because paint cannot be carried over. For l litres the best plan is no buckets, ⌊l/S⌋ buckets plus single litres, or one more bucket than that; take the cheapest and add up the rooms.

All coding practice