Landscaping

No attempts yetTime limit1sMemory limit128 MB

Problem

A gardener is landscaping a garden and must move a large amount of dirt in the process.

The garden is a row of $N$ flowerbeds ($1 \le N \le 100$). Flowerbed $i$ currently holds $A_i$ units of dirt, and the gardener wants it to hold $B_i$ units instead. Every $A_i$ and $B_i$ is an integer between $0$ and $10$.

Three operations are available:

  • Buy one unit of dirt and place it in any flowerbed, at a cost of $X$.
  • Remove one unit of dirt from any flowerbed and ship it away, at a cost of $Y$.
  • Move one unit of dirt from flowerbed $i$ to flowerbed $j$, at a cost of $Z \times |i - j|$.

Compute the minimum total cost to make every flowerbed $i$ hold exactly $B_i$ units of dirt.

Input

  • Line 1: four space-separated integers $N$, $X$, $Y$, and $Z$ ($0 \le X, Y, Z \le 1000$).
  • Lines $2$ to $N+1$: line $i+1$ contains two space-separated integers $A_i$ and $B_i$.

Output

  • A single integer: the minimum total cost to finish the landscaping.

Explanation

In the first example there are 4 flowerbeds holding 1, 2, 3, and 4 units of dirt, with targets of 4, 3, 2, and 0 units. Buying, removing, and moving one unit cost 100, 200, and 1 respectively.

One unit of dirt must be removed (from flowerbed 4) at a cost of 200. The remaining dirt is rearranged by moving 3 units from flowerbed 4 to flowerbed 1 and 1 unit from flowerbed 3 to flowerbed 2, for a moving cost of 10. The total is 210.