{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TupleSections #-}
import qualified Data.Bits                   as Bits
import qualified Data.Word                   as Word
import qualified Control.Arrow               as Arrow
import qualified Data.Foldable               as Foldable
import qualified Data.ByteString.Char8       as BSC8
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import           Unsafe.Coerce

getI :: BSC8.ByteString -> Maybe (Int, BSC8.ByteString)
getI = fmap (Arrow.second BSC8.tail) . BSC8.readInt

getAN :: Int -> IO (VU.Vector Int)
getAN n = VU.unfoldrN n getI <$> BSC8.getLine

radixSortInt :: VU.Vector Int -> VU.Vector Int
radixSortInt = unsafeCoerce . radixSort64 . unsafeCoerce

{-# INLINE radixSort64 #-}
radixSort64 :: VU.Vector Word.Word64 -> VU.Vector Word.Word64
radixSort64 v = Foldable.foldl' step v [0, 16, 32, 48]
  where
    mask k x = fromIntegral $ Bits.unsafeShiftR x k Bits..&. 0xffff
    step v k = VU.create $ do
      pref <- VU.unsafeThaw
        . VU.prescanl' (+) 0
        . VU.unsafeAccumulate (+) (VU.replicate 0x10000 0)
        $ VU.map ((, 1) . mask k) v
      res <- VUM.unsafeNew $ VU.length v
      VU.forM_ v $ \x -> do
        let !masked = mask k x
        i <- VUM.unsafeRead pref masked
        VUM.unsafeWrite pref masked $ i + 1
        VUM.unsafeWrite res i x
      return res

solve :: Int -> VU.Vector Int -> Int
solve n (VU.reverse . radixSortInt -> xs) = snd . VU.foldl' step (1, mm) $ VU.tail xs
  where
    !mm = VU.head xs
    step (!cnt, !res) x
      | cnt == n - 1 = (cnt, res)
      | cnt == n - 2 = (cnt + 1, res + x)
      | otherwise    = (cnt + 2, res + 2 * x)

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