{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE ViewPatterns #-}
import qualified Data.List             as List
import qualified Data.Maybe            as Maybe
import qualified Data.ByteString.Char8 as BSC8


readInts :: IO [Int]
readInts = map (fst . Maybe.fromJust . BSC8.readInt) . BSC8.words <$> BSC8.getLine

main :: IO ()
main = do
  n  <- readLn :: IO Int
  xs <- readInts
  print $ solve n xs

solve :: Int -> [Int] -> Int
solve n (List.reverse . List.sort -> xs) = snd . List.foldl' step (1, List.head xs) $ List.tail xs
  where
    step (p, q) x
      | p == n - 1 = (p, q)
      | p == n - 2 = (p + 1, q + x)
      | otherwise  = (p + 2, q + 2 * x)