#include <iostream>
#include <vector>
#include <algorithm>

#define rep(X, Y) for( int (X) = 0; (X) < (Y); ++(X) )

int main(){
	int i, cnt;
	std::vector<int> vec;

	while( std::cin >> cnt, cnt ){
		while(cnt--)
			std::cin >> i, vec.push_back(i);

		std::sort( vec.begin(), vec.end() );

		rep( i, 2 )
			rep( l, (int)vec.size() - 2 )	
				vec[l + 1] += vec[l];

		std::cout << vec[std::max((int)vec.size() - 2, 0)] << std::endl;
		
		vec.clear();
	}
	return 0;
}