eolymp
bolt
Try our new interface for solving problems
Problems

Lemurs rearrangement

Lemurs rearrangement

King Julian lined up n lemurs in front of him. The height of each lemur is an integer between 1 and n, and any two lemurs have different heights.

Julian wants to divide the line into several parts of non-intersecting subsegments, which, when combined, give the entire line. And then make sure that in each part the lemurs are arranged in ascending order of growth from left to right. If Julian decides to split the line into k pieces, he will have to pay the lemurs k * x shells.

After Julian breaks the line into parts, he can swap two lemurs, standing side by side in one part, an arbitrary number of times for one shell.

Find the minimum number of shells that Julian will need to get what he wants.

Input

The first line contains two integers n and x (1n300 000, 1x109) - the number of lemurs and the cost of one part.

The second line contains n different numbers hi (1hin) - the heights of the lemurs. It is guaranteed that all hi are distinct.

Output

Print a single number - the minimum number of shells that Julian will have to spend in order to achieve what he wants.

Time limit 5 seconds
Memory limit 128 MiB
Input example #1
5 1
5 4 3 2 1
Output example #1
5
Input example #2
1 1
1
Output example #2
1
Input example #3
10 10
9 10 8 3 7 5 6 2 1 4
Output example #3
35
Source 2020 Cycle of Internet Olympiads for schoolchildren, Fifth team contest, Novemver 28, Advanced level, Problem B