#agc032d. [agc032_d]Rotation Sort

[agc032_d]Rotation Sort

Problem Statement

You are given a permutation p=(p1,ldots,pN)p = (p_1, \\ldots, p_N) of 1,ldots,N\\{ 1, \\ldots, N \\}. You can perform the following two kinds of operations repeatedly in any order:

  • Pay a cost AA. Choose integers ll and rr (1leql<rleqN1 \\leq l < r \\leq N), and shift (pl,ldots,pr)(p_l, \\ldots, p_r) to the left by one. That is, replace pl,pl+1,ldots,pr1,prp_l, p_{l + 1}, \\ldots, p_{r - 1}, p_r with pl+1,pl+2,ldots,pr,plp_{l + 1}, p_{l + 2}, \\ldots, p_r, p_l, respectively.
  • Pay a cost BB. Choose integers ll and rr (1leql<rleqN1 \\leq l < r \\leq N), and shift (pl,ldots,pr)(p_l, \\ldots, p_r) to the right by one. That is, replace pl,pl+1,ldots,pr1,prp_l, p_{l + 1}, \\ldots, p_{r - 1}, p_r with pr,pl,ldots,pr2,pr1p_r, p_l, \\ldots, p_{r - 2}, p_{r - 1}, respectively.

Find the minimum total cost required to sort pp in ascending order.

Constraints

  • All values in input are integers.
  • 1leqNleq50001 \\leq N \\leq 5000
  • 1leqA,Bleq1091 \\leq A, B \\leq 10^9
  • (p1ldots,pN)(p_1 \\ldots, p_N) is a permutation of 1,ldots,N\\{ 1, \\ldots, N \\}.

Input

Input is given from Standard Input in the following format:

NN AA BB p1p_1 cdots\\cdots pNp_N

Output

Print the minimum total cost required to sort pp in ascending order.


Sample Input 1

3 20 30
3 1 2

Sample Output 1

20

Shifting (p1,p2,p3)(p_1, p_2, p_3) to the left by one results in p=(1,2,3)p = (1, 2, 3).


Sample Input 2

4 20 30
4 2 3 1

Sample Output 2

50

One possible sequence of operations is as follows:

  • Shift (p1,p2,p3,p4)(p_1, p_2, p_3, p_4) to the left by one. Now we have p=(2,3,1,4)p = (2, 3, 1, 4).
  • Shift (p1,p2,p3)(p_1, p_2, p_3) to the right by one. Now we have p=(1,2,3,4)p = (1, 2, 3, 4).

Here, the total cost is 20+30=5020 + 30 = 50.


Sample Input 3

1 10 10
1

Sample Output 3

0

Sample Input 4

4 1000000000 1000000000
4 3 2 1

Sample Output 4

3000000000

Sample Input 5

9 40 50
5 3 4 7 6 1 2 9 8

Sample Output 5

220