#include<iostream>
#include<algorithm>

using namespace std;

typedef pair<int, int> Pi;

int N, P[100];
Pi dp[2][501 * 100];
//dpは　枚数　コスト　の順番で持つ
const int INF = 1145141919;

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

int main() {
	while (1) {
		cin >> N;
		if (N == 0)break;
		for (int i = 0; i < N; i++)cin >> P[i];

		for (int i = 0; i < 2; i++)for (int j = 0; j <= 500 * 100; j++)dp[i][j] = Pi(0, INF);
		auto now = dp[0], next = dp[1];

		now[0] = Pi(0, 0);

		for (int i = 0; i < N; i++) {
			for (int j = 0; j <= N * 500; j++) {
				if (now[j] == Pi(0, INF))continue;

				if (1 <= P[i] % 1000 && P[i] % 1000 <= 500) {
					//千円札で払えばかならず１枚手に入る
					update(next[j + 500 - (P[i] % 1000)], Pi(now[j].first + 1, now[j].second + P[i]));
				}
				else if (P[i] % 1000 == 0) {
					//何もしない
					next[j] = now[j];

					//1000円札＋小銭で、五百円玉がおつりででるように払う
					if (j >= 500) {
						update(next[j - 500], Pi(now[j].first + 1, now[j].second + P[i]));
					}

				}
				else {
					//何もしない
					next[j] = now[j];
					//千円札で買って、小銭を増やす
					update(next[j + (1000 - (P[i] % 1000))], Pi(now[j].first, now[j].second + P[i]));

					//小銭を使って、五百円玉がおつりででるように払う
					if (j >= (P[i] % 1000) - 500) {
						update(next[j - (P[i] % 1000 - 500)], Pi(now[j].first + 1, now[j].second + P[i]));
					}
				}

			}
			swap(now, next);
		}

		int coin = 0, cost = 0;
		for (int i = 0; i <= N * 500; i++) {
			if (now[i] != Pi(INF, INF)) {
				if (coin < now[i].first)coin = now[i].first, cost = now[i].second;
				else if (coin == now[i].first && cost > now[i].second)cost = now[i].second;
			}
		}

		cout << coin << " " << cost << endl;

	}
	return 0;
}
