func readInt() -> Int {
    return Int(readLine()!)!
}

func readInts(separator: String.Element = " ") -> [Int] {
    return readLine()!.split(separator: separator).map { Int($0)! }
}

func mainD() {
    let N = readInt()
    let frendly = readInts().sorted(by: >)

    var point = 0
    var circle: [Int] = []
    circle.append(frendly[0])
    for i in 1..<N {
        var maxPoint = 0
        var maxPointIndex = 0
        for j in 0...i {
            let left = j == 0 ? circle.last! : circle[j - 1]
            let right = j == i ? circle.first! : circle[j]
            let point = min(left, right)

            if maxPoint < point {
                maxPoint = point
                maxPointIndex = j
            }
        }

        circle.insert(frendly[i], at: maxPointIndex)
        point += maxPoint
    }

    print(point)
}

mainD()