# coding: utf-8

from collections import deque





def solve(*args: str) -> str:

    n = int(args[0])

    A = sorted(map(int, args[1].split()), reverse=True)



    Q = deque()



    ret = 0

    for i in range(-(-n//2)):

        if 0 < i:

            ret += min(Q[-1], Q[0])

        if i % 2:

            Q.appendleft(A[i])

        else:

            Q.append(A[i])



    for i in range(n-len(Q)):

        ret += min(Q[i], Q[(i+1) % len(Q)])



    return str(ret)





if __name__ == "__main__":

    print((solve(*(open(0).read().splitlines()))))

# coding: utf-8



def solve(*args: str) -> str:

    n = int(args[0])

    A = sorted(map(int, args[1].split()), reverse=True)



    return str(sum([A[i//2] for i in range(1, n)]))





if __name__ == "__main__":

    print((solve(*(open(0).read().splitlines()))))

# coding: utf-8
from collections import deque


def solve(*args: str) -> str:
    n = int(args[0])
    A = sorted(map(int, args[1].split()), reverse=True)
    Q = deque()
    ret = 0
    for i in range(-(-n // 2)):
        if 0 < i:
            ret += min(Q[-1], Q[0])
        if i % 2:
            Q.appendleft(A[i])
        else:
            Q.append(A[i])
    for i in range(n - len(Q)):
        ret += min(Q[i], Q[(i + 1) % len(Q)])
    return str(ret)


if __name__ == "__main__":
    print((solve(*(open(0).read().splitlines()))))

# coding: utf-8
def solve(*args: str) -> str:
    n = int(args[0])
    A = sorted(map(int, args[1].split()), reverse=True)
    return str(sum([A[i // 2] for i in range(1, n)]))


if __name__ == "__main__":
    print((solve(*(open(0).read().splitlines()))))

-from collections import deque - - -    Q = deque() -    ret = 0 -    for i in range(-(-n // 2)): -        if 0 < i: -            ret += min(Q[-1], Q[0]) -        if i % 2: -            Q.appendleft(A[i]) -        else: -            Q.append(A[i]) -    for i in range(n - len(Q)): -        ret += min(Q[i], Q[(i + 1) % len(Q)]) -    return str(ret) +    return str(sum([A[i // 2] for i in range(1, n)]))