from collections import deque





def main():

    eval(input())  # n

    array = [int(x) for x in input().split()]

    array.sort()

    coming = deque(array)



    edges = deque()

    noob = coming.pop()

    edges.append(noob)

    ans = 0

    while coming:

        ans += edges.popleft()

        noob = coming.pop()

        edges.append(noob)

        edges.append(noob)

    print(ans)





if __name__ == '__main__':

    main()

def main():

    n = int(eval(input()))

    friendliness = [int(x) for x in input().split()]

    friendliness.sort(reverse=True)

    ans = 0

    for i in range(1, n):

        ans += friendliness[i // 2]

    print(ans)





if __name__ == '__main__':

    main()

from collections import deque


def main():
    eval(input())  # n
    array = [int(x) for x in input().split()]
    array.sort()
    coming = deque(array)
    edges = deque()
    noob = coming.pop()
    edges.append(noob)
    ans = 0
    while coming:
        ans += edges.popleft()
        noob = coming.pop()
        edges.append(noob)
        edges.append(noob)
    print(ans)


if __name__ == "__main__":
    main()

def main():
    n = int(eval(input()))
    friendliness = [int(x) for x in input().split()]
    friendliness.sort(reverse=True)
    ans = 0
    for i in range(1, n):
        ans += friendliness[i // 2]
    print(ans)


if __name__ == "__main__":
    main()

-from collections import deque - - -    eval(input())  # n -    array = [int(x) for x in input().split()] -    array.sort() -    coming = deque(array) -    edges = deque() -    noob = coming.pop() -    edges.append(noob) +    n = int(eval(input())) +    friendliness = [int(x) for x in input().split()] +    friendliness.sort(reverse=True) -    while coming: -        ans += edges.popleft() -        noob = coming.pop() -        edges.append(noob) -        edges.append(noob) +    for i in range(1, n): +        ans += friendliness[i // 2]