Problem:
Score: 400 points

Problem Statement

Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i.

The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere.

When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0.

What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the maximum total comfort the N players can get.

Sample Input 1

4
2 2 1 3

Sample Output 1

7

By arriving at the place in the order Player 4, 2, 1, 3, and cutting into the circle as shown in the figure, they can get the total comfort of 7.

They cannot get the total comfort greater than 7, so the answer is 7.

Sample Input 2

7
1 1 1 1 1 1 1

Sample Output 2

6

Solution in Ruby (2.7.1) (judge verdict: Runtime Error)

### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

# require 'pry'

n = gets.to_i
array = gets.split.map(&:to_i).sort!.reverse

div = []
seat = []
happy = 0
# 1回目
if n >= 3
  k = 3
else 
  k = n
end 
1.upto(k) do |i|
  seat.push(array[i-1])
  next if i == 1 
  happy += seat[i-2]
  div.push(array[i-1])
end
# i回目
4.upto(n) do |i|
  j = seat.index(div[0])

  if seat[j-1] > seat[j+1]
    seat.insert(j,array[3])
    happy += seat[j+1]
    div.push(array[3])
    div.shift
  else
    seat.insert(j+1,array[3])
    happy += seat[j+2]
    div.push(array[3])
    div.shift
  end
end

puts happy



# res = Array.new(n,0)
# 0.upto(n-2) do |i|
#   res[i+1] = res[i] + array[i]
# end 





# puts res[-1]
# 2 3 4 7 8 20 1

# 20 8 7 4 3 2 1
#  0 0.0 0 0 0 0