Under construction

Still being built. Things may change

Strange Grid

Interview

Time limit1sMemory limit1024 MB

Summary
Given N people on a grid where each direction has its own movement cost, find the minimum total cost for everyone to gather at one cell.
Level

Medium5 of 10

Topics
Sorting, Prefix sum, Math
Solved
No attempts yet

Problem

On a strange grid, every move to an adjacent cell costs health. Moving from (x,y)(x, y) to (x−1,y)(x - 1, y) costs AA, to (x+1,y)(x + 1, y) costs BB, to (x,y−1)(x, y - 1) costs CC, and to (x,y+1)(x, y + 1) costs DD.

NN people are scattered across the grid. What is the minimum total health they must spend to gather at a single point?

Input

The first line contains NN, AA, BB, CC, DD in that order. (1≤N≤200 0001 \le N \le 200\,000, 0≤A,B,C,D≤1060 \le A, B, C, D \le 10^6)

From the second line, NN lines follow, each with the integer coordinates XiX_i, YiY_i of one person on the grid, in order. (−106≤Xi,Yi≤106-10^6 \le X_i, Y_i \le 10^6)

All numbers in the input are integers.

Output

Print the answer on the first line.

Examples1

  1. Example 1

    Input
    3 2 1 1 2
    1 0
    0 3
    3 3
    
    Expected output
    11