from collections import deque





def main():

    eval(input())  # n

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

    friendliness.sort()

    friendliness = deque(friendliness)

    edges = deque()

    popped = friendliness.pop()

    edges.append(popped)

    ans = 0

    while friendliness:

        ans += edges.popleft()

        popped = friendliness.pop()

        edges.append(popped)

        edges.append(popped)

    print(ans)





if __name__ == '__main__':

    main()

from collections import deque





def main():

    eval(input())  # n

    friendliness = deque(sorted(int(x) for x in input().split()))

    edges = deque()

    popped = friendliness.pop()

    edges.append(popped)

    ans = 0

    while friendliness:

        ans += edges.popleft()

        popped = friendliness.pop()

        edges.append(popped)

        edges.append(popped)

    print(ans)





if __name__ == '__main__':

    main()

from collections import deque


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


if __name__ == "__main__":
    main()

from collections import deque


def main():
    eval(input())  # n
    friendliness = deque(sorted(int(x) for x in input().split()))
    edges = deque()
    popped = friendliness.pop()
    edges.append(popped)
    ans = 0
    while friendliness:
        ans += edges.popleft()
        popped = friendliness.pop()
        edges.append(popped)
        edges.append(popped)
    print(ans)


if __name__ == "__main__":
    main()

-    friendliness = [int(x) for x in input().split()] -    friendliness.sort() -    friendliness = deque(friendliness) +    friendliness = deque(sorted(int(x) for x in input().split()))