//土尔逊Torson 编写于2023/06/13
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <queue>

using namespace std;

int main() {
	int n;
	while (scanf("%d", &n) != EOF) {
		priority_queue<int> MyQueue;
		for (int i = 0; i < n; ++i) {
			int leaf;
			scanf("%d", &leaf);
			MyQueue.push(-leaf);
		}
		int res = 0;
		while (MyQueue.size() > 1) {
			int leaf1 = MyQueue.top();
			MyQueue.pop();
			int leaf2 = MyQueue.top();
			MyQueue.pop();
			res = res + leaf1 + leaf2;
			MyQueue.push(leaf1 + leaf2);
		}
		printf("%d\n", -res);
	}
	system("pause");
	return EXIT_SUCCESS;
}
// 64 位输出请用 printf("%lld")