Under construction

Still being built. Things may change

Landscaping

Time limit2sMemory limit512 MB

Summary
Move, buy, or remove dirt so each of N flowerbeds reaches its target amount at minimum total cost.
Level

Medium7 of 10

Topics
Dynamic programming, Graph
Solved
No attempts yet

Problem

Farmer John is rebuilding his garden, and the work involves moving a large amount of dirt.

The garden is a row of NN flowerbeds (1≤N≤100 0001 \le N \le 100\,000). Flowerbed ii starts with AiA_i units of dirt. Farmer John wants flowerbed ii to hold exactly BiB_i units of dirt once the work is done. Every AiA_i and every BiB_i is an integer between 00 and 1010.

Farmer John has three moves.

  1. Buy one unit of dirt and place it in any flowerbed, at a cost of XX.
  2. Remove one unit of dirt from any flowerbed and have it shipped away, at a cost of YY.
  3. Transport one unit of dirt from flowerbed ii to flowerbed jj, at a cost of Z×∣i−j∣Z \times |i-j|.

Compute the minimum total cost of bringing every flowerbed to its target state.

Input

The first line contains NN, XX, YY, and ZZ (0≤X,Y≤1080 \le X, Y \le 10^8, 0≤Z≤10000 \le Z \le 1000). Line i+1i+1 contains the integers AiA_i and BiB_i.

Output

Print the minimum total cost of the landscaping work.

Note

The same task appeared earlier with much smaller limits. This version raises them considerably, so a solution written for the easier version will not finish in time.

Examples3

  1. Example 1

    Input
    4 100 200 1
    1 4
    2 3
    3 2
    4 0
    
    Expected output
    210
    
  2. Example 2

    Input
    1 5 7 3
    4 4
    
    Expected output
    0
    
  3. Example 3

    Input
    5 10 20 0
    5 0
    0 5
    3 3
    0 4
    2 0
    
    Expected output
    20