#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
using namespace std;
const long long int INF = 1 << 60;
int main() {
	int n;;
	while (cin >> n, n) {
		vector<long long> a(n);
		for (auto &x : a)cin >> x;
		sort(a.begin(), a.end());
		long long sum = 0;
		for (auto &x : a)x = (sum += x);
		sum = 0;
		for (auto &x : a)x = (sum += x);
		cout << a[n - 2] << endl;
	}
	return 0;
}