#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int n;
vector<int> p(101);

bool input() {
	cin >> n;
	if (n == 0) return false;
	for (int i = 1; i <= n; ++i)
		cin >> p[i];
	return true;
}

using pii = pair<int, int>;
const int MAX_CHANGE = 100000;

void update(pii& a, pii b) {
	if (a.first > b.first) return;
	if (a.first < b.first) a = b;
	else if (a.second > b.second) a = b;
}

void solve() {
	static vector<vector<pii>>
		dp(101, vector<pii>(MAX_CHANGE));
	for (int j = 1; j < MAX_CHANGE; ++j)
		dp[0][j] = make_pair(-1000, 0);
	dp[0][0] = make_pair(0, 0);
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < MAX_CHANGE; ++j) {
			dp[i][j] = dp[i - 1][j];
			if (p[i] % 1000 > 500) {
				// p[i] に?000円支払う
				int change = 1000 - (p[i] % 1000);
				if (j >= change) {
					pii tmp = dp[i - 1][j - change];
					tmp.second += p[i];
					update(dp[i][j], tmp);
				}
				// p[i] に?000 + p[i] % 500円支払う
				int use = p[i] % 500;
				if (j + use < MAX_CHANGE) {
					pii tmp = dp[i - 1][j + use];
					++tmp.first; tmp.second += p[i];
					update(dp[i][j], tmp);
				}
			}
			else {
				// p[i] に?000円支払う
				if (p[i] % 1000) {
					int change = 500 - (p[i] % 1000);
					if (j >= change) {
						pii tmp = dp[i - 1][j - change];
						++tmp.first;  tmp.second += p[i];
						update(dp[i][j], tmp);
					}
				}
				// p[i] に?000円 + おつりを用いる
				int use = (p[i] % 1000) + 500;
				if (j + use < MAX_CHANGE) {
					pii tmp = dp[i - 1][j + use];
					++tmp.first; tmp.second += p[i];
					update(dp[i][j], tmp);
				}
			}
		}
	}
	pii res = { 0, 0 };
	for (int j = 0; j < MAX_CHANGE; ++j)
		update(res, dp[n][j]);
	cout << res.first << " " << res.second << endl;
}

int main() {
	while (input()) solve();
	return 0;
}
