King's Roads

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

King Byteasar wants to introduce an innovative road network in Byteland. There are nn cities in Byteland. There are a_ia\_i citizens living in ii-th city.

Initially, there are no roads in Byteland. The king wants to build several roads in such a way that all cities are connected (directly or indirectly). He also wants to minimize expenses on maintaining the roads.

Naturally, if a road connects populous cities, it is used more heavily and thus is more expensive to maintain. Formally, maintaining a road between cities ii and jj costs a_i+a_ja\_i + a\_j bytalers per year. However, if a_i+a_ja\_i + a\_j is at least MM, the road is considered a national highway, and it brings revenue of MM bytalers per year from taxation (thus, the effective cost for this road is a_i+a_jMa\_i + a\_j - M per year). Note that all a_ia\_i are less than MM.

Help King Byteasar find the minimum annual cost for maintaining a set of roads so that all cities become connected.

입력

The first line of input contains two space-separated integers nn and MM (1n200,0001 \leq n \leq 200\\,000, 1M1091 \leq M \leq 10^9).

The second line contains nn space-separated integers a_1a\_1, \ldots, a_na\_n (0a_i<M0 \leq a\_i < M).

출력

Print one integer --- the minimum annual cost for maintaining a spanning set of roads in bytalers.