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

#define int long long

using namespace std;


class Solver {
};

signed main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0)break;

		vector<int> prices(n, 0);
		for (int i = 0; i < n; i++) {
			cin >> prices[i];
		}

		int change = 50000;
		int cnt = 100;
		vector <tuple<int, int>> dp(change + 500);
		for (int i = 0; i < change + 500; i++)dp[i] = make_tuple(0, 1e9);
		get<1>(dp[0]) = 0;
		for (int i = 0; i < n; i++) {
			vector <tuple<int, int>> next(change + 500);
			for (int j = 0; j < change + 500; j++)next[j] = make_tuple(0, 1e9);
			for (int j = 0; j < change; j++) {
				int cnt_tmp = get<0>(dp[j]);
				int price_tmp = get<1>(dp[j]);
				if (price_tmp == 1e9)continue;

				if(get<0>(next[j])<cnt_tmp
					|| (get<0>(next[j]) == cnt_tmp 
						&& get<1>(next[j]) > price_tmp)) {
					next[j] = make_tuple(cnt_tmp, price_tmp);
				}

				int next_price = price_tmp + prices[i];

				if (prices[i] % 1000 == 0) {
					if (j >= 500) {
						int next_change = j - 500;
						if (get<0>(next[next_change]) < cnt_tmp + 1
							|| (get<0>(next[next_change]) == cnt_tmp + 1
								&& get<1>(next[next_change]) > next_price)) {
							next[next_change] = make_tuple(cnt_tmp + 1, next_price);
						}
					}
					continue;
				}

				if (prices[i] % 1000 <= 500) {
					int next_change = j + 500 - (prices[i] % 1000);
					if (get<0>(next[next_change]) < cnt_tmp + 1
						|| (get<0>(next[next_change]) == cnt_tmp + 1
							&& get<1>(next[next_change]) > next_price)) {
						next[next_change] = make_tuple(cnt_tmp + 1, next_price);
					}
				}
				else {
					int next_change = j + 1000 - (prices[i] % 1000);
					if (get<0>(next[next_change]) < cnt_tmp
						|| (get<0>(next[next_change]) == cnt_tmp
							&& get<1>(next[next_change]) > next_price)) {
						next[next_change] = make_tuple(cnt_tmp, next_price);
					}
					if (j >= prices[i] % 500) {
						next_change = j - (prices[i] % 500);
						if (get<0>(next[next_change]) < cnt_tmp + 1
							|| (get<0>(next[next_change]) == cnt_tmp + 1
								&& get<1>(next[next_change]) > next_price)) {
							next[next_change] = make_tuple(cnt_tmp + 1, next_price);
						}
					}
				}
			}
			dp = next;
		}

		int res_cnt = 0;
		int res_price = 1e9;
		for (int i = 0; i < change;i++) {
			int cnt_tmp = get<0>(dp[i]);
			int price_tmp = get<1>(dp[i]);
			if (res_cnt < cnt_tmp
				|| (res_cnt == cnt_tmp && price_tmp < res_price)) {
				res_cnt = cnt_tmp;
				res_price = price_tmp;
			}
		}

		cout << res_cnt << " " << res_price << endl;
	}
}
